instruction
stringlengths
34
19.9k
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: ...
I'm building a ASP.NET Web Api 2 solution for learning purposes, and I've hit a snag. I was wondering if anyone could tell me what exactly it is that I'm missing. My Web Api solution has 4 Layers: Data, which contains the Data Models ( POCOs ), Fluent API Mappings, EF Context, Migrations and Seeding Repository, which ...
I'm trying to determine the technical details of why software produced using programming languages for certain operating systems only work with them. It is my understanding that binaries are specific to certain processors due to the processor specific machine language they understand and the differing instruction sets ...
During grooming, we usually have work items which get approved based upon the team understanding that what needs to be done? The product owner does not discuss the details of how it will be done and stops the discussion if team tries so. This applies to all work items (new UI, new API or changes to existing UI/API). Pr...
Having looked at some languages for functional programming, I always wondered why some fp-languages use one or more whitespace characters for function application (and definition), whereas most (all?) imperative/object-oriented languages are using parentheses, which seems to be the more mathematical way. I also think t...
In most popular programming languages like Java and C# there is a way to define enums, which are essentially datatypes with a fixed set of values, e.g. DayOfWeek. The problem is, given a value, e.g. DayOfWeek.Monday, how do I get the next value of the enum, in this particular case DayOfWeek.Tuesday? I realize that not ...
Can the single responsibility principle be applied to databases? relational databases I mean. I'm asking this because a typical database will have several tables and we may find something like that between them: Tables handle ACL and permissions. Tables handle user authentication. Tables relating to cron jobs and sche...
I've been struggling with timezones online for a few years now. Because I've had enough of it, I want to develop a Chrome extension that leverages moment.js so I can paste in a representation of a time and it will return the time in the user's current timezone. So this is basically a GUI front-end for moment.js. I wou...
Hi I want to implement a search on a website which includes imperfect search results. Meaning, if the search term is misspelled or slightly different from a 100% match, the function should still return results which are sorted by similarity in terms of the search keyword. I already have implemented algorithms like Smit...
We have a C++ application, with C++ interfaces changing regularly during development. We also have a C API which is designed to be stable in spite of such changes; the C API is tighly focused on operations which client code might want to do. Now, we want to add a Python API to make it easy for outside clients (or our o...
I am currently reading a book titled "Numerical Recipes in C". In this book, the author details how certain algorithms inherently work better if we had indices starting with 1 (I don't entirely follow his argument and that isn't the point of this post), but C always indexes its arrays starting with 0. In order to get a...
I am writing a game in C++ which has different enemy types. I have defined a base Enemy class and I also have derived classes enemy1, enemy2 etc. Now for updating these enemies in each iteration of the game, I want to have an array: EnemyArray with its elements pointing to the existing enemies so that I can make sure t...
In the past, I've worked in a variety of environments. Desktop apps, games, embedded stuff, web services, command line jobs, web sites, database reporting, and so on. All of these environments shared the same trait: no matter their complexity, no matter their size, I could always have a subset or slice of the applicati...
I'm working on a web application for our business with my brother. Our application is pretty simple, and will be developed with php and mysql. Clients and providers ABMs Articles Inventory (we do not manage stock, because we resell from our providers) Purchases Account balance for our clients and providers I'm stuck...
I'm writing a method and depending on a config field I need to change where I get my data from. What this results in me having to write code that looks like this: List<string> result = new List<string>(); if (configField) { result.Add(fieldA); } else { result.Add(...BusinessLogic...); } I'll have to write that...
I've seen around the Internet and Github, implementations for the design pattern Repository that knows about database table and column names. I was think, if I want to work with the database as a plugin, that I can unplug and plug another respecting Open/Closed for the rest of my code, my repository should not know abo...
Maybe a little tongue-in-cheek, but as I can't find this answer anywhere through Google, so to ensure Software Engineering has the answer: What is a helper? I have seen the name being used everywhere (module names, class names, method names), as if the semantics were deep and meaningful, but in the context of Computer ...
With all the noise about EC6, one thing that I realized I haven't heard about is expanding Javascript's standard library. Javascript has a fairly sparse standard library. You need a 3rd party library to do many basic things like date manipulation. I'd rather have more built into the browser via a standard library then ...
I am mainly a C programmer. In my world, writing likeThis or like_this is just a matter of style. In Haskell however, it seems that camelCase is the definite choice. Personally, I find the later much more readable. Think pthread_mutexattr_init vs PthreadMutexAttrInit. What's more, I have configured vim to swap the numb...
I need to know where in the MVC should I apply the business rule. Imagine the situation: I have a school and I need to generate a calendar of classes for teachers. Each teacher has a school subject and is only available certain times. I need to generate this calendar in such a way that teachers can performing without t...
I am working on an application that reads a log file, looks for a specific string, sends alert emails and saves data from the file into a database. The reading functionality is working well, but I am coming across an issue when I stop and restart my program. Basically, it always starts from the beginning of the log fil...
Excuse my ignorance but we've got an application that we'd like to sample out on a mobile app The app is a C#/asp.net application connected to our sql server database. If we are going to write an android application for this app how exactly does one connect to the sql server instance? I've tried to find many articles...
I am relatively familiar with Go, having written a number of small programs in it. Rust, of course, I am less familiar with but keeping an eye on. Having recently read http://yager.io/programming/go.html, I thought I'd personally examine the two ways Generics are handled because the article seemed to unfairly criticize...
I'm developing an application where: Models keep data as a multi-dimensional array, which are saved as-is to a MongoDB database. The model is used to provide methods to manipulate the data, and outside of those methods, the data properties are read-only. The model factory instantiates each object in a standardized wa...
Perhaps it is my scripting background, but my perspective is that the purpose of an object should be to contain data. Classes are necessary in that they provide templates and standard ways to classify and construct objects with particular data attributes. Standard protocol in object oriented design seems to be to inclu...
Consider these polygons: For reasons of simplicity I only consider triangles or polygons with 4 vertices. These shapes are specified by the vertices, the output of the program should be modified vertices. I am trying to find an algorithm to create a space between the polygons, the colored area depicts the space: I ha...
What are your preferences for referencing official documentation (like a white paper) for an algorithm from comments in the code that implements it? I'm trying to decide between two methods, as illustrated by the examples below, but am open to other suggestions. RFC 1321, for instance, describes the MD5 hash algorithm....
When designing an application where scalability is going to be important, it would be useful if the application could be designed to "scale out" on cheap commodity servers. However, there are many scale up applications (see my previous question). Is it always possible to design an application to scale out, or do some r...
I have a database that collects and process large volumes of records However due to the legacy nature of the system im working with (and the powers that be) i need to transfer (processed) records to a different database instance (with some small field modifications along the way) The options i have identified are as fo...
Let's say you have class Car with Car->tune() and Car->drive() class CarDriver class CarMechanic Each CarDriver and CarMechanic object has a reference/pointer to a Car object. The CarDriver object will call $this->car->drive(), the CarMechanic object will call $this->car->tune(). The question is, how can I prevent a...
I've recently started studying Domain Driven Design and so far it looks like it will help tremendously with my team's current project. I'm running into a bit of a problem though actually determining what the domains are in our project. After my inital pass, I ended up with something like this: I have three domains: A,...
I'm trying to better understand performance in PHP. One issue I'm thinking about is the n+1 problem. By n+1 I mean something like this: $posts = Posts::getPosts(); foreach($posts as $post) { $comments = Comments::getComments(array('post_id' => $post->id)); // do something with comments.. } It's quite inefficient...
We have two in-house projects, A and B, developed by different teams with B dependent on A. Since source code for both projects is stored in git, I've included project A as a submodule into project B and configured the build system to build both in right order. An alternative solution would be to consume A via a binary...
Fact that now a days everyone is moving to cloud due to ease in scalability, configuration and maintenance. But my question is should we develop all web application scalable event if it is not required? If an application is low budget with no such special requirements then why we should add efforts to make it support ...
I have some methods that perform some data changing in a database (insert, update, and delete). The ORM I'm using return row-affected int values for those type of method. What should I return for "my method", in order to indicate the success/failure state of the operation? Consider the code that is returning an int: A....
I develop quite often scripts that are primary used as a console application but later they are used in other scripts, webservices and other things where it is very convenient, to just import the script and call methods directly rather than using a Process and parsing stdout. The question is now, what is a good design ...
In C++, we have the option to pass by reference or pass by value. The client code does not need to know which one a parent function uses; that is, int func(int param) and int func(int &param) are called in exactly the same manner from the client code. Isn't this dangerous? If I'm writing code on the client side, I don'...
When upgrading Visual Studio to a newer version, a new directory is created e.g. "Visual Studio 2013". I understand that that makes sense as we want to differentiate between code targeting different versions of .net. But since some projects use other projects as their dll's for some repeated code - this raises a questi...
Imagine I have the following code: class A: pass class B(A): pass class C(A): def __init__(self): self.b = B() Is the above code correct in terms of correct inheritance? I mean is it a good practice to reference another subclass in a subclass?
I have a website where I'm going to be partnering with another website. They want to view one specific page of mine, in their [WordPress] website. They aren't developers, so I looked into how to do this. At first glance, it appears as though the WordPress iFrame plugin is the easiest route. My next thought is, they'll ...
I stumbled across a need to create a thin I/O Layer interface to abstract away a class from the need to know about I/O public interface IFileIOProvider { Task WriteFileAsync(String contents, String path); Task<String> ReadFileAsync(String path); } Is it a good idea to test a default implementation that only fa...
I've created a PHP-based document management system and hosted it on my Raspberry Pi. I created a "backup" function that zips together all the documents, but it takes too long due to the hardware constraints of the Pi, as well as the fact that compression cannot be disabled when creating zip files in PHP. This has led ...
I have a colleague who has come up with a way of 'genericizing' information from a database so that all his web application's drop-down lists can share the same object in his MVC.NET C# code and Views, which can contain different data depending on what tables it is being used against. We work for a government agency, ...
I don't have compilable code, because the code in question depends on a large function that's irrelevant to the question, but say I have the following scenario: savePath = "C:\\..." changePath1, changePath2 :: String -> String changePath1 passedPath = 'Do something with passedPath' changePath2 = 'Do somethin...
What type of exception should I throw? I have a console class which describes rectangle of cells which a user can index by passing in a coordinate: width, height = 80, 25 console = Console.new(width, height) x, y = 2, 5 point_on_screen = Point.new(x, y) console[point_on_screen] = 'a' I am now wondering what types of ...
I am developing a Windows Runtime Component (C#) to be used in an HTML/JS frontend for a Windows Store App. Now, one of the requests is to have a database on the local system to store metadata about files that will be downloaded. After looking everywhere I have started using SQLite combined with the sqlite-net wrapper ...
I'm aware there are a lot of topics about MVC design but it's hard to find good explanations: what I should do, what are the consequences of the different possibilities... So I'm working on an ASP .NET MVC application with a HTML/Javascript front-end. Currently there is a view which allows the end-user to edit some obj...
In reading about various sorting algorithms I've seen it mentioned that some are "stable" and some are not. What does that mean, and what tradeoffs are involved on that basis when selecting an algorithm?
I'm trying to figure out the right way to handle permissions in a single page app that talks directly to several RESTful APIs, that implement HATEOAS. As an example: "As a user of my application I can view, start and pause jobs but not stop them." The underlying rest API has the following resource: /jobs/{id} Which a...
I would like to complete a pharmacy software proof concept. But I have a few questions I do not know. Physician information In order to refill or dispense a new RX the software needs to have access to a database of current doctors, is there a downloadable database or a service I can interact with to get a list of curre...
There are three versions of Neo4j apparently, called Community, Advanced, and Enterprise. Neo4j's Licensing Guide says that Community is GPL3 (which I confirmed from the LICENSE file in the tarball) and the Advanced/Enterprise seems to be dual licensed under AGPL3 and a proprietary license. What exactly does statemen...
I'm trying to automate a task and I lack the right vocabulary to look up the correct algorithm. It really feels like a common problem that has likely been solved many times before. All I'm looking for is for someone to point me in the right direction or help me with the right search terms to look up a solution / algori...
I've run into a problem where I have a set of inputs, as well as a couple known input-output pairs. I am interested in the output, but in order to get that, I need to figure out how the input is used to generate the output. So for example, I might have the following input strings along with a few known output strings c...
We are working with some screens whose in the production process change their state from a transparent state to a colored state. This colored state is achieved to block light transmittance. In this process where the screen gets tinted, this tint must be applied homogeneously. This is a very important point of the proce...
so this is C# but it could apply to any OO language where different sets of objects exist across different layers of an application. We have been trying to come up with a convention within the team for where to put the code when mapping objects in one layer to objects in another layer. For example; mapping a Data Trans...
I am writing automatic assignment of tasks to the users. Every user has a weight (integer) and tasks should be distributed to the users according to their weights. For example I have 10 tasks and User A with weight 5, User B with weight 3 and User C with weight 2. Mapping function should assign User A with 5 task, B wi...
I've got a table with the following structure : Col1 | Col2 | Col3 A | B | C A | C | B E | D | C The primary key is (Col1,Col2,Col3). I get the data in another project and display it in view with a grid. When the user edit a row in the grid, for example : A,B,C -> A,B,E, I get (A,B,E) and try ...
I have one huge file.asp with all my reports. I have modularized the page using querystring, so this creates a lot of "virtual pages" with Report #1, Report #2, and so on. I have some blocks of code I use more than once in the page. Actually I am repeating the code, but I already started to use Function to, for example...
I have following class model that I'm quite happy with: A Whole has a special mandatory Part. Furthermore it has a collection of parts, that contains at least the mandatory part, but may contain many more. In the OO model parts don't need to know where they belong. So now I came up with this RDB model: Whole: id - ...
I start a new project this summer, consisting in developing a web version of a proprietary desktop ERP. The main goal of my company is to be able to propose a web version of its ERP, with all advantages it involves (mobility, possibility of selling SaaS versions, modern look and components ...), without losing any bus...
I was stumbling through Wikipedia when I came across the entry for FLOPS, specifically the table in this section. The first entry is for a computer from 1961, the comment on the right reads The 1620's multiplication operation takes 17.7 ms.[46] What is this operation? I assume it means it can do multiplication in 17....
I'm writing a PDE solver, and I have a bug that only shows up in very large test cases. That is, with small grids the program gives correct answers, but there's a large amount of unaccounted-for error (I've accounted for roundoff, discretization, and other standard types of error that unavoidably occur) that creeps in ...
I'm currently working on some closed-source proprietary software that makes use of a library (SharpAVI) distributed with the MIT License. The SharpAVI source isn't being used directly anywhere in my project, only the unchanged .dll provided for download on the codeplex site linked above. The .dll is referenced in one v...
The C11 standard says the arrays, both sized and variable length "shall have a value greater than zero." What is the justification for not allowing a length of 0? Especially for variable length arrays it makes perfect sense to have a size of zero every once and a while. It is also useful for static arrays when their ...
We are a group of enthusiast engineers who are developing a series of application using Excel as our front end. We are using VBA but plan to start doing in VB.net. Some people in IT have questioned the wisdom of using Excel as a platform because it crashes, it's unsafe, difficult maintain, slow, etc.
I am currently working on a website which implements infinite scrolling on it's search page (the results themselves coming from Elastic search) and, unsurprisingly, the more you scroll the slower things get. This is especially prominent on mobile devices, and in particular lower cost devices (which most people use). We...
As far as I know Jetbrains PHPStorm is programmed in Java but while I don't have Java installed in my Windows 7 PC, PHPstorm is installed and working without any problem. How It's done?
I am running into a situation where my program can have different outcomes depending on the state of some variables. 4 variables are involved and they can all have different ( 3 to 4 different states). All the possible combinations are leading me to about 48 different cases which would be resolved using a 4 level deep ...
HDD Failure Paranoia I tend to make small programs for myself. Whenever I make an application I use a database application like MS Access or MySQL. I can CRUD my data as I want. No problem in finishing a task. The problem is when I try exploring more into File IO. I have heard of HDD crashes due to high read/write ope...