instruction
stringlengths
34
36.1k
Web app users can delete their accounts, they re-enter the password and if it fits, the account and its assets are removed (soft deletion). They can register using an email (and a password) or using Facebook (hellojs and passport). The self delete is simple for email+password registered users, for the rest we can't ask...
My problem is fairly complex, so here is a similar, simplified example. Let's say you wanted to predict the Miles Per Gallon (fuel consumption) of a car, based on the following information: you have the weight of the vehicle in pounds, the number of cylinders in the engine, and a number which corresponds to a type of v...
Even as an outsider to neural network development, they still seem to be a hot topic... I get lots of projects I see being starred on my GitHub homepage relating to neural networks. These projects look interesting, they come with lots of visuals. Typically with images being mixed together in various ways. Their patt...
Oracle summarises the purpose of unchecked exceptions as: The next question might be: "If it's so good to document a method's API, including the exceptions it can throw, why not specify runtime exceptions too?" Runtime exceptions represent problems that are the result of a programming problem, and as such, the API cli...
for me the app that I'm building, a very simple slot machine app where there is which users can deposit money to buy credits, and use those credits to play teh slot machine, and withdrawl their earnings. That's it. I get that event sourcing makes sense here since we need a proof of all transactions and must be auditab...
I'm planning to use publish–subscribe pattern with Azure Service Bus in my logistics application, but I'm confused whether publish–subscribe pattern is suitable for my case. My scenarios: Users will subscribe set of topics such as reset password, change password, load assign, user approval, user rejection etc. 80% top...
Assume we have a string s (a C char *) that is a program in a language L. I want to parse L and know the following from the specification The following characters must be quoted if they are to represent themselves: | & ; < > ( ) $ ` \ " ' So let's say I scan and parse the string checking char by ch...
I'm creating a Java (Spring Boot) application for creating Entities. I've got my @Controller for getting the data from a web front end, I've got my @Service for processing the data, and I've got my @Repository for permanently storing the Entities. So, your basic, simple layer architecture. Now, I need an audit trail of...
I've got a Rails eCommerce project communicating with an iOS app. The iOS app receives JSON data from the Rails back-end, but there's also HTML rendering when a user comes to the project from his browser. They basically call the same actions (create, destroy, update, etc.) from both sides. /website/my_action → HTML ren...
Problem I recently read a lot about Singletons being bad and how dependency injection (which I understand as "using interfaces") is better. When I implemented part of this with callbacks/interfaces/DI and adhering to the interface segregation principle, I ended up with quite a mess. The dependencies of a UI parent whe...
I would like to design and develop school application using PHP and MYSQL as backend. The frontend - a combination of HTML, JS and CSS - has a registration form for every school. Every school has its own students, classes, teachers and the like. I would like to use a single database with one students table having a cli...
Statement I often find myself still writing the following statement all over my code: // TODO: (the work that needs done) I do this in order to flag that I need to come back and do something later on. It often happens when the functionality of the code is dictated by other code that will be written later on. I did a qu...
I'm designing a simple user login/register program with user login/register and a repository. The passwords for users should be encrypted when stored but I don't know where to put the encryption step either on the repository or in the service that handles the logic for registering/login in a user. the user passwords sh...
following problem: I need to save a lot of xml strings of variable length and structure. As it is with xml, a lot of substrings are the same (some elements, attribute and value combination). Often the whole document is the same, except for a few small parts. Because I have a lot of these strings, I need to save the xml...
I am approaching a project where I'll be having to implement a database with my boss; we're a very small start up so the work environment is deeply personal. He had given me one of the company databases before and it completely went against what I was taught (and read about) in school for RDBMS. For example, there are ...
I have two friends that want to create a jewelry store, focused on customized jewels. The core feature is the jewelry designer, based on a jewel model. Here's an example of the sort of thing I am looking to create : http://www.gemvara.com/jewelry/wisteria-pendant/pear-citrine-18k-yellow-gold-pendant-with-diamond/155hh...
After a month or so of reading and researching DDD, I decided to start my own project and created DDD with these bounded contexts> Clients Products Orders Billing Each bounded context has rest API as a presentation layer, domain layer, persistent layer. So far so good, code is running smooth, but coming from a monoli...
Terrible title, but this is the situation I find myself in often and have not found a good design to make it nice. Lets say I'm working with Javascript and I have an object I am working on that needs to persist to a DB when changes are made. obj = { users : [ {425: {name:'test'}}, {427: {name:'test1'}}, {...
In every place I've looked, it says that double is superior to float in almost every way. float has been made obsolete by double in Java, so why is it still used? I program a lot with Libgdx, and they force you to use float (deltaTime, etc.), but it seems to me that double is just easier to work with in terms of storag...
Suppose I have a POJO A and some client code that serves it. I have created POJO B, which doesn't have anything in common with A, but I want to use it in the methods that use A, so I decided to create a marker interface C, that both implement and change the signature of the methods to serve them both. Considering that...
Is it bad practice to name classes after the façade pattern? public class OrderFacade {} public class InvoiceFacade {} public class ThingFacade {} ... These classes do follow the Façade pattern.
I have some javascript/webgl code. I want to have some idea of whether it will work for someone with a different browser/machine/gpu. This is difficult, because there's so much diversity in support for features. For example, on my machines, I can pass GL.FLOAT to readPixels, but I know that really I should only use GL....
The original library has this statement in its readme, with a link to CC0 1.0. To the extent possible by law, [redacted] Company, LLC has waived all copyright and related or neighboring rights to this library. If I forked this library and modified it, would I be able to publish the fork under the MIT license?
Okay so I read through this: Does immutability entirely eliminate the need for locks in multi-processor programming? And this was the main takeaway for me: Now, what does it get you? Immutability gets you one thing: you can read the immutable object freely, without worrying about its state changing underneath you But...
I have everything I need in 2 services in form of REST api's, is it a good idea or even possible to replace my existing asp.net app by writing ONE single html page (embedded with Angular templates) invoking the web services from JS controller? Then that html page will be published onto production IIS My existing asp....
This is strongly linked to these two questions: https://stackoverflow.com/q/15800945/279112 Should Controller know about View & Model? or vice versa? as well as this one: https://codereview.stackexchange.com/q/126373/39907 In particular, one part of this answer to the third one, mentioning the way the Windows Forms / U...
So I have an assignment from college where I have to apply multiple metaheuristics to different problems. I thought that I should make everything as modular and reusable as possible to reuse metaheuristics with different problems with as little change as possible. I need this classes: Solution NeighbourOperator Explo...
Reposted from Stack Overflow - I think this is a more appropriate place to ask the question. I have an algorithm that for an integer x and a starting integer i such that 1 < i < x the next value of i is computed by i = floor(x / i) + (x mod i). This continues until we reach an i that we've already seen. In JavaScript (...
Context I have a line of business application "MyApp" in C# using EF. Layers are separated as MyResusableLib.DataAccess // Class Lib: EF based utils, extension methods, MyApp.DataAccess // Class Lib: EF edmx, generated Model classes MyApp.DataServices // Class Lib: Depends on Model classes in MyApp.DataAccess (Note: ...
I'm a couple of weeks into dabbling with haskell and I've made a pretty big dent in Learn You A Haskell. I feel like many of the type classes and common implementations up to applicatives and monads make a lot of sense to me and I understand how they work, but I still lack a lot of practical experience. One thing that ...
If my class implements an interface then can I say that I'm following inheritance? I know that when a class extends another class then it's inheritance.
Today I have to search items of list from another list individually. I am just thinking about some better approach. Below is scenario described. Lets say I have two arrays, arr1 having 100 elements (may have duplicate entries) and arr2 having 1000 unique elements. now i need to find elements of arr1 from arr2 and perfo...
I'm starting a greenfield app and I want to use ASP.NET (4.6) and Angular 2. For the backend I have created a project in Visual Studio, and now I'm wondering where to put the Angular app. I really want to use npm and node-tools for the front-end, but in the end it will be hosted in the same Azure App Service instance w...
My superior asked me to validate each and every input field in the project that includes the Exception messages. So, am I correct in using Exceptional Handler for validating Exception message. ExceptionalHandler public class ExceptionHandler { public void handle(String s){ if(s!=null) { thr...
I want to possibly use Java Reflection to set some data at RunTime. My problem is I can't figure out how do I get sub-classes information and use as a part of reflection. I want to use Reflection to keep it generic functionality for future flexibility. Java Structure - Class & Fields (field data type in brackets) follo...
I'm currently working on a commercial application using a piece of software registered under the MIT license. Recently, the author of this software removed every entry from Github, for an unknown reason (he didn't provide any details). What are the implications on my side ? Will I still have the right to use the versio...
How could I simplify the following code? I suspect that it can be simplified by using the $.Deferred class, but I don't know how. if (condition) { $.get('url').done(function () { done(); }); } else { done(); } I don't want to repeat the done() function twice.
One of the basic precepts of object oriented programming is that subtyping represents the "is-a" relationship. That is, the child is always a specific form of the parent. A common example is that a square is a specific form of rectangle, so it seems to make sense to make a Square class inherit from a Rectangle class....
Concise problem definition: given n and {a,b,c}; (1 ≤ n, a, b, c ≤ 4000); Constraint -> a*i + b*j + c*k==n (i,j,k>=0); Objective-> maximize(i,j,k) Examples: n=47 and a=7,b=5,c=8 -> max=9 (i=1,j=8,k=0) == 7*1+5*8+8*0=47 n=7 and a=5,b=5,c=2 -> max=2 (i=1,j=0,k=1) or (i=0,j=1,k=1) My first solution is just brute for...
I believe most people are in agreement that using container components is a good practice - described in this popular post: https://medium.com/@learnreact/container-components-c0e67432e005#.qhw8yfodx I bought into it, however, I think I was doing so a bit too strictly. One comment in that article mentions that not usin...
JavaScript is the only language I've come aross which allows variable-length argument lists by default. A case where it would be helpful to detect too many arguments would be Mozilla's Add-On SDK's test cases. To test whether two values are equal, you write assert.equal(3, 4, "error message"); If you wanted to write e...
I have a couple of users who have a User Interface for an application that they must use to do their job. The UI can be cumbersome to navigate to perform some time critical tasks. This UI does not expose any API and has no integration points. I would like to be able to do something to help the users to perform various...
I have started learning about Redux and React in the web-world, and the more I learn about it the more I'm realizing how painful state management is in the desktop-world with WPF's MVVM-style architecture (using Caliburn specifically to bind Views to ViewModels). Redux has a few simple principles that dictate how state...
This is kind of a multi-part question. Is it possible to do a binary search tree if the data does not possess natural ordering? Would you be forced to impose artificial ordering to such data? Like images? Or executable files? Or video? or sound files? Items which do not possess an obvious alphabetic or numerical o...
I'm looking for a language agnostic approach for the following. We are prototyping this in both relational and graph DBs, so, again I'm open to hearing all opinions with respect to those. Here is the scenario: - User views portion of org chart - User edits org chart so that some people report to new manager - Us...
Below is the problem for which I have created a UML diagram with Staff as superclass and waiter, manager and hosts as subclasses, I understood other parts, except for the relation between table and cover classes, should it be Aggregation(or composition) or Association. Rough UML sketch There are three kinds of staff m...
I'm writing an automated installation script for a bunch of software, in Python. The purpose is for the script to fetch compressed files from a directory and install/configure each utility or application on a case-by-case basis. Since each of these requires special treatment (and when it isn't required it's the excepti...
Let's say I have the following appointments: Appointment 1 = 1:00 Appointment 2 = 2:00 Appointment 3 = 3:00 Appointment 4 = 4:00 I need to reschedule all of these one hour later: Appointment 1 = 2:00 Appointment 2 = 3:00 Appointment 3 = 4:00 Appointment 4 = 5:00 The problem is that I want to do this in one atomic ope...
If I want to compare two numbers (or other well-ordered entities), I would do so with x < y. If I want to compare three of them, the high-school algebra student will suggest trying x < y < z. The programmer in me will then respond with "no, that's not valid, you have to do x < y && y < z". Most languages I've come ...
I would like to hear arguments for or against a plan I am considering. I have a large network of nodes each of which has vector-valued properties. Accessing these properties (read or write) requires a timestamp. Plan A: pass the timestamp to every method that will access properties (and every method calling those met...
I was reading about Reactive programming, and came across this article The introduction to Reactive Programming you've been missing with the quote I put in the question title: Reactive programming is programming with asynchronous data streams. but this confuses me a bit. For example, the most common example of Reacti...
I want to write a suite of methods that act as getters when passed zero arguments and as setters when passed a single argument. I have two two reasonable implementations, shown below. Is one better than the other, or is there perhaps an even better way? class Thing(object): def __init__(self): self._size...
I was wondering, if I have a table that stores, lets say, a user's transactions, then when I need to fetch the user's current balance I would have to go and use SUM() like SELECT SUM(value) FROM transactions. But that seems redundant in the php + MySQL world because a user can refresh the page 3 times in a second if th...
I came across the following in some sample code: if (urlStr) { NSImage *iconImage = [[NSWorkspace sharedWorkspace] iconForFile:urlStr]; node.nodeIcon = iconImage; } else { // it's a separator, don't bother with the icon } Is this style of using an else statement only for a comment good practice for product...
I have a library that I use in several applications. It has a method that returns a URL: class UrlBuilder { public function url($config) { $config = do_some_checks($config); return make_url($config)); } } Often an application wants to alter the way the URL is built, and I would like to make that clear from...
I have a monolith application on a server and I want to break it into multiple microservices. Because of that for the moment I have to use the same database for all the microservices and each microservice accessing only his own tables. So my question is how can I reuse the database connection among microservices and st...
What are practical uses of base64_encode and base64_decode? At what particular situations are they used? For example, in terms of security? What is the usage of using this function when sending an image via a URL like this? echo '<img src="file_viewer.php?file=', base64_encode($dir . '/' . $file), '" alt="', $file, '"...
I have very limited experience with C++ but I do have plenty of experience with Java and NodeJS. I've decompiled and tried to make sense of a small C++ compiled file and I've come across something that I do not understand. To me this looks like a value being assigned to an expression which seems weird to me. What is ac...
I'm about to push my first project to GitHub (a mini toy lisp interpreter written in C). I've noticed that the vast majority of open source projects include their license in every source file (at the top). Is that a necessity for open source?
We need to customize a desktop application at compile time. Users cannot change the configuration. Only developers and release managers can do it. The configuration is a little complex. There are more than 10 modules. Each module needs configuration including values, capability flags, etc. We have 5 configuration group...
One of the major benefits of the repository pattern is that you can easily switch out implementations for other implementations. After learning about this pattern I started to make tons of things into repositories like an HttpClient repository for example, this way I can decide which client I want to use. Another examp...
Let's say I have a sale order with multiple rows of products. Multiple users insert rows so I must check for concurrency. In my db the ID of the order and the number of the row makes my record unique. In the past I've used one of the following two methods: Insert a blank record with default value,the max number of row...
I don't have a formal computer science education, meaning that I did not study computer science topics in a university. However, I work at a programming job and write a reasonable amount of code. Naturally, programming means that I also have to document and comment my code. The problem I seem to be having is deciding b...
I am looking for a cache conscious data structure that does not require hashing. This is to avoid HashDoS without needing to use cryptographic PRFs such as SipHash, which are slow (~1 cycle/byte) – I think that one can do better. So far, I have found HAT-tries, radix tries, and Judy arrays. HAT-tries still require ha...
I wonder, if the below idea makes sense for our web application. We show various lists of entities, which typically refer to other entities and so on. In the table view, there are columns showing some properties of the entity itself (like e.name) and also of the linked entities (like e.owner.email). The classical way i...
I'm on the way to build a Chrome app, dedicated to fulfill shop/marketplace orders. The orders come from marketplace APIs like Amazon MWS. The data is stored only in the app (with backup). The system need also to work in a quick way if 50.000 or 100.000 orders are stored. So how to structure the IndexedDB for that? Eac...
I am working on a Laravel Project where we are Payment Express. What currently we are doing is that we have Payment Express Class with static function (Not a single property) like given below: Class PaymentExpress { public static function first() { } public static function second() { } } We are usi...
I'd like to build a RaspberryPi-based device that can communicate with my Linux laptop over USB (don't think it matters, but I'll be using a custom made USB dongle that has an FTDI chip on it, and my laptop will have the FTDI drivers installed on it). I'd like to rig my device with a simple control stick and a simple k...
I don't know about all programming languages, but it's clear that usually the possibility of overloading a method taking into consideration its return type (assuming its arguments are the same number and type) is not supported. I mean something like this: int method1 (int num) { } long method1 (int num) { } It...
I have a series of reference codes that my end users create during the course of the day. These reference codes correspond to a transaction code that is stored in a database. As of now, there are 15 difference transaction codes. Here's an example: Tranasction Code - Reference Code BB01 - 48912388 C949 ...
How would I write something that fills with the right-most bit (<<< is used to denote this non-existent operator): 1 <<< 7: "11111111" and 0 <<< 7: "00000000" 9 <<< 1: "10011" and 10 <<< 7: "10100000000" as in the reverse of the Sign-propagating right shift (which fills with the left-most digit): -256 >> 8: "11111111...
I have a scenario wherein I need to do certain specific steps in a specific order. For clarity lets take a simple example. Let's say I have a Student and some Student Properties which I encapsulate in a class StudentDetails. A simplistic StudentDetails class: class StudentDetails { private String name; private Int...
Considering a deck of N playing cards with X different rankings and Y different suits (i.e. there are Y cards with X ranking, thus N=X*Y). What is the fastest algorithm to sort them assuming that X, Y, and N will be known at run-time and may be passed as parameters into the algorithm? Can we beat the performance of qu...
Currently in a part of my project a domain object like below exists: public class Address { public virtual string HouseName { get; set; } public virtual string HouseNumber { get; set; } public virtual string RoadName { get; set; } public virtual string Postcode { get; set; } public virtual strin...
Recently I've been wanting to experiment with NoSQL databases, especially document store ones. After reading, I still don't understand how one might model information that is contained in a relational SQL database (i.e with tables and records) in terms of documents. For example, a music database might have a table for ...
When defining bounded contexts of a Domain, what should be a primary guideline: departments (Sales/Manufacturing/Warehousing), where each department has a common context (https://softwareengineering.stackexchange.com/a/316829/226099) work load, for example Sales BC could be broken down to Client Administration, Billin...
I am using REST API as a presentation layer of a DDD project. In order to secure API calls, I am using token based security. Security in Web APIs-Basic Authentication and Token based custom Authorization in Web APIs using Action Filters. If an API user administration context is persisted by a different API or BCs (dep...
let closure = { (args) -> ReturnT in ... } vs func function(args) -> ReturnT { ... } Why didn't Apple follow the principle of Occam's razor and make closure and function declarations equal? For example, a closure could be defined like this: let closure = (args) -> ReturnT { ... } This is how it is implemented in Jav...
If an application has already an opened WebSocket for live feeds, should I use it over AJAX for the other communications with the server? Because the connection is already opened, should we use it for requests that are Request/Response and not real time? I prefer RESTful HTTP requests because I find them more easy to ...
There is a bad practice in software engineering where a single piece of data is held by value in multiple places. For example, in an FPS, the location of the player could be held by the AI class, the input class, the main class, and the graphics engine. Multiple problems can arise from this: Synchronization issues Inc...
I'm using Unity as IoC with C#, but I guess the question really isn't really limited to Unity and C#, but IoC in general. I try to follow the SOLID-principle, which means that I got very few dependencies between two concrete classes. But when I need to create new instances of a model, what's the best way to do it? I us...
I am using Protractor and Jasmine to create end-to-end tests for a webpage. To test this initial page, I have abstracted made some common utility functions to create about 20 test cases for this particular page. An example of this is shown. describe('User is on the page and', function () { beforeEach(function () { ...
I'm integrating an enterprise application with an existing pattern. The main problem is how to synchronize data between my system and an external system through RPC (HTTP API calls to be precise). What I have done so far The first thing I have done is dividing the interface in business methods such that at the beginnin...
After some googling I found some debates about whether constructor injection or property/field injection is better, but there is yet another alternative that strikes me as more beneficial. In most programming environments, there is something called "the call context", which is information implicitly passed from caller ...
case 1: Sometimes I cannot figure out how to make things to work like in this question,Sending drive names to the combo box. In this case I know how to add items to a combo box as well as about getting drive names but I could not figure how to combine those two in order to work. So I asked the question and since I have...
So in general when you perform a crossover in GA, you directly flip a random section in the "genome", with the corresponding section in the other parent, and mutate it based on the mutation rate. Consider the sequences below: 0100 1000 0001 1011 0010 0110 1101 1111 A crossover without any mutation might look like th...
I am trying to currently get a good grasp on the Observer design pattern, but I am stuck wondering about one specific issue. In the examples I have been able to find of implementation, they are all rather basic in terms of having a specifically designed state. For instance, the "subject" class that is being observed on...
Is there a specific data structure, object oriented programming methodology, and/or approach for achieving what programs like LT Spice, Altium Designer, and Cadence Virtuoso use to manage components/nets/nodes on schematics? Specifically in Java? Above is an example, a sample schematic from LT Spice. There are a bun...
Question 1 I have a login API endpoint http://127.0.0.1:8080/api/account/login It checks if the phone number has been validated. If not it will call POST http://127.0.0.1:8080/api/account/sendsms country_code=1, phone_number=1234567 How can I prevent abuse to requesting sms? (It'll cost money on my part. I also have...
OK let's say I have something like this: public class MyObject { public static int DefaultValue = 9 private int _value = DefaultValue; public int Value { get { return _value; } set { _value = value; } } } That way, changing the DefaultValue will change Value for all future instances - so having a consta...
The issue that I have is that I need information from an object that a method returns when it throws an exception. It is a little hard to describe so I have this java pseudo code example. I have a solution, but I don't like it (problems listed below), and was wondering if there was a better one: public class OuterClass...
My company wants me to write UI tests that test the business logic (all of the use cases MUST be independently testable) I decided to do it in selenium. I have managed to create a decent product (as of now about 80% of use cases are covered, I have a video recording feature of the test run and a screenshot feature for ...
I'm skimming through a very popular game's source code at the moment and I came across these variables inside of this class. public static final BlockPos ORIGIN = new BlockPos(0, 0, 0); private static final int NUM_X_BITS = 1 + MathHelper.calculateLogBaseTwo(MathHelper.roundUpToPowerOfTwo(30000000)); private static fin...
I have two Java applications deployed on tomcat. For inter application communication I provide jar file of application (Java API) to other application and it becomes a method call which is fast. Now I am thinking of creating rest service, can it add some extra time. Of course yes but how much in worst case. Keeping in ...
I have a Data class that can be placed inside a DataCollection class that can be placed inside a DataCollectionCollection class. Kinda like an egg can placed inside a box that can be placed inside a crate. The Data class can be "standardized" through a special process. Standardizing it will create a new StandardizedDat...
If I want my program to be able to run in debug mode, is it a good idea to make it accept a flag such as -D=DEBUG when I run the program? I currently have a DEBUG variable in a .h file but that I can't change after I compile. #define DEBUG false I'd like to be able to run my program both in debug mode and "stable" mod...
I'm trying to create a vector (like in physics) class in Java. I want to support vector addition, dot product, scalar multiplication, etc. So, my question is, is it possible to do this with generics? Generics can only take objects as parameters but I'd like to use primitives (double or float).
I have built a library that is being used by a few people. They say that library has a few print statements which is wrong because a library should give freedom to users to use the library the way they want and forcing a few print statements is not good that way. Should there be print statements in a library by any ide...
As i am executing a one pipe example pgm from libc.pdf,I noticed that the parent process first completed then only child process completed.From my knowledged about os the child process must complete before the parent completes.so what happens here
Background Time ago I learnt something about package design, in particular about loose coupling: The Acyclic Dependencies Principle The dependency structure between packages must be a Directed Acyclic Graph (DAG). That is, there must be no cycles in the dependency structure. Robert Cecil Martin aka uncle Bob, Granular...