instruction
stringlengths
34
19.9k
I'm trying to understand the three phase commit protocol by reading the wiki page (http://en.wikipedia.org/wiki/Three-phase_commit_protocol#Motivation). In the description for the diagram I posted below, it says the following: "If the coordinator succeeds in the prepared state, it will move to the commit state. However...
My team and I are making a game to support multiple languages, and we want to work on localizing the game to reach a wider audience. Where would I start? How would this be accomplished? I would work on providing different scripts with multiple languages and there would be more than one language to translate to. What ar...
I use Unit of work pattern to commit all new, dirty, deleted entities to the DB (using a db_mapper). Example of entities are: Student and Class So Student->registerDirty() will add this entity to the dirty pool that will be saved to the DB when commit() will be called. My problem is that Student can also hold collectio...
I would like to ask a few questions about software licenses, with regards to a (Java) program I am making. I am very very new to licenses, so please bear with me. 1. If I produce a Java program using 'internal' libraries (such as JavaFX), am I allowed to sell my program? Do I need to include (distribute) my source code...
I've been reading a lot about unit testing recently and there seems to be a debate online about whether private methods should be tested or not. If I have an interface that exposes one method, but that method is quite complex and calls multiple other private methods and also makes use of other objects, how do I go abo...
I am building an API that will utilize access tokens so that I can track usage among various departments and for access control. My plan is to utilize the HTTP verbs appropriately - GET will retrieve information, POST will add, DELETE will delete, etc. My question is, how should I handle access tokens on the GET calls?...
I'm 15 and have been programming for about 3-4 years. I mostly program in Java as it was my first language. I would like to be a programmer when I'm older, but I'm not sure about the differences. I've used a website, named hackerrank.com, and struggled immensely on the EASY questions. I can program games, applications,...
I try to implement a PriorityQueue with C#: public class PriorityQueue<T> : Heap<T> where T : IComparable<T> { ... } The Heap is abstract. I have MinHeap and MaxHeap that are derived from Heap. public abstract class Heap<T> where T : IComp ... public class MinHeap<T> : Heap<T> ... public class MaxHeap<T> : Heap<T>...
I have a project that I'm working on currently using Tomcat, Spring 4, Spring Security, MySQL, and JPA w/ Hibernate. I picked JPA from the standpoint that it's suppose to make swapping out the underlying implementation of ORM providers seamless, or at least less painful. I would say that this is mentally using the spe...
To get some practice in C, I'm writing some basic functions for operating on a linked list of ints. I started out with functions that accepted as a "list" a pointer to the head node. Now, I find myself running into more and more occasions when I either need to limit the spec of the function more than I would like, or I...
I've been reading about 3PC in a text book, but there aren't any diagrams or examples, so I found one on wikipedia that I posted below. My question is, what does it mean by "cohorts?" There is no mention of cohorts in the textbook and I don't see anywhere in the wiki page explaining what it is. Is it simply another wor...
I'm working on a simple bytecode interpreter to learn how virtual machines work. I've read about VMs and it seems that all of them are either stack based or register based. At the time it made sense, but then I started working on my interpreter and realized what am I doing? (I decided on a register machine.) I'm just l...
In my project I have an object Player (attr example: pl_id, pl_data1) that is one of these types: Its GoalKeeper (attr example: gk_data1) OR Defender (attr example: df_data1) OR Forward (attr example: fw_data1) In mapping this objects to database : Option 1: Make a Table Player with columns (pl_id,pl_data1,gk_data1,...
I am a backend developer and always create tests for my applications. Recently I study and apply the interface tests (using selenium), but I doubted whether I who should create these tests, developer or QA? How can we decide if automated interface testing should be QA responsibility, or Developer responsibility, or b...
I need to represent a directed rooted tree in memory. What would be a good data structure and algorithms for performing main actions, given the particulars listed below? Size: ~40,000 nodes. But ideally should scale well to 10x the size or more. Arity: Very variable. Some nodes have 2-3 children. Some have 10. Some (r...
I am reading the Bloom Filter implementation written in ruby. It should have k hash functions, but it looks like the same hash function is being used with different seed values. Is this a common way to implement this Data Structure, or is this just an exercise in this case? https://github.com/igrigorik/bloomfilter-rb/b...
I need to represent a directed rooted tree in memory. The caveat is, that nodes have properties. And those properties are inherited (but not 100%) by the child nodes, recursively. What would be a good data structure and algorithms for storing this in memory? For the purposes of notation: D(V) - depth of the vertex (d...
I am kinda trying to implement a windowing library in C++, the circumstances are forcing me to implement it all myself, that's not the point of this question however. My question is: What should be in a PIMPL class? What attributes, to be more accurate. For instance, as I stated yet, I am implementing an windowing lib...
I'm sure I'll botch some of the specific terminology, but what is the difference between object and object2 in this implementation? Is the only purpose of the first method (prototyping the class's function by the same name of the class) just to save typing? At the end of the code, does object==object2? //first method c...
I have a form that writes to a database. Other than creating a class handle an external API, this project is done. However, the processing script is your standard procedural calling of queries using a Database class. Is there any benefit to creating a class to model the data for the processing?
I'm sorry in advance if this isn't a good fit here, as it is a pretty open-ended question. In a nutshell: where / how / when does one learn about application architecture(s)? Normally for web applications there are several layers to the stack, generally starting with a reverse proxy or load balancer and "ending" with...
If a feature is not supported on a platform natively what would a programmer do? For example, when building an iphone app, if you are trying to slide a picture(just as an example- I know you can slide a picture) and it's not supported natively. What would a programmer do? Same thing with a programming language. If some...
This seems extremely basic, but I've read a lot of related questions and haven't found a proper answer. Using Ruby on Rails or other similar MVC framework, how am I supposed to load data that is displayed in sidebars on multiple pages? Options I know of, with the problems I see: Load it in every controller method that...
What should be taken into account when choosing between desktop and web as a platform for a new application? There are definitely a lot of arguments for both platforms but what are the most important to consider? For example: I think that it is easier to develop a desktop application; On the other hand it is much easi...
First of all, apologies if this is posted in the wrong site. I thought it is more suitable here than SO because the question is quite generic, more an algorithm question than a specific programming question. Now, let me describe the scenario: I have a cloud server that, due to some requirements, has to connect to anoth...
I have a lot of confusion about Java's CopyOnWriteArrayist. I know, when we have a modification on it like update, insert of set, it will lock the whole list, copy out a total copy of the source list, do the modification and then release the lock. So, My question is: When doing the modification, why cannot we just loc...
I was reading the following code listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(getApplicationContext(), "Click ListItem Number " + position, Toast.LENGTH_LONG) .show(); } ...
I'm currently building a server responsible of storing and managing few million records of fairly complex and interconnected data. For reasons beyond my control the work has to be done with C++. I have my concerns about error handling and especially pointer safety. Dereferencing a null pointer can cause the entire serv...
Actually i'm using this project directory structure http://framework.zend.com/manual/1.12/en/project-structure.project.html But recently i started using namespaces in all my php-classes like: Myapp\Configuration\ Myapp\Controller\ Myapp\Persistence\Entities\ Myapp\Persistence\Dao\ Myapp\Validation .... and now I'm a ...
Lets say I have the following function with a docstring: def foo(*args): """ do some fooness +----------------------------+----------------------------------------------------+ | kind | ndb property | +============================+========...
I am currently trying to come up with an algoritm which would take at least two numbers (say user IDs) and then come up with an unique number which is generated based on these two numbers. Each integer can be as big as an INT(11) in a Database (a number with 11 digits) Example: User A (with ID:23, would like to intera...
I have an app that wasn't written by myself. If there is an error such as an invalid ID given as a parameter, I would return something like: (200 code) { "success": 0, "error": "The row could not be found in the database" } ...but the person who wrote the application done it like so: (404 code) The row could n...
So, quite often I'll come across a situation where I'd like to process hostnames in a hierarchical manner. For example, given a hostname "foo.bar.baz.example.com", I might want to compare it against a data structure that contains a higher authority like "example.com" or "baz.example.com" and see if I get a match. Usual...
What is a good limit to use on the quantity of files in a directory, and why? EDIT: Why shouldn't someone create a system that puts hundreds of thousands of files in the same directory? Why I ask: Someone set up a system that dumps files in a folder with a human readable date-time. My task it to create a system that ge...
Here is a simplified requirement: User creates a Question with multiple Answers. Question must have at least one Answer. Clarification: think Question and Answer as in a test: there is one question, but several answers, where few may be correct. User is the actor who is preparing this test, hence he creates question a...
While investigating the accuracy of floating point numbers, I've seen in a few places a statement similar to "float and double are (designed for/used often in) engineering and scientific calculation" From my understanding, the strength of floats and doubles are the amount of memory they use for their (good, but not pe...
We are giving services a complete overhaul at work: Swapping soap for rest, resculpting the domains to give better separation of concerns, etc. These new services will be publicly available. During one of our on-going conversations to refine our architectural vision, the idea of a "Composite API" was introduced. I am h...
Several years ago I wrote a desktop application, a small accounting system, in Delphi 7, that is in user in a medium-sized company. The code belongs to me. I ported another Accounting system that I had built years before (Delphi/IB), to use SQL Server and added new business rules, in my free time, then I gave the appli...
I have a plain text file with some data that I can't change, so I have to create a datastructure to use in reading the file and with that datastructure do some thousands of interactions. The file follows a defined pattern like this: AAAAAA:zz_something sometxt1 sometxt2 AAAAAA:zz_something sometxt1 sometxt2 AAAAAA:zz_...
Background: I have a C application running under Linux utilizing shared memory. I also have a debugger written in Python that can link to said shared memory and access individual variable values of global scope. Question: How can I develop a local browser-based application/page that, via my Python process, I can connec...
As an example for this question, consider a content management system that has a content database table which contains things like the page title and location as well as the content itself which could be quite a large amount of text. There is a second database table with details of resources (such as images and files) ...
I read that Scrum meetings should be less than 15 minutes long. Is this how long they usually are, or do they depend on the size of the development team? Must every team member speak in these?
Do methods (and their variables) that belong to an object instance go on the stack or the heap? Ex Main() { Myclass Myobj = new Myclass(); Myobj.Doit(); } class Myclass { Void Doit() { Int myint = 5; } } I use c# primarily, but I assume the answer is language agnostic.
I'm growing my understanding of event sourcing. My understanding is that it provides a means of recording events as they happen so that given a common beginning state and an audit log of recorded events, the events can be replayed to achieve the same final state. I know that sometimes events are triggered by other eve...
Most of the companies that offer public api these days do it through a web service. What was used before web services were popular? For example, if a company wanted to release a c# public api would it have release the dll files implementing a remote database connection? Or did they do something different from my assump...
Update: I edited my question to make my intentions more clear. So I think this question about logging will be different to the often asked questions. First things first: I have an application that is doing some stuff. While the stuff is beeing done, some situations can occur where the application has to give notice to ...
Previously while working on database in asp.net I was using stored procedure with no tier architecture. So I was including connection string, crud query etc in every button click event. Then I was told to use three tier architecture. I googled some way and found not so convincing answers. Help me find a proper one, the...
I have a list of doubles that need to be sorted and changed so that there are no two numbers that are the same (difference smaller then 0.05) and I need to do it fast. I don't care about preserving order for values that are the same. What I'm doing right now is: List<double> values; bool sortfunction(double a, double ...
I'm working on a calendar project, on my own. In this project I've to use Swiss Ephemeris. It is licensed under GPLv2 and commercial. With commercial version of license, developers entitled to distribute the software, as his/her wish. But as this is my personal project, I've to use the GPLv2 license. By using the libra...
I'm looking to transfer the ipaddress for my site from one ip address to another. Reading through the Register.com documentation it says that it may take awhile for the DNS changes to replicate/propogate. Since this transition includes a different sql database, how do I force the update so I don't lose any data that ma...
I am currently implementing an AngularJS directive. It is fundamentally a reusable widget comprised of a select box and a table which populates based on the item in the select box. My point of contention is whether or not I should inject a data dependency into the directive so that the directive can initalize itself f...
I am wondering which principle should I use. Here is my situation. I have a class named TravelOffer. This class looks like this: public class TravelOffer { private final long id; private final StartZone startZone; private final EndZone endZone; private final List<Waypoint> waypoints; private final...
So I have different seniors taking different positions on this. Some saying hide nothing, those codes are there for a reason. Others saying to hide most status codes, reducing the number to a much smaller group (like only 400 and 404). Even RFC 2616 suggests a few substitutions are allowed (403 being treated as a 40...
I'm writing a report generator for an automation tool. Right now I have a report template html file which is read by the generator and the results are filled in by the tool to be written to another html file. I suppose the benefit of using the <style type="text/css"> tag inside the html file would be that the report ca...
I don't know much about migrations, but this is a specific question I'm not sure how to answer. In production, how can one change the database format/schema when there is already user data in there? (Is the answer different for our Meteor app on MongoDB vs our master Postgres database?) Basically, if you write new code...
I am tasked with designing an application framework that will allow each implementation to customize parts of the user interface. One such example would be that the implementation (let's call it client from now on) can define the collection view cells to return for a particular screen. The framework is simply responsib...
I've got a python script, which should read a subdirectory and make all the scripts within it callable like this: python mainscript.py subscript arguments I've figured out most of the details but I'm having a lot of trouble deciding on how to export an API (object or selected functions) to subscripts that mainscript i...
I have an array of strings ["abb", "bbxxaa"]. I would like to print all characters that occur equal times in each index so in above case I would print bb because they occur twice in both indexes and a occurs once and twice in first and second index respectively. My approach: Keep track of only the characters in the fi...
It's preferable to write programs that depend on interfaces rather than on superclasses, but what if you want a class to have certain variables? Sometimes you want a class to implement a certain variable. (For example, imagine you have a datasource interface, and want all classes to implement a "String user"). In this ...
I have three layer Spring web app: dao, service and controllers. A controller never calls directly the dao, it does it through the service layer. Right now, most of the time if there is dao exception (runtime) that is not handled, it'll be caught by a JSP showing an error message to the end user. Should service layer...
I have a log-in service that runs a CPU-intensive hash multiple times when a user logs in. In order to reduce the effect of a login DDOS, is there any sort of function that I can "ask" that the client to run that would be somewhat CPU heavy and verify it's result (via a light-weight operation), prior to running my pass...
It's a "how decompiler prevent decompile itself" question. I have tried : rename the Mach-O 64-bit executable x86_64 file remove the LC_UUID and LC_SIGNITURE load commands but somehow hopper can still identify itself, saying You are not allowed to disassemble this program with Hopper. anyone knows the trick?
I have been Googling my problem but haven't been able to come up with anything; here's the situation: I have a PHP / MySQL website hosted with 1and1.com. I also have a Python program that runs on a desktop computer I own. I want users to be able to submit files and modify personal information on the website and then h...
I will try to explain my question with an example. Let us say that we are writing a hotel reservation system which is web based using Java. We will have different payment methods, say Paypal, Master Card and Visa Card. Different customers of our product will use different payment methods only. (Hotel XYZ, who is our cu...
I have little experience with unit testing, but at the project we're working on right now we decided to do unit testing. The project is a WPF/Entity Framework application, and the part I'm being confused about is a filter function. Our universe of entities is like this: there are Products, Evaluations and Collections. ...
I'm using Entity Framework Code First with ASP.NET MVC. This handles my database design based on the domain models within my application. As it stands, the engine I'm writing will have a website class and store class. store is a property of website linked by a ForeignKey in the database. I want to implement some option...
I was reading an article about bad programming practices. It mentioned - "Yo-Yo code" that converts a value into a different representation, then converts it back to where it started (eg: converting a decimal into a string and then back into a decimal, or padding a string and then trimming it) I don't understand why ...
I have some questions about spring's initialization in different environment. 1. In web container context, such as tomcat. I knew that spring can be initialized by declaring org.springframework.web.context.ContextLoaderListener in <listener-class> field. It will be initialized automatically when tomcat is started. (I...
I am going to be working with VSS but I am much more productive and diligent with GIT. I have to fit within the workflow of VSS and keep good history in VSS. The standard work flow here with VSS is get working copy do work right click on folder -> show differences in that view: checkout (without overwriting local c...
I have my own company, and I would like to release our customer management system as open source so everybody can see what we do. But it is very important to me that I don't want anyone else to use or modify the software. My idea is to modify the MIT license, because it is simple to understand. But I am not sure about ...
There are times when an enum's values are important: it is not necessary for them to be unique, they also need to have specific values. In such cases, should the values be explicitly defined, even if they coincide with the defaults? An example: enum Car { DeLorean = 0, Lada = 1 }; Imagine that for whatever rea...
I have built a PDO adapter class because I thought, at the time anyway, it would be a good idea. After fighting with it, it makes no sense to me. Isn't the design of PDO the way it is to keep you from having to create special adapters for a given database? For a connection, I understand, but I seem to be replacing PD...
I'd like to understand how (modern) filesystems are implemented and having trouble to fully understand superblocks and their backups. I reference ext4 and btrfs, but the questions may also apply to other filesystems. Ext4 stores a couple of superblocks (my fs for example has one primary and seven backup SBs). I do und...
I am programming in Python. I have several complicated/hard-to-understand XML files that describe the structure of an election. I am trying to write a python wrapper that makes it easy to access this data. The structure of the entities I am trying to model is: there is an election. Elections have races. Races consist ...
I'm building a roulette game for fun, and the game will use a RESTful API. I'm building out the functionality for spinning the roulette wheel. I'm using MongoDB and have a collection for players _id username balance games _id game_name last_bet_at created_at last_logged_in_at created_at and another col...
If given a list of players, their salaries, and their projections, one can easily find the top 'n' projected teams (where a team is a combination of players), such that every team is under the salary cap. Yet, these teams will share very similar rosters. Is there an algorithm that will diversify the solution set, while...
From the technical point of view it is possible to add some pre/post push hooks which will run unit tests before allowing some specific commit to be merged to remote default branch. My question is - is it better to keep unit tests in build pipeline (thus, introducing broken commits to repo) or it's better just not to ...
I come across these kinds of expressions and I have hard time reading it. How do you read it properly to see if it is the right logic when debugging. if (!(userLoggedIn || isAdmin)) { console.log('User does not have rights'); }
As both a C programmer and a C# programmer, one of the things I don't like about C# is how verbose math functions are. Every time you would have to use a Sin, cosine, or power function for example, you'd have to prepend the Math static class. This leads to very long code when the equation itself is pretty simple. The p...
I currently have an application that is used by a single end customer. For ease of discussion assume the application only needs a single database table for all records. I now need to support multi-tenancy and so in the future I will have about 500 customers using the same database server. 1) A possible solution is to h...
Breaking the build is a bad thing. Different teams take different measures to encourage their members to avoid breaking the build at all costs. Some measures are moderate. For example Joel Spolsky tells that his Excel team had a rule that “whoever broke the build had to babysit the builds until someone else broke it.”...
I would like some advice on how best to architect a website comprising the following: tool a landing page, open to the public, main marketing tool the main website/app, that people can access only if registered, where users can access certain modules depending on their level of registration (free/casual/premium user) ...
I've started learning BDD but I think I have some misunderstanding of how to use it correctly. Currently I'm writing an API for a product. This API will be used by other developers only. Is it ok to write features and scenarios from the developer point of view? Something like: Feature: Authorization In order to acc...
How to spawn multiple "monsters" from a single class? Can store it in an array, ok, but later on, how can I paint it? Because if I do: enemy = new Enemy(); enemy2 = new Enemy(); I create two instances of the object, but after how can I paint it? I use: g2d.drawImage(Enemy.getImage(), Enemy.getX(), Enemy.getY(), this);...
I was wondering about this. Suppose I have a user resource with id and name fields. If I want to update a field I could just do a PATCH request to the resource like this PATCH /users/42 {"name": "john doe"} And then the application will update user 42 name. But why if I repeat this request the outcome would be differ...
Let's say we have two kinds of resources, user and group. Every user can belong to multiple groups and each group can have many members. Thus I can model my API like this / |_ /users/{id} | |_ groups | |_ /groups/{id} |_ members Let's say our resources exposes only two actions. You could either add a user ...
I will bring a concrete case here. I have a project involving Sketch and Arduino. Since I was they only guy willing in the group, I had to take the Sketch part. The problem is that our informatics group is part of an bigger organisation, and the organisation doesn't allow us to take the Arduinos with us at home. We are...
I recently learned about unit tests and TDD and have started going back to add unit tests to my code (and thank god, it's proven that some things I've written are much more broken than I thought). That being said, I'm having a hard time figuring out how much (or little) should go into each test. For example, consider ...
I use spring-boot with spring xml in my project. I wrapper the DAOs in a DataAccessService class to serve as a DB service layer, both the service and the DAOs are injected in spring xml and used by Autowired. Now I want to have a XXXutils class to provide some static useful functions. Some of the functions need to acc...
I've seen conflicting definitions for the term "bandwidth preserving algorithms". The two definitions I've seen are: Any spare CPU capacity is used for aperiodic processes. One or more periodic processes are created to service aperiodic processes (with #1 above being called "slack stealing algorithms"). So, which is...
By now, most web containers have an annotation variant of their xml configurations for Java EE. I'm guessing this is because it's better to keep things in Java where they can be managed, coded with and controlled. The problem, however, still remains that with annotations you cannot efficiently debug and diagnose an iss...
To deal with transient overloads with a real-time system scheduled with rate-monotonic scheduling, one can use period transformation to reduce the period of important processes so that they have greater priority. In Scheduling Hard Real-Time Systems: a Review, A. Burns says (pages 4 to 5 of the PDF) that this can be do...
Context: I'm working on a database of museums and Categories will be one way the user will be able to search. e.g click on "Music" and a list of music related museums turn up. Pretty simple. Problem: I'm stuck and confused on the Normalisation process of the "Categories" table... categories_PK IF is the entry point t...
There are a number of programming languages available today. My question is given a specific job what is the criteria one should use to eliminate other programming language choices which serve the same purpose? What does one need to know about the language to say confidently that we are not going to use this language f...
I've been over Fielding's paper on REST and all over the web, including StackOverflow trying to understand this. After reading everything I can about REST, I was under the impression that Fielding based REST on top of HTTP, using it as a stepping stone. But then I go and read some people saying that REST actually does...
Rasterizing a polygon in this question consists of creating an array of binary pixels that "represent" the polygon. The reverse of this process is easy to approximate in linear time to the perimeter in pixels. It uses a "detail threshold" D to define how complex the polygon will be. As D decreases, the polygon becom...
I'm using C# for a several years, never actually willing (until I really need to) to dig into its "deep" mechanics and to intervene in GC work, IL-compiled code and so on. My point is if you ever need to even call GC manually (speaking general - to "help" C#'s or .NET's mechanics and frameworks to do their job), then i...
I'm only a beginner, and my book doesn't cover this subject. I have researched my problem and found that an implementation of the consumer-producer pattern is the ideal solution, and have Googled it, read what I could, tried to enact examples... but haven't been lucky. I would really appreciate a bit of guidance. I am ...
I'm a Java/C#/PHP developer, through my OOP programming experience I find myself asking the same question: Why static members can't be abstract and don't implement polymorphism especially in situations involving factory methods, for example: abstract class Resource { public void doSomething(); } abstract class Use...
In C++, when I declare an array like int array[10];, it sometimes uses memory assigned to other variable where as this problem is non-existent when I use an integer pointer and malloc to allocate memory to it. Why does this happen?