instruction
stringlengths
34
36.1k
Whenever I solve a problem with overlapping subproblems, I reach for memoization because it's so simple to implement. However, memoizing in an immutable language that doesn't have built-in support for memoizing without copying the memory on every insert isn't that efficient. What techniques are common in immutable lan...
I am wondering what is the difference between DDS and AUTOSAR. As I know, both of them are communication middlewares. AUTOSAR WAS originally proposed by a group of car manufacturer that's why I guess should be much more suitable for intra-vehicle communications. DDS was proposed for military and critical-mission use ca...
I'm about to fork an MIT licenced project, I'm planning to use it as a starter. I was wondering how I have to handle the licence. What I understand When I will mimifie my javascript application, I'll have to include Copyright 201x (c) Original Owner in the header. Questions Can I modify the LICENCE file to include m...
Question: For a 16 bit word with 6 bits for an opcode How many different instructions could I fit into the instruction set? What is the largest number that I could use as data? Answer: Number of instructions: 26 = 64 largest operand: 210 - 1 = 1023 Source My question is how did they calculated 210 from 16 bit wor...
I wrote a supersuccessful answer to a question on an SE site that got (at least) 21 upvotes in a 24-hour period. In theory, I should have gotten 210 rep points, but there is a daily reputation limit of 200 points (20 upvotes) on a single site, so my daily score was capped at 200. This much I understand. Then I received...
I am doing a summer assignment for AP Computer Science. For this I am learning about different number base systems and how to convert them. These topics led to me wondering about why programmers use different number base systems. So I was wondering Why do programmers use different number base systems? Why not use the f...
I'd like to be able to request Linux to schedule two or more threads in the same time. I mean today when my multi-threaded program is being executed I know that in worst case only one of my threads is being physically executed (scheduled) at a time. Now I'd like to tell Linux: here is the list of thread Ids, please tr...
Why do we use normal form(like Conjuctive Normal Form and Disjunctive Normal Form) in Artificial intelligence?What is the specific purpose of Making a sentence in Normal Forms?
I have been studying DDD for 1.5 weeks now, and I came a cross the use of the Unit Of Work pattern together with Data Mapper pattern. I understood why they are both important and when to use them but, I couldn't find anywhere how the Data Mapper can "know" that a save method, for example, was called in the middle of a ...
I'd like to design a robust version of this class (C++11): class Oscillator { private: std::vector<double> trajectory_; // Some numbers that are needed to get the trajectory double xinit_; double vinit_; double omega_; public: Oscillator(double xinit, double vinit, double omega): xini...
From Roy Fielding's comment on his own article decrying fake REST apis: A truly RESTful API looks like hypertext. Every addressable unit of information carries an address, either explicitly (e.g., link and id attributes) or implicitly (e.g., derived from the media type definition and representation structure). Q...
In larger projects, there can often be a group of tests that test the functionality of related classes. These tests often share a lot of setup and preparation functionality. What happens then is that a base class is defined for these test cases so that they can share there instance fields and common functionality. Thi...
Problem description I have a situation where I want to enforce that a relationship can only be defined once and I want to solve it on database (Postgres) level. The following situation I consider invalid, because the relationship is defined twice. user_id | friend_id ---------+----------- 1 | 35 35...
I am new to Java and was reading its documentation on exceptions., and especially the Unchecked Exceptions — The Controversy page. The bottom-line says: If a client can reasonably be expected to recover from an exception, make it a checked exception. If a client cannot do anything to recover from the exception, make ...
I am inexperienced with iteration in R and am hoping to speed up a process as I am implementing some analysis in a website. I realise that this may be a Q for SO but I couldn't get an answer from them... I found a very useful tutorial that allows me to iterate through a matrix, pick out the criteria data above a certai...
I'm currently working on an Arduino project where I need to keep track of entries for a certain amount of time, in this case, 30 days. Our company will attempt to sell this product to cities and governments. Therefore it really has to just work, which makes me want to refrain from dynamically allocating memory. The ent...
Forgive me if I'm using the wrong terminology, but I'm attempting to explain to a non-technical person the difference between something happening in a program due to either a Math.Random (seed PRNG) and something happening every nth time. So, picture you have a queue of items, every 10th item will be stamped. This is ...
I am going to develop which will be web application as well as mobile (android / iOS / windows) application. The database in this application will be managed by Hibernate. Also as it is cross platform application, web service will also be used. What I know so far is: HIBERNATE: POJO Files (the getter-setter ones which...
I'm developing a desktop application, and this application requires some information to run, but it doesn't change any of this information (the data must be loaded on every execution of the app, but the data is never changed). The data must be stored on the same computer as the app is running (client-side storage?). It...
I'm wondering the following: suppose we are building a system where there needs to be some filtering functionality to search for some entity. For example, one might want to apply the filtering to a table listing the entities to find something, or use it to generate a report on a filtered set, whatever. The point is: we...
I am currently developing a web application (in Ruby on Rails) for my university's department. The web application's user base have several roles: director (the director and assistant director of the laboratory for the department), lab assistant (students who work in the laboratory ), faculty and student. The roles div...
I'm wondering if there is any good convention for key attributes in relational datatables. ID or Id seems to be good. however it conflict with others ids when joining. MyTableNameId does not conflicts when joining, however your software must know the ID name for each table. There is any good practice?
I want to store temporary data that can be accessed across multiple http request. The question may be similar to How to persist temporary data over multiple HTTP requests?. The accepted answer is too specific to ASP. However, in my case i'm using rails as the framework. I want to know possible pattern that at least wil...
Currently I am working on php application, to create interface that will receive POST data from mobile app, and process them into shared database. To do things right at a first time, I was searching for rule of thumb to design the web service. Quickly I found the recommendation by using RESTful API . I have read throug...
I'm writing a lot of stored procedures for a SQL Server database that take an id or code that is a CHAR instead of an INT. Most of these haven't changed size in a long time, but when a customer wants to increase the size we generally do. This wouldn't be a problem except for the fact that any stored procedure with a pa...
I want to explore code paths in Cassandra database, so after getting the code from git and explore it a bit I noticed that it starts a daemon process when I run it from Eclipse. I supposed that when this happens, I can no longer use the IDE to follow where the code is. Due to another problem I created this question and...
We start with a variable that holds an integer for the "number of items" that we have somewhere, somehow. Then, the algorithm is applied: each one of those items have a 70% chance to be destroyed. If the algorithm was something like round( num_of_items * 0.7 ), that wouldn't work as expected, for obvious reasons (one w...
I am currently working with a contractor who's code instantiates a large number of objects upfront at the start of the application. This application is written in ruby, but I wonder how something like this is viewed in programming in general. So, are there any cases where instantiating a large number of objects upfron...
I just want to ask an opinion, which are the best practice to use html between this two option: 1) Use JSP by creating html page there 2) Generate html using Java server side by using PrintWriter Which one are the best practice? And if I got some situation like only to generate small line of html, is it better to crea...
I want to build a .jar that encapsulates a vendor api, so we can use our own objects as parameters to communicate with the api. I've read some articles and topics here in SO, but I still am a bit confusing if I'm getting dependency injection right. For examples of House objects with Doors and Windows, it's easy to unde...
I've seen in some applications that were written in compiled languages where plug-ins are accepted and the solution to the question of how still eludes me. For example in Eclipse, Google Chrome, Firefox, and IntelliJ developers can write plug-ins for the software and it runs as though it was apart of the program. From ...
I have a standard C# MVC project which has a domain layer using EF and repository pattern. Say I have a model like: public class MainModel { public int MainModelID {get; set;} //Many other properties public List<Organization> CompetingOrganizations {get;set;} } On submission I need to populate the list of...
Here is how I was told to deploy my ASP.net(mostly intranet) website\program\application to the production web server in my company. Change necessary settings in web.config for production web server. Copy EVERYTHING of my source codes, then paste in the designated virtual directory\folder in the web server. As far as...
I am developing web apps using the Model-View-ViewModel approach with Knockout.js. After reading on the original introduction of MVVM by John Gossman, I realized that my ViewModel always contains ALL the app's logic, not only UI logic, but everything. I've read somewhere that with Knockout, the model is considered the ...
I have an external ecommerce link that varies based based on environment (testing and production systems). Where should it go in Rails? Possibilities include: a conditional directly in the template, on the button (not a good solution, IMO) database (though there's no model for this so it would be a specific case possi...
I am consuming a web service in C# using REST APIs. So, I have created a wrapper classes for each endpoint. It seems like a good idea to implement the wrapper using statics. This makes code look much cleaner. For example, consuming a method on Albums endpoint looks as follows. List<Album> albums = AlbumsEndpoint.GetAll...
I got to develop a web service that will help synchronize some of our data with APIs from Google, as well other services in the future. I thought, and my boss too, we should go for a stand alone web service mounted on a React server, allowing everybody to interact with it through HTTP. There's a synchronization databas...
We have an occasionally connected, event sourced system: a budgeting application where each client can pull other client's event store from a separate storage (network share, dropbox,...). It is our idea to assign each event the current client's (incremented) vector clock so that we can determine a global order of eve...
Every time a user submits a score, Socket.IO causes all the users get their leaderboard updated. This causes every single user connected through Socket.IO to read from the Dynamo DB database (every time the a user submits a score). As a result, my database gets several reads/sec. This costs me ALOT! How do I reduce re...
In this book I'm reading I'm going over bitwise operators. Its says the following in the book. Bitwise operations can potentially store a lot of information in a small amount of memory. Many traits in the world have only two possibilities that are either this way or that way. You are either married or you're not. you...
I want to write assembly program using windows syscall Interrupt number , so in order to use system call in assembly level using int of sys call, In windows are there kernel calls like posix library unitsd.h in assembly level. where can i find windows system call list for opening file, mkdir,etc.(interrupt number), ...
I am attempting to write a python script that with remove some of the tedium of my everyday actions. Specifically, I always need to run Eclipse, Java VisualVM, and a docker container. I had planned on importing the os module and just executing a few os.system commands to get everything running: # set_up.py # Starts up ...
Assume that we have a 4GB RAM processor. Let's say we want to play a 4GB movie in VLC player. Now, processor first starts VLC Process and then starts to load 4Gb data. My question is how does this data transfer occur, Is it like getting almost all of 4Gb and storing some in swap area and bringing whenever it is require...
What I need to do : I've been asked to add a feature to one of our application that would allow a supervisor to send a message to all or one of the users currently using the application. The application is a winform application using c# and ef6 with a mysql database and is using a RabbitMQ server for different purpose...
I'm struggling to understanding how I can deserialize the following response from an RSS feed. I need the text blah blah blah etc as well as the embedded image source http://host/path/to/picture.jpg. <description>blah blah blah blah br /&gt; <![CDATA[<img src=http://host/path/to/picture.jpg>]]>&lt;br /&gt; blah blah bl...
Our application is composed of a main webapp and a handful of windows services that perform a variety of jobs that feed, sanitize and optimize that webapp. In order to ease the task of maintaining this services I would like to unify them in a single application and while I have several years of practice in C# developm...
Following up with this, I have a bunch of coordinates and I draw them on a bitmap image as a coordinate system. Now, I would like to get rid of all the noise, and filter coordinates to give a "clearer" or "cleaner" path and "less" or "better" data to work on. To explain more, I will need to expose my awesome painting s...
In an Android project, I am using dagger 2 for dependency injection, applying mvp design pattern, and I am writing interface for almost every class. Although it does achieved the separation of concerns, each individual logic is not coupled with others. But for just making a simple REST call, it involved 20 plus java cl...
Here is my scenario. I would like advice on which path to follow, along with good reasons as to why. It would even be better if you could give an example based on experience of a similar decision but not absolutely necessary. I am working at a company wherein we have a backbone.js frontend app which has been around fo...
I am writing an API (using Java) that takes locale as a parameter. We want the clients to be able to specify "en-US" or "en_US" as they both seem to be widely used across all languages. I did go through these links How to get locale from string representation in Java en_US or en-US, which one should you use Java Loc...
I usually prefer to follow "composition over inheritance" rule, until I start stepping in the world of Java GUI. In my experience, for adding custom requirements in a GUI components, for example, add custom function in a JButton, usually create a class extends from JButton like this: public class CustomButton extends J...
In some books the implementation of Data Mappers simply update the whole row of a table using the data inside an object, but in a system is possible that two different operations update different fields from a same row in a database, which can make an update simply overwrite another one if both of them retrieve the old...
A while ago I've made a simple script in Javascript that tested how much time it takes to add elements to arrays. I've used 3 different methods: array.push(), array[array.length] and array[x] where x is the counter in the for loop. These results were stored and drawn to a simple graph using canvas. The script could bas...
I have a function that retrieves raw data from the database and returns an object which represents this data. Should the conversion between the raw data and the object be written in that method or should I dedicate a separate method for the conversion, according to SRP?
I was looking at bitwise ways to multiply and add numbers without using * or + operators. But I want to know that it might be possible that java may already be using a better approach underneath. I tried to find the algorithm for *,+,_,and / operations. I read some paragraphs of JVM Specification but could not find sat...
Java here. I have always used Spring DI (for Spring projects) or Guice (for non-Spring projects) for dependency injection, and have always loved them. I recently took a job where they do 100% "DIY DI". That is, every project's main/driver class has an init() method that creates all of their objects/factories for them: ...
This might be a little unrealistic bu i will ask anyway. Would this be possible to create literally create a new class during the run time execution, i don't mean a new instance, i mean a new class created from the code itself. I'm actually using reflection in java, i can get the field's name of the class and the met...
Background:I'm a not very experienced software developer, currently working on a legacy project where all the business logic is in the database(sqlserver) using stored procedures. Now we are asked to rewrite the application from foxpro to .net but using the same database. Question: My team architect suggest a n-layer a...
I am working on a project based on the Java EE technology. First I'd like to tell you what I want to achieve, then what I already tried. Task: Imagine two types of configurations, which you want to choose and edit/define in the JEE application via GUI entries. Config A is for the communication with System A and Config...
I have been reading some similar questions here but they are not the same. The project we have inherited from our partner has fixed scope and a fixed deadline to deliver. We are now thinking about way how to manage and agile seems to be the way (providing the framework). If there is basically nothing left to juggle wit...
Edit: There is no "right" or "wrong" answer here, I was merely trying to get people to share their dos and don'ts. Behind this rather vague topic I would like to address a few problems I've been having in my last projects. As a general rule, I try to keep it simple, follow design patterns and the Single responsibility ...
Recently, while writing some Spring/JPA code, I stumbled on an issue I tend to face with from time to time: I passed an empty collection to a repository method that generates an IN expression for the WHERE clause causing an SQL query syntax exception (WHERE column IN ()). To work around this issue I just return an empt...
In ASP MVC we have the Authorize attribute to perform check at either a controller level or at a controller method level. But what if you need to do check permissions inside a controller method e.g let say your doing some update or create action to submit a blog post. Some users with revant permissions can attach files...
I'm creating a library. I want to use it in multiple projects which may use multi-byte or unicode (std::string or std::wstring). I've adopted the old MS method of conditional compiling: namespace my_namespace { #ifdef UNICODE typedef std::wstring String; typedef std::wstringstream StringStream; #define Str(...
I am currently working in a project that is to build a online judging system like codeforces. That is where someone can upload a file for a programming solution and our system will compile the code and generate the output and finally send the result that the solution is correct or not. The front end is going to build ...
There are several database version control solutions out there to assist with controlling not only the versioning of a database, but also deploying and synchronizing databases. These systems are typically based-off either a "source/target difference synchronization" model, or a "direct application of migration scripts"...
I have following hierarchy of topics I am working on DataStructure Linked List Array Stacks Tree Enterprise Apps EJB JMS Android App Games Productivity Apps My question is how can I best organize it into GIT (Gitlab or BitBucket). Should I create one repository for DataStructure or individual for LinkedList, etc...
I have a web app with JavaScript front-end which communicates with back-end via REST API (AJAX calls). Front-end have a Sign Up page. When user decides to register, front-end makes REST call to register that user (POST request sent to /users resource URL). Users can also login/register via Facebook. When someone choose...
I'm struggling to set up a database to use in my School Academic system that is supposed to record all student's scores and then be able to prepare a report that shows students ranks. The hardest part is, if I have many students and many courses/subjects, and students take 2 tests every semester, how do I set up db tab...
I've been playing the rerelease of The Logical Journey of the Zoombinis recently, and trying to implement some computer algorithms that can solve the various puzzles. I'm stuck on how to approach the Captain Cajun's ferryboat puzzle. For those unfamiliar, a Zoombini is a creature with 4 attributes: hair, eyes, nose, an...
I really need someone to confirm the following, and if necessary help me filter what I have read so far. AJAX, which stands for Asynchronous JavaScript and XML, is used to exchange data and is a form of communication between client and server. Practically, it is used to retrieve data and update a page without having t...
I see that in many projects and examples that local includes are listed before external libs and before header files for built in compiler functionality. Is there any advantage here that I am missing? I have always used the following model: 1) built in header files 2) External lib header file A) External lib depende...
I am currently building a small project that is supposed to keep track of recipes. Each recipe has a bunch of information, including a rating for said recipe. Since the rating has some additional logic i put it in it's own class. Now i am thinking about how to call a rating vote on my recipe object: public class Recipe...
I am building a management tool for recipes. Recipes have a bunch of data, including very generic stuff like an ID, tags, ratings and trivia. I currently only manage recipes, but i want to add support for ingredients, products, etc in the future aswell. These will share the same attributes mentioned above. Does it make...
I'm searching for a way to open a TCP connection, send a HTTP post request and keep the connection open. It would be great if I can achieve this without administrator/root rights, from a command-line interface (CLI), cross-platform and with passing parameters. Some background info. I managed to rebuild a direct HTTP re...
I am maintaining and Android app that now suffers from an unsafe X509 TrustManager implementation. Since the app doesn't make any HTTPS calls except through dependencies, one of the dependencies is causing the issue. The problem is that I don't know what any of these dependencies are for (there are ~20) except for one,...
What will be the result of the time complexity of this piece of code i.e. int sum(int A[], int n) { int sum = 0, i; for(i = 0; i < n; i++) { sum = sum + A[i]; } return sum; }
I want to learn AngularJS but on the website I see a button with the text Try the new Angular 2. Is Angular 2 ready for production use or should I learn and use AngularJS 1?
I need to find an optimal distribution of some matching tasks on multiple jobs; each job is limited by a maximum workload and the grouped tasks should maximize the workload within the same job. However, tasks with similar values within the same source should have a higher priority to be included in the same job. For ex...
MongoDB is a NoSQL database which I've found quite easy to use. Recently I had to develop a simple application which needed to collect some data using HTTP requests and store some results after processing the data, and I tried using MongoDB. From this experience I found it much nicer to use than traditional relational...
I've switched to PHP 7.0 very recently and I was wondering that if password_hash was better than making your own salt and using the crypt function. I have three examples of code and I don't know which make the passwords the most secure. Example #1 (BCRYPT): $options = [ 'cost' => 12, ]; $hashed_password = passwo...
I have noticed that I recently wrote the following commit message: Since HTML changed, getting the index would always result in zero, since the element is now enclosed in a parent block. For someone who starts by viewing the diff of the commit commit first (for instance after doing a blame on a file) and doesn't get ...
I'm writing a program in which I fscanf a file and write to the same memory address repeatedly. I tried the following: FILE *f = fopen(fname, "r"); int* num; while(fscanf(f, "%d,", num) != EOF) { printf("%d\n", *num); } which, when I run it, produces Bus Error 10, which means to the best of my understanding tha...
I wondered whether a while loop is intrinsically a recursion? I think it is because a while loop can be seen as a function that calls itself at the end. If it is not recursion, then what is the difference?
You're writing an app where the model (as in MVC) is an object graph. Occasionally, you want to save this object graph to disk. What are some best practices to ensure that the write is consistent? (That is, how do you prevent the object graph from mutating in the middle of a serialization/write?) In my app, whenever a ...
I have 2 objects that I'm not very certain what is the proper (or better) way I should use. I have a query builder object that constructs an SQL statement like $qb = new SelectQuery('users'); $qb->columns('id', 'email')->where('id', '=', 25); print_r($qb->build()); print_r($qb->data()); Output SELECT id,email FROM us...
I have created a class HidDevice to form objects which concatenates input from each HIDDevice separately until a special key (ENTER) is pressed. So each instance of HidDevice have fields like int deviceId, String concatedInput. public class HidDevice { private int deviceId = -1; private String concatedInput; ...
Lets assume that we have a Spring Boot application that uses microservices architecture. Each of the services has its own domain models, but each service must reference a User domain object. What would be the best approach on how to solve this issue? Would it be better for each service to just have a userId and then, w...
I realized I haven't seen this type in Objective C or Swift. But we have UInt. Is there some more Computer Science specific reason we do not have an Unsigned Float? Afaik it's not in c# too.
Just to be on the same terms: Aggregation is a has-a relationship, where the owned components can exist independently of the owning component.E.g. a pond and some ducks swimming in it. A duck leaving the pond doesn't mean the duck giving up its existence. In an OO language (or actually any language without referential ...
Should an interface method implemented by a class always use all parameters? By interface I do not necessarily mean actual interfaces, these could be other (abstract) classes which are extended, too. I sometimes find it hard to use all parameters in all implementations. However, that seems to me as bad design. It makes...
There are lots of good resources on μServices that focus on concepts like Single Purpose, REST, Implementation and Deployment, CI/CD, Encapsulation and Isolation, Separating UI from API, etc. However, having made all the promises about μServices (plural), they all immediately go deep into designing a μService (singular...
Suppose I have a function f that uses two helper functions h and g to get the job done. There are two possible ways of dealing with this situation. (1) take explicit arguments and returns new objects from each helper function: def f(x): def h(x): <do something> return y def g(y): <do som...
At the moment, my (pretty standard) REST interface looks like this: POST /foo # creates a new foo PUT /foo/{id} # updates a specific foo GET /foo/{id} # returns a specific foo GET /foo # returns a collection of foos Only authenticated clients are able to use these operations. When using GET or...
I'm interested for some time in CPython implementation of Python. I understand that .pyc files contain serialized bytecode, including opcodes. However do these files contain mnemonics? I think that interpreter could use just opcodes. Am I right?
I have film's storage (3 tables in database): films{id:int, film:string} genres{id:int, genre:string}, films_genres{film_id:int, genre_id:int, probability:int(%)} (film_id, genre_id) is UNIQUE KEY(compound key). For example: films = { 1 : 'Some film 1', 2 : 'Some film 2' } genres = { 1 : 'comedy', ...
I've worked on a large Rails app where the use of ActiveRecord callbacks was rampant and harrowing. Saving a record often had unexpected side-effects and it was a challenge to reason about the system. At the same time, I've seen hooks used to good effect as part of inheritance (e.g. a parent class using a template-meth...
I'm currently re-factoring a part of our application at work. I'm normalising a data structure from a flat list of fields to a parent/child relationship. This has an impact on all layers in the application: The database Models Business logic; and The UI Instead of creating a few massive commits - where each commit co...
I am about to start prototyping a 'quiz'-like web application that tests test-scoring methodologies, and I have an interesting architectural question. Each quiz given to a user needs to use a set methodology to score it (e.g. Formula Scoring, Number Right Scoring, Negative Marking, etc.). A quiz consists of a series of...
I'm working on a C++ codebase targeted at multiple platforms, and we've just moved over to CMake as our buildsystem. Previously our buildsystem was a pretty ad-hoc affair; getting our code under a single common buildsystem has been a real step forward. The next pain point I've encountered, though, is that I'd like to b...