instruction
stringlengths
34
19.9k
If you search for examples of creating a seeded (pseudo)Random number generator, you will run into stuff like this (specific example http://indiegamr.com/generate-repeatable-random-numbers-in-js/): // the initial seed Math.seed = 6; // in order to work 'Math.seed' must NOT be undefined, // so in any case, you HAVE to ...
I'm working on a project in which I have an entity, we may call Users and another entity Address. I want to define the entity User in a way that an user would have a collection of addresses (typically a One-To-Many relationship), but I also need an attribute of user, let it be main_address that would target a single va...
I had the following question I was trying to solve: You are given a n*n matrix. Every cell of the matrix contain some value (positive). You are currently at (0,0) and you have to go to right most and bottom most cell ((n-1)*(n-1)). You can move either right or down. I am aware of finding the most optimal solution for...
so this is a logic question as to creating the proper relationships in a MySQL database. What logic would you choose for the following scenario? This is a back-end for an app where people can have friends they can interact with, or "Add" if you will to their own "Network" for lack of better terms. So, for example, shou...
I just read the de facto standard for HTML5 offline/localStorage. It has me curious: if I build my web app to work regardless of whether or not there's an internet connection, and I use HTML5 localStorage to do this, then how are web app URLs affected when in "offline mode"? For instance, normally my web app's home pag...
I m working on Web API project, and it is using WebApiConfig.cs file to defined routs for Web API. Web API fold RouteConfig.cs file. I have googled and they say RouteConfig.cs is for MVC routing. It is actually a confusing statement. Can you please guide why WebAPI has RouteConfig.cs file ? Why would one need MVC rout...
I often have a workflow where I develop some feature in a Git branch, switch to another feature-branch, etc. During development, the original develop branch and the feature branches diverge. Now when switching branches I am all of the sudden developing on an older version of my project (which is to be expected, of cour...
I have a rich model, where e.g. one model A depends on many related entities/value objects. Therefore we have methods in A for retrieving collections of related objects: getFoos(), getBars() and so on. At one point, one or many of these related collections should not be fetched eagerly, and, moreover, should be fetched...
I have a model e.g. Book. Besides 'natural' attributes of a book, I have some mandatory IDs I need to carry on, like companyId, groupId. They are related to which organization unit this book belongs to. Now, I see these two flags like something that is not part of the Book interface. Since all the work with a book is d...
A system I'm building includes a set of UI sliders (the number varies) each with a scale of 0-100. By slider I mean a UI where you grab an element and drag it up and down, like a volume control. They are connected by an algorithm that ensures they always total 100. So when one slider is moved up, the others all move do...
So, i've started working as a freelancer and therefore find myself copy/pasting util methods from one class to another. Not good to say the least. I do this on my mobile frontend dev and backend .net. I'm thinking of creating a Utility library for each platform I develop on. Then, when I start a new project drop the li...
I am attempting to structure my solution projects in such a manner as to improve testing, reuseability, separation of concerns and all that good stuff. Whilst I understand these concepts in theory, I find myself going around in circles in regards to its implementation, specifically what goes where. I have the followin...
i'm simulating an ensemble of random walkers in 2D in python, I set [x,y] coordinates of my walkers to be gaussian in a 2D grid, then use a rand array of -1 and +1 to move up down left right: N=20 #number of walkers Coor[:,1]=100*random(N) #X's coordinates Coor[:,2]=100*random(N) #Y's coordinates To do the simulation...
If I want to run a job at the end of the month to calculate the commission for all the sales consultants based on the current transaction data, eg commission rate for the person, sales done in the month, and payments received from their customers, that becomes potentially a complex batch operation. My existing resource...
I'm currently in the early stages of designing an e-commerce application. I'm working out some designs for my classes which have so far been fairly straightforward, but I've run into something of a problem which I suspect is related to the Circle/Square problem. The following (simplified) class diagram outlines what ...
So I've created an API that I want to leverage to add some functionality to an existing web app. My current website authenticates users using SAML. What I'm looking to do is instead of moving the code into the existing codebase is to find a way to authenticate to the new site and leverage the APIs that are already the...
I understand how to work with interfaces and explicit interface implementation in C#, but I was wondering if it's considered bad form to hide away certain members that would not be used frequently. For example: public interface IMyInterface { int SomeValue { get; set; } int AnotherValue { get; set; } bool S...
Forgive me if this is a noob question - My CS education is a somewhat incomplete Basically, I need a way to hash an input, so that someone seeing the output doesn't see the original input value. Security is not an issue, and I need to be able to make this unique across about 1 million inputs. Originally I was using a h...
I have a csv of employee ids, names, and a reference column with the id of their direct manager, say something like this emp_id, emp_name, mgr_id 1,The Boss,, 2,Manager Joe,1 3,Manager Sally,1 4,Peon Frank,2 5,Peon Jill,2 6,Peon Rodger,3 7,Peon Ralph,3 I would like to be able to generate a (json) object representing ...
I was trying to be smart and elegant, and I ended up shooting myself in the foot by coding my entire application to use flags to store various combinations of settings. Now, I have hit a point where I have > 64 options. I need to move away from flags or I will be forced to create additional fields, which will make my...
My Problem: I have been tasked with re-implementing a software key generator routine on an external web server running cPanel v.11.44.1.18. Currently, the key generator is implemented using a proprietary Database Management System (DBMS) which we run on a local server. We want to relegate the key generator functionali...
I was just writing a function (in C# in this case) that stored huge amounts of data in a local variable early on in the code, let's say at 5% of the functions code. After that point, the data in this memeory are no longer used, also the following 95% of code have a variable runtime, as part of it depends on external re...
If we use a nice library like TetGen, generate a simple application-wrapper that simplifies our needs and publish it as open source, can we use it inside some Pipe/Chain of applications used in our commercial product? Is this allowed by the GPL and AGPL licenses, or they do force all of a commercial product that consis...
I'm wanting to mimic something that I saw in Photon Server with my application. Entity Framework does something similar. Photon Server has an Operation class. You pass it a dictionary of <byte,object> and it auto fills the class members and also does some data annotation. For example public class MyCustomOperation : Op...
When programming events in C#, it is advised to create a delegate in form of: delegate XEventHandler(object sender, XEventArgs e); My question is on the first argument of the delegate, object sender. Does it always have to be a generic object? Having a sender of type object always results in code similar to this. val ...
I tried to look into concurrent HashMap source code to look in to how it is implemented. To me it looked very difficult to understand((In no way i am saying its not required :))). I thought if i need to implement it myself and how should i go about it. Here is brief algo about it :- 1) Maintain a list of 16(Default) cu...
I have 4 types of users: Admins , normal user , company , service provider admins and normal user share some attributes (id .first name ,last name ,phone ,mail) company and service provider share some attributes too (id .company name ,phone ,fax ,mail ) and they interact too with other entities in application to acces...
I am trying to implement the 24 Game in ansi C. This game goes as follows: For a list of four given numbers, try to find a solution involving these four numbers, that, using addition(+), subtraction(-), multiplication(*) and division(/) ends up at 24. Each number can only appear once, but the order of the numbers might...
Suppose you have 3 classes: ClassA, ClassB and ClassC. Now suppose you have a class Message. You want a one-to-many relationship between each one of those three classes and the Message. The goal is that a Message must 'belong' to either a ClassA, ClassB or a ClassC object. A ClassA/ClassB/ClassC object can have zero or...
I have some computationally intensive functions in my python script that I would like to cache. I went looking for solutions on stack overflow and found lots of links: https://stackoverflow.com/questions/4431703/python-resettable-instance-method-memoization-decorator https://wiki.python.org/moin/PythonDecoratorLibrar...
Hello I am a student with no industry experience. My question may sound dumb, but, me and my friends were having discussions on use of DDL directly in programming language (any language may be Java, PHP etc), I wanted to know to is it a bad practice to use DDL commands (CREATE,ALTER,DROP tables) in a programming langua...
I am part of a team that develops and maintains a B2B web portal that had evolved over several years. We follow an agile development process. My department has plans for a major platform upgrade because of the non flexibility of the existing solution to our current needs and to conduct a POC for exploring the ideas. T...
I have my own knowledge graph representation, read from ConceptNet and NELL, containing tens of millions of nodes in which I want to calculate the nearest distance (if any) between two concept nodes. The application is to find out how two concepts are related in the simplest explainable way. Typical connectedness of th...
I very recently found out that VanillaJS (document?) is a library that's just bundled with 99% browsers and isn't exactly native JavaScript (shock of my life). While writing a lib of my own I normally avoid all helpful things, mostly libs. Now I have three questions: Is VanillaJS still considered a lib? Is there a way...
In small programming examples, it is established that one will probably use foo, bar, and/or baz as variable/function names. Are there accepted human names one can use? For example, if a program is sorting a list of people in alphabetical order, should I just use whatever names I think of?
I have a model class, let's say it's a Book. I need it to be displayed on the screen. I want to have an escaped version of it, so I do not need to escape fields manually. What should I do? I can add a wrapper over the Book that returns escaped values (e.g. EscapedBook); but every time when I change the book, i need to...
The mantra is to become a better software developer, write more software. However, are there activities I could partake in when I am not actually at the computer programming such as doing certain kinds of logic puzzles reading certain kinds of material doing mathematical problems on paper nurturing an artistic or mus...
What's the name for those diagram used to sketch the flow of a program? What are these sketches called? The shapes of the objects are by convention ellipse for an action, rhombus for a question, rectangle for a statement, etc.
We have an aggregate of: entity: Poll (representing a question) two or more value objects Choice Adding choices is done through Poll, repository stores only the aggregate, i.e. everything is done as expected. Now, I need to select specific Choice that user chose. From the UI I will have only the choiceId of selected ...
Let's start out with an example [1,1,1,5,3,1,1,2,78,2,3,1,1,...,1] As you can tell by the example, 1 is repeated a lot, but there will be outliers (like 78, and really anything that isn't 1). The catch to my question is, when I uncompress the numbers, they must retain the original order. The algorithms that I have fou...
I am looking to implement the callback pattern with error handling such that error is caught and pass to the callback code with the response. Since I am using .NET 3.5, I cant use Task (TAP) pattern which provides us with t.Result and t.Exception properties. I tried some googling for best practices and ended up with th...
I'm trying to design a generic interface for enumerating over a list files. Each iteration will open a file, allow the consuming code to access the file to perform some task, and then close the file. At first this seemed like like a simple enumeration pattern, but the consuming code actually needs to know the status of...
I am storing the data for my app in Google's NDB, but am confused as to what architecture to use. The app data is mostly text based, but has some non-text properties like DateTimeProperty, FloatProperty and one or two BooleanProperty's. I could store each property correctly (e.g. a datetime is stored as a DateTimePrope...
I'm working on a fairly large project that involves 3D drawing, and I want to add some visualizers (for example, to see the bounding boxes of the objects) to make debugging easier. However, I'm having a problem in deciding how to go about this. One option would be to create a public function to draw the visualizers, an...
I guess the title says it all. There is a debate at our firm, weather we should deploy internal jars, which are only going to be used in one specific project, to Nexus or is there any better solution? The argument for not deploying it to Nexus is that it will not be reused so there is no point in having it there.
This question is about the clock that keeps current time, not about the signal that sequences the circuitry (the wall clock, not the metronome). First computers were pure calculators, just very large, so I'm pretty sure they did not have system clock (simply because that's a lot of extra circuitry). Modern computers us...
I'm writing a neuron network simulation program and every operation or additional byte per neuron scales insanely. I prefer C++ as a language over the others, but now I'm wondering if the class structure takes additional space or resources after compilation in comparison to C for example. If I have a : class Neuron{ fl...
I was asked to calculate the running time of an algorithm which finds the square root and cube root of a given number. Is it possible to apply Master theorem with regards to this? First, I need to build the recursive relation to it. Recursive algorithm : (for square root) The cube root is also similar with slightest ...
I want to send information from one .Net application to multiple other .Net applications. I want the applications to be loosely coupled. The number of applications receiving the information could change at run time. What is the simplest way to do this? I thought about using MSMQ, but from what I can tell, there the br...
Consider a web application that works with somewhat sensitive data on reliable, high performance clients. The data needs to be processed and manipulated. So far I have learned that when possible, data processing should be a serverside concern because of the following reasons (amongst others) There is no data exposed t...
I'm using ASP.NET MVC 4 and SQL Server 2012. I have no problem going for either of these solutions but I want to know which one would fit better in the particular application I'm creating now. I'm making a sort of a library system application. The only images the application will store are: Users' profile pictures (...
I am tasked with creating a development, design and architecture guide for a large multi-year project. I have to dictate best design practices for a number of architectural perspectives. See the below diagram to demonstrate how I see this looking. So based on other architectural mandate, MQ based asynchronous servic...
I've started work on a large, open-source project recently. This project uses a mailing list for development, thus all patches must be mailed to this mailing list. This marks a change from my previous work where I used Gerrit or GitHub pull requests. One of the biggest issues I'm finding is how to collaborate on these ...
Let's say I have a Spring MVC project, in which I'm using DTO to get data from a database and to pass data to the UI. Let's suppose that I have a UserDTO and in my business layer I have to do something with that, but I need to put logic in the User and the DTO pattern says that no logic is allowed (or just simple logic...
I'd like to create a simple class property which can contain multiple values set from the outside. (Values are of the same type.) Example of property name and contained items: KnownHidScanners "\\?\ACPI#IDEA0100#4&b74a345&0#{884b96c3-56ef-11d1-bc8c-00a0c91405dd}" "\\?\HID#VID_045E&PID_071D&MI_00#9&e6a1767&0&0000#{884b...
I am trying to make a very simple todo list application with PHP, MySQL, Jquery templating and JSON... However, my schema seems to complicate things in JSON. What's the best way to do it? A new table for each list, containing the items. or a table for lists, and a table for items that are joined somehow? Because I ...
There are different conventions of representing the new line character in different types of OSes. Does the newline convention have nothing to do with what encoding is used? Is the newline convention not part of any(most) encoding method (e.g. ASCII, utf8, cp1253, ...)?
I have a flat file (CSV) that brings me the data I want, but it needs to be cleaned and processed before it can be used, so I built an intermediate Database (MySQL) in order to get the structure from flat file as I want and like I want (cleaned and formated)... so then I use that data and insert into a CMS. This proces...
Question: I would like to set forth dependency mapping from a *.config file from a project that has no reference to the project that contains the concrete class. Scenario: I'll be using terms from C#, Microsoft Unity and Visual Studio: I've got a presentation layer with a web service project and a winform project, an i...
I'm too often facing situations where I need to get several types of information from a method. I usually think long and hard to circumvent these situations but I'm thinking it's pointless work that I'm doing. My question: should I prefer to take a slight performance hit in these situations, like iterating over an arra...
I'm trying to better organize my application architecture, so I've been doing some reading, but I keep running into references to "Business Logic" and "Business Rules". I've never really understood what these actually are. I generally just focus on Use Cases and "User Stories". Could someone explain what Business Logic...
I'm working on developing a personal finance applications (e.g. Quicken/Mint.com/etc..). I plan to store the data in a SQLite database. I'm stuck trying to determine how I want to represent splits in the database. Each transaction will be assigned a category such as "Food and Dinning" or "Rent". However, a single trans...
This might be silly, but: let's say I want to delete a Book from the repo. Should I: deleteBook(bookId) - send the ID since in the most of the time, the ID is passed from the UI or deleteBook(Book) - but then I need to fetch the book first? And this would be just a shortcut for above: deleteBook(book.getId()). My g...
Lately I've discovered that the latex and pdftex (with some other one) binaries in Ubuntu are the same: lrwxrwxrwx 1 root root 6 лип 29 18:03 latex -> pdftex* lrwxrwxrwx 1 root root 6 лип 29 18:03 pdflatex -> pdftex* lrwxrwxrwx 1 root root 6 лип 17 20:22 pdfcslatex -> pdftex* Executing al...
I am using MVP for creating an android application, which takes data from server and sets to activity. I am forced to create one presenter for each view. Each view is unique because each view has different textviews/labels. The presenter will read values from model and call setter method for each control in view. For...
In my project, I have several types of Web API controllers (and their corresponding services and repositories). When I started out, I made an interface of a generic type that would describe the basic functionality every controller/service/repository should have. Since then, there have been new types of entities that th...
I'm implementing classes for simulating and generating different kind of automata. I'd prefer to use the same State and Transition classes for all the automata: NFA, DFA, PDA, etc. For a PDA a transition from one state to another work require some sort of an extension, because the transition requires to pop something f...
If I have the following relation R = (A, B, C, D) And the functional dependencies: A -> B, B -> A, CDB -> A, CDA -> B The candidate keys are CDA and CDB. The third normal form says that there can not be a functional dependency between non-prime attributes. A non-prime attribute is an attribute that doesn't occur...
My company is going through an agile rollout and is currently considering options for what that means. The ScrumMaster role is somewhat straightforward, but Product Owner has many candidates: Product Managers, UX, Software Analysts. The favored candidate for the moment is for each development manager to be the team Pr...
Let's say we have Book entity in our library. A requirement says: Librarian may disable 'available' flag to books published before some year. For example, librarian may 'hide' some old books from being publicly available as they are rare. This behavior is easily done with single SQL command. The method name for this ...
I am trying to model a business transaction that operates on two aggregates. Let's say we have a Bag aggregate type that contains Items (entities). I would like to have a command TransferItemToBag(itemName: String, fromBag: BagId, toBag: BagId) which extracts an item from the first Bag and puts it to the second one. Wh...
Our domain is operated within certain context. This context is described by some additional values, like a fooId - id that does not have a meaning in domain business, but it's more a flavor for the whole application and modules. I need to store this fooId with entities, like Book. But I do not want Book to have this id...
I've been reading up about Model View Controller, Model View Presenter, Model View ViewModel, and so on, and generally, the underlying concept seems pretty simple to understand: keep the pretty visuals and sciencey guts as separate and ignorant of each other as possible. No getting the logic peanut butter in the design...
I am working on building a Windows application that will require a connection to at least two different Microsoft SQL Server databases (for example, a source and a target), which may or may not be on the same server. So, in the application settings, I would like the user to be able to specify both the server(s) involve...
I have pseudo-ownership of a fairly old db (original data from 30 years ago; current design is >15 years old). In my opinion, the schema is pretty broken, and one of the implications of this is that there are a lot of inconsistencies/issues with the data. I'm planning to write a new schema and port the data across, whi...
I have a hierarchy of objects, mostly connected by composition. I.e. (not showing the class methods for readability): class A {} class B {A a;} class C {B b;} etc... class Z {Y y;} class Z provides the API for executing commands from another program - a control panel. I think this is called Chain of Responsibility, bu...
In this talk, Rich Hickey introduces Clojure. He gives an Ants demo and talks about his motivations for implementing a Software Transactional Memory (STM) system. His reasoning for STM is that "locks are hard to reason about". I took that to mean that the deadlock situation, where two threads are trying to update th...
I recently failed three projects with a similar pattern: I had to work on each of them alone With time I started to take the project too personally, like it is my spiritual child, and I tried to make it perfect Soon my progress slowed to a halt, and effected everyone, which in turn made me feel more guilty and desired...
Let's start with an example: we have an entity: Book. It has unique identity: Isbn - a value object that wraps a String. This is an UUID. The Book entity also needs a surrogate id from the repo (sql db). We need it so we can e.g. find the books in faster way, since databases find by number faster then by string. From w...
On page 382 of this book there is a passage talking about using value objects in aggregates, under the (entity) root. There is an example of Product that, besides other values, contains a Set<ProductBacklogItem> - collection of entities. Now, Vernon tries to explain why ProductBacklogItem is an entity and not a value o...
I'm developing an object model that has lots of different parent/child classes. Each child object has a reference to its parent object. I can think of (and have tried) several ways to initialize the parent reference, but I find significant drawbacks to each approach. Given the approaches described below which is bes...
My first introduction to programming was Java, which was horrible so I learnt Actionscript3 which was nice... "The point is" OOP was my introduction to programming where by I went on to gain a career in PHP and while I can confidently write programs/scripts in imperative languages I am no where near as comfortable in ...
I have one service method that receive parameters as a Map. I will need to add new attributes to this map inside the service. If I pass the original Map object to the parameter instead of a copy, the original parameters object will be changed. My question here is: which class is responsible for maintain the integrity o...
The following extension method was set up in some code I maintain. public static Int32 GetInt32(this System.Data.Common.DbDataReader reader, string name) { return reader.GetInt32(reader.GetOrdinal(name)); } Which is then called like this: int field1 = dr.GetInt32("field1"); Is this really any better than just cast...
Let's take an example: we have two related entities, like Question and Choice. This is a poll: it contains of single question that may have 2 or more choices. Each choice can be voted for by users, each vote is stored. Obviously, on paper, Question would contain a collection of Choices. And probably we would have somet...
I have a blackbox system whose code is hidden from the end user. That's the intent anyway, I know some may break into it, but generally it's closed. It's running on PHP, and I need to export a database for backup purposes. This database contains some data I don't want the user to tamper with, so the idea is obvious - e...
I just read that in XP, tests are written before code. Scrum is a different Agile Methodology but does scrum also involve writing tests before code?
I'm developing an object model that has lots of different parent/child classes. Each child object has a reference to its parent object. I can think of (and have tried) several ways to initialize the parent reference, but I find significant drawbacks to each approach. Given the approaches described below which is bes...
Say I have a C/C++ software licensed under GPL that gets converted into hardware design. By this conversion I mean that the exact functionality of the original software is being programmed into an FPGA. Does the resulting software that will load into an FPGA to make it work classify as a derivative work of the original...
I did some research before posting this question. Among other questions or post, one of those is provided below. I could not get a clear mind how to determine.. Business Objects within a Data Access Layer I have a Repository and the Business Layers call the repository to retrieve the data. For example, say I have the f...
I want to generate a 6 digits serial number, ranged from A-Z (only uppercase allow), e.g. serial = "ABCDEF" the problem is, some letters are considered confusing to others letters/numbers, e.g. U <-> V O <-> 0 (number) I <-> 1 (number) So, are there any existing set of safe letters can be used as seed to generate a s...
I would like to ask you about optimizing reduce operations (e.g. count) on multiple databases. Let's say there is a user table that is stored in various countries and sharding is made based on the country field of the entity row. Think this as a situation where sharding and replication can occur so same record may exis...
Does any Continuous Integration system out there offer building a project on several operating systems at the same time? Like, building the code on Windows, Linux, *BSD and OSX per commit? I understand that most CI systems are "cross-platform" but that could either mean the above or it could also mean that you need a d...
Is there a specific term (name of a "metric") that represents the growing level of unstructuredness (or just plain badness) of a s/w component that is caused by too many changes, by too many people, over too long a time interval?
UPDATE: an issue would arise from stuff that is not strictly defined by a formatter, like consecutive empty lines etc., that would get lost in the process (local to server to local reformatting) which would annoy people (me as well :) I'm used to adopting some shared code formatter so my question is not about "should I...
I'm experimenting a bit in C and I'm trying to implement my own Reference Counting System. I've mainly worked with Objective-C in the past but AFAIK autoreleasing objects is something that is unique to Objective-C. The problem with reference counting is that, when returning objects from methods, there is no correct way...
I think I have came across a few times when I reformat some segment of code, it performed the way I wanted it to other than the other poorly formatted segment of code? Does code format affect performance? Or is that a myth?
I am implementing a RESTful web service and one of the available actions will be reload. It will be used to reload configurations, cache, etc. We started with a simple GET to an URI like this: ${path}/cache/reload (no parameters are passed, only the URI is called). I am aware that data should not be modified with a GET...
I was just going over some kernel code, I noticed that rb->__rb_parent_color = (unsigned long)p | color; is kinda wired. The first field of a struct is accessed by casting the pointer and not by using the field name. Here is the definition of that struct, as you can see the color is the first attribute, so simply casti...
I'm developing a language like Vala and OOC that compiles back to C. This means that, eventually, every feature needs to be adoptable to C code in some way or another. Generics is one of the features I'd like to implement in my language. As you probably know, C is a strictly typed language. Except for the opaque void p...