instruction
stringlengths
34
36.1k
When I try the below code I am not clearly able to analyze malloc api internal calls.What I am not clear is about the system call mmap is called only once for 2 or more malloc calls.If I am assigning more then 4069 bytes also it is calling only one mmap internally(trace is identified by using strace -p processid ). #in...
I have 6 web servers which are giving me problems due to cache inconsistency. I am thinking of building a cache invalidation service such that there is a topic on which all the servers can publish a message to invalidate an object. I am considering using the Amazon SNS for the making the topic. Now for the servers to r...
I recently moved from Java to JavaScript on Node.js. I was very excited, opened up my IntelliJ IDE for an existing Node.js project only to find I cannot know what the parameters I see functions receiving actually are except for their names (in java I could click the parameter type and see what it is..), I cannot use C...
Open source software should be developed by different contributors in decentralized fashion. I understand that Open JDK is reference implementation of Java which is open source and it allows contributions towards security and bug fixing. I believe Oracle makes most of the contributions to Open JDK. Does Java qualifies ...
What is the best practice for logging user-related data in microservices architecture? In example: I would like to audit/persist to database information on who deleted a resource. I have user info on the first (client-facing) service, but I don't pass it further. I wonder if there is a smart way of doing it - like inje...
In the past couple of weeks I have seen a couple instances of people passing an ErrorAccumulator type of object into functions that aggregates errors as Strings inside of the function then after the function returns the errors are iterated over and logged. To me this feels like bad OO design because you are modifying t...
I'm reading Domain-Driven Design at the moment and I'm trying to understand what should go in services and what should go in domain models. Say there is an application where you can reserve seats for concerts. Then after this you have a certain amount of time to pay for the tickets, after which the reservation is...
I would like to draw a UML sketch to communicate part of a software but the type of relationship between classes does not seem very clear cut to me. Let's say I want to periodically fetch the recent orders from the database and update a graphical view that has the order details. This is a highly simplified pseudo cod...
I am currently working on a pet project in Python with scrapy that scrapes several ebay-like sites for real-estate offers in my area. The thing is that some of the sites do seem to provide more structured data in their web pages(ie. presenting a table of all the utilities the apartment has etc.) while others don't. Th...
Background My program communicates with a device that is usually asynchronous, but can sometimes behave synchronously. I have an event handler that I use for receiving the data asynchronously, then I have a separate event handler that I use when the device is in the synchronous mode. So, when I need to communicate with...
There is a Java program that reads a list of orders and for each order starts a thread that receives data from SQL and prints the list of items in a given order to an order_name.html. I want to write a class that would generate all_orders.html that contains a list of items and the quantity of each item in all orders. ...
I want to structure my Python project in a manner such that others can use a package manager (PIP) to easily clone the environment for team development, and GIT to contribute to the project, plus a library dependency. My confusion relates to organizing a project around PIP and GIT (I'm familiar with SVN). The project d...
We are trying to adopt some CI practices and methodologies into our organization. I'm currently reading over some of the points in "Continuous Delivery" book written by Jez Humble and David Farley. And the point that I am debating is when unit tests should be run - before or after git commits. The book seems to sugg...
I made a few classes for processing and validating data in xlsx and csv. However, I am curious in testing how fast the methods I wrote in C# for the heavy lifting are. Here's what I currently am thinking of (written in C#): // use this to test the performance of the method on files with various sizes class FileProcess...
Why code in C? Isn't C++ basically C but with better features? Why do people still use C? Would it be easier to make a game with C or C++?
Chatting with a friend about a game we used to play, and thinking how to implement it in code. Here are the rules: Given a list of number e.g. {1,2,3,4} Try to use all the numbers from the list to perform +,-,*,/ operations to reach a target number (e.g. 2). The numbers can be used only once, the operators can be used ...
In my game I want characters to be able to cast spells which deal a certain amount of damage of a certain type to other characters in the game. I also want abilities that negate an amount of damage of a certain type to be equipped to a character. I don't want to have to program a huge wall of damage resistances that us...
Suppose a web application relies heavily on the third party APIs and I am expecting a response from it but somehow I don't get any, maybe because of the API exception or missing value on the API side then, in that what should I do? As far as I can understand if I get the API exception I can catch it and send some error...
I am trying to create a thread that will sit and wait to detect new objects in a vector (the queue). Using a loop will crush the resources on the given machine, so I am trying to figure out how I can create a blocking thread that waits for a notification from the main thread. The application will essentially wait for n...
I have these two classes (Getter/Setter/Constructor omitted): public class Company { private String name; private String adress; private List<Employee> employees; private Uuid id; } public class Employee { private String name; private int age; private Uuid id; } The two entities and their ...
Given a piece of code, I may use one of many methods to determine the big O complexity of the code manually (runtime and memory). But, for a given piece of code, how do I determine whether what I found earlier is correct or not? Are there tools available where I give an EXE, give test cases and I get an output saying t...
Hello i'm developing an app that needs to do many requests with different socks connections. I was doing it in C# but i'm not sure how well it will work on a linux server even with .net core . Java Socks connection is unique for the JVM correct? It needs to have 100+ different socks connection and can't be that thread ...
I wanna ask about Neural Network. I have a research and programming about Neural Network using Backpropagation algorithm for prediction. My input data using binary form. But, i'm still confuse, because i get some input data from expert. I have separate some data for training and the remaining data i have use to testing...
What is the difference between the following two methods of creating an array in C#: int[] arr = new int[] { 1, 2, 3 }; Array arr = new int[] { 1, 2, 3 };
I have three questions concerning Demeter's law. Apart from classes which were specifically appointed to return objects - such as factory and builder classes - is it okay for a method to return an object, e.g. an object held by one of the class's properties or would that violate the law of demeter (1)? And if it violat...
I'd like to check what best practices are avail out there. I have the following requirements: I have a repo which is used for development (master and develop branches). I would like to keep track of alpha/beta/release candidates and release build. I am considering to create branches for alpha/beta/rc/rel and then when...
I am writing a program to crawl the web and find frequently used words. What would be a good way to store the data? I was thinning of using an RDBMS with a single table (with columns 'word' and 'count') but for something so simple it seems like overkill. I need to achieve some functionality like sort by count/find n le...
I'm reading the head first c# book and don't quite understand what this means. "Any class can see private fields in another instances of the same class"
Often when I program in C I write the expression for (int i = 0; i < j; i++). I never wrote a macro or a define expression, but could I write a #define to simplify the above expression so that do i,j gets pre-processed to for (int i = 0; i < j; i++) ? Or, is it for some reason not a good idea?
I'm reading the 'Refactoring' book, and i'm at the "Extract method" technique: Original code: void printOwing() { printBanner(); //print details System.out.println ("name: " + _name); System.out.println ("amount " + getOutstanding()); } Refactored code with "Extract method" technique: void printOwing() { p...
I am very confused about what should a SPA's REST backend do and expose. In most blog posts and books I read they depict the backend pretty much like a direct access to the DB, practically CRUD methods that allow access to the DB after authenticating the user. However I don't see where to put the actual business logic....
Inside system I'm developing I have several Windows Services, couple of applications running in Scheduler and COM+ application that is running my custom DLL's. Some of them are running on same PC, but most of them on different machines but in same local network. I'd like to monitor status of tasks each element does. Fo...
Is it possible to add a new row to a database using DataSet? When I created a new DataSet and dragged the table from the database I could see that in the DataSet methods there was one called insert that in the preview showed a parameterized query almost like a stored procedure to insert data. However, when I create a n...
Background Thinking about OOP I feel that it binds data and behavior together, taking the real world example we already have array data type which is a collection of homogeneous type and in Java we have build a nice abstraction over it hence, we have methods like clone which does its job perfectly i.e. we have data and...
We are contemplating breaking up our monolithic monsters into microservices based architecture progressively. We have 5 teams, each team containing 2-3 C# developers, at least 1 database developer, and 2 QA engineers. Besides the huge culture and paradigm shift going from a monolithic architecture to microservices ther...
We all know that properties in C# get compiled to actual plain old methods. But unlike method(-group)s, they can't be given as arguments to other methods that expect a delegate like a Func<T> or Action<T> (getter and setter). Is there anything special prohibiting this, or is it just a feature that didn't come "for free...
I have been teaching myself how to code for about a year (I'm 17) and one of the most common things that I've come across while reading articles about programming is automated tests for your code. I know automated testing is something very helpful but I still don't get it, what are you supposed to test in your code? I...
I want to provide rest api for my iot service to read state of a sprinkler on/off. So far I've come up with two solutions: GET /api/sprinkler that returns 204 if on and 404 if off GET /api/sprinkler that returns 200 and {"status": "on"} The first example is based on this. By returning code 404 we imply that the resou...
I was assigned to a new project recently. Well, an old project actually, written in classic ASP. Now a new version of the application is being written in the latest ASP.NET, but it's not expected to be RTM in a while (estimated release date is January 2017) so I have to perform some maintenance on the old application u...
the What is free software page on the gnu.org web site states among others: »An example of such an acceptable rule is one saying that if you have distributed a modified version and a previous developer asks for a copy of it, you must send one.« I like this clause, but I do not know how to add it in my licensed software...
So I have a set of given locations (i.e. two-dimensional points) G, a set of wanted locations W and a natural number N. Assume |W| < N. I want to choose N elements of G such that the elements of W are somewhat covered (i.e. for each element of W there is a chosen element of G that is "nearby") and the choosen points a...
I'm a freshman in a Computer Science academy. Every semester there are a lot of different classes like Discrete Math, Linear Algebra, Algorithms etc most of which I find very interesting. Unfortunatly each day has only 24 hours and I find myself unable to get a more indepth knowledge of each of those classes, beyond th...
We are a bunch of freelancers working together making websites and apps and we starting using Scrum recently. We're enjoying Scrum and its transparency but we're encountering a problem with the budget side of the equation. It feels like Scrum doesn't consider budgets, but we are too new to know for sure. Is there a way...
I'm trying to find a good name for a library where I can put in all non-UI related code that I want to share between iOS apps (networking, filesystem, logic, algorithms, data structures). Names that I don't like too much: Model Backend NonUI Core Suggestions?
Haskell’s String type is an alias for [Char] (i.e. a linked list of Chars). Does any other language use an implementation of strings like this?
Most architectures I've seen rely on a call stack to save/restore context before function calls. It's such a common paradigm that push and pop operations are built-in to most processors. Are there systems that work without a stack? If so, how do they work, and what are they used for?
Are events only used for GUI programming? How do you handle in normal backend programming when something happens to this other thing?
In my unit tests, I often throw arbitrary values at my code to see what it does. For example, if I know that foo(1, 2, 3) is supposed to return 17, I might write this: assertEqual(foo(1, 2, 3), 17) These numbers are purely arbitrary and have no broader meaning (they are not, for example, boundary conditions, though I...
I am using GhostScript on a desktop application that I intend to sell online. The GhostScript library has an AFERO license (see here). I do not mind to make the source code of my application available to anyone who requests it. Therefore, can I license my application under the GNU Affero General Public License (GPL), e...
Question: In a database for a clinical reference lab a specimen, when taken, triggers a test order (for testing obviously) creation.If that test order produces a failure, the specimen is given a new test order and tested again until a non-failure result is obtained. And test order is created for exactly one specimen. ...
final CyclicBarrier cb = new CyclicBarrier(value,new Runnable(){ public void run(){ ...statements } }); suppose you have a cyclic barrier in which one of the the arguments is the direct override of the run(). Is there a specific term for this kind of object creation? Are there significant pros and cons in t...
When is memory allocated to a constructor in a C++ program run? I think it may be when the instance(object) of the class is created or so. Is it correct?
Some methods are deciared this way: public int myMethod() throws Exception { (return an int or throw Exception if method fails). However, stub methods in NetBeans look like public class JavaApp { public static void main(String[] args) { if(false){ //this branch is never used int a = ...
I have a SQL database to which I store and from which I read several objects into my C++ code. I wrote a single database wrapper which handles all the reads and writes to the DB. Of course this class got too large. I could make a Database wrapper for each business object but then I have to instantiate all these diffe...
I'm creating my first online game using socket.io, and I'd like it to be a real-time multiplayer game like agar.io or diep.io. But I've run into the issue of trying to figure out how to get all the computers to work at the same speed. I have three ideas for models, but none of them seem right, and I'm wondering how nor...
Let's say you have many paths that an application can take at a certain point based on the value of a specific input (for example a simple int). Is there a certain method that is most efficient for picking which path to follow? A nice and organized way would be a simple switch statement, but does that scale as the numb...
let's say I have a database connection in the class Database which offers the following public methods public synchronized void open() {} public synchronized void close() {} public synchronized void addData(Object data) {} My main program looks as follows: Database databaseConnector = new Database(); for (Feed feed :...
In an ASP.NET app, I've got to decide whether to put a complex piece of code on either the client in JS or on the server in C#. I've considered performance (if on server, it would be a small callback), IP protection (all behavior is visible on the page), need for server interaction (none during the execution of this ...
I'm a building a registration form for my website and need to populate the country, state and city field. All these fields are inter-linked i.e depending on country, state field will be set and depending on state city will be set. I'm trying to figure out what's the best approach to model this using Neo4j. Do I need to...
The last time I used asp.net 4 years ago, the "ASP.Net Membership provider" was the best way to do user authentication in an ASP.Net application. Nowadays, is using the "ASP.Net Membership provider" still a good way of authenticating users in an ASP.Net MVC application or is there something new for this purpose? Is the...
I am writing a game in c++ with the v8 javascript engine embedded in it. I have a c++ workflow system I use to tell things how to do specific things. It's nice and I like it, but I need it to work in javascript as well. The code describes the whole process, but it is asynchronous-ish and only selectively runs the p...
In many of my personal and professional projects inevitably comes the moment where we have to weight pros and cons of integrating third parties versus developping a home solution. I've always been a fervent user of open source resources and faced programmers I respect who were following other path. The arguments are co...
When I'm working on a project, I tend to write a lot of code. A lot of code means alot of bugs. If I commit my work early on , I have to edit that commit when I encounter a bug and fix it. This is why I have started to commit at the end of the work on the component I'm working on. This means I could do changes without ...
I am designing a data warehouse for a sales platform. There exists a group of users that offers and a group of users that demand entities. The production data base holds two sources of information: The current status of each entity and to which users it is assigned (this can be versatile, "placed a price for an order"...
The setup So we have a RESTful JSON API. There are iOS and Android applications that consume the said API (one of each). The code for the applications is such that the endpoints are hardcoded to "http://api.mycompanyname.com/json/someEndpoint". In order to test the applications our sysadmins have setup DNS poisoning ...
I made an extensive research in previousv related questions, but since my questions is somewhat peculiar, I decided to create this new one. I am implementing a visualisation application (in JS). There is a class, called Graph, that contains the visualisation of a graph, along with all the necessary components (nodes, ...
I am working on a project where you have controllers that expose an API and services that implement some logic. In this project, each service* checks for the user's permissions to use the service. When asked, I am told it makes life easier to the service's consumers because they don't have to bother themselves with p...
Functional programming is often explained to agree with lazy evaluation. As far as I know lazy evaluation means that a method gets called if the evaluator/browser/etc. thinks that is the next best thing to do. I've read about lazy evaluation here. That makes me think; promises are designed to run, and after they are do...
I often find that "!" characters (meaning "not" in C-based languages) are easy to overlook. So I sometimes create methods that return the inverse result. For example, instead of doing this: if (!dataContext.Permissions.HasAccessToFeature("FeatureX")) { ... } ...I create a second method that is the inverse of the othe...
I've been working on a project based off of this tutorial. Unfortunately, the controller classes in this are quite dense and have terrible separation of concerns. I should have realized this originally but, I ran with it and now am stuck dealing with the terrible design from this tutorial with my added features/bad de...
We are using ORM with bunch of database models and those ORM database queries (and models, of course) - are literally all over application from top to bottom. And when change in model structure happens it wreaks havoc. Changes are expensive, difficult and stressful. My suggestion is to surround database schema with nic...
Assuming the compiler is smart enough to only evaluate the if in the second example once, which version should one (semantically) use and why? if (b) { for (auto a : as) { foo(a); } } else { for (auto a : as) { bar(a); } } vs: for (auto a : as) { if (b) { foo(a); } else { bar(a); } } I...
I suppose that maybe what made me ask this question is, that every time I do a commit in Git the .sln files comes up whenever there were changes. So, as a person who reviews all my changes when I do a commit I tend to look at the solution file as well (just observing what projects may have been added, or maybe configu...
As I'm sure most of you are aware; tmux and screen have features that allow the sharing of a concurrent terminal session with a remote host. At first this seems great, and for some purposes it is, but there's one problem: Even though both users (local and remote) are able to send keys and observe the changes live (i.e...
I am dealing with a lot of legacy, reverse engineered binary file formats, often with lost source code and reading/writing these files needs to be recoded in C++. I am wondering if there are good examples or ideas on simplyfing the process of converting documentation of the file format into code with goal being to load...
I am learning how to read Excel workbooks in Java and want to know what a good Data Structure will be for holding Column names with the values under them. Example: I want to be able to call a method: getColumnValue(String columnName, int indexOfValue) and get the value at that position for the specified column name. I...
I was reading the Spring Cloud Netflix documentation when I found out about a way to share an interface between an HTTP server and its client. They use this example for microservices, although there's no reason why it can't extend to generic HTTP communication: // The shared interface, in a common library public interf...
I am concerned about whether or not I am using FactoryMethod correctly. Background: I am refactoring legacy code and I have identified a pattern: there is a God Object that is created in memory, and later various parts of it is saved to many different tables. For example, various parts are called Selection, Design...
I know that most of the pos tagger algorithms measure their accuracy token wise I.e. whether the token is tagged correctly or not Some pos taggers provide sentence accuracy too. How is sentence accuracy calculated. Is it like if one token in sentence is wrong then entire sentence is wrong or a sentence is correct if th...
I was finishing one of my earliest C++ projects which is (according to the framework) supposed to be cross-platform. I developed the project fully in Windows and Visual Studio, thinking that since the libraries are all cross-platform, then doing the OSX build "later on" would be trivial. This turned out not to be the c...
I'm in the process of building out an architecture that will heavily leverage DynamoDb. My organization is considering the possibility of storing sensitive data (config info) in DynamoDb, as well as non-sensitive data (e.g. telemetry data). Historically, our SQL Servers have been protected by numerous layers of network...
The question can be summarized as: In a database (regardless of type), would it be considered a good practice to always include updated, created (and possibly deleted) properties, for all entities, regardless of nature? The question is asked in the abstract, but I'm looking for real life answers, common - and hopefull...
Suppose I have two blocks of code, A and B. A is to be executed before B. As I understand, I can do one of two things: 1) Put B in a separate thread that is to be executed after A's thread, or 2) Put A and B in the same thread, with A preceding B in the order of execution. Option #1 means more memory will be allocated ...
I am maintaining an app that uses a lot of sql server 2008r2 stored procs, views etc. The problem that I have is that certain stored procedures/views have code that is specific to the environment: production, test or development. That's how I inherited the system. The differences come from the way the linked servers h...
I wrote a command-line utility and I want to develop a GUI for it. I saw that almost every tool on linux comes command-line, and it eventually has a GUI which interacts with the command line utility making life easier for those who aren't familiar with command-line. I want to do something similar, what is the standard ...
I work at a mostly .NET shop. A coworker has more of a background in open-source MVC (think RoR and Spring MVC). She seems to really enjoy .NET MVC, but she practically refuses to work on Web Forms, and has a hard time switching gears/working in Web Forms apps. And I hear similar things from others. I for one also much...
I've a web application that consists of 3 main technologies: JSF, jax-rs and websocket. All three are coupled together with the help of CDI injection and JPA. That means that when a user login, he does so through a managed bean. Then he can use websocket (chat) and Rest service (to have notifications) and JSF for norma...
Consider a function like this: function savePeople(dataStore, people) { people.forEach(person => dataStore.savePerson(person)); } It might be used like this: myDataStore = new Store('some connection string', 'password'); myPeople = ['Joe', 'Maggie', 'John']; savePeople(myDataStore, myPeople); Let us assume that S...
As I know, according to "composition over inheritance" rule, we should avoid reusing a method by inheritance, but how about class members? Suppose I have parent and child classes like the following: public class Animal{ protected String name; protected int _id; public String getName(){ return name; ...
The idea is inspired by the fact operators such as +, -,%, etc. can be seen as functions with either one or two arguments passed, and no side-effects. Assuming I, or someone else, writes a language which stops more than two arguments from being passed, and also only works via return value: a) would such a language lead...
So my problem is, I have users entering their data(names, address) in a mixed form- some with first letter in caps and some without, some inserting more than necessary spaces and so forth. Also, since there are some with titles in their names(happens in some parts of Europe), the title words have to be in small. Now ...
I've found it difficult to find a definitive answer to this question. Using Semantic Versioning and GitFlow should my release branch include the minor version number? I'm not referring to tags. My application tags looks like this: v1.9.1 v1.9.2 v1.9.3 I'm now ready to do a release candidate. Should my release branch i...
I want to be clear when discussing an implementation that we're using soft-deletes (not immediately removing data from the database). What can I call our approach? The best I have is "CRUD with soft delete", just "CRU", or CRUH (create, read, update, hide), which afaik is a neologism.
There are times when I will need to modify a value passed into a method from within the method itself. An example would be sanitizing a string such as this method here: void SanitizeName(string Name) { Name = Name.ToUpper(); //now do something here with name } This is purely harmless since the Name argument ...
In the new java.time package the core classes are using the factory method of instead of a public constructor. Even though I like the cosmetics of the of method I can't see a good reason to not use a constructor. The documentation I've found just explains that this is the case and doesn't really go in to why it's the c...
I currently have a setup looking like this: __________________ _________ ________ ___________ | Front end server |----| Varnish |----| NodeJS |----| C-service | ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾ ‾‾‾‾‾‾‾‾‾ ‾‾‾‾‾‾‾‾ ‾‾‾‾‾‾‾‾‾‾‾ NodeJS and C-service runs on the same virtual server. The front end server ...
I am developing a simple RESTful service for tournaments and schedules. When a tournament is created through a POST request containing a JSON body, the tournament is inserted in a BiMap, declared as follows in a DAO implementation: private BiMap<String, Tournament> tournaments = Maps.synchronizedBiMap(HashBiMap.create(...
It's really nice to have automatic binding with Jersey-Jackson (well, I believe it's actually MOXy the one who manages the bindings), so object serialization and deserialization is done under the hood. Examples of both that I use in my RESTful service: @POST @Consumes(MediaType.APPLICATION_JSON) public String createTou...
I recently picked up learning PHP and MySQL and I am trying to build a small usersystem as a coding exercise. While learning to use classes and functions, I also stumbled upon the MVC model and would like to implement the model in my code. Is the following approach correct MVC? index.php, message.php, user.php are all...
I have an ASP.NET Web API 2 web service. This is the interface customers will use to submit data. I have a Windows Service running on an internal server. I will be sending the customer's POST data to this service adding a unique ID to the message. There exists another service running on another internal server that wil...