instruction
stringlengths
34
36.1k
All the documentation, examples and tutorials I've found on $resource were using it directly in the controller. So far I'm just using $http from services and those services are further used in the controllers. I thought $resource should replace $http and not my whole service. Is my thinking wrong, or were the examples ...
C++ tools and libraries have become more powerful than ever. For instance, we can replace arrays by vectors. We can replace pointers by references. We can use smart-pointers. Is it a common practice among professional programmers to avoid the use of raw pointers?
I'm learning more about algorithms and data structures. According to Wikipedia and other reliable sources, an insertion sort has a worst-case time complexity of O(n2). I'm attempting to measure that complexity in code: def swap(n, i, j): first, second = n[i], n[j] n[i] = second n[j] = first def insertion...
I've a "RSS feed", want to filter its results according to a DOM element in its content! So, this is the mission I'm looking forward to do: Monitor a "RSS feed" continuously. If new RSS elements were added, get its URLs. Go through every URL's page to check for a specific element. If the checked element's value was "...
I created a system which hopefully will have many users. We are afraid our user database will be filled by "trash users" which take high-demand usernames, or maybe they just register and never come back. I know this is common, I do this myself, as I have 3 google accounts, but I only use 1. How can a large website mana...
Lets say I have a simple code like this (fiddleLink): using System; public class Program { public static void Main() { //Dependency register logic here var service = new DataServiceAdapter(); var client = new Client(service); Foo(client); } //Work class public stati...
I was reading this answer about testing private methods and it mentioned several possibilities: extract methods as public to another class make them public separate the env of test and production so that methods are only public in the test env I am currently coding in Java and I was wondering what does the communi...
This question is in the context of web based applications. A web server exposing an HTTP api for clients (e.g. running in a browser but not necessarily). Usually the web server would be connected to somekind of datastorage. My concern is the API exposed by the HTTP server, and how to design it. I find that, often, a bi...
Since this question is not about "code not working", I'm asking my first question here instead of StackOverflow. Inform me if any required information is missing from the question. Setup: I have two dictionaries of type Dictionary<int, int> where the keys are a range from 1 to n and the values are the frequencie...
I work at a company which has it's source code managed using subversion. Our code base is huge (800MB) but we want to work with branching. For what I noticed is that when branching, SVN just duplicates every file which makes it almost impossible to branch because of the space. I would like to separate our library and o...
We have a third party supplied application with a button that enables the opening of another application showing related data when pressed (these applications are made by completely different companies). However, the application with the button does nothing more than the equivalent of clicking a url with a query strin...
Why is doing <% if(blahblah) { //do something } %> in a JSP considered to be bad practice when noone who writes PHP seems to have any problem with doing essentially the exact same thing? <?php if(blahblah) { //do something } ?> I don't understand why people are going out of the...
One of the issues of pimpl is the performance penalty of using it (additional memory allocation, non-contiguous data members, additional indirections, etc..). I would like to propose a variation on the pimpl idiom that will avoid these performance penalties at the expense of not getting all the benefits of pimpl. The i...
In Java, if I create an object that has a method to do something, and I pass that object to multiple threads which call the method, is there a performance difference from creating an individual instance of that class in each thread? In other words, does it cause a bottleneck for thousands of threads to be trying to acc...
I started learning Java and Android development recently, and I'm learning by building a small app for myself. Nothing fancy, it's just a simple mileage tracker for my car. I know there are tons of them available, but I figured it would be an easy app to learn on. Anyway, I've reached a point now where I want to dogfoo...
Assume I have two different software sub systems and I need to interconnect them through an Enterprise Service Bus. What sort of modifications do I need to make in the existing systems to integrate this ESB? For example assume vendor A developed System A, and vendor B developed system B. In order to make these two c...
I'm building an app in C# that needs a fixed-length id, which is a string representation of a hex number. E.g. "0fa5" is an example of such an id of length 4. The length would not need to change within the program at runtime, but may be changed in the future or for example in tests. My question is about how to approach...
I have a for loop in python like this: for item in items: onwards = make_flow_decision(item) if onwards == 'break': break elif onwards == 'continue': continue elif onwards == 'carry_on': process_the_item(item) So idea is that flow control for the loop is factored out because it ...
I'm working on a new iOS app project, on the mobile side. Some architecture changes are happening and it turns out we will have to rely on a custom built private API that will be used by the app we are building and also by other clients such as a website. The API being designed follows the Rest style of resources-centr...
I see this notation used throughout documentation and discussions on SWT, but I've yet to see it actually defined. The comment on Stack Overflow by MarsAtomic makes me think it is just the object that is associated with a method call, or is it more complex than this? It seems to not be the case, but that is probably m...
I'm trying to figure out if I can use code licensed under Creative Commons Attribution-NonCommercial 3.0 (CC-BY-NC 3.0) in a Wordpress plugin (which must be released under GPL). I think the answer is "no," based on here (https://www.gnu.org/licenses/license-list.en.html#CC-BY-NC), but I find the whole licensing mess t...
Take a look at this implementation of the state pattern in JavaScript: var ON = { switch: function() { Object.setPrototypeOf(this, OFF); this.state = "OFF"; } } var OFF = { switch: function() { Object.setPrototypeOf(this, ON); this.state = "ON"; } } var lightBulb = Obje...
I have the following abbreviated class: public class Player { final private DoubleDuple position; final private DoubleDuple momentum; public Player() { position = new DoubleDuple(0, 0); momentum = new DoubleDuple(0, 0); } public Player(double xPos, double yPos) { position =...
I have the constructor: public class Player { final private DoubleDuple position; final private DoubleDuple momentum; public Player(double xPos, double yPos, double xMom, double yMom) { position = new DoubleDuple(xPos, yPos); momentum = new DoubleDuple(xMom, yMom); } } I have to allow ...
I have following layers in my solution: App.Domain App.Service App.Core (maybe you call this one App.DataLayer) App.Web Software design pattern is not my question, I have following Model in Domain public class Foo { public int Id {get;set;} public int Name {get;set;} public int Value {get;set;} } I want ...
Someone who has a PHP project invited me to do the front-end work on his site. I don't know PHP, I've only ever worked with HTML/CSS/JS files. I cloned the project files from GitHub, and all of the html is generated using controllers and views in the Laravel framework. So here's the question: as a front-end developer...
In functional programming language, a function can be passed as an argument to another function. In programming language like C/C++, a function pointer referring to a function can be passed to a function that can invoke the external function through dereference. Then, does function pointer have the same expressive pow...
I want to add a logging mechanism to my project but I am afraid to have logging code spread all over the place. I thus had the idea of having only one class Logger responsible for writing relevant information into the log, and all the other classes A, B, ... having a Logger object and just calling the corresponding lo...
Main purpose of encapsulation is to protect in-variants of any class(in java). Here is the complete code for class DList/class lockDList/class DListNode/class LockDListNode. class DList and it's subclass class LockDList has following invariants. /* DList invariants: * 1) sentinel != null. * 2) For any DListNo...
Given a relatively simple mobile app that consumes semi-static (infrequently updated by hand) data, is it a good idea to simply store said data in a public GitHub repo, in form of a structured collection of JSON files? That data contains nothing sensitive or secret (thus there is no risk in making it public) and it doe...
Every JavaScript programmer is familiar with this "problem" (it can be considered as a feature, depending on various conditions) - this is lately binded: let foo = { bar(){return this;} }; let _bar = foo.bar; _bar() === foo.bar(); // false; _bar() evaluates to global object or undefined depending on presence of '...
I'm building a web application using a MVC pattern. Following this kind of architecture we can see that all the methods used to interact with database are implemented in the model. But what happen if I have to call a service exposed by others on web? For example, I would like to access the Facebook API in order to get ...
I am beginning to learn how to create web applications from a golang tutorial. For simplicity, it persists data to files instead of a database. The complete code creates a server that can handle multiple simultaneous requests, but the program doesn't seem to ensure that only one user is interacting with a fixed file at...
I have a tree that consists of 5 types of nodes - V, W, X, Y, and Z. V represents the root node, and a given tree has exactly one element of type V. A V contains one or more Ws, a W contains one or more Xs, an X contains one of more Ys, and a Y contains one or more Zs: Looking at this, I decided to model this with the...
When working with finite state machines, is there or can there be a well defined concept of 'before' and 'after'. The ordering would, for example, tell me that one state is always considered to be 'before' another state, in the sense that any sequence of transitions through a state machine from some start state, to som...
in my application I provide a Qt/C++ wrapper to certain web services based on the Danbooru software. Basically the API wraps a series of REST calls and produces / parses the JSON responses to display this in an application. Links to the source which wraps the web API: https://git.dennogumi.org/kde/danbooru-client/blob...
I'm working on a small library that provides implementations of basic, well known string metrics. Mostly for my own education. So development happens whenever I've got a bit of spare time. Because of this I've automated most processes so I can release a version as often as I work on it without too much effort. However ...
Background: I'm an intern tasked with learning Selenium; my organization plans on having QA/Testing use it to simplify testing. We use JSF and WebSphere Application Server. One of the persistent issues I (and other users) have had with using Selenium is identifying input elements that have dynamically generated ID attr...
we have a data set that creates a graph, it works but the graph has many up and downs and looks really bad, what I like to know if there is a known technique or algorithm or even an API that can smooth it out. a very bad drawing of mine is demonstrated, so what I like to do is to get from A to B I hope the picture belo...
As a learning project, I am trying to create something similar to the WebGrid that comes with ASP.NET MVC. Now this component MyGrid<T> looks like this: public class MyGrid<T> where T : class { public MyGrid(IEnumerable<T> dataSource) { ... } public bool AutoGenerateColumns { get; set; } public MvcHtmlString Html...
Sometimes when you create a class you can add there several properties (new data members) that you are not certain if you want to do or not. For example, I have a casino slots game. I have tiles and tiles are spinning on different reels. So once 3 tiles come on the same line then player wins 3$, 4 tiles - 4$ and 5 tile...
I'm developing a wpf-based application and I'm currently struggling to find the best way of supporting a recurring scenario in it. This app uses grids a lot. There are a bunch of features I want in it that are meant to be used in grids, such as drag & drop, multiple row edition, conditional row coloring, etc. But at th...
Tl;dr: Should we return null and not know origins of the error or throw exceptions and handle them appropriately? A few years ago I found this article: http://stackify.com/golden-rule-programming/ It says: If it can be null, it will be null This kind of thinking leads to defensive programming throughout the applicatio...
I want to be able to add some objects to my application by simply adding a XML node to a config file. Should I put it in the app.config file or should I make a separate XML config file? A node would look something like this <Books> <Book> <title></title> <author></author> </Book> </Books> In that case ...
Lets say I'm running a PHP app like Magento, PrestaShop. Now these system have their own complex autoloaders to load controllers based on routes, required classes, models, etc. Most of the time as a developer I create module to implement some sort of custom functionality. These modules reside in /modules/mymodule/. Som...
I was reading an article that explains some solutions to the "unpredictable emergencies" situation during Agile sprints. The article suggests having triage to determine if issues are truly emergencies and if they should be worked on by resources involved in an active sprint: So solution 1 is: a strong Product Owner wh...
I am developing a database server similar to Cassandra. Development were started in C, but things became very complicated without classes. Currently I ported everything in C++11, but I am still learning "modern" C++ and have doubts about lot of things. Database will work with Key / Value pairs. Every pair have some mor...
I am making a neural network in Clojure that can take an array of integers,and return a data structure representing the layers of a neural network: so (make-layers [1 4 5]) would evaluate to: [[0] <-- input [0 0 0 0] <-- hidden [0 0 0 0 0]] <-- output When I run my activation function on the weights of ...
The values of all of the neurons in my neural network are initialized to 0 and the connection strengths between the neurons are set to randomly generated floats, between 0 and 1. I have seen other people setting their ranges from 0 to .5, however. Are there any benefits of one over the other? and Should the neuron valu...
I have a workflow wherein I walk recursively through a bunch of directories, then for each file perform some action. I'm using goroutines to walk each directory, and also to process each file. The problem I have is keeping track of when the work is "finished" as each directory spawns a new goroutine and there is an unk...
I have a table that is connected with 2 other tables like so: Main table ID_1 | ID_2 //Foreign key of table1 //Foreign key of table2 Table1 ID | Some information |More information //connected with ID_1 Table2 ID | Some information | More information //connected ...
check this picture out before I explain further: How can I count the amount of lines there are from the yellow line to line #5? OCR sounds like overkill, because I don't really care what the text says.
In my web application that uses an MVC framework which has different modules for models, views and controllers I talk to several databases and APIs. Those are implemented as individual models. A lot of data gets entered by the user accross several different screens. That data goes into the session. Some of that data is...
For example, you use some MVC framework for your web application and for most of the time you are thinking in very object oriented way, and that is why you opted to use an ORM framework in the first place. However, when it comes to reporting. You decided to use reporting framework like BIRT, for example. BIRT does not...
There is task that from the business point of view is really critical but, even it has been estimated in 40 days of works [of course worst case], involves a really small part of the project (a couple of java classes, some JS and JSP pages) and, in my opinion is really complicated to be assigned to more than one develop...
I am looking for ways of passing around a set of contextual variables that are required by functions. As a Python programmer, right now I can see three ways of solving the problem: passing them around as explicit arguments, class encapsulation and closures (function factory). I find that explicit arguments tend to obs...
I am working in Visual Studio 2012. I have several C projects in a single Solution. Each project currently produces a single production output (dll/exe) and a single test (exe). I manage the multiple outputs through custom configurations and settings including ignoring files per configuration. My motivation for doing s...
We are moving from subversion to git for branching and distributed development reasons. One struggle in the past with our old repository workflow was that every application had its own repository. A huge application had its own repository and a small application that had 15 files and barely ever changed had its own. Mo...
Callback functions are able to accept some parameters, but they are not explicitly declared when calling the function. How does this actually work? What is going on that allows us to pass a function as a parameter to another function, and implicitly include a parameter in there? For example: Javascript $.get('somefile....
I recently noted that adding [TestInitialize] to a protected method in a .NET assembly wasn't respected, but if I made the method public it was called by the unit test runner (Resharper in this case). I've noticed this several times in the past with test methods. Technically speaking, its just as easy to reflect on a p...
SQL injection is a very serious security issue, in large part because it's so easy to get it wrong: the obvious, intuitive way to build a query incorporating user input leaves you vulnerable, and the Right Way to mitigate it requires you to know about parameterized queries and SQL injection first. Seems to me that the ...
On the software project I'm working there are 4 teams of 6 people. The project itself is a moderately complex distributed system, but the current user stories are mostly about implementing CRUD operations and such. My problem is that we are working in pairs non-stop. I think that this brute force approach to pair progr...
I am currently working on a little MonoGame project. While planning this, i came to a problem: I want to separate the game logic to an other assembly. The client and the server need this logic assembly, the client can also start a server. My question is now: should i separate the server in an specific assembly, or shou...
Without using the power pack to convert Expr to C# expressions, it seems like once I create an Expr, the only thing I can do with it is either print out a string representation of it, or...create another Expr. If I print out a code quotation of an expression, I see that it prints out calls to static Expr methods. How c...
In my professional work I started noticing that the more advanced developer you are the more meaningful comments you leave on a code review. Recently when I was asked to interview several candidates I came up with a fairly simple code snippet (these were inexperienced candidates) in several languages (so they can choo...
I'm very new to Java and want to understand the difference between class variables and instance variables. For example: class Bicycle { static int cadence = 0; int speed = 0; int gear = 1; } How are instance variables and class variables different from each other? Which variables here are class variabl...
I am trying to use dependency injection in a WPF application, and I really can't figure how to avoid using service location, which is considered to be an anti-pattern in many articles. I am using the MVVM Light framework. Interface I Property N As Integer End Interface Class A Private _i As I Sub New(i As I) ...
I am brand new to embedded programming and am wondering if RIOT-OS has the capabilities that my small project requires. I have 3 executables, fizz, buzz and foo. They all do separate - but very important - things. My understanding with real-time OSes is that you typically: Take your app’s source code and somehow merge...
In my C++ project I am relying on some libraries that do memory management for me. I make wrapper classes, for ease of use and memory safety, for example the class below. Note that this is a much simplified example, to demonstrate my problem. #include <library> class Wrapper { private: lib_type* data; public: ...
I have a question about whether a programming technique is at all possible. Most of the apps these days come with sign up with Facebook, Twitter or gmail functionality. My company has its domain name (for example www.mydomain.com) and our email address are as (john.smith@mydomain.com) and we use outlook to access the...
I have an iOS App which currently pulls in all the data from the MongoDB using a Node.js server. Currently my API / my node server handles all the data manipulation the iOS app/Swift only displays the data within the app. My server carries out all the functions on the data being returned from MongoDb. I have a Joomla w...
I have several projects on Python I am currently versioning with Git. I also have the input-output data that is gradually changing over the course of the project. I need to be able to re-run my pipeline later exactly in a way it was executed at a given time. What would be the best way of doing it without inserting the...
I decided to write a singly-linked list, and had the plan going in to make the internal linked node structure immutable. I ran into a snag though. Say I have the following linked nodes (from previous add operations): 1 -> 2 -> 3 -> 4 and say I want to append a 5. To do this, since node 4 is immutable, I need to create...
We have several disparate systems. These systems assign ORDER numbers. Basically, these are sequential numbers. They are NOT database ID numbers. These order numbers are like "A01457" or "Z4T456", etc. The problem is that each application issues its own order number and obviously order numbers can (and are) duplicated....
Intuitively, I know that (in terms of a maintainable, understandable codebase) the following code is bad practice var foo = fooFunc(barFunc(),wooFunc(chewFunc())); and might be better stated as var bar = barFunc(); var chew = chewFunc(); var woo = wooFunc(chew); var foo = fooFunc(bar, woo); This makes debugging easie...
I've been writing a lot of unit tests lately and have become somewhat obsessed with code coverage. However, I'm struggling justifying going for 100% code coverage, when so many tests would be a redundant, and really clutter up my unit tests. For example, imagine an customer endpoint of an API. The user posts a customer...
The IEEE 12207.1-1997 guide (Software life cycle processes - life cycle data) has a list of general content requirements for all description documents (section 5.1, page 12). This includes "notation for description" (bullet f). Does this just refer to whatever system or structure is used for the description (e.g., des...
I have a simple object like this public class Book { public List Chapters { get; private set; } public TableOfContent BookTOC { get; set; } public string Identifier { get; private set; } public string Title { get; private set; } public string Publisher { get; set; } ...
I am in a current iteration between design and implementation, and ended up with the following "one-liner": IEnumerable<Channel> ActiveChannels = Receiver.AcquisitionInfo .ActiveIndices .Select(v => Receiver.Sensors ...
Some time ago I read, on a Stack Overflow answer that I can't find, a sentence that explained that you should test public APIs, and the author said that you should test interfaces. The author also explained that if a method implementation changed, you shouldn't need to modify the test case, as doing this would break th...
Problem: I am trying to design a system which takes requests from customers in real time and log them in a database. For example - request to purchase an item. The customer then gets a unique request-ids for his request and also is asked to wait for 'X' days because the request is being processed. Then the system noti...
I've got a fairly substantial code base that I'm trying to simplify. One section in particular deals with probabilistically creating objects. It currently uses hundreds of random number generator calls in if-then statements to achieve the desired result. Example: if rand(20) >= 2 then //Make Object A if rand(20) >=...
In the design of a javascript based web app I was concerned if my app would run on inactive windows on Android and IOS since is basically a webapp wrapped by a native app. Does anyone know how these two Operating Systems Manage running javascript on inactive tabs?
I have started freelancing for couple of weeks and have done few projects. While doing it I found myself in risky situation when client ask progress and also want to see it done. which means I have to send them what work I done to the date. So they can know their project is on progress and will be completed on time. Bu...
I am designing a Bank Application which deals with Customers having FD Accounts. There are two approaches to this : Approach 1 In this the customer has a list of accounts. The bank application will manage the accounts through the customers. My mentor feels this is the correct approach. :-P class Customer { String...
I have noticed in java programs at least, that people tend to prefer to start their programs by creating and instance of the class that contains the main method, and activating a non-static method within it, like so class MainClass { void start() { //start the program flow } publ...
Most, if not all, open source software licenses allow others to obtain a copy of the source code, edit, and redistribute both source and built versions of the software, edited or not. Also, more often than not, that includes commercial redistribution. My question is: is there anything legally preventing someone, beside...
On slide 19 in a presentation Margaret Hamilton describes three primitive control structures. My goal is to reduce the probability of errors in my code by working with this "design framework". I am wondering if someone could explain to me how these structures work. Perhaps someone could point me to a simple implemented...
In Java the typical way of storing configuration is by using property files. So I have several such files, one for each environment type (dev, test, prod, ...). This configuration is needed in different parts of the code base, i.e. in different classes, but in order to avoid duplicating code for opening the right file ...
As a simple demonstration of the efficiency of Haskell style, I thoughtlessly ran the following: take 100 [(a, b, c) | a <- [1..], b <- [1..], c <- [1..], a^2 + b^2 == c^2] This should be a way of deriving the first 100 Pythagorean triples, with duplicates. In practice however, it never halts, because the algorithm its...
I'm facing a problem I'm not sure how to approach. I have to generate a calendar for employees, each of them having specific work constraints (some personal, some common) What I'm working with : I have Doctors Each doctor has to work 5 day/week. Each doctor has to work 1 night/week Each doctor has to work an equal amo...
There are a bunch of methods in a class that I want to clean up. These just build up a data structure (with different values) over and over again and add them to a container passed in, like so: SomeClass::Foo(ContainerType& cont) { AnotherType dataItem; dataItem.item1 = true; dataItem.item2 = 42; // blah bl...
We've developed an algorithm that depending on the check-in time of some workers and their living place, calculates the way to group them into some vehicles and the route which must be followed by the vehicles to carry them to the workplace. This has been accomplished using the TSP (Travelling Salesman Problem) algorit...
I have a triple buffer implementation that is often used in threads in such a way that when new data is expected, there's always a WaitData(n) function called on the buffer (A condition variable's timed_wait(n) function is called) and afterwards a HasNewData() is called on the buffer. If both return true, the buffer ca...
I'm building a websocket server in python and I've hit a block regarding my program's flow and structure. Here's what I'm doing at the moment. The program creates a instance of 'server' and listens on the port. The client connects to the server -- this creates an instance of 'connection' and passes 'server' as an para...
I'm playing around with async and await, and they seem pretty intuitive, but some of the things I'm reading about these keywords doesn't make sense to me. In fact, some of it seems to me to be flat-out wrong, or at least misleading, even though it's coming straight from Microsoft. Consider the code below: namespace Asy...
I am new to makefiles and I am developing a (non-executable) library in C++. Additionally to the library I have (executable) unit tests and an (executable) demo program. I would now like to be able to compile the unit tests and the demo program using make. What is conceptually the correct way of doing this? Does th...
I'm currently developing a small component-based framework the Android platform. The framework has some ready for use and some abstract (has some internal logic, but the developer needs to add some code to make it fully functional) components. All communication between the components is satisfied using interfaces. My q...
Our application is hosted on a dual-server environment - when one server is overloaded with work, a secondary server will take its place in processing certain actions. For most purposes, this isn't a huge problem. However, our application generates documents and writes them to a database - and to do this, currently ...
I have a hard time understanding the use of MSB (Most significant bit) vs. LSB (Least significant bit) and why they're used at all. It is my understanding that it has to do with Endianness, but I cannot get my head around it. Basically: If I read a specification on X and they specify that the data needs to be read LSB ...