instruction
stringlengths
34
36.1k
I've got an application which has generated a rather heated discussion between a couple of the developers. Basically, it's split into a web layer and a backend layer. The web layer collects information by a simple web form, stashes this data as a JSON document (literally a .json file) into a watch folder used by the b...
I need to create a container app which contains several apps (imagine something like iCloud): once I've been logged in, I can see all the apps by means of icons, click on them and use them (a new tab/page is open and no login is required). The container app, as well as the other apps, will have a dedicated folder on th...
I'm attempting optimize and figure out why for input n a function I wrote f(n) appears to never finish executing when n > 26. TL;DR I need to figure out how to find the complexity of various python instructions that involve concatenating an empty string and dictionary lookups all within a while loop. The rest appears ...
I am building a web application in php. I am following TDD (write tests before production code) for my unit tests and using BDD to drive discovery of my applications features and to provide integration tests. My architecture is based around Robert Martins Clean Architecture where by I have application use case classes ...
I am doing GUI tests for my network application and I'm wondering if I should stub out mock responses, or if it's OK to keep using the network for the GUI tests. It seems to me the main benefits of stubbing the responses are: Speed Robustness - no false errors because of network problems And the cons are: Server in...
I've recently read a lot of arguments against using the repository pattern with powerful ORM's like Entity Framework as it incorporates repository-like functionality, along with Unit of Work functionality as well. Another argument against using the pattern for a situation like unit testing is that the repository patt...
If I want to use for example the Electron Quick Start as the base of a new app, should I use a normal clone and just delete the .git folder, or is there a more elegant way of doing it?
Now this question might sound (/ is) stupid, but I'm just getting into OpenGL. So I installed GLFW source and I'm looking at some easy examples. What I'm noticing is, that the code still contains "typical" OpenGL functions, like glColor or glVertex, but it also contains "glfw" functions like glfwSetErrorCallback. I don...
I want to implement the repository pattern in an old legacy project. I already did some research, and found that, without an ORM, it's completely acceptable to have methods like "GetBySpecialProperty", and skip the creation of a generic repository. My current setup is: public class FooRepository { private IMapper<F...
I know several basic string-matching algorithms such as KMP or Boyer-Moore, but all of those analyze the pattern before searching.However, if one has a single character, there is not much to analyze. So is there any better algorithm than the naive search of comparing every character of the text ?
The past years I have had the need to implement business logic in a larger type of service, most often orchestrating a handful of atomic/microservices. Operations like "search and update document, then email HR team", "sign contract and update ERP", "start ERP batch job". But it always feels weird mapping these composi...
Statically-typed languages such as Java afford the benefit of compile-time checking of types - you are guaranteed that an object is of a given type, so: there is no need to spend time and resources investigating the TYPE of a variable or parameter, because we don't know if this is a None, List[string], or just one str...
I've been using a simple json to the steam API to get player inventory, but now I have discovered that steam impose a rate limit to the number of requests allowed. A rate I feel is not enough for my requirements. Are there any programming techniques I can use to get around or avoid hitting this limit?
So my problem may be relatively rare, at least the majority of the "how to learn to code" questions I've come across deal with a lack of fundamental understanding of computers or languages. I'm fluent in Linux, repairing PC's to an extent, learning new languages is not a problem for me (learned a bit of Scheme to hand ...
Many companies struggle with even basic sensitive information handling. One screaming example I can give is the attack on TalkTalk's servers resulted as 4 millions customer's personal information being exposed. Definitely a not good situation to be at. My question is - what are the best practises for startups to handle...
So imagine two HashMaps that need to be mirrored across two different machines, A and B. Whenever I make a modification to machine A, machine B sees it and vice-versa. Problem is: These two hash maps need to remain always identical. What computer science strategy can we use to accomplish that? Is it possible to do it w...
I am a software developer with limited exposure to designing larger systems. I am interested in determining some common techniques, maybe even common diagrams, to help me complete the design of a middle-tier notification system that will be used in an enterprise to route notifications to subscribers. There are a numbe...
I have some problems understanding the concept of a runtime library, especially the Python one. So I have written some a hello world python program and intend to execute it, so I write python ./hello_world.py. What steps happens between me hitting the Enter button and the machine code generated from my python code bein...
example: public class Something { private Set<String> names = new HashSet(); public void add(String n) { names.add(n); } public void add(Set<String> set) { names.addAll(set); } } But, I am curious why AbstractCollection.add(E e) is not overloaded in the same way I overload my Something.add(String n). Why ...
I have a Presenter ( RoomPresenter) and a Model ( RoomModel). My RoomModel have some methods like: void createRoom(RoomData roomData, List<User> users) void addUsersToRoom(int roomId, List<User> users) void joinRoom(int roomId) This is the createRoom() implementation: void createRoom(RoomData roomData, List<User> use...
The article An OCL Extension for Real-Time Constraints describes and interesting extension to OCL for the specification of time constraints. New types OclConfiguration and OclPath are defined along with a new post() operation which is able to generate a set of possible OclPath for a specified time interval. At pag. 18,...
I am working on creating a c# design for following requirement. I am creating this for a fitness website. I have an article (as Text) and a exercise (as Image or Videos) as the base entity. Now i have workouts, middle entity, (A workout is basically a set of excercises or articles to be performed in a instructed manner...
Taking for instance Google mail and Facebook, they both have a huge database of users. It would be easy to search through a database of 100 similar logins and find a match in a second, but not in the case of Google and Facebook. When you try to sign into Facebook or GMail, given a correct credential, you will will be l...
Why is it legal in Java to declare an object of the enclosing class inside the nested class? It cannot be meaningful as enclosing class is not completely defined at the time of the declaration of its object.Furthermore, if A is the enclosing class and B is the nested class, then an object of class A will also include ...
I am developing an application which sends certain notifications to the user as read from a read-only external service. The user might dismiss notifications, and those should not appear again. I cannot ask the server to give me only entries newer than than my last query because I am particularly interested in a value t...
We are currently having an internal debate on how our business logic classes should be structured. At the moment we structure our business classes like this: public class OrderBL { public void CreateOrder(OrderDTO order) { //save order //send email } public void CancelOrder(OrderDTO ord...
We're working on a BugTracking system and are still in the learning process. A BugReport has a title, description, (...) and also a tag. A tag represents the progess of the BugReport, e.g. New : Freshly created BugReport Under Review : A fix has been made and is under review. Duplicate : The BugReport is a duplicate ...
Several of our customers have come to us with an interesting problem that involves adjusting data that occurred in the past which is rolled up and reported based on an org hierarchy. For example: If you run a report by "Sales Team" in March it will roll up sales closed by members currently assigned to that team. Then s...
So master-slave replication is great, but it leaves the master as a single-point of failure. What is the strategy to solve this problem, if there is one? I'm looking for the computer science theory behind it, not for a product that magically supports it. Ok, the slave could become the new master, but what's the theory ...
Does the C++ committee test their new design specifications with some sort of prototype compiler before releasing a new standard? Or do they release a standard which is, in effect, only theoretical until the big compilers implement it?
So after reading "Implementing Domain-Driven Design by Vaughn Vernon" I've decided to refactor my code for better re usability by isolating what I believe to be core domain concepts into separate modules. Each module contains their own set of distinct architectural layers which include the Domain, Infrastructure and ...
In most coding languages (if not all) you need to declare variables. For example in C# if its a number field then int PhoneNumber If I'm using normal English language I do not need to declare PhoneNumber as int to use it. For example if I ask my friend Sam to give me his phone number I say: "Sam give me the phonenumb...
I have been building a greenfield application. It is three layer (data-access, domain-models, presentation) with the presentation layer being VMVC. This is the cleanest application I've ever built by far, and everything has fallen into place in the architecture very well. However, there is one fly in my soup aggravati...
So I have a simple method I'm calling millions of times a second, and I noticed that it was taking 16% of all processing time!! The offensive routine is as follows: public void placeHolder(){ for (i2 = mnY; i2 < mxY; i2++){ runInternalLoop(); } } Coming in with a self-time of 27015ms, or 14.5% (Excludi...
How can I improve this UML class diagram? I'm really confused about the relationship between Expense and Category, because Category and Expense can exist by themselves: you can register Expense and not assign a category, you can add new Categories to the categories list, and so on... Do I really need separate List clas...
There are three common ways, AFAIK, to implement reusability when it comes to OOP Inheritance : usually to represent is-a relationship (a duck is-a bird) Composition: usually to represent has-a relationship (a car has-a engine) Traits (e.g. the trait keyword in PHP) : ...not really sure about this While it looks to m...
I am building a website that looks beautiful in Web but worst in mobiles. I want to build the same site but different designing for mobile. Whenever user opens site.com then it auto redirect to m.site.com OR site.com/mob only if on mobile.
How to recognize when there is a bug in program or you have an inability to solve concrete problem? I noticed when I concentrate too much time on a problem and can't find a solution, I am starting to be so subjective and can't recognize one of those two states. How far to go with a search for solutions, and not kill yo...
I've been writing 'driver' sql scripts (is that the correct name?) to run multiple sql 'sub' scripts in order, writing errors to log file etc. My Oracle version seems to be more or less ok, but my sql server one I'm struggling with. Specifically, when a script fails, I'm getting line numbers bigger than files for the e...
While researching technologies for a new "pet project" I analyzed a few well-established project's source code and I noticed that they hardly use any dependency injection frameworks at all. For instance, Hazelcast and Cassandra don't seem to use any. The only big name I could find which seems to use one is Elasticsear...
For quite a long time now, I have been using a calling convention from C++ google style guide, which boils down to the following: "[for a function] arguments are values or const references while output arguments are pointers" The reason I like it so much is that at the point of call you can clearly see whether an argum...
I am cleaning up our git repository and there is a feature branch which contains a prototype of an interesting feature which the management decided not to include soon in the product. What do you do in such a situation with the feature branch? Is that a situation where the github gist functionality might be helpful? ...
I am developing a converter from objects of different domains, which accepts both, converting one object to other, or a list to another list. Please consider the following example: public MyObject2 decode(MyObject1 originalObject) { String name = String.valueOf(originalObject.getId()); return MyObject2(name); ...
I am seeing that more and more new APIs use page tokens to let the user move between the pages of results containing a lot of items. However from an API designer point of view I'm not clear on what the benefits of using a token are when compared to letting the user specify how many items he wants to skip. So here are m...
I'm working on a somewhat simple game. Currently trying to implement the game logic for moving the pieces around. Logic is something like this: does player have pieces in inventory? if yes: did they try to move it to an empty location if yes: ... if no: ... if no: ... As...
I am having a hard time deciding how I should manage my OpenCL source code so that my program can compile it at runtime. There seem to be two many strategies. You can create them in you C source as strings (I really don't like this approach since this seems like a horrible way to write code). The second approach see...
I just started working on some data analyzing for an e-commerce site that is moving about 250,000 packages per year. It is very seasonal and need to try to gain insights on both a macro and micro level. I am just looking for some best practices for how to get started. Should I run a daily script that looks at several k...
When you use an IoC container, like so: var svc = IoC.Resolve<IShippingService>(); How does the IoC Container choose which implementation of IShippingService to instantiate? Further, if I am calling the above to replace the equivalent code: var svc = new ShippingService(new ProductLocator(), new PricingService(), ...
I often find myself writing programs that operate on fairly large datasets and complex problem formulations, which usually take on the order of 30 minutes to 2 days of running to identify a bug. The psychological effect of these long testing iterations can be very taxing, and I find it very difficult to change focus an...
Let say there is an array of strings, I have to process. I'm using a «heavy» third-part object which gets the string and performs its analysis. In order to optimize a performance, I create a number of threads (according to a number of CPU cores), separate the array to the number of sub-arrays and each thread executes t...
Everyone (who knows C) always tells me to be careful when using gcc to compile on Windows, yet they never actually tell me what the compatibility issues are. I'm left to believe that gcc is just 'not optimal' for Windows usage. I've already designed several applications using gcc, and everything seems to work fine. Cur...
I have a shopping website which allows users to place orders. In my web application when the users click 'Create Order' i call an OrderService class which looks like the below: public class OrderService { public void CreateOrder(OrderDTO dto) { SaveOrder saveOrder = new SaveOrder(); ReduceStock...
I frequently see people extending a class like this for example: public class Bananas extends Fruits { public void eatFruit(){ } } rather than public class Bananas { Fruits fruitsObject = new Fruits(); fruitsObject.eatFruit(); } What is the reason behind doing one rather than the other? I was t...
For my thesis I am trying to extract some data from Excel. I want to create a list with the name as in excel and then append the values to said list so I can work with it. EDIT I realize I was unclear in my last post. This is simply because it was hard to find material on openpyxl (I didn't find the documentation that ...
I can't see the point of constants. For example I can use the famous example of PI: PI = float(3.14) Here I get the job done without a constant. Who cares if the value never changes during the lifetime of the program or if it's best practise. I can define PI as a variable and get the same task done just as well.
What is the correct initialisation of a smart pointer? std::unique_ptr<Class> ptr(std::make_unique<Class>()); or std::unique_ptr<Class> ptr = std::make_unique<Class>(); Is there an implicit copy with the second usage?
I read some posts about "composition over inheritance","where to use composition/inheritance" , "Is-a relationship..." or "Liskov substitution principle" for some time, but I am not sure if I get the right idea about "composition over inheritance". Alternatively, in my experience, it seems just one simple golden rule t...
One of the functions of an application I manage is to operate a fleet of vehicles. I have an object vehicle with which I can do tasks that are vehicle-related; getMileage(), setDriver(), etc. I also have a collection of vehicles with which I can do tasks that are multiple-vehicle related; fitWinterTyres(), updateInsura...
I'm talking of members of a team in charge of dealing with external providers, cloud services, social services, marketing services and so on... They are not building the core application but they develop interfaces, with API services, data exchange and synchronisations.... Services might be (Facebook, Google, Mailchim...
Here is my problem: I have and class structure like this: class Base { private: SomeType something; bool isSomeValue; public: virtual void myMethod() = 0; }; class Child1 : public Base { virtual void myMethod() override { // do step 1 for (int i = 0; i...
I have a set of items strictly ordered on time. Each item can either be single (no Next, no Previous) or part of a span (with either 1 or 2 further endpoints). For example in the picture A is part of a 3 element span 1 -> 4 -> 5, B is part of a 2 element span 2 -> 3 and C is part of a 2 element span 6 -> 16. As you ...
I mean it in this way: <?php $number1 = 5; // (Type 'Int') $operator1 = +; // (Type non-existent 'Operator') $number2 = 5; // (Type 'Int') $operator2 = *; // (Type non-existent 'Operator') $number3 = 8; // (Type 'Int') $test = $number1 $operator1 $number2 $operator2 $number3; //5 + 5 * 8....
I have the wikipedia data dump and trying to decode special characters in the page titles, except a lot of characters don't match up the "standard" ascii encoding (referencing from here.) As an example, in wikipedia ë and ã are given as: ë = %C3%AB ã = %C3%A3 Is there a defined key anywhere I can pull from?
I am fairly new to MVC5 Development and I have been doing a lot of reading about Layered Design, DI, IoC, etc... I feel that I am getting a grasp of concepts, however when it comes down to writing a good example I struggle. To ask my question I need to set a base and here is that base, the goal is to create a new Tea...
I'm getting a list of items from an external API and each item has a number of ratings and an average rating out of 5. What is the best way to rank them? Is it statistically sound to just convert an item with 1000 ratings and a 4/5 average to an item with 800 upvotes and 200 downvotes and use Wilson Score? If not, are ...
I have an angular service that fetches data that will be used by multiple controllers. I only want to fetch the data from the db once and then have the service store the data in an object which controllers can reference through the service. I'm using ui-router with multiple and nested views. Where should I put my servi...
I have two coding styles: public class Age { public double AgeYear { get;} public double AgeInDays {get;} public Person GetAge() { int x; //implementation that calculates AgeYear and AgeInDays return this; } } Age a = new Age(); Age a1 = a.GetAge(); Second implementation: public...
I was told to come here from Stack Overflow because I was "looking for an algorithm". I'm trying to implement it in Python, but there is nowhere on the net that gives a straightforward way for calculating the multiplicative inverse of a number in a Galois field. The requirements for the algorithm are pretty simple: In...
We have moved to a more SRP model and found coming up with class names challenging. Previously we had a Order class that looked something like this: public class Order { public void Create() { } public void Dispatch() { } public void Cancel() { } } We are now splitting these 3 met...
I'm trying to fit an arbitrary number of HD videos on screen so that they all have equal size, maximizing the size of the videos, with no scrollbars appearing. Given N number of tiles of equal aspect ratio (16:9), displayed in a viewport of arbitrary height and width, how can I resize the tiles so that: a) all tiles a...
I'm using Google as a login system for my latest project. So, my users table has a column named googleid, which stores Google's unique user id, which is a number, with a few dozen digits. For example, it might be 105561241212957286025. Since I'm not going to do any mathematical operations on this data, should I store i...
I need multiple "random" URLs that just mask the original URL, i.e.: /ABC /CBA /CAB All resolve to /6 I came up with matching a letter to a number and then you can sum them to the single value. A = 1 B = 2 C = 3 ... /ABC = A + B + C = 6 /CBA = C + B + A = 6 /CAB = C + A + B = 6 ... Is there a name for this? It doesn...
Problem I run a website which has a requirement for a new feature - to enable users to upload CSV files into the website. The users will only ever need to upload 1 CSV file at a time, and only 1 or 2 CSV files per day on average. I get to define the file format of the CSV, so I will be specifying what the fields are an...
In my current architecture, I connect from my local script to a server in SSH, and execute a .sh script. The purpose of the script is to execute an SQL query and to output the result in a file. My .sh script contains mysql -h ${hostname} -P ${port} -u ${dbuser} -p${auth} ${dbname} -e "cat ${sqlfile}" > ${outfile} At t...
I'm using C++ for implementing a project that requires to import a file once. All the data in this file needs to brought in memory as key value pairs, but only when the file is imported. Since this is a one time operation, I don't feel like it requires a class. But I don't know where to put a function that does this f...
Using C# I want to create one or more text files to store all the data pertaining to a particular 'Thing' on the same line. I am presently leaning towards StringBuilder as per the following. sb.AppendFormat("{0}{1}{2}{3}{4}{5}{6}{7}" , _ThingClass /* Thing class */ , _ClassType /* Property class type */ , _P...
I need to compress an id for marketing campaigns. The current campaign id is 32-bit integer but obviously this is too long for a customer to type by hand. I would like to compress this to minimum length while still maintaining two-way compression/decompression and uniqueness of id. What algorithm should I use?
For a scientific simulation I need to write some computations in C++. Since this became extremely tedious, I built myself a small code generator: In a scripting language (Python) you put together a syntax tree consisting of assignments and mathematical operations. A self-written codegenerator transforms the tree into C...
When should I use database for logging and when text files? I see that web servers and web frameworks (that your app uses internally) usually (always?) log requests and errors into text files by default. But I see that people who develop their app around those servers and frameworks sometimes log into database (even th...
I'm working on a simple resource allocation problem, that I'm solving using backward DP. The full code is at: https://codereview.stackexchange.com/questions/123641/allocating-a-resource It works fine, but I'm a bit puzzled on how to retrieve the optimal policy once the optimisation is done. I use a memoization decorato...
Here is an excerpt from code from Google's recaptcha API (https://www.google.com/recaptcha/api.js): /* PLEASE DO NOT COPY AND PASTE THIS CODE. */ (function() { if (!window['___grecaptcha_cfg']) { window['___grecaptcha_cfg'] = {}; }; if (!window['___grecaptcha_cfg']['render']) { window['__...
I know that an attribute defines the state of an object. So, is it correct to keep attributes that don't define the state of an object of a class? For example, I have an Employee class, which has these attributes: emp_id, fname, lname, mname, salary, mobile, email, gender, maritalstatus, position, birthdate, hiredate, ...
Windows 10 ships with "3D Builder", a Universal App that contains utility functions to prepare STL, OBJ, 3DS, and other files that represent geometries for 3D printing. The utility looks like this: In particular, they have triangle mesh functions there that: "Detect" when a mesh is not suitable for 3D printing; "Repa...
I am working on a well established (aka clients using it for a while) video player. We recently found out that the drawing engine (ddraw) is deprecated in windows 8 and 10, and choose a modern solution to replace it. Issue is, a completely different and apparently minor feature is affecting the usability of the new vid...
We are a small software company with one product. We use scrum, and our developers choose the features they want to include in each sprint. Unfortunately over the past 18 month period, the team haven't once delivered the features they committed to for a sprint. I've read a lot of posts/answers stating something along t...
What will be the best way to handle these scenarios, if they are not one-time, but regular: Self-hosted services on quite a bunch of machines are needed to be reconfigured to a different database in a centralized way. So it requires changing app.configs and restarting services. All services need to get new logging con...
I have read some articles on SQL Server query optimization. The point I get is SQL Server generates a query execution plan for each stored procedure when it's executed for the first time. Those execution plans are stored in the database, and will be used for future executions of the same SPs. The part I didn't understa...
To simplify my question let's assume for a minute that all users are using the latest version of Chrome to view a particular website. Using the latest libraries (Polymer for example), I can render a VERY large list of constantly changing records in DOM and it will only create enough DOM elements to render what is visib...
Typically, I see a few using statement at the top of class file. Example: using System.Collections.Generic; using System.IO; using System.Xml.Linq; But in a project I am working on, on several occasions I see 20 or more usings/imports in one class file. Is this bad design? It seems to be that classes designed to do...
I'm currently designing a conceptual web app, where users can submit posts, comments, and "like"/"dislike" both of those. However, I am not sure of how to store the (dis)likes, because of how many there could be and how many queries would be run on their corresponding table. (For example, getting (dis)likes per post, g...
I went on an interview last year and was shown a sequence diagram and was asked to describe the the sequence. There were 2 things in the diagram I had never seen before. I asked what one of them was and was told that's how an if statement is shown in a sequence diagram. The other was an arrow going back to the actor th...
I'm making a framework for building simple html websites for an embedded system and I want to make it bulletproof in a way that a user can't make mistakes in building the html document. As I've learned, it is hard to make and maintain an html markup inside c++ code. In one framework that I found (only one I could find)...
I have millions of tweets currently stored in HDFS and I plan to analyze them from Spark (Data mining, text mining, Frequent Term-Based Text Clustering, Social Network Analysis) however, do not know if there is any benefit in using a database instead of HDFS for handling data. There is some justification (in terms of e...
(and alternatives to a workflow engine) Problem: I have various inputs with various attributes. For example {name: john, country: US} and {name: Jose, country: MX} And I have the following workflows for the task Enter Country US citizen: Step1 Validate US Passport Step2 Declare Goods at Customs Non US citizen Step1 P...
On PPCG, we frequently have King of the Hill challenges, which pit different code bots against each other. We don't like limiting these challenges to a single language, so we do cross-platform communication over standard I/O. My goal is to write a framework that challenge-writers will be able use to make writing these...
I heard numerous times that when comparing Strings in Java, to avoid null pointer exception, we should use "abc".equals(myString) instead of myString.equals("abc"), but my question is, is this idea already problematic in terms of business logic? Suppose myString should not be empty in normal conditions, if we just use ...
Context Perhaps I'm just use to C-esque styled languages but having a sigil in front of a variable (e.g. $VAR) always strikes me as weird. Question Why do some languages such as Perl and shell scripting have sigils in front of the variable names? I can see it making sense for older languages like Basic (1960s) where t...
Here i want to replace price in data1 to price from data2, and it updated if the id is same. Is it possible to do that without nested loop? var data1 = [{ "id": "56e641d4864e5b780bb992c6", "price": "1000", "quantity": "1", "name": "def" }, { "id": "56e65...
Let's consider an example from WebDriver where I create two different classes to deal with page object, one stores the element locator and other actual operations dealing with page - public class ContactPageElements { private By nameTextBox = By.id("name"); public static By getNameLocator() { return name...
I'm working a PHP project where I need to authenticate users to a portal. Just wanted to get your opinion on the code, statistics of the website show some strange behaviour with the login form. Wondering whether the code is strong enough. conn.php <?php if(!isset($_GET['login']) && !isset($_GET['pwd'])) { header('...