instruction
stringlengths
34
36.1k
Problem: A Hibernate bi-directional One-to-Many relationship does not map easily to JSON. If default (Jackson) mapping is used there is an infinite recursion issue as the parent contains the children each of which contains a reference to the parent. The easiest way I've found to fix this is to mark the Many end attribu...
I made an android application for the creation of personal timetables. I need two things for the user interface: The grades list and the student lists of the senior grades. To retrieve those, I made a java websocket from which I can get the list. Since I don't want everyone to get the student lists from my server, I se...
I've been reading up more on the Inversion of Control principle and Dependency Injection as an implementation of it and am pretty sure I understand it. It seems to be basically saying 'don't declare your class members' instantiations within the class'. Rather that the instantiations should be passed in and assigned thr...
This post teaches us to separate object graph construction from the application logic into two different classes and the end goal is to have either: classes with logic OR classes with “new” operators. Sounds really nice, as coming from this post you can understand that if you have started to do DI you should do it comp...
Lets say I use Dependency Injection and don't use a DI framework. So the injection is direct rather automatic. How I should handle the logger class? All the objects, (thousands) should have a Logger reference in their constructors? (We don't consider Singletons and Service Locater as they hide the dependency, and are p...
I'm writing a rest service. For each request I use about 4-8 queries. Should I try to refactor those into a single query?
I am building a security mechanism and I need a Pseudorandom functionality in my app. More particularly I need to convert a String to fix length. My strings are random already, they just to long so I want to convert them to fix size. A trivial solution(the one that I am using now) will be just cut the extra characters,...
If some model can only exist if set of values are passed to it and validation on them are performed, then how to load such a model if only one of those values is needed for some action? It seems a little overhead to do hydration of model all over again if only one value for action on that model is needed. That can be e...
In different forums, I have found the statement that in C++::stl, insert and find for unordered_map have guaranteed amortized time complexity O(1). This puzzles me, and I would like to see the official document (perhaps ISO) to see exactly what is being demanded. Could someone provide me with the link? Here is why I th...
Just to be clear, by authentication I don't mean user-authentication, but I want to make sure that my app is running on the customer's server and in a defined time-span. Some of our customers use our web apps in their Intranet and on their own servers, on the other hand some of them use Hosting services and they don't ...
I have to model a store with all kinds of articles. The user has to be able to filter these articles by type, price, ... . The store would contain a list of Article objects. I've been stuck on whether to implement the Article class with a type field or to subclass new articles from the Article class. Biggest problem I...
I know how code coverage works in general, and I know what branch coverage is. But I can not seem to find an explanation for how branch coverage handles loops. Does it work like path coverage? Where a loop which runs 10 times is a different path from the exact same loop running 11 times. Or would those two cases be the...
We're currently in the following situation, where a feature branch has been branched for a sub-feature branch (like, working on backend and frontend things for the same feature): o | o development |\ | o feature-a | | | o | |\ | | o feature-a-sub | | | | | | | \ | o merged feature-a into feature-a-sub | / o featur...
I am rather new to WCF (or rest, or Json for that matter) and I'd like to have some expert opinions on which methods to define. Some short introduction to give an idea of what the webservice should expose: I am building domotica software (software that can control a ZWave network) which has different interfaces (a GUI...
I am currently building a library in C++11, where I spent a lot of time trying to design a good interface. After some small redesigns along the way, I've ended up with a design that I am happy with. The main public interface only consists of two functions in a namespace (ignoring extra utility functions etc.). Later I ...
I have been working on a few algorithm questions the last few days, and one bubble sort problem in particular has been giving me headaches. for (k=1; k <= A.length - 1; k++) { //Line 1 for (m=1; m <= A.length - k; m++) { //Line 2 if (A[m-1] > A[m]) { //Line 3 Swap (A[m-1],...
I am writing a web service in Java which reads some information from a DB and generates multiple JSON files which are written to S3. For each type of file, I have a POJO which is serialized to JSON using jackson. The schema of the files can change over time - new fields can be added, existing fields can be removed etc....
Z = X ∨ Y (where X, Y, Z are 96bits binary numbers) If I have "Z" value and "Y" value. Are there any possibilities to retrieve "X" value from "Z"? What I know is it is possible to do this with XOR operator, but is it same with OR operator?
Java programmers know that new String("some-text") == new String("some-text") evaluates to false because two different objects/references are being compared [and that String.equals should be used to compare Strings instead]. So, can you think of any reasons why a person may want to see false for comparing different poi...
In light of the recent OBJ_obj2txt vulnerability in LibreSSL (which was found during the OpenSMTPD audit, and does not affect OpenSSL), it came to my attention that the memory leak issue likely resulted from some earlier code refactoring, where the block scoped variable char *bndec was moved out to be function scoped i...
I'm working on a project that requires several different users in the system, all of which have overlapping responsibilities; we've isolated two possible ways of tackling this problem, but we're unsure which of them are the most correct way of going about it. Option 1: Create a virtual super-class for all the user-clas...
I wonder if there is any reason to call the base constructor when inheriting from object. class Foo { public Foo() : base() // calling the Object constructor { // Foo construct here } } Is there a way to inject code into the base constructor? Object doesn't seem to have multiple constructo...
Ok, so in our 'innovation lab', there is currently a push to use Ionic, an hybrid app framework built on top of Cordova for native access and angularJS for the ‘web code’. There are also some projects which are pure mobile web, using Angular + bootstrap for responsive design for example. The thing is some projects co...
Hope this question is right here. TL;DR Database design for event places (venue and hotel), hotels can be venues. Long Version Introduction I'm developing a software for trainings. Trainings are like a template with information and events show time and place where a specific training will happen. Events have a place wh...
While understanding how yield keyword works, I came across link1 and link2 on StackOverflow which advocates the use of yield return while iterating over the DataReader and it suits my need as well. But It makes me wonder as what happens, if I use yield return as shown below and if I don't iterate through entire DataRea...
I tried writing UI unit tests for my GUI apps and I face the problem that, while they work well when I initially write them, they turn out to be brittle and they break whenever the design changes (that is, quite often). I'm struggling to find a set of guidelines that would lead me to having maintainable unit tests for ...
I have a method which implements a small section of a (complex) algorithm. This algorithm has taken me several weeks to perfect and is by far the fastest method I can find. The method in question has 3 levels of nested loops and each run of the innermost loop refines the values of 6 variables which in turn determine th...
I want to check group of algorithms which has up to 8 input options. The native idea would be to check all possibilities via brute force. How can I reduce it without leaving out required combinations? Since I do not know it better I'm using multiple loops which ends in worst case in a O(n8) complexity. To give a hint w...
My first programming language is python. And recently I'm learning C and javascript. In javascript, there is a design which confused me a lot, default the function isNaN. Put aside its weird exceptions in specification(Which is hard to find), such as isNaN(""), isNaN(["22"]). The more frustrating thing is that the resu...
Please suggest best design for accomodating different versions of configuration file(INI format) into a single file. My requirement is I have three different versions of a configuration say V1.config, V2.config, V3.config. The different versions needs to be supported. I would like to achieve a file V.config from which ...
I have the following code statement that calls a separate class. if (newOrEdit.Equals("New")) { try { BusinessLayer.InsertOperator(operatorDetails); } catch (Exception) { MessageBox.Show("Error unable to insert details."); } } This calls a simple method that tries to insert the...
I have an odd conceptual question, It's not about a specific incident, just a general best-practices approach. I have asked myself on occasion when defining java Equal methods, what makes two objects equal. The simple approach is to check rather every field is equal, however, there are occasions when this isn't alwa...
I have a massive library written in C++ that handles a lot of mathematical operations, using C++ makes it fast and in all honesty, I don't want to re-write the whole functionality. I am thinking about opening this library up to other, web languages (Such as PHP) and will pass the data between the two using JSON. The i...
There are many different types of charts and diagrams we use to formalize scenarios and study them tangibly -- activity diagrams, sequence diagrams, etc. I've been faced with a pretty complex locking scenario and I'd like to try and bring all the information together into one diagram so I can explain it (to others and ...
Background: My bosses want to merge two application that have two separate purposes. One being for monitoring of equipment and bandwidth for our internal network operations. The other is an application to view similar data just less granular and with less detail. This second application has to also perform tasks such ...
I need to redesign distributed Publish-Subscribe solution in our product. Problem description We have several producers (NT service), queues (MSMQ) and consumers (IIS server). Task handling requires access to the MSSQL DB. There are two types of tasks in the system: ad-hoc tasks, pushed to the queue by ongoing flows. ...
I have two threads, one that is reading messages from the web and putting them into some sort of a queue. The other is suppose to read it. I looked into a ConcurrentLinkedQueue and it looks good for my purpose. But when I was scanning through the documentation I see this: " A ConcurrentLinkedQueue is an appropriate cho...
How do I implement REST service description in a Content-type agnostic way? Background I am developing a RESTful API for Web Application. Now this app is somewhat different than a standard run-of-mills solution. This app uses a SIP B2BUA (asterisk), PHP+Mysql on Apache & NodeJS. It is a call center solution that uses a...
I'm building a rather large (web) application where I'm using Entity Framework to communicate with the database. My solution is set up in layers like so: Client Website (MVC web application) Server BusinessLogic (contains, well, business logic. There's a lot of business rules involved in this project) Repository ...
I want to confirm the right approach of using try-catch exception handler. I have written a query in a try block, and if any exception is thrown, it will execute a query in a catch block. Is this the right way? try { $query->fieldOrderBy($column_name, 'value', $sv1); } catch (Exception $ex) { if (!empty($ex)) {...
I'm working on a solution that should work in C++-Builder and Delphi, that's why I use Object Pascal syntax, but I'm not very familiar with it. I try to access a file mapping with a size that is not defined at runtime with Free Pascal/Delphi. I tried type TFileMappingLayout = packed record Size: DWORD; Data: ...
I have a basic Database class, and it has a mysqli property (an object itself) which contains the connection information. Other classes uses this class to read and manipulate the database. There are built-in functions in any database connection object (in this case, PHP's mysqli::multi_query, mysqli::next_result etc.),...
Recently, I started to use TDD. It's really cool and fun but creating expected object for assertEquals is very boring and tedious. At the moment I see only two way for that: Straightforward Creating object in code using million of setters. Using that approach greater part of tests is creating expected object. I think i...
In sut I should I have two kinds of dependencies to be stubbed: 3rd party dependencies (mongodb & co) and own dependencies: var async = require('async'), // This dependency should not be stubbed mongodb = require('mongodb'), // 3rd party dependency, should be stubbed myOwnDependency = require('../my/ownDependen...
I've read up on the theory/reasoning behind a swap chain in Graphics. Everywhere I've read, they talk about pointers to the front and backbuffer(s) which are swapped instead of actual data exchange. My question is, where exactly can we see this swapping? is it in some function? is it automatic? if it's automatic, where...
PHP allows you to increment strings. Why? Let's jump ahead a bit. Take the following code: $string = '9ZzZ'; echo ++$string; // 10AaA From a purist point of view this may seem like nonsense, however, you can see there is clearly a pattern here. Each column is treated as a set, (numbers, uppercase letters, lowercase le...
I have a client that is looking to get a website/mobile apps/desktop apps built that deal with very sensitive data (more sensitive than bank/card details). Because of the sensitive nature of the data, they do not want to save it in a central database but they still want their apps to synchronise (let's say I add some d...
I am using Dependency Injection for a .NET MVC web application in which I have three basic layers: 1) Web App 2) Service Layer 3) Data Layer I inject the data layer into the service layer and the service layer into a controller in my web app which is all fine but I am confused over where the registering of these classe...
I am having some trouble writing a variant of sub-string search. Essentially the goal is to write a method that can perform sub-string search except that the source data is in an array of Strings rather the one String. I have looked around and can't find anyone who has managed to solve this elegantly. Consider some inp...
User can create a box with text inside. When a box is created it will have a key (UUID) assigned. This key is then will be sent to recipient. When recipient activates the key, he receives a text inside corresponding box to email. So given this requirements I found 2 aggregate roots: Box and Key Here is a box creation f...
In Run Length Encoding (RLE), a large set of information is encoded by storing the quantity of consecutive sequences. A canonical example is: WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW Becomes 12W1B12W3B24W1B14W I'm using an algorithm that is similar, but slightly different. The data to enco...
I have built quite big WinForms application working in industry for a few years. It communicates with many HW devices. Application can be configured to use or not use some of these devices and GUI is modified by this configuration. Now, even more devices (and application possible configurations) are going to be added, ...
I am new to Akka and actor framework - I am sure I am missing something obvious, please accept my apologies in advance. I keep reading that one of the main points to choose Akka is the way it manages concurrency. It is not clear to me why Akka is so special; I understand that there are many little actors which are ver...
Algorithms class was a such a long time ago and I can't remember the name of the algorithm to balance an acyclic graph. Let's start with a graph that looks like this: 1 | 2 | 3 / \ 4 7 / \ | 5 6 8 The solution to balancing this out would be: ...
I am working with a new codebase that makes heavy use of async/await. Most of the people on my team are also fairly new to async/await. We generally tend to hold to Best Practices as Specified by Microsoft, but generally need our context to flow through the async call and are working with libraries that don't Configure...
When trying to follow the the gitflow model, we have a branch for the releases. However, we've had complicated merges when trying to merge from develop and bugs have crept in to that branch from this. What are we doing wrong and how do we keep these merge bugs from showing up? Our git tree looks like: d r m | | | ...
I have a set information that I am able to read in as raw data which corresponds to different physical quantities depending on which device provided that information. Every device contains the same amount of data and the same types, just different fields are interpreted differently. Here's how I have implemented it so ...
Hey there I'm not new to programming nor javascript but I'm new to the object oriented world of javascript as it differs from languages I know such as java, c# when it comes to object oriented apsects. Basically I'd like to know is this the way to do inheritance in javascript, how can I improve it, and what pit falls ...
I don't entirely understand check and set behaviour.. here is an example: public static void main(String[] args) { List<String> list = Collections.synchronizedList(new ArrayList<>()); String abc = "123"; if (!list.contains(abc)) { list.add(abc); // ... some several lines of code ...
So, I'm learning assembly, and I've come to know the ABIs and i got some basics tests working using the cdecl calling convention to use the c's stdlib under nasm. But I've seen other Calling Conventions (like topspeed/Clarion/JPI/watcom/borland register(delphi), fastcall, etc). And I wonder, what are the REAL benefits ...
I recently read an answer regarding MVC and web development, mostly about how it was originally designed for older systems and has since been applied poorly in web development. That being said, I'm sure every pattern has by now been used poorly in web development. But I'd still like to make sure that I don't make the s...
I receive zip files and they have as content 8 different files, each with it's own metadata inside. I have to combine these files into 1 object containing certain metadata. The big issue here is that there will not always be 8 files and the metadata i want to retrieve could be in any of these files stored in there own ...
I have data set with ~5M entries/rows (~2GB). Every entry contains a location field (lat/lon coordinate-pair) and n keyword fields (keyword-1, keyword-2, ... keyword-n). The keyword-fields can all contain multiple keywords, but they are of different importance/"quality". I need to perform a query on this data set that...
I am designing an api that can give developers read-only access to a large dataset. The data is stored in a mongodb database. All the results of the api, will basically either be a count of matches to a certain query filter, or returning the actual rows that match the query filter. If possible, I don't want to limit ho...
We have a document management web application, which users use to collaborate on a document. There are 2 roles at the application level - Editor and Reviewer, and 3 rights at the document and document section level - Edit, Comment and View, View. Documents can be shared between all users in the application. Documents c...
I am investigating how to introduce parallelism into an application to improve performance. In particular, I am looking at parallel for loops and their variants and my initial experiments show significant overhead to using collections from the System.Collections.Concurrent namespace. Typical scenario Want to iterate ov...
In order to keep clean architecture of my node.js microservice I have controllers, services and e.g. repositories. I want a synchronous data flow: controller -> service -> repository -> service -> controller. In this flow (in simple user story) repository returns data to service and service to controller. But reposito...
I want to create a little GPS tracking program. Simplified: Users can create Tracks. To make things scale Track and User are two separate AR's. Track contains an AuthorUser which it refers to by UserID. The following rules apply: A User can create an unlimited amount of Tracks. Users can be removed from the system. I...
One part of a project I'm working on is interactive scripts for call centre staff. Pretty much every possibility I can think of in this case can be represented on paper as a flowchart, which is why I'll be making an interactive "script builder" that is essentially a flowchart builder in HTML5/JS. This will let me add c...
I am trying to understand MVC, but for most of the Q&A's I have seen, the description is great but I cannot quite understand it, I think it works like this scenario I thought of: User Registration (sorry for the wrong order): Controller: The user, they input the data (username & password) Model: The UserRegistration c...
During an interview today I was asked to write a function that accepted an array of integers and return the positions of two values in the array that the sum was 10. My code was C# public string ReturnIntegers(int[] arrayOfIntegers) { for(int j = 0; j < arrayOfIntegers.Length - 1; j++) { for(int k = j + 1; ...
I have a PHP application which is pretty simple: It allows the user to create, edit and read a post. Basic stuff. I have a Database class which handles the connection and the queries execution. The thing is that I want my models (I am using a self-built MVC framework) to be clean, so I created in Database some function...
I have a REST Service based on Spring MVC. JSON is the only interchange format for any client to talk to this service. I'm working on implementing a user registration workflow. So I have created an endpoint (/register, payload=User object in JSON) that accepts the User entity and does it's thing. So I'm transferring th...
I have to write a unit test for a method like: void doSomethingWith(Country country) {...} There are the following classes: Interface: public interface Country { String getName(); ... // and a lot of other methods, more than 20 } Class, implementing the interface: public class CountryInst implements Country { ....
I'm starting my way into Ruby development and have some questions that I hope you can give your best opinion to better design some command line applications I'm developing. What are the best patterns when creating data layers in Ruby? I've seen a lot of articles talking about ORMs (ActiveRecords and others) and also sa...
In dynamically and weakly-typed languages*, I often find myself with structures like the following pseudocode: class Stateful: # [ various datamembers / attributes / properties / fields / etc. ] define constructor(arguments): configureA(arguments) # [ maybe set a variable or two here ] ...
We're using Azure Cloud Services and would like to have a workflow where deployments flow as Cloud Service #1: testing/QA => staging => production Currently Azure Cloud Services only have staging and production environments where you can swap the deployments. How are folks accommodating a more traditional 3 stage appr...
I've become a leader of a group of 30 developers. We run Scrum and we have different teams for each Product Backlog. We have no testers across the teams and I'd like add them. My main question is: 1. Creating a different backlog and a Testing Team, where they would be shared among all Product Teams? Pros: We could hir...
I'm working on our company's lib. I see a lot of code like: std::vector<int>::iterator it = market.vec.begin(); for (size_t i = 0; i < market.vec.size(); ++i) it[i] = i + 1; I think a reference should be better: std::vector<int>& ref_vec = market.vec; for (size_t i = 0; i < market.vec.size(); ++i) ref_vec[i] =...
we have a 1-d space [1...N]. We are given M intervals of the form [L(i), R(i), C(i)] for 1 <= i <= M, where L(i) is the left most point, R(i) the rightmost and C(i) the value of that interval . Now, for each point from 1 to N of the 1-d space, we need to find if the point lies in some interval. If it does, then we need...
How can I explain a concept when I don't know its name or any formal reason for it? The reason I ask is this... A new programmer has entities with a property title in his system. He uses the title to derive image paths. Then we discovered that the titles weren't the same case as the actual paths. His environment (more ...
Context To be fully compliant with the REST principles enumerate in Fielding's dissertation, a resource must contains links that redirect to other resources that have a relation with it functionally, like for a bank account that display dynamically a withdraw link, or semantically as it could be related to an other con...
A support ticket has been raised whereby a mac user saved a file from an email, then uploaded it to our web based system. By default, when doing this the mac does not save the file with a 3 letter file extension. While this caused our system some initial problems (it looks at the file extension to work out what kind o...
I searched the internet and really can't find a good answer to this question. Imagine there is a View that contains a simple tab-element. Each tab-content is loaded dynamically (via ajax) when the tabs header is clicked. The View itself has the document.ready-handler to do things when the View (not the partial) is load...
I've read in several sources about Kanban. Using Atlassian's description as my current main source of information about how it works, I wonder how the effects of estimations on prioritization should be included in the flow. Mentioned description suggest a Kanban board with these lanes: To do In progress Ready for revi...
I'm currently trying to learn best practices in C++ after coming from a C# background. I understand that there are three ways of handling objects: By value (objects are copied or moved when passed into and out of functions) By reference By shared or unique pointer (raw pointers are frowned upon unless you really need...
I study the topics of compilers and interpreters intensively. I want to check if my base understanding is right, so let's assume the following: I have a language called "Foobish" and its keywords are <OUTPUT> 'TEXT', <Number_of_Repeats>; So if I want to print to the console 10 times, I would write OUTPUT 'Hello World'...
I'm pretty comfortable with the core concepts of Outside In (especially from this question). However one thing eludes me concerning the mocks you created at each level which then lead to creating the real implementation that the solution requires... Do you keep using the mocks in the higher-level (outside) tests, and t...
Our current queues publish messages that consumed by 3rd party services with rate limits. Currently the messages are retried with exponential back-off. However there could be cases where data is coming in so fast that the retries will never catch up. Most of the 3rd party services offer alternative batch imports, and t...
I am creating an app that uses some components of Symfony2 along with React, Webpack and Sass. We will mostly code in PHP, with the other things adding functionality to our app. I'm having a hard time figuring out how to make my folder structure. Please note that I don't want to make an app entirely dependent on Symfon...
I want to separate the communication protocol from the communication medium in a project. For example, I want to have a serial class and whatever other medium class and separately have a checksum protocol class and a crc protocol class and so forth. That way, a device class can have a member base class pointer to the...
So I need a bootloader for an avr chip and after some research, I selected this one. License OpenSource, base on GPL license. It needed minor modifications to compile without the dedicated AvrStudio. Namely: conformance to c99 writing a makefile custom configuration for my PCB and chip. I would like to push the mod...
I have a question regarding finding relevant events in a line graph. The following graphs show the views (y-axis) of a video over time (x-axis). Certain events lead to an huge increase in views and what I am trying to do is finding the timespan in which the event happened programatically. The problem here is that there...
My state machine handles requests and returns the next state. In the below simplification, I've got two states here, CreatedState and RunningState. Running state is the end state, and just returns itself. Running state has state (as in memebers) that need to be preseved, I'll use the integer count to represent them. st...
We have a new piece of functionality coming up. It comprises of 9 different user stories, covering the functions needed. Three of these are listed below: As a user I should be able to add a person so that... As a user I should be able to edit a person so that... As a user I should be able to delete a person so that.....
I have worked on two different desktop applications and both had the problem of enabling/disabling functionality and associated GUI elements depending on available licenses or "user-roles". In the first application I worked on, a mess was created by cluttering the code with conditionals that checked for certain license...
Lets say I want to test a method of a class representing a user account. I have a fixture which contains several user records from which I want to choose one. What is the preferred method here? Pick user record by unique ID ("pick user with ID=X") Pick user record by some readable date like name or email address ("pic...
I need to design a piece of software which is invoking some actions regularly. By regularly I mean that there is x things that need to be done at 12.00, y things at 12.30 etc,etc. The times and dates are accessible from the DB. My question is - what would be the best approach to handling never-stopping nature of the ...
Let's say there is class called AccountingService. Using this class I fetch all kinds of ecommerce records like products, customers, etc. The fetching happens inside a controller action. Once fetched, I should process and save these records to some kind of ecommerce shop. What I want to do is create an implementation o...
So i was thinking about writing a document (layout?) system. Why reinvent the wheel? Well, I want a wheel that fits my cart. Im doing a “larger” web-based application and need to generate/edit/distribute many kinds of mainly-text-documents. One use case is: Generate a prefilled letter that’s presented to the user, w...