instruction
stringlengths
34
36.1k
I have an entity class package org.demo.stack; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; @Entity public class ValueHolder{ @Id private Long id; @Column private Long value; /* getters and setters... *...
I'm doing a lot of code analysis using lexer and finite state machine. For time being I'm using table to describe FSM: | token | current state | target state | +-------+---------------+--------------+ | . | start | dot | | trace | dot | method | | ( | method | detected ...
We have authorization server which is in charge of checking token validity, expiration etc. Which HTTP status code should be returned if the authorization server is down? Should it be 401 with "Authorization server down" message, error 500, or something else?
Is it correct that homeitem should be declared inside the OnLoad method and overgiven to all the render methods instead of just declaring it as a global variable and accessing it by all the render methods? public partial class Default : Page { /// <summary> /// Initializes the module. /// </summary> ///...
The following code snippets are simplified to demonstrate the context! The actual interfaces and classes are POCOs having additional properties. The types are part of library I am working on, the interfaces are public API, the classes internal API. I have: an interface IValue public interface IValue { Int32 Value ...
Say I'm offering a REST'ish API that offers you Meals Now If you want to get ALL meals naturally you get it through something like: GET /meals if you want to filter those meals you can do something like: GET /meals?vegetarian=true But what do I do for a very complex Request where the "query" looks more like: [ vege...
First: This is for a project that is already deployed, and requires a solution that isn't "rewrite how the whole thing works"! I have a "record detail" screen of sorts that is storing the corresponding RecordID in a static variable. Within this screen you can drill down, which passes the RecordID into a bundle and is r...
I am new to the Java 8 time package, and am trying to better understand it and make sure that I am making good use of it. Is there a specific reason that LocalDateTime's truncatedTo(TemporalUnit) does not support ChronoUnit values past Days. I think I put together a successful implementation of such a method, but had c...
Given a list of items, I want to break it up into four groups with as equal length as possible. The items need to stay grouped by the first letter in each item as well. 26 letters / 4 groups would generally cover 6.5 letters in each group. If we had an equal amount of items starting with the same letter in each group i...
Context: We have 2 servers (internal and external) that have to hold identical data and remain in sync the entire time. Our internal system is like a local cache and we allow read/writes to the data before saving. Saving triggers a local save and a save to the external system. Single atomic changes are easy, but we ...
With respect to computer vision (CV), I always hear these three terms used almost interchangeably: Structure from motion (Sfm) 3D reconstruction Stereo vision/processing However from what I've read, these are similar-yet-different, but nowhere can I find a universal definition of how they are different. According to ...
My main language is currently JavaScript, and I'd say I'm fairly proficient in it. That is, when I think "I want to do x", I don't (generally) Google "how to do x", but I think "I know! I will use features/techniques a, b and c to do x". I am not very familiar with the new ECMAScript 6 features (basically an update to ...
I am new to MVC, and just inherited a project that is still in it's early stages. The scope is a user interface to manage a single SQL table. There is a model that represents the entire table (select * from table). The previous programmer also created several models that represent a single column (select columna from t...
It is clear that it is preferable to put your source code in a version control system e.g. SVN. When a source is compiled, you get an executable. Different versions of the executable and various different input parameters (which in my case ~1000) and other input data is proving to be hard to manage. On top of this I ma...
I heavily use Excel and CSV at my workplace. File 0 Excel File The initial file is an Excel file. Let's call this File 0. This may or may not change with time depending upon the requirement of the project and input of the client. File 1 CSV Data Sheet By observing the notes in File 0, a CSV file is created. Let's call ...
I am trying to figure out an implementation for a solution to a problem I outlined in another Programmers.SE question. I need to find a solution for this problem in C# most likely using the collection in the System.Collections.Concurrent namespace. My problem is a classic problem related to the Dining Philosophers Pro...
Unit testing has been widely lauded as an indispensable part of software development, and TDD has many proponents. However, due to the combinatorial nature of various pieces of code, it can be difficult to know when you have enough coverage of even a single method. Consider a method that checks for an intersection betw...
As any good password storing developer I have user unique salts that I use to generate password hashes. ie I store a uniquesalt and SHA1(salt + password + "applicationuniquestring") in the database for each user. If someone were to get my database they could theoretically create a rainbow table for every user and have ...
Some people have this problem that they cannot think without words. And writing down their thoughts and decisions is the most effective way to proceed. So - is it normal and acceptable that I write down my thoughts and decisions in some Notepad++ file during coding? Sometimes it should be acceptable, e.g. when recreat...
DI frameworks like Guice and Spring are the common tools to abstract out dependencies to make Java code testable. However, there are several alternate methods to achieve the same goals. One in particular is making the code to test depend directly on certain classes and then varying which implementations of those classe...
I want to keep the end-user (often myself) from being presented with inapplicable methods when coding directly in an interpreter, but I also don't want the user to have to inspect the incoming data and then determine which class to instantiate. This is probably the XY problem, but here's a working example, in which I s...
What name can you give the surrogate key column in a database table when the convention suggested name collides with that of an existing user field business key? For example, if I am creating a Product table and ProductId is already used and known by that name in the company, business-wise. A example value of existing ...
So I'm coding a way to send events to multiple clients, and then having the clients decide how they want to handle it. I'll exclude the bits that don't lend themselves to explaining the situation. class Event_Beacon def add_event_eater( self, ee ): self.event_eaters.add( ee ) def broadcast_event( sel...
I have inherited an application which performs approximately 100,000 executions in a C# for-loop against SQL Server. for (int i=0; i<100000; i++) { //Execution can take 0.250 to 5 seconds to complete. ExecuteProc(i); // no result returned } To reduce the time it takes to execute all 100,000 procedures, would it be...
I have a web application and a REST API server (Microsoft Dynamics CRM 2016) that I don't have access to it's code, but I have access to the available resources. I need to create a data sync between both servers, some of the tables are one way and the others two way data sync has to be done, I haven't found any good so...
In my Django web app I want to monitor my remote Raspberry PI clients - up to hundreds - using WebSockets: I have to check in their status in real-time (online, working, offline etc.), send commands to them (start, stop, reboot etc.) and so on. I had a look on Django Channels and, following this tutorial, I set up a wo...
I have a object that needs values from a grandparent object to perform a calculation. What is the best way to handle this? Should I create a separate calculation class to get the data, perform the calculation, and return a value? Or a "parent" field, so I can traverse back up the object to get the data? Or a service th...
On the GPU, each thread has access to "shared" or "local" memory, which is analogous to cache on the CPU. So instead of just caching the most recent page, I can tell my program which pieces of memory will be accessed most frequently and manually keep those in cache. My question is: why do CPU designers not allow an ana...
I want to implement something similar to the algorithm described here. I don't even know if "algorithm" is the right word, since many of the steps are considered to be algorithms themselves. What I've done in the past in situations like this is to encapsulate each step in a private method of a class, and then provide a...
We have a big set of survey questions, which we distribute to users online. We collect submission from users and based on their submission, we decide the answers for those questions. Now, each user gets a set of questions, say N. For each submission given by user, he/she gets some points(cost c). Now, there is a upper ...
I am trying to implement the use of two database in my application, sqlite and mysql. Currently i added references to both database connection library, and duplicate all first checking which database option the end user selected, and calling the appropriate function. Though i only implemented a test, i thought this wou...
What are the actual perks of using an annotation that adds a particular functionality to a class or a block of code (other than rapid development purposes of course)? This may come down to preferences but I do not use annotations at all, as they can put a limit on the developer. One can easily lose the freedom of custo...
I am developing an application which will use user sessions stored both in the client and on servers. Should I treat them as different repository implementations and use DI to use them inside domain services? Any suggestions?
On my team of 5 coders, we've traditionally adhered to a common git commit message standard stating (only) two rules: commit messages should include the why rather than just the what and they should be written in the past tense. This is quite loose (e.g., some people prefer writing longer messages, some write shorter o...
I've joined a very large new company who have very different ideas about what constitutes quality in development. In trying to convince managers about what should change, are there any well accepted documents about development practices in an agile environment? We work in mobile development and the existing developers...
I have just finished an iOS application for a company that will be sold commercially to schools and other organizations for a flat rate with an access code. I was wondering if anyone has had any previous experience with access codes, and what would be the best way to implement this design in to the app? I received equi...
I'm a heavy VBA user that when has the chance to do a little project in python it's like going from hell to haven when it comes to programming itself. Still, I know that my users want reports in excel (for good reasons) and I'm just not ready to give up how amazingly easy is to deploy a new version in excel: just save ...
I've created maybe five services like RoleService, AuthService, etc. Each of them has some state (e.g., RoleService.role, AuthService.isLoggedIn) affecting a lot of controllers and some other services and directives. Sometimes I need to $watch the variable, so my hacky solution was to put the whole service in the $scop...
I have recently started a project where I need to make extensive use of videos and books. And all of them are needed to be stored locally. I want to be able to search all these books and get access to them as quickly as possible. I don't want users of my application to have access to the content (books and videos) out...
for example, I have A.h, which has a class A with some empty methods: class A : public B{ public: A(){ } virtual void b(){ } ~A(){ } //other methods }; should I move all empty methods definition into A.cpp: #include A.h A::A(){ } void A::b(){ } A::~A(){ } //other methods ? and which i...
While working with one project I was assigned to, I noticed a small problem with our SVN strategy. A few months ago, someone created a new feature branch from our trunk. In this branch he implemented a second implementation of an already implemented feature (but in a more efficient way). He changed actually only one c...
I wonder whether there is a concept for attribute dependency in object oriented terminology? It's an example showing what I mean with attribute dependency: 2DShapeclass may have an areaattribute. Then, Rectangle is a 2DShape and it has lengthand widthattributes. Now, area is dependent to lengthand width. It's a one-wa...
I have created a Project in Java which helps generate HTML's from an Excel Sheet & a template file. I am trying to understand, if I want external users to use this facility from an external service, then what should be the thought process to choose an infrastructure for setting up this service. By infrastructure I mean...
I am currently debugging a very old game (so there is no customer support) that keeps crashing under certain condition and I have found out it is because unsigned short to unsigned int conversion was done by signed conversion (possibly code similar to "short int x = 0x8000; unsigned int y = (unsigned int)x" which lead...
I am building an API where the user can ask the server to perform multiple actions in one HTTP request. The result is returned as a JSON array, with one entry per action. Each of these actions might fail or succeed independently of each other. For instance, the first action might succeed, the input to the second actio...
Code context I have a complex page as part of my web app that is dynamically populated with information using knockout.js. The page has dynamically created anchor tags that link to each other. For example, there might be a tag <a data-bind="attr: { id: 'top-' + myArray().length, href: '#bottom-' + myArray().length }">...
Imagine you want to have a room painted. You are the owner of this room and a Painter is capable of painting the room. There are different types of Painters: a BluePainter, a RedPainter etc. For every color there exists a Painter! You don't care in what color the room is going to be painted, as long as the room gets pa...
We cannot serialize registrations as there are millions of users registering at the same time. Parallel registrations need to happen. Let's say the database doesn't contain username 'user1'. When two users try to register at the same moment with 'user1' it'll accept it. But it will later cause problems. This shouldn't ...
I'm looking at building out the architecture for the following, and wanted to see what others think about it. Assume that the system is running some non-trivial algorithm (so it's not simply a sum of something etc.) on the data collected on each user. Some users will have 10 rows of data, some will have tens of thousa...
When I read about unittests I keep reading that I shouldn't rely on external resources, but in some cases I would like to test reading in Excel files so I can be confident this portion of my code is working. For instance if I'm using pandas I might want to unittest that Excel files are being read with no errors. import...
I am trying to implement CI for one of my projects that generates a NuGet package which is published to our private NuGet repository. Obviously, for dependent applications to see the new packages as upgrades, they must have higher version numbers. To achieve this, we are letting MS Build append the build number to th...
I was trying to understand structure padding , so i wrote a simple program as written below and i executed it . just to make clear i made two copy of this program program1.c and program2.c and executed both together to see the member address but something strange came up Both program giving me same result , as like h...
I have a process loading a UI provider via dll and another system resource that provides functionality which I forward to the UI via callbacks. In some cases, the underlying resource faults while the (MFC) UI is showing. I'm in a discussion with with the person in charge with the UI about the appropriate way to shut do...
The syntactic sugar provided by extension methods can be addictive. Take for example public void TagNode(SiteMapNode childNode, string url, string title) { //do stuff } vs public static void Tag(this SiteMapNode source, string url, string title) { //do stuff } and the usage: TagNode(myNode, myUrl, myTitle); vs m...
Excuse my ignorance, I come from the C family of languages but zero exposure to functional languages. I've read that pure functions only generate output based on a given input. Same input gives the same output regardless of other conditions. But something bothers me. A simple case would be array.filter which takes in a...
New to the field of QA, I've been asked to do SQA for a project that I'm unfamiliar with and that is close to completion. An example of a specific functional task to be tested looks like the following: 51: Rename Excluded Words at the Topic and Subtopic levels to be Not in Topic and Not in SubTopic I could see how if...
You can already ask a spoken question and receive a (synthesized-)voice answer. So what kind of re-design/re-factoring/whatever would be required to take a fork of that code and modify it for fact-checking? In the current "Conversations in the Digital Age" http://www.digitalage.org/ interview with Deborah Norville rega...
Traditional programming could be done quite readable. Like this: FUNCTION do_HTTP_request(url) { if(!ask_user_if_he_wants_to_connect()) return; if(!network_is_enabled()){ enable_network(); } var content = download(url); // … do something with ‘content’ } However, nowerdays frameworks are ri...
I have a project and I follow Repository and UoW patterns. I also have a "service" layer which I also use as my BL layer. Taking for example a Customer domain model, I might have information that I need to retrieve along with the customer, so in the customer repository class I have the following methods: public Custom...
I create page to import records so users can import records using a CSV file. I am already using Sanitization to remove unexpected characters for specific field of the record, Do I have to validate each record in csv file before insert it into Database then display the errors to user or just using sanitization only cau...
My employer still uses VisualSourceSafe6. Everything is checked-in into the main project directory in VSS. They are not using branching in VSS. Check-in's are supposed to be ready for release to QA and should not break the build (not enforced). I want to use git as my local repository so I can track changes per feature...
I apply comet long polling which uses usleep inside while loop until no new data returned by server like below: PHP while ($currentmodif <= $lastmodif) { usleep(10000); // sleep 10ms to unload the CPU clearstatcache(); $currentmodif = filemtime($filename); } My aja...
Most of the underlying workings of the operating system is hidden from the programmer. I believe that is also one of the purposes of an operating system. Then what are the reasons a software developer should learn about how operating systems work?
I have a situation where I want to call a function which requires a number of parameters. This function is not called directly, it is called indirectly and the parameters are delegated several times. Some extra parameters may be added in between the different layers, but those aren't included in the example for the sak...
I'm the sole developer on a project that, like for any software project, may be taken by somebody else in the future. Let's say I used the pattern X to implement feature A. After developing and finishing the feature, I realize I could implement the same feature using pattern Y, which I just learned about. But feature A...
While trying to figure out the optimal ordering for optional parameters to a function recently, I stumbled across this blog post and accompanying GitHub repo, which provides a header for a Pythonic kwargs-like facility in C++. Though I didn't end up using it, I find myself wondering whether this is a good or not in a s...
I have a question related to cqrs + event sourcing. I have two aggregate roots (AR1 and AR2). When AR1 received a command/event it will be recreated from previous event sourcing stream from repository (in this case it will have list of some values x,y,z) and after updating internal state to (a,b,c,x,y,z) it will emit n...
Can anyone explain what exactly Microsoft means on the below linked page when it says: "Do not catch an exception unless you can handle it and leave the application in a known state." https://msdn.microsoft.com/en-us/library/ms173160.aspx
Every time I have used the InternalsVisibleToAttribute when developing an API, it feels a bit smelly. Like the API is not being designed in a truly encapsulated way. A lot of the times this is out of time constraints - exposing the internal functionality in an elegant, encapsulated way takes time, and a lot of times on...
In the recursion section of K&R's ANSI C book, they demonstrate a version of quicksort [that] is not the fastest possible, but it's one of the simplest. --The C Programming Language (ANSI C) - pg. 87 In its entirety: /*qsort: sort v[left]...v[right] into increasing order*/ void qsort(int v[], int left, int right){ ...
If some fields are required when inserting data, should I check if null when retrieving them (suppose I need to do something with this fields that may throw exception if null), or I shouldn't unless I changed my system and started to accept null for these fields ?
I had a discussion with one of our senior developers who's been in the business for 20 years. He's pretty well known in Ontario for a blog he writes. The strange thing is what he told me: he said that there is a piece of code that is a nightmare to work with because it was written from a textbook, and doesn't account f...
I work with monolith web application written in PHP that is being migrated step-by-step into microservices. I would like to keep the same UI with several new features that have been implemented during the migration. Currently, new elements of the app are written in Angular and they communicate with microservices' via R...
We currently have over 300 web projects that are legacy code, that is kind of spaghetti like based on a modified version of an old framework. Our one developer that knows these systems best is leaving and I'm the replacement, what are the best questions to ask before they leave? I want to make sure I can support all th...
This might be a silly question... from somebody looking to make his programming more structured/less chaotic. I would like to develop an application (web and mobile) just for fun/for myself. Before starting writing any code I would like to describe (in words) what the application is going to do and how it is going to l...
I use Gulp to generate minified CSS from my SASS code for a project I'm working on. I wondered whether it's considered best practice to regenerate this minified CSS when pushing live from Git... or To store the minified CSS files in Git so they are automatically pushed live to production without further work on the ser...
There's an internal research and development application that has developed use cases based on our own vision for the product. We are starting to get feedback from prospective clients from different industries to which this application could apply. This application has working backend and frontend components. Both the ...
I interviewed for a job at an ecommerce company a few years ago, didn't get the job, with most of the (stated) reasons being related to my having no experience working with an ecommerce company (I worked for a payment systems company at the time). There is an interesting job with a different ecommerce company bei...
I'm writing C# applications that store their data in MS Access databases, (I'd rather use a different type of database but currently have no other option). The applications are in use by multiple people at a time and so when there are multiple connection attempts (or someone mistakenly opens a table), some of them fail...
I am new in DDD and my understansing of the repository pattern is that it acts like a collection of aggregate roots where you can add, delete, update,etc a certain aggregate root. My question is, where code that performs aggregate functions (count, group by, sum, etc), should be placed, since it does not return or ope...
My team is faced with a big challenge. We are building a greenfield app against a legacy codebase. The legacy code contains .NET controls with a certain look and feel. Our front end is ReactJS. We are tasked with reproducing the look and feel of these legacy controls. The designer is tasked with creating Mockups, ...
I know how to parse normal JSON objects using the org.json library, but I am confused as how I would parse this one as it has no array/object names. [ { "value1": null, "value2": null, "value3": "example" } ]
In the context of web development, who designs databases? Despite a whole host of information associating back-end web dev with server-side processing, data modeling, and the like, the database design aspect of the equation seems to be mysteriously absent. I am not talking about who sets up the physical database, I'm r...
I want to create generic response codes, for an API that I am developing. Now I know there are HTTP response codes that are usually recommended to be used, but my API will be handling multiple USSD gateway responses. So a generalized mapping of response codes within API will highly be useful. After brief Googling I di...
99% of software comes in different versions. And quite often developers like naming versions. Example - Android versions: Froyo Gingerbread Ice Cream Sandwich etc.. It really bothers me because it makes me remember which version is old, which one is new - I cannot tell it from the name. I know, I know: Android follow...
Several RFCs use the term 'HTTP protocol' (example). However, the acronym 'HTTP' already includes the word 'protocol' in it. Hence, isn't it redundant (and hence incorrect) to use 'HTTP protocol', whereas the correct usage would be simply 'HTTP'? Why do RFCs make such usage?
I started to work on several C projects that are building using gcc. I believe this choice was made for several reasons: Had to cross-compile for arm very early on (I think). Performance is the first and foremost spec. gcc was and is still the easy first choice. I have no reason to contest that choice and I am not in...
We have a cart and cart has line items, now line items can be products, discount coupons, rewards and promotions. I am looking for some inputs in design consideration here. The backend is in Ruby on Rails. for products I have already designed the URL to be post: cart/line_items to create a line item for product put: c...
Accessors and modifiers (aka setters and getters) are useful for three main reasons: They restrict access to the variables. For example, a variable could be accessed, but not modified. They validate the parameters. They may cause some side effects. Universities, online courses, tutorials, blog articles, and code e...
I have recently left my previous student job as a part time developer for at small ERP management firm. During my time at the firm i have developed several modules for integration with the ERP system. Furthermore i have developed an application, and a backend for said application. I have been asked to document the co...
I have found several documents about statement and decision/branch coverage in testing, but these terms aren't clear for me. There are two types of this problems, that you can see below. Code: if(a || b)) { test1 = true; } else { if(c) { test2 = true } } } Text: Consider th...
On stackoverflow I asked, what is the preferred way to expose custom STL-style iteration?. The answer seems to be to implement twelve functions: six members, six non-members (perhaps using some macros to assist). In C#, I can do about the same with just a single function using yield return; C++ is great, but it's thin...
There's a common interview question that will be some variety of the Parking Lot simulation- the gist of which is you have a parking lot with parking spots of varying sizes (small, medium, large) and cars of varying sizes (small, medium, large), and it's your job to simulate inserting a car into the lot, and removing a...
What is the advantage of using pull requests instead of simply merging a branch into master without one? Particularly on a team where all developers have full access to master.
I am mobile developer and always have one particular fight with my web-service/backend developer which believe in designing restful api. Issue: As per Restful design,every api should be atomic in nature,but this create alot of problems to clients especially mobile based. Since to perform any operation like opening of ...
I am writing a function that operates slightly different depending on the data passed in. The common and unique code is mingled. I don't like what I have and am looking for a better way. Hopefully, this case demonstrates the situation. Consider that each print line below is just a proxy for one or more lines of mor...
I am building a digital marketplace app. I would like to know what the best practice design patterns are for the backend (No SQL) object store. The primary characteristics of the app are as follows: The app presents users with a series of editable lists (with CRUD functionality: create, read, update, delete). There is...
We have one feature in our REST API which could have a reason to be shutdown temporarily, or permanently. Let's say the resource is: www.myapp.com/api/v1/needs_shutdown Right now, /needs_shutdown is a GET request that returns data. We want to make returning data happen only if the service is marked as active in our con...
Nand is known as a 'universal' logic gate, because it allows you define all other boolean logic gates: not(x) = nand(x,x) and(x, y) = not(nand(x, y)) or(x, y) = nand(not(x), not(y)) nor(x, y) = not(or(x, y)) xor(x, y) = nand(nand(a, nand(a, b)), nand(b, nand(a, b))) This is known as nand-logic, and is commonly used in...
I understands that most of the recent browsers use JIT compilation to execute javascript. What I do not understand is: which part of javascript is JIT'ed - the script, or the bytecode? Let me explain. From what I understand, V8 takes your JS and compiles it into machine language (not bytecode) with output being placed ...