instruction
stringlengths
34
36.1k
Suppose that I am developing a relatively large project. I have already documented all my classes and functions with Doxygen, however, I had an idea to put a "programmer's notes" on each source code file. The idea behind this is to explain in layman's terms how a specific class works (and not only why as most comments ...
I am having difficulty with the answer provided here, but I couldn't understand how to implement it. My code is pretty much identical: <script language="javascript"> function check(form) { if(form.userName.value == "User" && form.userPass.value == "averyobviouspassword") { window.open('testok/menu.html') ...
Here is the situation: I have a database and a class that is basically a representation of a set of fields of different tables in it. Let's call it Message. "Message" does not know of the database and whenever I need to synchronize it to DB I use separate functions accepting instances of Message to do it. Whenever I ne...
It's about what the class gives access to through inheritance. It has a three letter abbreviation but not API. I've seen this before but can't remember at the moment. The term is usually used in the context of a framework where you are expected to extend classes from the framework. This would be closely related to...
I was installing the Office 2016 Preview yesterday (link for anyone who's interested) and noticed that you can actually use the Office applications provided before the installation is complete. When running the Office applications while the installer is still running, I sometimes see a message in the bottom right corne...
Passwords are recommended to be stored in char[] instead of String, as Strings are stored in StringPool. Read more here As per this question Strings in StringPool are not available directly. To obtain Strings in Stringpool, we would need a password-dictionary to check them in StringPool. If we have a password-dictionar...
At our company, I have been given the task to develop a Mobile Application (iOS, Android and in the future, maybe Windows). Given those devices, it's likely that we'll have a high number of installations spread over all those devices. Off course, for a mobile application it's very important to be responsive, so therefo...
I'm working on an ASP.NET MVC solution that has two projects, WebUI and DAL. WebUI references DAL. DAL has the repository and context, while WebUI contains Authentication and Authorization classes. The problem is that I have to send some of the Claim's information to the Entity Framework's context constructer. I have s...
A few times in my career I've encountered design problems that couldn't be elegantly solved with single dispatch and required double dispatch (which I implemented using visitors). However, I've never encountered a problem that required triple dispatch. They must be exceedingly rare, but that doesn't mean they don't exi...
I am a Ruby on Rails developer and I like its simplicity and rapidness. On the other hand we need to use Java for some projects that we develop for our clients. My question is why (pure) Java does not have a framework like Rails? I searched and found some alternatives but they have big disadvantages: Spring-roo: small...
I've written an Android application and I want to publish it as a FOSS application, however, I want to restrict others from publishing it in Android markets (e.g. Play Store) with only changing the name or the package. Which open source license should I use to achieve this requirement?
I am working on time attendance module and I managed to read the data from the timing machine in the following format: Id CheckIn Type Status 0000142 5/15/2015 6:00 PM 2 OK 0000142 5/15/2015 2:00 PM 1 OK 0000142 5/15/2015 6:00 AM 1 OK 0000142 5/15/2015 3:00 PM 2 OK where Type [ 1 - stam...
I am in the process of removing direct dependencies from an existing project. I have now come to removing the direct use of $_SESSION inside scripts. This is to make the same scripts available for an environment other than a web server such as PHP CLI. The code base I am working on consist primarily of classes, so I ha...
Some hyper-modern C compilers will infer that if a program will invoke Undefined Behavior when given certain inputs, such inputs will never be received. Consequently, any code which would be irrelevant unless such inputs are received may be eliminated. As a simple example, given: void foo(uint32_t); uint32_t rotatele...
I read the Spolsky blog the post with title "Evidence based scheduling" (http://www.joelonsoftware.com/items/2007/10/26.html) but I don't understand the mechanism to predict and estimate interruptions. If I understand, Splosky says to prepare 100 scenario for a task in ramdom way At point 3 of the article, Spolsky says...
I have a piece of software that I have been working on for a while now. You can find it here. Since it is now at a stage where it could potentially be useful to other researchers, I decided to cover it by the GPL. While most of it is code that I wrote myself, one set of functions, contained in butterworth.c and butter...
I need to write a messaging protocol between client and server for a game application. I need to send messages back and forth such as, Player joined a game, player left game, player performed this action, etc. I have a ClientMessage class that will construct a udp or tcp message to the client and send as plain text for...
Using a JWT authentication, the user doesn't have to log in each time he uses my app. I would like to save in DB the last time the user used/opened the app. Technically, I have a set of REST API that could audit each request and save in database the timestamp corresponding to the current user access but ... for each r...
I think I've found myself in a situation where things are quickly spiraling out of control, and I'd like to get some feedback to select a way to proceed. BACKGROUND I'm working with a library based upon C++03. The library is cross-platform and supports multiple compilers. There are no external dependencies or prerequis...
I am working on some Qt/QML/C++ app and I've got myself into some kind of dead end. Namely, this app uses mysql database and here is my questions: Is performance hurt if I instantate new database connection for every database query I need or is it better to connect to database at app startup via singleton object and re...
It seems like a pretty straightforward thing to add, but I just want to be sure .NET doesn't already provide one and save me from adding unnecessary code: I need a lookup table (like a Dictionary) that instead using a key/value pair, uses the first key to find the second key, and vice versa. For example - theList.Add("...
To read an integer from user input, you can use: int number = Convert.ToInt32(Console.ReadLine()); But why won't the following work? int number = (int) Console.ReadLine(); What's the difference between Convert.ToInt32 and casting with (int)?
I've got this code in Mathematica that fetches the left or right side of an equation by turning it into pure text then textually getting rid of the other side through regex. I've isolated the faulty pattern and can't understand why it is producing "infinite" backtracking: (\S+\s*)+(==|>=|<=|>|<)\s* sample text: x <= f...
I'm introducing git to a junior team member (a co-op). They are comfortable now with the basics of adding, committing, pushing and pulling. Now I want to introduce them to pull requests and branches. If they start doing pull requests in branches, should I do the same for my on-going work? I will be the one merging thei...
In Domain-Driven Design there's the idea of bounded context which is basically a way to stablish a boundary within which a certain model is valid as far as I understood. I've found this idea very useful because prior to reading about it one of the main challenges I've faced to use object orientation correctly was the e...
I've been building an application and the whole thing is built around a simple data storage system. Create an array. Convert it into JSON. Add <?php die() at the beginning to prevent access. Save to PHP file and save to disk. Then. Open file. Remove <?php die();. Decode it from JSON. Edit/Read array. Save it back t...
I'm writing a JavaScript style-guide for my team, so that we can organise and contribute our documents easier. But I've hit a small bump which is where my question applies... What am I supposed to call an anonymous JavaScript function that's called immediately. I know I could quite simply call it an "anonymous functi...
Suppose we have a method foo(String bar) that only operates on strings that meet certain criteria; for example, it must be lowercase, must not be empty or have only whitespace, and must match the pattern [a-z0-9-_./@]+. The documentation for the method states these criteria. Should the method reject any and all deviati...
I want to create a mapping in Python that will use images as keys, but treat similar (but not identical) images as the same key. I have an approach for deciding which images are similar enough: I shrink them, convert them to line art, and then compute the md5 sum. Two images are "similar enough" applying this process t...
I am new to Junit. I have a class with four methods. I am creating a test class with test cases. Can I have a test case that uses more than one methods of testing class or there should one test case per one method. What is good practice ?
In our application we have multiple layers. UI -> This can be JSP/ JSON result of the API Controllers -> as in MVC Services -> perform single business operation per service DAOs -> Data Access Layer (including connection/and DB layer) And two types of ValueObjects FormValueObjects --> More close to View Entities ...
In my earlier project I wrote an app that is used in-house. My usual practice is to capture errors/exceptions from different classes and threads and put them in different log files corresponding to different classes and threads grouped logically. And few simplified errors I targeted to the text area in the UI. So user ...
I'm making an iOS App, well, two actually. App A will be able to write TO-DOs to a remote MySQL database, and App B will be able to read what App A has written/modified. App B needs to be always up-to-date and there can be more than one instance of App B running on different iDevices. App B stored the almost-exact copy...
It's very interesting how to restore read model in system based on CQRS. In regular mode system processes commands, creates domain events and posts them to message bus. Then another part of system (call it RM subsystem) processes these messages and saves them to read model. This mode is good enough for regular purpose....
I have code that was written by someone else that goes like this: On a ViewModel: public static ACertainViewModel Default { get; private set; } On the same ViewModel's constructor: public ACertainViewModel() { Default = this; } On a method in the class that ACertainViewModel implements: if...
I'm new to Node and JavaScript (well, asynchronous programming in general) and I noticed when I was working on a project that the following code is a circular pattern and that these are bad practice for the obvious reason that the module might not have loaded yet (and the example code is throwing errors because of that...
I am often in a situation where I have to design and code a process/algorithm, and there are different variants on that algorithm. For example, I am currently writing some database sychronisation code that has methods for download and upload. Those methods are similar, but not identical. Having written the code, and ...
(Background - skip to bold statement for the crux) I'm working through the book "Growing Object-Oriented Software, Guided by Tests" by Freeman & Pryce, while applying it to a project I'm starting. My app is a web app in PHP that manages a user's eBay interactions. I'm using Behat/Mink to write the end-to-end tests. I'm...
I've taken over maintenance of an Android app, and there are a few residual problems that I've more or less fixed, but still have issues because of different Android OS versions. For example, sending a web request with the MediaPlayer class has custom HTTP headers stripped by the OS before the request is sent out, but ...
I've been reading the Sutton and Barto book and following David Silver's lectures on youtube. The basic principles make a lot of sense to me and I've been building a maze (an arbitrary grid where the agent can move up, down, left right unless blocked by a wall) solving agent that learns by randomly sampling paths and a...
I'm using EF (Code first) and I'd like to isolate the properties from the methods (many of the methods reference other libraries that I don't want my database project to have to reference). As an example, say I have this class public class Person { public string Name { get; set; } public void SayName() { Som...
So I am making a Super Mario Bros NES clone in pygame and for all enemies that are drawn to the window, I have a class hierarchy that is 5 classes deep. Going in the order of: Object (A base class for all things drawn on the screen) Character (A class for any type of character, playable or not) Enemy (A class for any ...
I have a game with such events as GameOver, GameStart, PlayerWin, etc. I only have one class that is listening on these events, for the purpose of sending these events as TCP json messages to a client (player). But for every important game function I write, I have to write an event and then call if(MyEvent != null) ...
As the input, program would get a set of point (x,y), along with the time a certain point was drawn. (suppose on a tablet). Let's restrict ourselves to simple polygons. I implemented Hough transform, in polar coordinates. Mapping points from (x,y) space to curves (r,fi) space. P:(x,y)->(r,y), Re->Re^2 Define function...
I just learned how to create a class or object in C++ and I'm practicing and learning. I'm writing a text based version of a popular board game and I was wondering if it's overkill creating a class for six sided dice instead of creating a simple function generating two random numbers between 1 and 6 and returning the s...
I had a very large ArrayList in Java, and I often need to check if it contains a particular value. This has proven very slow. Then I discovered that you can use a data structure based on a Hash. Because apparently, a method like containsKey() is O(1). Nice result - but, how is this achieved? Clearly it doesn't go key b...
I recently watched this presentation of Robert C. Martin about the Single Responsibility Principle: https://www.youtube.com/watch?v=Gt0M_OHKhQE He presents an Employee class with multiple responsibilities and suggests splitting the functionality into classes like EmployeeRepository and EmployeeReporter. I can very much...
1. Imagine you have the following: void Foo::doFoo() { if (!isConditionValid()) { log("doFoo not possible because condition is not valid"); return; } if (!isTheOtherConditionValid()) { log("doFoo not possible because the other condition is not valid"); return; } ...
I've only recently learned about the qualified this, and was curious as to when was it introduced in the language, as I've been using Java here and there for around 18 years. Oracle keeps only the specifications for Java SE up to 6, but I cannot find any earlier versions online. I'm curious if it was there all this tim...
Here is the situation: While working by company A on project A you developed a very fast and perfect search algorithm. Then you switched to company B to work on project B which is totally different from project A, but you find yourself in need of implementing a search algorithm. But you know or think that you are not g...
I found out that some languages like C don't have support for boolean variables and programmers use integers with values of 0 and 1 instead. Is there any specific reason why some languages moved away from this other than improved readability?
I have a device that is a source of data. It is connected to a PC where my program is running. I have two scenarios of how to get the data from that device. I am wondering, which one is synchronous and which is asynchronous data transmission? I start the device and my program executes a thread that periodically polls ...
I'm developing a web app in PHP where part of the code I'm developing for it will also be used in the tests. I'm not sure how to handle this. That code in question is an abstraction to communicate with eBay's soap/xml API. I hope the following makes sense...Apologies for another long question!! Specifically I'm writing...
Given a Python class which will be instantiated only once, i.e. there will be only one object of the class. I was wondering in which cases it makes sense to create a single class instance instead of working directly with the class instead. There is a similar question, but it has a different focus: it is about groupi...
I am thinking of starting with the "Start Bootstrap" theme from Bootstrap and I want to change it and add stuff, new pages to work with Wordpress and then put it up for sale. http://startbootstrap.com/template-overviews/creative/ Under the Apache License Version 2.0 can I change (back-end and front-end) a theme and the...
I have a WebAPI application and I have a controller method which is used to return a json result to the UI. Now, I can either return a string (because the json is basically a string - and it works properly), or I can return a JsonResult from System.Web.Http.Results. Are there any advantages to using the JsonResult?
I am struggling with making a design choice in the following setup: I am writing (C++) functions which take a pair of iterators (to template containers) and compute a return value of the same type that the iterators are pointing to. Let's say I want to implement a sum function (this is just an example to illustrate th...
In C++ let's say I have some class A: Class A { int a1, a2, a3; void foo(); } and I need to use a subset of members (a1, a2) in a member function for a second class B. What I'm wondering is whether I should define the arguments of B's member function by passing a pointer to A as an argument, o...
In a nutshell, I needed to traverse any number of dimensions of a multidimensional array (or not) and I wanted the process to be as predictable as possible (in order to proliferate the pattern throughout a larger body of work). So I came up with this - it feels too easy. Are there any performance sinks using ksort like...
I made a project and put it on github, it's basically a small powershell function that is pretty useful in some situations. I've since made some improvements to it to add functionality...but someone else liked it as well and made his own 'dev' branch to it. I don't want to be a jerk and ignore his changes, but I als...
I'm working on an open source project for the first time and I'm adding a feature to the source. The way I've been going about, is I've squashed my individual commits into on clean commit for the feature. Now every time I need to fix the something code in the code because it fails tests, I'm editing the code and rebasi...
What is the best practice, to write my PHP code inside my HTML code or HTML inside PHP? PHP inside HMTL: <p class="lead">Welcome to the <?= COMPANY_NAME ?> website.</p> HTML inside PHP: <?php echo '<p class="lead">Welcome to the ' . COMPANY_NAME . ' website.</p>'; ?> Is there a difference in performance? Wh...
I have a scenario where I need to 'watch' an Amazon queue. When a message arrives I need to get this message and process it. Right now this is implemented with a do/while and Thread.Sleep when no messages is found. It's working but I would like to know if there is a better approach, possibly with a design pattern or so...
I have a superinterface that several different abstract classes implement: Coverage. This is for insurance rating. There are several types of different coverage, and those coverages might vary by state. The "type" of coverage is an abstract class, and then the concrete implementations depend on the state where whoever ...
When generating a ClaimIdentity for use by oAuth in generating a token, is it safe to include database information as a claim? My application uses a different database depending on the specific scenario (e.g. A demo user vs a live user). I need the database connection details on every call in order to hit the correct ...
Would it be useful define a type in C# that defines something similar to a data table so it can be instantiated but may not contain logic and also act as an interface? In addition I'm thinking this could be used in place/in addition to interfaces. record A { string S { get; set; } } could be "syntactic sugar" fo...
I'm creating a webapp that has a variety of models: Product, Category, ProductOption, etc. All of these models have a set of shared attributes: name, description, image, etc. There are two options I see: 1. adding all of these attributes as columns to each of the model's table. 2. create a separate meta table that cont...
I run into this issue where if I do a read to check for data too often, my CPU skyrockets, and if I don't check often enough, it's slow for client performance. What's an effective way to deal with this & NIO?
I am having confusion while choosing a database relation and Restful URI for application I am developing. I am making a simple library application with following requirements. Book can belong to many categories e.g Physics book belong to Textbook and Science Category. We can say book have many categories/labels/tags. ...
Every time I am working on a project, specially a project from scratch, I always feel like I am doing a messy job. I feel bugged all the time by the need or organizing code that is clean or proper way. For example; Avoid hard-coding file paths in gulpfile. Require all node modules in similar fashion. What should be th...
I'm building a website using Django and I'd like to include django-wiki, however it is licensed under the GPLv3. Does this require me to open source my front end code and/or server code? Or can I apply the license only to the wiki portion of the website? The wiki will be quite separate from the main site, but will cont...
Let's say I have a API with regular updates and many developer who are using the API. Whenever the API updates I don't want to bother the developers with all the change updates. I want to send them updates about only the functions or classes that they are using in their code. I have a faint idea, but not sure if this w...
I am showing a graph on HTML5 canvas using the flot charting library for a between a start date and an end date. It's fine as long as the period is less than a year or so but if the user selects a big time period I will have to send large dataset and have browser process it every now and then. We have data points on da...
I’m relatively new to web development, and I’m amazed at the variety of new concepts in the field. I could probably use some help to synthetize. I have to deal with is a backend written in Delphi, that provides some poorly written SOAP services. I originally developed an ASP MVC 5 web app making use of the SOAP API. My...
I have a website that has full support for mobile devices but since opening a browser window seems too much and some people are obsessed with installing apps, I'm now creating an android app which is essentially just a browser inside of an activity. I thought, I'm creating it anyway, so I might just go one step further...
I have a restaurant review app which stores reviews in a db, MySql. There's 2 tables. 1 for Restaurant. Another for reviews. To increase the performance, I am considering to store the avg review of restaurant instead of calculating it on the fly. I am not sure where to store that bit though. Should it go into Restauran...
I'm writing a PHP application, following test driven development principles. I want two different configurations: one for development, and one for production. I will be continually expanding the application's features, so one problem is I don't want the production credentials/configuration to be overwritten each time ...
We have an important legal document that our app generates in WordML, with foreign characters represented via Unicode. These foreign characters vary widely, and include languages with special characters like Korean and Cyrillic. We have all of the unicode hex values for WordML, but our print room has informed us tha...
Let's say we have a generator that is indefinite, where new elements can arrive at any moment with significant (up to indefinite) delay. An example of such generator is tail -F command. In python (omitting various edge cases) it could be implemented as the following: def tail_follow(file): while True: line ...
I am in the process of designing a chat application with cordova for android devices. I have been researching and have come to the conclusion that there are two ways to go about this that could work. Websockets. Using websockets the client application could send a message to a webserver, the webserver could lookup the...
I have a github repo that is currently set to private. I'd like to make it public but before doing so would like to clean it up a little bit by squashing some commits and possibly rebasing so that the history is easier to read and contains less minor commits (version bumps, typo fixes etc.). I know that changing histor...
If I am building a webservice/Web API for servicing requests, there are 2 threading strategies I can think of. I will explain this in terms of Java (though the question may be relevant for any other language also) In the main thread, I accept the request and pass it to a thread. The thread does the processing. In t...
Base Class I have a class called Remote. This class represents a remote machine and has properties such as ip, hostname, username, and password, as well as methods for transferring files to/from the machine and running code on the machines command line. Classes Based on Specific VM Providers I have multiple subclasses ...
When a C program is running, the data is stored on the heap or the stack. The values are stored in RAM addresses. But what about the type indicators (e.g., int or char)? Are they also stored? Consider the following code: char a = 'A'; int x = 4; I read that A and 4 are stored in RAM addresses here. But what about a an...
I have started learning c# and am confused by the following feature. The following code uses a function Algs.Combinations(n,m) to produce an IEnumerable which contains the combinations of n objects taken from m. Its implementation is exactly as can be found on the Rosetta code page for combinations. For example, apply...
Is it possible to parse data between compute shader voids without having to create a new buffer and cpu link (Using unity with C# interface). For example I have a kernel with position data on a set of vector arrays. I then want to adjust those positions after that kernel has sent them to my shader and rendered. Edit: ...
Both underscore and lodash refuse to implement deep plucking, despite many requests from users and gists or modules that implement the feature. _([{o:{a:1}},{o:{a:43}},{o:{a:234}},{o:{a:23}}]).pluck("o.a") Why is deep plucking a bad idea?
I've seen this example in a text book and am a little confused how to interpret the operator precedence rules. Given this struct: typedef struct { char *data; size_t start, end; } str_wends; Let B be declared as a pointer to this struct,that is. str_wends *B = malloc(sizeof(str_wends)); and assume B->...
Sorry for yet another FP + side effects question, but I couldn't find an existing one which quite answered this for me. My (limited) understanding of functional programming is that state/side effects should be minimised and kept separate from stateless logic. I also gather Haskell’s approach to this, the IO monad, achi...
Are technical user stories allowed in Scrum? If so, what is the standard template for writing technical user stories in Scrum? Is it the same As a <user> I want to do <task> so that I can <goal> ?? I have read in some blogs that as-a-developer-is-not-a-user-story, but I have also read that Scrum does not mandate these....
Here is some fake code under test: public void saveItem() { try { databaseInterface.saveItemToDatabase(item); } catch (Exception e) { // deal with it return; } itemList.Add(item); } When writing a unit test, if you were to not stub out that database call, test engineers would say that it is an...
I normally code in either c# or Objective-C and recently took it upon myself to learn Apple's new programming language - Swift. The first thing I noticed is that you don't need to add semicolons to end a line in Swift but if you do-at least from what I've tested-it does not interfere with the compiler. When I write: ...
I have decided to learn Perl as my next language and I am currently reading about the scalar and list contexts, although this question is not specifically Perl-related, I will just put it in a Perl context (hah, get it?!) So, the basic idea is that operators expect either a scalar or a list value, and if they get an ar...
I am planning a website with an html/javascript frontend input and a php backend. The user has to input data which will be saved in a database. Now I want to inform the other users of my site accordingly about the changes made on the database. Is this possible in any way (at this point of planning I cannot say how many...
We have an ASP.NET application which allows users to report on their data. We have a number of reports that the user selects the start and end date from a datepicker and then we returned the filtered result. By default the time from the datepicker is 00:00:00 In translating the query for the database, we have always qu...
I've spent six full days so far working on a spec for a web-app component. Apart from personally wanting some task that doesn't involve Word, I'm wondering if there is a point at which I know that the spec I'm working on is finished (but isn't a spec a constant work-in-progress?). I feel that the spec still doesn't exp...
I have a stream of integer data and want to perform some statistical analysis on it. I want to calculate the mean and the standard deviation of it. So far it isn't hard, but keep in mind that I am talking about streams of data, I'd prefer not to store all of the data. There exists both an algorithm for the mean and the...
Our company has started to design a system where many (typically 4 or 6) force-sensitive platforms, containing load-cells, would stream data to the PC via TCP. Each platform and the PC shall be connected by network cable to a network switch acting as a hub. Each platform will be running a microcontrolled device, with a...
I'm writing a pretty simple TCP server/client application for the first time. It is a personal project for education, but I really like my applications to be extendable and to scale in case the code is good enough to use somewhere else. I am using Microsofts async TCP server/client as my starting point https://msdn.mic...
In our Agile process we have 2-week Sprints. Tasks are delivered on a daily basis (daily builds), and the Test Team completes their testing immediately the next day or even the same day. We also have Dev code reviews, which require some time (1-2 hrs), so they are scheduled 3 times a week: Mon-Weds-Fri. Developers get ...