instruction
stringlengths
34
36.1k
How would you relate the indexes of an array to an enumerator without leaving the chance of mismatch? Example public enum difficulties { easy, medium, hard } public List<Lobby> easyLobbies = new List<Lobby>(); public List<Lobby> mediumLobbies = new List<Lobby>(); public List<Lobby> hardLobbies = new List<Lob...
I'm trying to understand this piece of C++ code from a text book: template<typename T, int N> struct Buffer { using value_type = T; constexpr int size() { return N; } T[N]; // ... }; It demonstrates stack allocation of the T[N] array, but the array is not named. Later in the text this declaration is made: Buf...
Background: My boss made a comment on porting a C program that acts as some a simulator that communicates with a remote process through sockets to Java. He didn't assign it to me, or to anyone for that matter, it was just a project he had in mind. He showed and gave me access to the C source code file for said program ...
I am learning functional programming, working generally with JavaScript. Many things look promising, like immutable data and stateless flow. Now, I want to build quite a basic CRUD app as a pet project to practice functional techniques. I am going to use Node for server-side part of the app and vanilla JavaScript for c...
Currently our service is implemented using a multilayer architecture dividing the whole service into three: API Business Persistence However this introduces a lot of redundancy within our system. A common adage in the industry is "DRY" (Don't Repeat Yourself). The redundancy has increased the development time, and ma...
Should I just copy the project files to him? Should I sit and explain the code to him ? If so, up to which level of details? Or do I just tell him where everything is within the solution and not how the code works? I would appreciate your input
We have a feature branch right now in development that must not be deployed to production. At the moment there is nothing that would prevent such a mistake from happening. Deployment happens manually at the moment (SVN export + FTP to production). Migration to a better model is planned but not available in the short te...
I have question about MIT licence code sources Can I publish code snippets [MIT licence] from site like bootsnipp to my blog? Do I have to include source link to site where I have found that snippet (it has been published there first and its MIT)? or not?
I would like to ask you a question about MySQL AUTO_INCREMENT. I already created my own function to generate AUTO_INCREMENT when the user inserts any data input a table in MySQL. This function works very well but I am concerned about the problem which I may face in the future because it is really new to me. This table ...
I work in a large software development group and we've recently made the switch from Clearcase to Git. Some predictions have been made with regard to the quality of the mainline in that it would become too noisy and unmanageable with commits from hundreds of developers and that the repo would get too large too quickly...
I've started with TypeScript 2.5 years ago with Visual Studio and ASP.Net MVC. VS Web Essentials would compile ts files on save and the WebOptimizer library would bundle them together at runtime in a specific order. Basically a disaster, once the project was sufficiently large. Than I had a look at some generated code ...
A doubly linked list has minimal overhead (just another pointer per cell), and allows you to append to both ends and go back and forth and generally have a lot of fun.
Java is object oriented, but, why do we need to create an object from the Scanner Class to get input? Couldn't next() methods, for example, just be Static? C looks to me pretty simpler as you just use scanf(), gets() or fgets(). I'm sure there's a reason for Java developers for creating the Scanner class, but how is it...
I find the concept of transactions really useful when working with databases because obviously it allows you to rollback changes if one step of a modification goes awry. Is there some way I can extend the same principle across multiple services? Say I have the following example of someone uploading something to a webs...
A question about DDD, for validating a Proof Of Concept. Let's say we have a webpage that triggers a Domain Event. For instance, updating the status of a client after an interaction occurred on that page. From a user perspective, we want the event to be handled immediately, and the page to refreshed in the server respo...
I hope I can make a clear question... I've simplified my code example for this question, I hope it still makes sense. public class PersonComponent { public bool IsQualified(Person person) { if (person.PropertyA){ return true; } if (person.PropertyB && !person.PropertyC) { return true; } ...
Over the last days, I've being reading questions as the one that follows: "Why is my input code not working?" I myself had a couple times problems getting the input working right... as far as good, i found a couple solutions to avoid the problem like typing nextLine() to flush the buffer. But I'm still not sure what am...
I am working on a project where I have to monitor the status of an elevator. So far, my design looks like this: We are using a third party library to read and monitor real-time values from the elevator's logic controller. A tag is an integer value in a memory register of the logic controller. For example, DM140 contai...
This might be a little dumb question but why do we save text in the db instead of something smaller? Couldn't there be some other way to store data in the db like in a compressed form, and then have "our computer", which wants the data, uncompress the data from the db? What I mean is to put the load on the computers an...
I am running a .net MVC4 web application. I want to be able to hit an action on a controller, create an email and send it to my service bus queue to be processed (sent). What are my options as far as creating a consumer for my queue? I've considered creating another project that runs when the web app is started that ...
I need to be able to convert generic numbers (instances of Num) to a Float. I searched Hoogle for a function with the signature Num n => n -> Float, but I couldn't find any such functions (although it may be possible to compose it). I also looked over the Num typeclass, and it doesn't seem to require instances of it to...
So I have a Django app hosted on Heroku that has an endpoint which accepts image uploads. The images are saved to my AWS bucket, which is charged to me. Right now, I am able to upload images by making a multipart request with the Postman app. My goal is to allow my android app to accept image uploads from the user. How...
I am building an app for Android that will have multiple data sources depending on who is using it. N-tier architecture with a repository pattern seems like the right way to go about this but I am struggling trying to stick to some base rules. From what I understand I should be able to write the BL without actually kno...
My current task requires me to use a set of web service calls to a 3rd party vendor in order to retrieve and update information. The objects used in these calls - namely the response from a get and the object passed to (and received from) an update - are identical except for the a prefix tacked on to the objects. For e...
In past, I used JNI to access some winapi functions, however winapi is C and therefore just procedural. Now my plan is different and I need to know whether I'm going in the right direction. What I want is: to make a dynamic C++ OOP library for Linux (Debian) that, possibly based on WiringPi C library, allows object or...
I am creating a function in matlab that takes in two lat/long coordinates (opposite corners of a rectangle) and returns information about data in the region. How do I group my inputs? e.g. [lat1,long1] and [lat2,long2]; or [lat1,lat2], [long1,long2]. To make it easy on the user I currently have the lats and longs group...
My C# .NET application has to read lots of files with electrical readings. There are several calculation to be done and output files need to be generated. Due to the nature of the input it would be very inefficient to output after each input line or even after one file, so it would be better to do so after a chunk of f...
I have a method that accepts an interface and does type checking on the parameter, and depending upon the type a decision is made to either send an email or an alert public void Bar(ISomeInterface someClass) { if (someClass is SomeClassToo) { Emailer.Send(someClass.Something()); ...
I've been going through the GNU GSL design document and came across this interesting line in the Test suites section: N.B. Don't bother to test for null pointers -- it's sufficient for the library to segfault if the user provides an invalid pointer. Having prepared for the Microsoft technical interview in the past ma...
I have some interfaces that I intend third-parties to implement in the future, and I provide a base implementation myself. I'll only be using a couple to show the example. Currently, they are defined as Item: public interface Item { String getId(); String getName(); } ItemStack: public interface ItemStackFac...
When I am adding dependencies in Scala, I tend to use mixin trait components for those that are inherit to the class itself. For example, DaoGenerator extends Generator However, for trait components likes FileIO, it is less straight-forward. If the DaoGenerator class requires it, I tend to make a judgement call. I f...
I have an architecture problem/doubt and I'd like some insight on this. Context : We're in a mobile app that solely relies on webservice calls to be used. There can only be one user logged in at any given time and all calls require a user. We're talking about (for the sake of examples and clarity) meetings (one user ha...
I'm working on a very large non-MVC project utilizing Entity Framework for database access. This is a new project, so we've got a wide-open canvas for development. The conceptual problem I'm running into is how to model the layer just above the EF Models. At the database level I've got a Customer, Order, and Item tabl...
I have an application where there is an "inventor" model whose data I would like to display differently in different areas of the application. Therefore, I'd like to create different view models backed by that one model. For instance, in one section, I might display just a list of inventors with their first, middle, a...
I'm actually studying the flux pattern and there's something that I can't understand concerning the stores. What are they exactly? I have read many articles, and it seems that it concerns the domain. Does it mean that this is the "abstract" part related to api calls or backend calls? It's not very clear for me. Edit: ...
I am at the beginning of a project which involves reading from several sensors and fusing the data from those sensors together. Altogether there will be 4 sensors connected via USB and a webcam, also connected via USB. One of my colleagues is very vocal about how nice it is to split up programs into smaller parts and h...
I am attempting to create a long running job to be used in Azure. I would like to be able to run multiple instances of this job if I needed it. I was thinking of seperating the primary functionality into two different webjobs. With one job called "the brain". while the other job(s) would be called the worker. Brain ...
I need to implement a transaction that spans over loosely coupled (SOA+MOM) components. When a particular event is received, FOO and BAR need to do a transactional operation: that is, both the transactions on FOO-DB and BAR-DB need to be successful or none of them. The consistency here is very important. When the even...
I don't know how to phrase this question properly so please feel free to suggest edits. I've helped develop an in-house RESTful service for a company I'm working for, and it seems to have hit a wall in terms of performance without saturating the network channel (I think). I need to make it run faster, but I don't have ...
Why do they just reside in java.util and not somewhere more specialized like java.collections or java.util.collections? It could contribute to mess up with different unrelated code. Couldn't it? Was it a decision motivated from communicate with the outside of JCF at package level or rather a historic legacy?
The issue I hit, is that I am packaging shared libraries with my code in order to load GNUTLS, except for libc, because I figured any system will have it. Most of them don't have the required 2.14 for it(except for Ubuntu or others with daunting upgrades and repo butchering). I know it's bad form to be dependent like t...
I'm working on C# code where a static method of an abstract base class is being overridden by the class that inherits the base class. Why is this being done? I thought that only a virtual method of an abstract base class should be overridden. What purpose does it serve to make the base method static, or is it the case ...
A struct I'm working on called fieldDefinition holds metadata about a field used by an object in my web app. One of the fields on fieldDefinition (it does get a bit confusing) looks something like this: type fieldDefinition struct { id string apiName string label string fieldType uint //Defined by a lis...
I'm looking for a best practice solution for creating an object whose responsibility it is to handle file storage for a single file. I want to be able to read data from the file, write to the file, delete the file etc. I have seen the repository pattern in use but that appears to be a solution for handling multiple fil...
With the previous team I used to work with, we used to work on the same project at the time. Or at least we used to use the same platform/programming languages. Code review was almost daily routine and established procedure. However, when I joined my new team as a senior developer, there was no code review followed at ...
We recently had a problem whereby a feature for our webapp (automatic signup) was postponed by management because they felt the start was too "cold" but they wanted all the other features we had been working on to go live. The problem is that this functionality had been merged into develop when it was finished along wi...
I am in a design dilemma. I have a set of data that can be interpreted in numerous ways, but I cannot really decide how finely grained should it be. To illustrate it with some simple code: class Base { Datamembers data; virtual void doStuff() = 0; }; class T1 : public Base { void doStuff() { // do ...
At $DAYJOB, we have the following release/delivery pipeline: Get new features, work on new features. Once all features are completed, our own QA performs regressions, etc. QA signs off on first UAT build, ships to customer UAT department (this is really customer's own QA force). This begins our initial version (e.g. v...
Me and 2 of my friends been working on a small app. The source code of the app is on a private repository on BitBucket but now we would like to make the code of our app public under the terms of GPL. The problem is, when we started the application, we did not put in the classes or anywhere for that mater the copyright ...
If I were to build a game using Visual Studio 2015 and (Most likely) SDL2, I think I'm right in assuming that in order for that game to run, the user's target windows version needs to have Visual C++ Redistributable for Visual Studio 2015 installed, which according to this page (https://www.microsoft.com/en-us/download...
I am trying to figure out recursive backtracking, i have good understanding of recursion and till some extent the concept of backtracking too but i am having difficulty understand the chronological order of how things are working when for loop is being used in following code. public static void diceRolls(int dice) { ...
I have seen, in many places, that it is canonical wisdom1 that it is the responsibility of the caller to ensure you are on the UI thread when updating UI components (specifically, in Java Swing, that you are on the Event Dispatch Thread). Why is this so? The Event Dispatch Thread is a concern of the view in MVC / MVP /...
ISO 8859-1 contains a few letter-free diacritics: The diaeresis (¨), the acute accent (´), the cedilla (¸) and the macron (¯).¹ Why were they included? As far as I know (please correct me if I am wrong), the ISO 8859 encodings do not support combining diacritical marks like Unicode, so you cannot even use them to creat...
I've seen this pattern used in a considerable amount of MVC applications. Let's assume we have a User model with the methods: hasSessionExpired displaySessionExpired The first method (hasSessionExpired) looks up in the database if the user's session has expired and returns true or false and the second calls the first...
Given a class: public class Node { public List nodes[]; public Node right; //NULL for now } What's the best way to fill the "right" element of all tree nodes? N | | / | \ / | \ ...
I know a few languages, and can program in them. How do multiple languages blend together in a single program? For ex. https://github.com/facebook/watchman. This uses C, PHP, Python, Javascript, etc. How exactly do these languages combine to give a single result? How do they interact with each other? How do I learn to ...
We have started to implement AngularJS in our web-applications using ASP MVC. I am wondering what approach to use for building application in the future. Keep using our current stategy: Build the website and provide the pages with ASP MVC. Authentication and authorization is provided out of the box by MVC. Possible new...
I'm implementing a long algorithm (about 500 lines of C++). The algorithm consists currently of about 10 different methods. Each method I have to hand over multiple data-structures as parameters, which are calling each other. Only one method is can (should) be used by the end-consumer. I was wondering if a class woul...
I've just used git-tfs to checkout a TFS repo into a Git repo. The .git directory comes to 2.33GiB, and the primary reason for this is a couple of large directories coming to about 650MiB each. Each directory is chock full of (roughly 1500) JPEG image files that range from 50KiB to 5MiB in size. This obviously makes ...
Is it possible to reconstruct the movement of an Android device in 3D space using data from accelerometer? For example, I may draw a circle with my hand in the air, holding an Android device. Is it theoretically possible to reconstruct this circle using accelerometer data in 3D space, relative to the ground accurat...
Form classes are intended (IMO) for submitted data against rules. For example: are passwords equal, is end date later than start date. submitted data--->|Form| Is it okay for Form classes to validate submitted data against data retrieved from a database as well? This seems like a responsibility issue, the Form class s...
In a normal application, a simple call to time.Now() in most languages will suffice for getting a timestamp, but what about in a web application spread over multiple servers? As I understand it time.Now() will use the current system time, but there's no reliable way of telling after the fact if that time was synchronis...
The Problem I need to develop a Software-as-a-Service application, that will be used from our clients. The application contains a lot of forms (Company Application) using a step-by-step forms. They users will fill these forms, and see some progress. The Company (our client), can have a view of they dashboard, showing t...
My little team is just a few days from launching our web page. Its another user content type page so a lot of our data will be about user preferences and behavior. We decided to get it out of the door as soon as minimal functionality is ready and tested but have grand plans of more stuff to be implemented while its liv...
I need some advice on my idea to write a controller file in Python, and not like the C in MVC type controller but a more simpler idea. Just a Python script that controls the operation of some other Python scripts. I will outline the idea, and any advice or ideas would be greatly appreciated. I have to write a system th...
I'm having problems defining the aggregate boundaries (and maybe even the aggregate root) to enforce the transactional consistency rule. Let me first describe the problem domain. In our domain we have a project that contains a budgeted plan, which in turn contains hundreds of purchase items that need to be purchased. S...
I've been using AutoFac for some time now to take care of the dependency injection we're using in a web project. All is well, but I now want to demonstrate DI outside of an AutoFac context for reasons irrelevant to this question. In doing so, I'm having to read up on 'manual' methods of achieving this pattern. All of t...
I'm a Java/Android Developer, I recently graduated college and currently working as a Jr. Android Developer. I feel very comfortable around Android and Java in general, also I'm always reading and exploring new things. Lately a colleague advised me to look into server-side development as well. After doing some research...
Our webapplication is using an ExceptionMapper to map some exceptions to Response. We log the exception messages before throwing a new exception as follows: catch (SomeException ex) { LOG.error(ex.getMessage()); throw new MyException(ex.getMessage()); } We are not re-throwing the same exception, so my question i...
Here's something I wrote ages ago as Java applet. I want to convert it into JavaScript and run in html5 canvas in the browser. From what I can see, canvas makes the most sense here. (SVG / DIV techniques aren't so friendly for what I want to do.) The canvas does allow for mouse drag and visual update, something you ...
I'm working on a social networking website where users gain ratings after specific actions taken and proper conditions are met on the tables. The ratings are calculated depending on 'total hours worked' and 'total points gained'. The cron php has an sql that INNER JOINs 7 tables. To keep this up-to-date we run a cron t...
Example: if float: print('float is true?') returns: Why do all objects other than ones explicitly defined as False or "False" evaluate truthfully?
ReDos attacks exploit characteristics of some (otherwise useful) regular expressions ... essentially causing an explosion of possible paths through the graph defined by the NFA. So does using a recursive-descent parser (such as ANTLR) necessarily avoid the problem?
I am developing an embedded application on an ARM platform. I want to use ArchLinux as the underlying operating system and then create my own GUI. I want the application to be extendable (have apps if you wish). I want to be able to run these 3rd party apps in a sandbox to limit security issues. I want the developers t...
I am new to golang and RunC and now doing some research on it as a part of my intership. What kind of contents do the ' _test.go ' functions check during testing a program or a container with Golang (Or RunC in case of Docker containers)? Can someone please explain me the testing process?
I am writing a whole new BIOS, from scratch, for the 5162. The already existing BIOS is on chips U34 and U35. Normally, exactly one byte (the odd byte) should be on U34, followed by exactly one even byte on U35, but this is not always the case. By examining the machine code and data in a hex viewer, and comparing them ...
There are different levels I'm asking this question at. Case 1: Let's think about the typical drill-down design. Say a table view controller has an array of custom objects, and tapping a cell will push a view controller that allows the user to modify the object represented by the cell. In this case, should the pushed v...
What am I suppose to do I am working on an API, where I get a list of objects from the output of an SQL query using an ORM. Now this API call needs to send following information down to the client. Output consists of a list and a dictionary. List contains dictionaries holding statistical data per day. One dictionary fo...
I've been reading up and trying out various workflows with Wordpress/git. There's a number of options available and I've got a few workflows roughly modelled but no matter which one I choose there's always someone or something that'll lose out. Workflow adopters Developers (competent, used to git) Designers (not used ...
I'm writing in javascript with 'should' library, but this doesn't matter. I should write test for method, which returns a quite big object with a lot of fields. How I should write my expected result? I just wrote the same big object in expected, but it about 100 lines of code and looks not good. Any suggestion? Or shou...
Assume I have following class class Student{ void method1(){ // Do Something } void method2(){ // Do Something } } And the object of this class is used as monitor in synchronization in some piece of the code as class ProcessingThread implements Runnable { void someMethod(){ synchronized(s...
I'm working with AngularJS on a browser game and I have a bunch of "business" constants. These constants will be often updated during game testing (game balancing) and are used by different modules/features. I'm currently managing them in a single file like that: constants.js var gameConstants = { BASE_COST: 100, ...
I'm thinking about how to decide whether it's better to encapsulate my work behind well-named function names, or to expose it - which will help developers understand what's going on more quickly? Is there a name for the study of this sort of problem? Specifically, if I'm running a bunch of bash commands ultimately, but...
Imagine for a second that I'm implementing the Memento Pattern, using the following classes. Classes An Originator class that has public and private, properties and fields respectively A Memento class that has many properties/fields representing state of Originator A CareTaker class that acts on an instance of Origina...
I have an app that uses Gson to serialize/deserialize data classes and persist data between runs. My code uses @NonNull annotations for many fields/parameters/method returns and one thing that was What if I (or another developer) adds a new @NonNull annotated field (or even just annotates an existing field) to a data c...
I have built a fairly robust program in c++ which tracks several points on a hand. It accurately quantifies the size of the palm, the center of the palm, and the fingertip locations among other hand traits. The points are all stabilized with a Kalman filter. I want to be able to recognize certain dynamic gestures such ...
TL;DR Do non-crashing bugs always affect Functionality, despite possibly affecting other quality attributes as well? Or is there a more specific quality attribute that non-crashing bugs always affect, like Functional Suitability? This might seem like an ambiguous or unclear question, but keep in mind that core softw...
I'm writing an interface to a lexicon in Java. I just started this project, and the lexicon is on version 3.8. When a new version comes out, say version 4.0, database columns may be renamed, removed, added, re-organized, etc. The database could be totally different, and my 3.8 interface would not work with it, so I wou...
I've been discussing this with colleagues, and we couldn't figure out what the use is of .Any for any given List<>, in C#. You can check the validity of an element in the array like the following statement: if (MyList.Any()){ ...} //Returns true or false Which is exactly the same as if (MyList.Count() != 0) { ... } ...
As a regular user of Standard ML and, to a lesser extent, Haskell, the following pattern is deeply ingrained into my "instinctive" approach to navigating and learning new APIs: Understand the types. Derive and use free theorems. Hoogle and Djinn are my friends. Only if and when I'm not getting any more information fro...
The following: var emptyArray = [String](); What do I need the parentheses () for? [String] says, that the array accepts strings only. But why do I have to put the () there?
How would you calculate the time and space complexity for a tree algorithm that creates a copy of a tree, but reuses as much of the original tree as possible? For example, A /|\ B C G /|\ D E F To change E, we can take a more efficient approach, rather than copying the entire tree: Copy E and change the valu...
I find myself consistently creating flags within my C++ program, that are later checked to determine if I need to do something, and it honestly feels kind of "hack-y" despite being a simple solution. For example, Let's say I have a function: update_employee_salary(EmployeeList employees_to_update ) update_employee_sal...
I am coming to terms with TDD, and the fact that I need to re-factor some code that I'm (re)writing. I am having a problem that I think is a classic conflict---TDD vs. encapsulation of private methods/data---and I need advice on how to structure my code properly so that everything is testable through its public interfa...
I want to create a polling website. A client requests to answer the poll using POST, and the server responds with the candidates. The client then sends a POST with the candidate information and the winner to the server, which then stores in the information. I want to prevent a client from manipulating results by repeat...
Where to place interfaces in a typical multi-layered app with DataAccess, BusinessLogic and an Endpoint modules? I propose 2 options In both cases there's only dependency from abstractions, but in first one we place interfaces in the same module with implementation, in second - we move all interfaces in the separate m...
I'm trying to create a Java API that I will use in other projects. I understand that if I create new classes I can make objects in the other projects that have those classes. But what I want right now is a way to just create a method that isn't part of an objects that I can call upon whenever I wish without having to c...
I monitor a variable in real-time where new value is generated every 1/25 second. Depending on the conditions, this variable may either be stable, i.e. fluctuate a little (+/-1%) around some value (for simplicity, I'll take real value of 40 from my recent experiments) or fluctuate widely from 0 up to 6x or 8x times big...
I'm creating a website CMS in Rails (for fun and learning) and I'm trying to figure out how I'm going to store the data for an "about" page. Due to the nature of this page, the data will only have one instance, it may change and will be persistent so I want to store it in my database but I'm not sure if this is the bes...
In a pure language like Haskell, all data is immutable and no existing data structures can be changed in any way. Additionally, many algorithms on immutable data and functional programming patterns generate large amounts of garbage by nature (chains of map creating intermediate lists for example). What strategies and t...