instruction
stringlengths
34
19.9k
Given an array of ordered pairs of values, what algorithm will find converse duplicates? [Converse meaning the same values, but in the opposite order.] That is, given [ab,ac,ad,bc,bd,ca,db] is there an efficient way to find ca and db, being the converse duplicates for ac and bd? The application is simple enough: the or...
I need help with organizing my arguments for why it's MADNESS to develop against production data. Backstory: I started working here six months ago and I noticed we're developing directly against production data. The codebase is local, but the database we're connected to is live data! So i have to be super careful const...
Context: Imagine you're writing a plugin to a program (let's say Foobar Plugin for Eclipse) and you want it to have an API which other people - such as the creators of Barbaz Plugin for Eclipse - can call in order to provide integration. ("Whenever a foo is barred, our plugin also bazzes it automatically! ... if the fo...
I'm struggling to point a finger into the right design pattern. I have a web site which user can register and interact with the system. I want to add the following abilities to a user: Each user will be in a stage. Let's say that we have 5 stages. when user is register, he will be in the 1-st stage. User will be able ...
The following is pseudo code, I tried it in Java and PHP and both worked: class Test { private int a = 5; public static function do_test(){ var t = new Test(); t.a = 1; print t.a // 1 } } Test::do_test(); Why can you do this in OOP paradigm and what's the use of it?
I'm struggling to point a finger into the right design pattern. I have a web site which user can register and interact with the system. I want to add the following abilities to a user: Each user will be in a stage. Let's say that we have 5 stages. when user is register, he will be in the 1-st stage. User will be able ...
The "value" ranges from 0 to 15 (its possible values). When will those 4 "if" conditions be met? If my (int)value = 2 does this mean 0010? if ((int)value & 0x1) { //statement here } if ((int)value & 0x2) { //statement her...
I'm in a situation at work where I have to transfer responsibility of a large code base that I inherited, re-factored and enhanced to another developer. This is the first time that I have to do such a thing and although I always thought it would be trivial the actual steps I have to follow seem vague. The code base I m...
We are currently refactoring our controller methods in ASP.NET MVC application. At the beginning we've separated data access layer (our goal was to remove LINQ from controllers entirely). Now we are thinking about another step - how to create a business logic layer to reduce number of lines and logic in controller. Cur...
I want to enable some real-time notifications about friend's activities (social network). Technical context is: Webapp calling backend (REST API's). Scenario is: Kevin follows Bob. When Bob posts a new comment, Kevin should be notified immediately (near real-time). Besides, when Kevin logs in, he should be able ...
I have an open source project (Cockatrice) that uses mysql for the server component. I'm planning some changes to the schema, but right now the only management I have is a script that runs the proper CREATE TABLE statements. Before I start rolling out changes I'd like to get a schema management solution in place. The a...
Let's say I am checking a directory for the existence of a file, and then depending on whether or not the file exists, I act accordingly. For example, see the two Python snippets below. if os.path.isfile(file_name): # do task A else: # do task B or if not os.path.isfile(file_name): # do task B else: # ...
There are IObservable and IObserver interfaces in .NET (also here and here). Interestingly, the concrete implementation of the IObserver does not hold a direct reference to the IObservable. It doesn't know who it's subscribed to. It can only invoke the unsubscriber. "Please pull the pin to unsubscribe." edit: The u...
We have decided to build separate applications for user authentication and user management. The reason is that the the former is a "this just needs to always work, and do so instantly" style service, and the latter includes a much-larger user-interface component with many requirements and features. Unfortunately, whil...
I've started a job as mobile lead in a 100employee company. Their Mobile products (iOS and Android) has been developed by external teams, and now they have decided to assemble internal teams, so I'm heavily involved in hiring ATM, both for iOS and Android. I will have teams of 5 people for each of the platforms. I've b...
Should the reporting logic to extract domain data in a certain format reside in domain objects or separate reporting objects? The reporting logic needs to: select entities/data which match selection criteria e.g. date range apply data validation rules e.g. date range, boundary values, missing values apply type of repo...
I just noticed that the FSharp.Core namespace includes generic array types of up to 4 dimensions, i.e. Core.[]<'T>, Core.[,]<'T>, etc. C# and VB seem to be doing just fine with System.Array - although it's not clear to me how they manage to support strongly-typed specialized array types like int[], string[]. I guess t...
I have an application where I have a set of core features. The application itself HAS to work in core only mode. I would also want to make the application extensible such that, when certain jar/plugin files exist in the classpath/installation location, additional features would be available, things would just be there...
First things first: I need to apologize in advance about the bad choice of title for this question, but I really couldn't come up with something meaningful. I'm actually looking for suggestions as to what this kind of problem in called, so that I can do some research on my own. I will gladly change the title once the s...
I am bidding on a government contract (my first) and there is a section requesting that I provide a high-level outline of a quality control plan that would ensure that the end product is ISO-9001 compliant. I don't know much about ISO 9001 so I am certainly doing my own homework and research on this, but thought I woul...
Abstract: So, as I understand it (although I have a very limited understanding), there are three dimensions that we (usually) work with physically: The 1st would be represented by a line. The 2nd would be represented by a square. The 3rd would be represented by a cube. Simple enough until we get to the 4th -- It is kin...
If I had a dime for every time I've seen this macro in use, today I would be coding just for fun: #define SAFE_DELETE(p) if ((p) != NULL) { delete (p); (p) = NULL; } Why do programmers insist in keep using this macro when delete checks for null? Is is because it sets the pointer to null at the end? Then why not at lea...
I use Volley to return JSON from an API. I parse this JSON and add StoreItem objects to a List, then use an adapter to display in a listview. I use the cache functionality in Volley, and I'm wondering how I can approach the issue of deleting/adding items. I know I'll need to make a POST/DELETE request with Volley to ac...
Disclaimer: I know that datatypes are a little bit subjective to which scripting/programming language you are using, I like to write in Python as a matter of preference; though I am happy to hear about any lanugage/implementation. What is the best datatype to store a three-state variable? Something capable or represent...
I have MS C# and MS SQL 2008 database project. It can capture employees' records with pictures of more than 1000 records. Presently, I'm able to capture say 150 records on PC1 using my installed C# application, save the records into XML or CSV file format. My friends are able to continue registration or entering (i.e f...
First I want to say Java is the only language I ever used, so please excuse my ignorance on this subject. Dynamically typed languages allow you to put any value in any variable. So for example you could write the following function (psuedocode): void makeItBark(dog){ dog.bark(); } And you can pass inside it whatev...
Please note that this isn't meant to be a Java vs. C# argument. I'm a Java programmer with no C# experience, asking just out of curiosity. I did some reading on C#, and it seems it has much more features than Java. A number of examples: Type inference. dynamic keyword. Delegates. Optional parameters. Lambda and LINQ (...
I have been asked to re-write an old C/C++ project in C++11. The old project is multi-platform, however, in order to deploy the system on other architectures the current process is to log into a remote service which has all the available target platforms (Red Hat Linux, Umbuntu, Sco Unix et al.) and build the .exe on e...
We have been using Team Foundation Server (TFS) for source code management of our solution which contains components for a number of platforms - asp.net, windows & android so far. We now wish to develop iOS apps for the solution but is there any integration possible between XCode and TFS? What's the best way to use TFS...
This may be an pointless question based on opinion, style, and context but I've been racking my brain trying to decide whether or not to make use of custom exceptions and would love to hear some pros and cons from anyone with experience from both approaches. For example I'm trying to decide between a custom ObjectNotFo...
At the place I work we are using a SafeReader class that wraps an IDataReader. One of the 'features' is that if the field you are trying to access wasn't in the query then it just returns a default value. So I am working with some code that is already in place, but apparently never fully worked as it accesses fields th...
You can find an endless list of blogs, articles and websites promoting the benefits of unit testing your source code. It's almost guaranteed that the developers who programmed the compilers for Java, C++, C# and other typed languages used unit testing to verify their work. So why then, despite its popularity, is testin...
I'm looking at using GCM to send notifications from my rails app to an Android app. The getting started guide says: In the resulting configuration dialog, supply your server's IP address. I'm using Heroku, so the IP address is changing frequently correct? Can I still use GCM? Was looking at using the rails gem and I c...
I know that when we speak about an array having 1, 2, or 4 dimensions, we mean arrays like this: 1: [0] 2: [0,0] 3: [0,0,0] 4: [0,0,0,0] ... Is the first 'axis' of an array the only thing that defines its dimensionality? Can an array with 4 dimensions be represented these ways? [0, [0,0,0]] [[0,0], [0,0]] or does th...
Consider the following Java code: public class HumanStateImpl implements HumanState { private boolean alive; private Color skinColor; // getters and setters, other state fields @Override public boolean isAlive() { return alive; } } Now imagine I want to have a class that represents Ha...
One of the code bases I work on has a development environment that is running on a dev server and cannot be copied over to my PC to locally test and develop. I am wondering what is the proper way to work with this code base? It is object oriented and I have found it to be very tedious and time consuming to do my work u...
Since what matters is not how the code does it but what it does, would you consider wrapping a function with a different name just to clarify it's behavior in certain situations a good practice? Real life example with pseudo-code: Let's say I have a small module to generate hardware signals. Now naturally one expects ...
I want to create a data access library that can build a DataSets with relations which can easily be written to XML with dataset.WriteXML(). This is a get to know C# endeavor that will hopefully gain me some productivity as well (lots of converting relational tables to XML from different data sources for document genera...
I've lately been developing my own MVC content management system using PHP and, at least in my mind, am a little stuck with the system design. I believe this would apply to building a content management system with an existing MVC framework as well. This is going to be a little difficult to explain, so sorry in advance...
In .NET, it is idiomatic to suffix exception types with Exception. But most, if not all, sources I have seen for custom exception types in F# don't follow this idiom. Most seem to use the suffix Error. From F# For Fun and Profit exception MyFSharpError1 of string exception MyFSharpError2 of string * int From Microsoft...
I have been working on Software-Defined Radio projects for almost a year. This is an area which requires lots of signal processing (digital filters and FFTs), communication theory (modulation, equalization and synchronization) and information theory (specifically, coding theory, as Huffman, Linear and Convolutional cod...
This post from Python creator, Guido Van Rossum, mentions an early attempt to remove the GIL from Python: This has been tried before, with disappointing results, which is why I'm reluctant to put much effort into it myself. In 1999 Greg Stein (with Mark Hammond?) produced a fork of Python (1.5 I believe) that re...
The place I work at does the following: They manage a dev version of an app They manage another replicate version of that app, they call this the rep version The live version of the app that is running They believe branches are evil We are asked to manually copy paste the code from one version to another. What are t...
I am working on a web front end + front end services. I receive good sized csv files (10k lines). My service processes them and condenses them into one larger csv file (up to 300k lines). This larger file will be turned into an html/pdf report after some extrapolation. My questions are: Taking 17,000 files and turnin...
I'm currently taking course on introduction to algorithm and I came across the parallel mergesort algorithm. My question is: Is there any differences in the algorithm plan if it runs on a 2d mesh instead of infinite linear proccessors ? Thank you,
I'm designing within an application that I inherited. I have done a lot of work to "consolidate" the CSS which was extremely overworked through much copying and pasting without a lot of strategy behind it. One curious thing I found was to style ALL divs as: <style> div{ float: left; } </style> Do any other applicati...
I've used parts of source from an existing Java library project with what appears to be a 3-clause BSD license. I've made significant changes to the library which makes it possible to use it in a new platform, and also added several new features, and new example projects using the modified library. I want to know if an...
Recently some people said that I was wrong when I explained why one cannot insert a Number object into a list declared as List<? super RationalNumber>. (This assumes that RationalNumber is a subclass of Number) My explanation was that in List<? super RationalNumber> the <? super RationalNumber> stands for an unknown su...
Say I have a class workStockItem, that I wish to serialize. Which is the better style? using a static method or using a non-static method (maybe even implemented as a property as seen below) Example implementations: internal static byte[] serialiaze(workStockItem toSer) { IFormatter formatter = new Bina...
I am working on Android with the query() method of the ContentResolver class and it accepts 6 parameters, (uri,projection,selection,selectionArgs,sortOrder,cancellationSignal) for selection and projection parameters. I am little bit confused with the selection and projection part of query. In below example, what is sel...
I am building a scientific application in matlab which handles several hundred large matrices (large as in 'very few of these will fit into ram'). Each matrix is contained within a dedicated object to handle its metadata (the property's name is .data). I use the getter method to load the data from file into ram as soo...
Context of my question: I am reading C#. Trying to understand Static keyword. I understand that when Static is applied to a member of a class, it can only be modified by the class and not the class object references. I will take an example here. public class BluePrint { public static string BluePrintCreatorName; }...
Let's say I wanted to close my "GPL v 2.0 (or similar)" licensed project, to which I'm the only contributor, and make it closed source. Do I still need to make the existing "GPL v 2.0 (or similar)" licensed code available after closing the project or can I refuse giving out the source code for old revisions that was p...
For example lets take this method: public List<string[]> ReadAll(int listCapacity) { List<string[]> list = new List<string[]>(listCapacity); while (Read()) { list.Add(GetCurrentRow()); } return list; } If listCapacity is less than zero, an ArgumentException will be thrown by the construct...
There are some good examples of well-documented code out there, such as java api. But, a lot of code in public projects such as git and internal projects of companies is poorly documented and not very newcomer friendly. In all my software development stints, I have had to deal with poorly documented code. I noticed th...
When referring to or documenting a typical lock-free circular data structure (or class or object) used to communicate between arbitrarily long asynchronous threads or processors: "queue", "fifo" or "FIFO" are commonly used. Is there a technical reason why one term might be the more accurate or better communicative usag...
I've been working on a ASP.NET Web Api 2 project as a learning exercise, and I was wondering what the norm regarding commenting is. I use the Repository / Service Pattern, and everything is very much decoupled, which results in having a large number of classes whose purpose is pretty clear. I also name my variables in ...
I'm referencing this link about closures: https://stackoverflow.com/questions/111102/how-do-javascript-closures-work This is specifically about javascript. In the second answer with 956 votes, The author returns the nested function "sayAlert" after assigning it to the var keyword as shown below. (Example 3) function sa...
I'm not a native English speaker, currently I'm reading some articles about Scrum. I was wondering if the English terms used in Scrum seem strange to you? For example, backlog instead of todo; artifact instead of element; retrospective instead of review; even the name of Scrum, it make no sense to me as a process name....
I want to make the basic trigonometric functions in maths inbuilt functions using my own header file . so as the users can do trigonometry in c language compilers.
I have been using Symfony2 with Doctrine2 for some years. I have recently started using Microsoft's Entity Framework with MVC5. From my Symfony2 experience I understand that a repository's job is only to retrieve and return objects, no additional operations like Saving. Now every examples I have seen for EF has a metho...
Say I had a PHP page with a calculator interface, but I want to transfer the sum to Windows Calculator.exe and then get a reply from the application back to my PHP page, how do you go about doing this? I understand that the sum could easily be done in PHP and it would be pointless using another application, but I just ...
I have a class that basically builds up a memory-efficient version of a structure to be used in a performance-critical section of code. The resulting structure is ugly but extremely fast, so not using it isn't really an option, but I also can't use it as the only representation of my structure because it has parts not ...
I have a project built with Gradle, which contains libraries which can be used freely outside the main project, like this: The folders with a square at the bottom right are project modules. I want to opensource this project (I mainly use Git and GitHub for tasks like this), but I have no idea how to organize it. Shoul...
I have a database class with the following interface: public Database { //returns false if p (its ID) is already available //otherwise adds p the the list and returns true public boolean create(Person p); //returns false if p (its ID) was not found in the list //replaces the available Person q (q.I...
Haskell's type classes are a very powerful tool and give Haskell a great expressive ability, compared to functional languages that don't have them. When were they invented, and who invented them?
Over the past few weeks I've been mulling and researching how to fill a gap in our testing methodology. In simplified terms unit tests are too small and traditional integration tests are too big. A frequent scenario comes up where A and B both use component C. However A and B have slightly different requirements for,...
So after a while of working in programming field I still haven't figured it out how exactly should programs be structured, in a large set I mean. Which I think it's also because of working in an enterprise development. Say that I want to write a program, a messenger for a LAN network. How do I really know what classes ...
shelve is a Python module that makes it easy to persist a Python dictionary to disk (under the right conditions). The documentation for shelve gives this example to demonstrate one of the pitfalls of using a shelf: import shelve d = shelve.open(filename) # ...snip... # as d was opened WITHOUT writeback=True, beware:...
I am trying to learn continuations and use them to implement coroutines in Scheme. I have two procedures (coroutines) a and b, and I switch between them in the following way: ;; c is a continuation. (define (a c) ... ;; Switch to the other coroutine. (call/cc c) ... (define (b c) ... ;; Switch to th...
I'm pretty sure there has to be a more idiomatic way of writing this: (defn update-2nd-level-vector [map index value] (assoc map :key1 (assoc (get map :key1) :key2 (-> map (get-in [:key1 :key2]) (assoc index value))))) Example of its working: => (update-2nd-level-vector {:key1 {:key2 [0 1]}} 0 1) {:key1 {:key2 [1 ...
I have read in this SO question that OpenSSL socket communication can be only half duplex in a single thread. Assuming what I have read is true, I am wondering if I can apply philosopher's dining problem to send SSL_write() and receive SSL_read() on a non-blocking socket in a single thread that communicates with a Open...
I'm at the point where I'm getting into the freelance development of some complex web apps, and I would like to develop a light weight framework for my personal use, but I'd like to get some advice from more experienced programmers first about one aspect of my big-picture design for the framework. It's heavily prototyp...
I recently took a course on AngularJS, and quite frankly I loved the concepts of a website that fetches json to handle subsequent requests, however I still feel like Javascript is far too slow for what I want to do on a server. I have recently been hired to build an online auction website. I built two mockups, one with...
We use RavenDB as our data store for transactional information, and it works well for data that is currently "in use". We also collect audit events as people use our application, where each event looks something like: Type, date, summary, etc. - pretty standard Related document IDs (could be one, could be 5) As a do...
Recently I've discovered such a thing as a Apache Mesos. It all looks amazingly in all that demos and examples. I could easily imagine how one would run for stateless jobs - that fits to the whole idea naturally. Bot how to deal with long running jobs that are stateful? Say, I have a cluster that consists of N machines...
I am running a web application which has to scan (MySQL query on a particular column) a huge MySQL table, which has over 100,000 records. The problem is that when a user requests another page from the same web application while the results are being fetched from the scan, the browser takes a long time to display the pa...
I found the tutorial of client (android) and server (pc) bluetooth tutorial from here. But my question is about the UUID. Is that okay if we define it randomly without the proper format? Because I heard UUID is generally for ID for each devices just like IP address used right? For example like this, instead of the fol...
I'm an inexperienced programmer. I have been assigned to develop a Firefox plugin with no prior experience. So I followed the tutorial at MDN. I learned so many things, it's exciting and overwhelming at the same time. When I finally started programming, I ended up using extension the tutorial gave me, and modify it. An...
What I have right now: A table with lot of records. About 200 users can select a record according to some rules based on the data in each record. There is a high chance that 2 or more users will select the same record. A user updates the record then saves it back to the db. That record won't be selected again (soft de...
I have some shortest path data for a graph. Can I reconstruct the graph itself from this data? More precisely, I have a boolean (0/1) matrix for each vertex v in graph (V, E). Matrix element [s,d] is equal to 1 iff v is in the shortest path from source vertex s to destination vertex d. All edges in the graph have the s...
I am basically working on https://github.com/KirisurfProject/ entirely alone. This is around 4000 lines of Go code, plus around 1000 lines of Racket (a Lisp) code for the GUI part; the equivalent in Java or some other less concise language is probably several times that. The project is currently a research project for ...
I have an array which stores a set of positive x coordinates in sorted way, say arr={1, 4, 5, 9, 12, 45} etc. And I have a maximum distance k which I can go from one point to another point let k=3. Now, given two points x and y(arr[x]<arr[y]) I need to determine if I can reach from x to y. I will be able to reach y ...
I need to model a database design to provide item level permissions to users based on the user's role access. I am using asp.net with sql server 2012 I am looking at similar experience on how SharePoint provides the security trimming when we access the resources with a SharePoint site (including search results) Is it...
I am asked to refactor and maintain an enterprise application. Normally I'm used to using the MVC design pattern. This time however, I'd like to separate everything into layers (multilayered architecture). Something along the lines of (Microsoft Application Architecture Guide, 2nd Edition - October 2009): My data sou...
I use Doctrine 2 and I've read some articles on inheritance strategies' mapping with ORM. I've seen three main strategies : "Class table inheritance", "Concrete table inheritance" and "Single table inheritance". With Doctrine 2, I managed an install of "Class Table Inheritance" (CTI) and "Single Table Inheritance" (STI...
I want to understand, from design point of view, in what situations I should use default access modifier, and when I shouldn't. I found this related question, that provides some basic explanations, how ever I am searching for an answer that will target encapsulation and single reason of change principles, and address i...
Context: I'm working on an HTML 5 game without persisted state. Every time you refresh the page, you start at the beginning. People are requesting that they can start where they left off if they leave the page. I plan to implement this as Local Storage. The thing that makes apprehensive about this is a new kind of ...
I run little scientific scripts and C tools on OS X from time to time. For the C tools, I just download the source and compile using the provided Makefile. I usually don't have any problems when using the tools. However, knowing that those tools were written on Linux most of the time, I wonder if the differences in arc...
The good folks who created the SVN version control system use a structure they refer to as "skip deltas" to store the revision history of files internally. A revision is stored as a delta against an earlier revision. However, revision N is not necessarily stored as a delta against revision N-1, like this: 0 <- 1 <- 2 <...
So normally I would only use JS to modify the dom after the user interacts with something or some event goes off. This seems right for some reason. But I'm developing a widget based app where widgets need the capability to draw (print) themselves and it feels redundant to send the widget's html via the initial http req...
I am reverse engineering a data file (from a synthesizer). It seems that e.g. -1 is written as FF FF FF FF, so in four bytes. while +1 is written as 00 00 01 (--), so only three bytes. Is something like this common? I only heard about either a 3 or 4 byte format, but not 3 OR 4 depending on the sign. And is there some ...
The title is a bit vague so I'll try to elaborate. I have a function makeFoo(int bar) -> returns Foo or throws Exception. I also have a batch version of this makeFoos(int[] bars) -> returns Foo[] which basically loops through bars and runs makeFoo() on them. Issue is, if while running makeFoos(), makeFoo() throws a...
I've recently disputed with my colleague about the following situation: I've developed a framework that processes the resources (in java, although its not really important). It goes (simplified, pseudo-code) like this: class Algorithm { Processor processor = ...; execute() { forEach(Resource r : readRes...
I have a (large) software project in a git repository. There is a benchmark suite that spits out lots of numbers (time per benchmark, allocations done per benchmark) I’d like to track. What is the best way to get a grip on intended and unintended performance changes in such a setup? (Ideally, I think, there is a piece ...
I'm working in a big software company and I'm developing a big enterprise-level web-solution with a team of about 25 people (2 architects, ~15 developers, 5 QA engineers, couple BAs, project manager). We are following agile methodology and scrum and it seems to be pretty convenient for such big team in circumstances of...
I am working on something that should be fairly simple. I have 95% of my program working, but one piece is still not fulfilling the requirement. (FYI, this is for a homework assignment, but I will prove that I have put good effort into it before coming here.) The piece of the assignment: * The ProductionWorker class sh...
In order to avoid the overhead associated with the shelve module's writeback option I'm interested in putting together a shelf class that only accepts hashable values, with hashability being a proxy for immutability. So I'd like to subclass shelve.Shelf and override the __set__ method. The catch is that shelve.open can...
I'm studying dependency injection and I want to know if required function parameters can be considered dependencies. I'd just like to make sure before I go around referring to them dependencies and that turns out to not be exactly accurate. function doSomething(required){ if(required !== null){ // do stuf...
I noticed that for some reason, Haskell's built in max function (which returns the greatest of two numbers) runs much faster than the one I wrote, even though they are essentially identical. From this site: http://www.haskell.org/onlinereport/standard-prelude.html, I found that the standard max function is defined as: ...