instruction
stringlengths
34
36.1k
I am studying different language games and trying to implement them in Common Lisp. Currently, I am studying a game which studies the relation between forms and meanings. An agent needs to store the association between these forms and meanings. One form can have multiple meanings (ambiguity) and one meaning can have mu...
I'm a newbie and couldn't find anywhere, concise information regarding which approach I should be taking when working with images. The thing is I'm developing an app whose main purpose is to keep track of things, for each of whose entry you can have an associated image. This image is to be selected via gallery through ...
Imagine I have a marketplace application - where users can search for products (we concentrate on clothes). Every product has an ID, name (text), description (text), price (numeric), size (numeric), brand, condition and so on. The users can search for clothes. Right now the data is stored in a relational database (Post...
I'm writing a CUIT ( Coded UI Test ) and I'm replacing variables with data fetched from a csv. Example: this.UIMap.IDBParams.UITboxFsEditText = TestContext.DataRow["num_fs"].ToString(); this.UIMap.IDBParams.UIArmGlCheckBoxChecked = Convert.ToBoolean(TestContext.DataRow["arm_gl"]); But I'm having to define over 100 var...
Suppose I have a data table of, say, cars with a bunch of properties for each record. Example: |Vin|Year|Make|Model|Color|Mileage| I want to allow users to define (arbitrarily complex) filters which can be used to return a subset of records from the table. However, there's a catch: each vehicle record can only appear i...
My understanding of a webservice and service layer is as follows - Service Layer: An abstraction layer which exposes a set of common operations which can be used by multiple consumers. For instance , I have a database containing customer data. Multiple applications may want to add / update / delete data in this data st...
Background I have a RESTful HTTP API. I have a resource. GET /my/cat HTTP/1.1 Clients may want to retrieve the image representation of this resource. GET /my/cat HTTP/1.1 Accepts: image/png Problem Clients have a very wide variety of needed resolutions, and it is important they receive the correct resolution. If it ...
My understanding... Advantages: Inserting at the end is O(1) instead of O(N). If the list is a Doubly Linked List, then removing from the end is also O(1) instead of O(N). Disadvantage: Takes up a trivial amount of extra memory: 4-8 bytes. The implementer has to keep track of the tail. Looking at these advantages a...
We have a large website made in PHP running in Apache on Linux. There are programmers as well as non-technical users modifying the website every day and we do it directly on the test server. Is there any alternative to modifying the files directly on the server? Sure, the programmers could all setup an Apache instance ...
Is it possible to write effective unit tests for unstructured code? I was reading through the various answers to this question. It explains the implications of unit testing procedural and OOP code, but there is very little mention about unstructured code. In my personal experience, I've only written unit tests for fun...
I have a base class B and several children classes of it. Every children B1, B2, B3... has a method that calls a method M of another class C. Class C has a component D (implementing an interface, think strategy pattern) Method M calls a method N of D. I want the behavior of N to depend on what class (B1, B2, B3) is cal...
When you purchase an HTML template, usually everything is mixed in together... html, css, images and js. An example template may look like this: account.html category.html contact.html /fonts /img item-detail.html media.html register.html style.css author.html category-tile.html /css /images index.html /js new.html sho...
Here is the problem illustrated using an example of an immutable class. A Book must have at least one of a title and an ISBN. public class Book { private readonly string _title; private readonly int? _isbn; public Book(string title) : this(title, null, true) { ... throw exception if ti...
I am playing with cache functions using decorators. First, I use a generic function def memorize(func): cache = {} print "printing cache" print cache print "cache printed" def decor_func(*args): if args in cache: print "cached value is found" return cache[args] ...
In the Alan Kays Definition Of Object Oriented there is this definition that partially I don't understand: OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme LateBinding of all things. But what does "LateBinding" means? How can I apply this on a language like C#? A...
When I write (unit) tests I always try to avoid for example microsoft fakes because then the edit&continue feature no longer works. However this often requires refactoring... and sometimes methods or properties that exist only to support (unit) tests. An example: With fakes I could do in each test method simply this: S...
I'm struggling with this problem for a long time now. Lets say that I'm trying to model some business that has Customers, Companies, Contracts, Invoices etc. All of them looks like good candidate for aggregate root for me. The problem is that, lets say Contract would have a huge list of fields, and most of them would b...
I noticed a long time ago that a number of files included with projects, especially files called README, LICENSE, and so forth, frequently have no filename extension. This is strange to me because it requires the reader of such files to perform some extra commands to open it. I visited Is it good programming practice t...
I'm working with Meteor, which is a relatively young Javascript framework. As such, it seems like I often run into problems which haven't been asked on Stackoverflow already. In one such case, I was agonizing over something that wasn't working, and it turns out it was a bug with Meteor. When I was working through this...
Is spinlock and polling the same thing? Wikipedia: a spinlock is a lock which causes a thread trying to acquire it to simply wait in a loop ("spin") while repeatedly checking if the lock is available This sounds awfully lot like: while(!ready); I was taught to avoid polling whenever possible as it was throughly su...
I'm working with a Rest Api that demands to send with any request a hash of the parameters of the request: Hashkey Calculation This hash key has to be generated by the device itself and has to follow strict rules: Get all request parameters and their values (except hashkey) Order theses pairs alphabetically by pa...
Class Design Question I am trying to figure out a good way to design my class system. I have a class Product to compute various product specifications. I have two product model groups, each containing several model numbers: {10, 20, 30} and {50, 60, 70}. They share some similar features (i.e. the way weight is comp...
I'm developing a Java web application. It is a three layered architecture: web > service > repository. I'm thinking of creating many exceptions - each specific to each individual error and in the service layer where my business logic resides I want to throw specific exceptions that is tied to the business error. And in...
My team currently uses a fairly simple branching/deployment process that looks like this: ┌────────┐ ┌────┐ ┌──────┐ Environments: │ DEV │ │ QA │ │ PROD │ └────────┘ └────┘ └──────┘ ▲ ▲ ▲ │ │ │ ┌────...
I have to provide my code to someone to look at and use, but wish to maintain a number of rights. Specifically, I want a license that 1) Limits my liability, 2) prevents commercial use and 3) prevents further distribution, including of modified copies. I have been unable to find anything that covers this. The closest I...
lets say: I have few environments, A, B and C (or development, staging and production) I have application X I have multiple versions of application (X), V1, V2, V3 each version of X has its corresponding configuration (C) {V1->C1, V2->C1, V3->C2} -by configuration I refer to passwords, key files, etc that is unique pe...
I think that the controller should bring the data to view from model. However, is it controller's duty to tell how view should display the data, or the view should know how the data should be displayed? To be more specific, I am writing a website, there are several databases as data model, the controller is written in ...
When a non-HTML file such as a PDF, DOCX, EXE, etc is made public to the WWW by an HTTP server, and a client makes a request for said file, www.example.com/download?=test.doc what facilitates the file transfer over to the client? Is it transmitted over HTTP or another protocol? In what format or encoding is the data r...
I'm facing an issue where I have a Model which I want to implement a GUI for. As I'm exploring MVVM and WPF I will of course use a View Model between the View and Model. I will also have a need to add coordinates to some model classes that represents objects that will be drag able in the GUI. At this time, this is the ...
I'm not going to ask what is the best unit test structure or how to do it again. There are already enough questions about it. Instead I'd like you to tell me what else I could consider in the structure that I came up with (borrowing from other ideas and adding new ones). I've been thinking about how can I improve my te...
In CQRS, if a saga (or more precisely a process manager according to the CQRS Journey book) sends out a new command to change aggregates how can I ensure that this command is not possible to send from anywhere else (e.g. by a programmer on UI part). That is the command is only for "internal" usage of the saga? How to h...
In CQRS with Event Sourcing, if the current domain lacks a feature so it has to be extended with a new command (sent from a new saga) and an event (sent by the aggregate handler of that command), how can I deploy such feature to an already running application if the command was never sent before and so even the event w...
I'm creating an application that internally will have have three totally different separated areas of interfaces. - One where users create content and interact with each other - One where one person invites the above users and administers her organization's account - One where several people are administers the whole a...
I have the following services: UserServices This has various methods: fetch_by_id(), create() etc. SessionServices Session handling: create(), destroy(), various getters. AnswerServices An answer is an entity, it represents an answer to a question. These are the services related to it. Now the problem is I'd like to ad...
In my Android app, there is a question like "Which of the following foods did you eat today?" (not the actual question), with a fixed list of foods (e.g. "Apples, Banana, Pizza, Burgers") from which the user can select all that apply. I now want to store in the DB, which answers were selected on which day. As I see it,...
I am designing an API with django and its rest framework (and I am already not sure if it worth the hassle to version it or not). I totally know the iOS and Android apps will call the API, get a token (maybe with expiration I need to read a bit more about it) and then use this token inside every subsequent calls to be ...
I am creating Qt application that uses database with huge amount of data to draw some charts. Fetching data from the database is time consuming, so is blocking the application thread or worker thread creating an unpleasant delay. I have an idea that instead of doing everything at once I can fetch data and draw charts i...
I'm trying to teach myself software engineering and coming up against some conflicting information which is confusing me. I've been learning OOP and what abstract classes / Interfaces are and how to use them, but then I'm reading that one should 'favour composition over inheritance'. I understand composition is when o...
If I have a bunch of nodes with differing numbers of inputs, but only one output, and each output can go to multiple inputs, but only one output per input; what do I call it? Trying to name a class to represent the whole thing. Assuming n1 produces a value, it flows to n2 and n3 which might perform different operation...
I was reading about that that old patch. The summary of that link is to create a 4Gb kernel space, instead of 1Gb by default. Since many dma capable devices can only access 32 bit addresses or 4Gb, would that mean that any free location in that custom kernel space (4G low memory instead of 1G) could be used without all...
I'm programmaing a visual novel which has the following parts: Script file Program code used for the events where parts of the scripts are displayed 2 different minigames Images Now one of the minigames is based on a open source code that uses the GPL v3 http://www.gnu.org/licenses/gpl-3.0.txt I copy pasted parts of ...
I have relatively-small algorithm that takes up ~60% of the total run-time of my scientific code (57 lines of 3600), so I would like to find a way to optimize what I'm doing and make the code order-independent so that I can apply a cilk_for parallel strcture. Here's what it does, verbally: I have an std::vector of poin...
I am writing a card game, in which I separated the "Core Logic" of the game from the UI. Communication with the player from the core logic part is done via callbacks which the UI implements and handles (in a separate thread if needed). The core logic library calls these callbacks, the UI handles them, passing an object...
I am using Amazon's dynamodb nosql database and as a result I need to think of some ways to do certain operations to fit into their limits (e.g 4k item limit, can't combine small items into the same read operation, etc). One such issue is I will have a database attribute which will contain a long string (the string wil...
I am currently developing a simple shopping cart using PHP & HTML. I've been having troubles with using the SESSIONS in Php like: Sessions not continuing when I switch pages even though I called the session_start() at the top of every page. Is it a better approach to use sessions in keeping track of a clients cart...
I am working with an API but I am unsure what the best way to store the API return values. Specifically, I am working with the RIOT API just as a small hobby project. I would like to store this information somewhere so that I can not only compare users with each other but also present user statistics without having to...
I am recoqnizing this pattern <.*> From string <a href="hello world">Hi Baby</a> Now, there are several match <a href="hello world"> is a match <a href="hello world">Hi Baby</a> is also a match. However, that's very confusing. I thought regular expression are solved with determined finite automata. So I would imagin...
How do you manage two-way synchronization between a 'main' database server and many 'secondary' servers, in particular conflict resolution, assuming a connection is not always available(offline syncing)? For example, I have an Android application which is use data from local database(sqlite). And user can deal with dat...
I was reading this wiki on the Stable Abstractions Principle (SAP). The SAP states that the more stable a package the more abstract it should be. This implies that if a package is less stable (more likely to change) then it should be more concrete. What I don't really understand is why this should be the case. Surely i...
From what I read, VLIWs execute instructions in bundles, i.e. the CPU loads a bundle of instructions and dispatches them all at once. This is possible because the compiler scheduled instructions in such a way that there are no data dependencies between instructions in a single bundle (on a superscalar architecture inst...
Several times now I have come across the situations where you have some kind of settings class that simply contains a mass of data. Often these classes are simply not valid without at least most of the data. However a constructor like this: public dataclass (int v1, int v2, int v3, int v4, string v5, double v6, ...
.*foo Academically, that is a regular expression. A string aaaaaaaaaaaaafoo will match that. Also string aaaaaaaaaaaaafooaaaaafoo will match that too. I would imagine that an NFA that solve that will have 4 states. State 0 will have an arrow going back to itself. Then an arrow f going to state 1, o to state 2, and ano...
I am currently writing an API for machine learning algorithms in Rust and I would like for a single genetic algorithm, artificial neural network, or Bayesian network to provide multiple outputs so that for instances in which there may be redundancy, the algorithms can benefit from each other. I intend to use these to p...
I'm experimenting with the deployment of ASP.Net 5 CoreCLR apps to Linux Docker containers. Literally all the articles, posts, etc. I found involve using the Visual Studio GUI. On publish a PowerShell script gets created, which I believe I could re-use on a CI server. But this script itself seems to depend on an instal...
I am developing a nethack-like game, and I would like an advice how to approach the design part. For now I got class like Location, Npc, Item etc. But I've got a problem how to easily access parts of location. Lets say I have an object Door inside (not inherited). If player is inside location it is easy to check wheth...
Currently we have one master branch for our PHP application in a shared repository. We have more than 500 clients who are subscribers of our software, most of whom have some customization for different purposes, each in a separate branch. The customization could be a different text field name, a totally new feature or ...
I have the following class(es) that I want to write unit tests for: public abstract class BaseClass { public bool IsFooBar(Order order) { return order.IsNew && IsFooBarOverride(order); } protected abstract IsFooBarOverride(Order order); } public class SimpleDerivedClass : BaseClass { prote...
I couldn't find a single example about repository pattern using something else then a database. My goal is to have a global static repository that stores some objects in memory. I don't want it to be a singleton with it's Instance property because it doesn't have any special function but Add/Removoe... just like a rep...
I've seen most languages have it be the case for their substring method that using the length of a given string in the method as the start index will give you an empty string. It is most definitely helpful when writing algorithms involving successive shortening of the string down to an empty string. The problem I have ...
I'm designing an application with DDD. I'm moving from flat POCO objects to strong domain models, so my question is: Would I have to call my basic CRUD operations (located in my repository layer) from controllers directly, without passing through the domain layer? I can't see any added value to doing that, but I'm not...
This is a little bit of follow up question to How to test private methods. I totally agree (and experienced what happens when you try) that we should not test private methods. Sometimes though it leads to duplication. This question is also not about If one test - one assert breaks DRY principle as suggested. The questi...
We are a startup kind of a project that fired pretty well and as all startups the main goal was to start ASAP. We made our project as a monolith application (PHP) that has 4 sub-applications, but will require more than that in a couple of months. We decided it's time to move to microservices before it's too late, so we...
I got into a debate at work today, I hope you can help me to settle it up. My colleague wants to separate UI, Model, DB, and Network like so: Create an API level between UI and controller, that will allow the UI to query all the models in the APP. There will be another controller that will break the models into their ...
I am writing a program that involves working with both polar and Cartesian coordinates. Does it make sense to create two different structs for each kind of points, one with X and Y members and one is with R and Theta members. Or is it too much and it is better to have just one struct with first and second as members. ...
Introduction Many "C-like" programming languages use compound statements (code blocks specified with "{" and "}") to define a variables scope. Here is a simple example. for (int i = 0; i < 100; ++i) { int value = function(i); // Here 'value' is local to this block printf("function(%d) == %d\n", i, value); } Th...
I am building a wrapper to a load-testing tool that will take configuration and scenario files as yaml and build a large, unwieldy xml file which will be destroyed when it is no longer needed. A sample yaml file would look like this: # basic.yml config: ip: 127.0.0.1 rate: 1 maximum: 10 iterations: 75 email...
I am working with PowerShell which doesn't seem to have an up-to-date language spec. This leaves me wondering about some edge cases. I've taken to testing my assumptions about how PowerShell's runtime behaves. Here is a concrete example: It 'the System.Exception that is thrown is actually a ParameterBindingException...
I'm developing a project, which I'm pushing to private repository on my VPS. However, I'd like to publish it on GitHub. I make a lot of commits(mostly as backups) which doesn't contain complete implementation of feature. I do not want to include history of these commits in public repo. So, private history would look li...
I have a Dictionary of Dictionaries that I need to traverse to find two records with various matching parameters. I have two foreach loops to do this which is O(n^2). I am looking for inspiration to find a better way of doing this by using the keys to improve lookup. Simple example below. edit: Each record contains ma...
I have a JSON end point for projects in a county. I am able to call a list of any of the object properties. What I want to do is to add together either all the values of budget property or the spent_encumbered by the value of category property. For example, the total cost of all the projects that were for bridges, gene...
My site allows users to create custom HTML templates for their profiles (very much like Tumblr and the theme system), and I picked the Twig template engine for the site. However, I'm not sure if it's a good idea to give users the control of being able to access a template engine. Is this a bad thing? How should I res...
I have an array of heights, with irregularly spread stations, e.g.: arrH=[100 500 1000 2500 4500]. During run-time I receive some height, h, and I need to determine which cell (index) contains the closest height to h. E.g.: h=720 -> arrH[1]. I can do any pre-processing, build any dictionary/hash table in an offline-mod...
Over the years i have seen multiple cases where data is accessed and/or manipulated using a representative value which is internally resolved to the right object/data-field/algorithm. Some examples: // 1. Provide same logger globally using it's name auto myLogger = LoggingService.getLogger("myLogger") // 2. Get person...
Let me start by saying I do generally understand copyleft GPL, but I'm having some trouble with this particular scenario. It's quite complicated to communicate but I'll try my best. First I'm working on an app in iOS that supports Russian voice recognition. The engine I use is pocketspinx which uses a BSD license so ...
How can a program enumerate the available IP interfaces, and monitor changes in them, to subscribe to and send IP multicasts on all of them? I ask because I am troubleshooting a problem with the mediatomb server which appears to want to run route add -net 239.0.0.0 netmask 255.0.0.0 eth0 and ifconfig eth0 allmulti ( an...
Here is the deal, I have joined a new company and have been asked to finish off the work on a branch which hasn't been touched for almost a year. In the meanwhile, the master branch has been growing with a steady pace. Ideally I would like to merge all of the changes from the master branch into the feature branch and c...
I have read this link Should I return from a function early or use an if statement? and it triggered a conflict in my head. I agree that it looks nicer and cleaner and I guess that would be the way I would write it. But I remember that there was something saying that we should always check the the conditions under whic...
I'm in the process of making a simple game using re-frame (and thus react and reagent), but I'm stuck at one point. In https://github.com/Day8/re-frame#control-via-fsm they claim Not every app has lots of logical states, but many do, and if you are implementing one of them, then formally recognising it and using a...
I've wrote a standalone java SE software which executes, for example, the features A, B and C. Now, i want to that, if a lock is enabled (and this lock is a command sent remotely by my backend), the feature C has not to be longer available for execution by the user. This lock has to be persistent, so, it has to survive...
The biggest issue I run into in JavaScript is silent typos. For example, the other day I had a variable inIframe. Somewhere else I typed isIFrame. 10-15 mins of debugging later I found it and changed it to inIFrame. It was yet another 5+ mins until I figured out it was still wrong. Should have been lowercase f. That go...
I work in a company of about 10 developers. When we start a project, each of the developers involved in the project have their dev environment. Once they complete a task, it is then pushed to phase two which is called "Staging", where QA takes place. Once bugs are cleared, it is then set to "Ready for UAT" and UAT (Use...
I'm wondering about the differences between XML and JSON. Without any regard to existing processing tools and backend systems and merely as a means of representing data is there anything JSON does better than XML or vice versa? Or can they both be used to the same extent ? I.e. is there anything that could be represent...
I make extensive use of DI, but I wonder, where is the 'granurality' limit, when some set of functionality should be separated to a class - lets take an example: public class DownloadManager : IDownloadManager { public Uri ResourceIdentifier { get; } public DownloadManager(Uri uniqueResourceIdentifier) { ...
I'm currently familiarizing myself with NoSQL by building a simple web application using MongoDb with the official C# driver. If i have understood the NoSQL concept correctly, then only the aggregate root document should have an id and the child collections are without identity. For example in C# code i would have the ...
I've been toying with some array examples in C. I want to understand more about memory concepts, alignment, and cache. Especially on large arrays on heap. Sometimes I work on large images (extremely large) so that's why it's important to me, but it doesn't matter for what I'm asking now. I wrote a following example: #...
I have a question in regards to Java conditional if statements. If I have a statement such as this: if(true || false){ //output } Will Java go inside of the the if statement as soon as it sees the true statement or will it still evaluate the false statement? I ask because I will have a condition statement which will ...
I've been writing a program to pick random words from my list. However, to do that I had to imitate some solutions on the internet, and I succeeded. Unfortunately, there is something that I can't understand in my work. def repeat(pic_word, n): for i in range(n): pic_word() My question is what is the meani...
And if so, why do they have different bit patterns? I read a book that said data types have different bit patterns and I was like "why do they have different bit patterns?"
This probably sounds like a dumb question, forgive me if I'm asking this in the wrong place, I'd be happy to delete it if so. I'm sort of new to unit testing and I'd like to learn best practices regarding this question, it's been bugging me for a while. Assume that there is a method which takes an array as the input an...
I have a converter module which encodes non-negative numerics to base 62 strings and vice versa. I'm not very experienced with testing, and I got this so far: Encode Test for negative numbers Test for non-numerics Test result for basic input Decode Test for numerics Test result for basic input Codec - encode and de...
I've written a small utility in Python3 to help me copy my music collection from my NAS to a mobile device. The usefulness of this is that it will auto-convert flac files to ogg-vorbis (to save space) and also exclude some files based on their audio tags (i.e. artist, album, date, etc). I'm not happy with the limited n...
I am building a MVC application. This app has a core which is where all interfaces, abstract classes and operation logic are situated. It also contains a directory called module, this application is based in module. For example there is a module User which contains controllers, models and views (it does stuff related t...
I wrote a simple DTO to transfer data from one point to another, or so was the initial thought. Now I just caught myself in the act of doing various things in the DTO, for simplicity's sake, like converting data in a DTO setter to make sure it fits the format, or even validating it and throwing an exception, to reduce ...
I'm trying to implement a little shopping system. I have a single product which has a limited stock. For example, my product can be bought 5 times. My problem is, if a user adds this product to his cart, fill the form and pay. Decrement the stock when he adds the product to his cart (problem: if he quits the site befor...
My company has recently started to take on smaller software development projects. Typically small web applications to be used on a client's intranet. They are usually 3-5 months work in total. Typically, the client doesn't know what they want exactly so they pay us for a smaller projects (3-4 weeks) to gather requireme...
I see in many places where the word Resolve is used, in Dependency Injection (resolve an implementation to an interface), Package Managers (ex: Resolve packages dependencies), Web (ex: Resolve a hostname). So what does make the logic of the code so special that makes someone choose the word Resolve over a simple Conver...
We have an enum in a class library: Public Enum FieldType Phone Span Gender DrawPath .... End Enum which we use with an attribute applied to properties, for multiple scenarios: HTML/CSV rendering, onscreen display formatting among them. Multiple projects use this class library, and we want to use p...
Was the first implementation of looping control flow effectively the goto (or something like a labelled JMP in assembler) or was there another syntactic construction? for (für) was introduced in Superplan in 1949 IIRC.
I use Python's asyncio library to create a server that can handle telnet requests. Because asyncio's server loop is single threaded, I thought it would make more sense that when asyncio tells me that I got data (asyncio.Protocol.data_received) to simply schedule a task, rather than block receiving further data until I ...
Is the word 'statement' in 'statement block' redundant? In other words is a block in a program composed, by definition, of statements?