instruction
stringlengths
34
36.1k
I want to retrieve data from internet and show them into a widget. In particular, I've a widget with a QComboBox containing some service from which I can retrieve a list of exchange markets. When I select one item, I want to show related markets in a QTextEdit on the same widget. In my mind I think to do following step...
At work one of my colleague asked to me to change the way a Spring StoredProcedure subclass class was initialised from injecting the parameters with Dependency Injection mechanism (Constructor Injection) to a "more straight forward and simple way". The actual code with DI initialization looks like : <constructor-arg><...
I have some code that is nearly identical, but uses absolutely different types, with no inheritance between them, on the main variable. Specifically, I am writing an analyzer with Roslyn for C# and VB.NET, with the following types: Microsoft.CodeAnalysis.CSharp.Syntax.AttributeSyntax Microsoft.CodeAnalysis.VisualBa...
I have too many write requests to database. Currently my app implementation is such that it makes pull call to server every 5 seconds to update the changed data. If I implement push through web sockets, does it increase the server load(mainly number of queries getting fired on mysql)? Because now on change of data (w...
I always followed the opinion to not abuse interfaces in case of decomposition. Usually I only implement them if I am absolutely sure to have a "is-a"-relation and avoid implementing them if there is a "has-a"-relation to another kind of object. Now, this ethic leads me to a problem: I'm writing a small library includi...
When working with an ORM such as Entity Framework, I've fallen into a comfortable habit. Make an interface with get/add methods on it, put this on a "Repository" class then add a constructor to each class that accepts the interface. Use the interface's methods in the class. It seems the most straightforward way to gain...
Is it a good idea to send Exceptions as EventArgs in C#? (And not actually throw the Exception). I have a class that performs a long running asynchronous task. If something goes wrong in the middle of the task, it will raise an Error event. Is it a good idea to add an Exception as part of the event arguments, or would ...
I've implemented a structural sharing algorithm for creating Clojure style persistent trees, but it relies on the child node knowing its own parent. function fork return new Node children: this.children value: this.value parent: this.parent.fork() Calling fork on a node in the tree will give you a new no...
I am doing a web application using struts2 framework. After user login, I show a dashboard about the current status of the user. To show the Dashboard UI(JSP), I used to get the information from the backend (Mysql). On page loading I trigger a request eg."getDashboardInformation" (via Jquery Ajax) to get user's current...
Say there is an online hotel management application. One feature is the Receptionist will confirm and cancel bookings made by the customer. So all Receptionists do the same things. Is it bad practice to add a single row to the database representing all the Receptionists in the hotel then let them access it to login to ...
A friend of mine has a small company that needs a new website, and I am interested in helping him, since I have worked a bit with Asp.net MVC. However, I am not sure if I'm allowed to sell or give away websites made with the community edition of Visual Studio. The license says IF YOU COMPLY WITH THESE LICENSE TERMS, Y...
What is difference between the BLOCKED and the WAITING states of a thread. As per JAVA code comments /** * Thread state for a thread blocked waiting for a monitor lock. * A thread in the blocked state is waiting for a monitor lock * to enter a synchronized block/method or * reenter a synchroniz...
I'm building a SPA (single page application) so that when a browser request a page from my server, it only receives a small HTML and a big JavaScript app that then asks the appropriate data from the server, renders the HTML locally and generally drives the local app. Think of apps such as Gmail or Google Maps that neve...
Say I have a class Foobar that uses (depends on) class Widget. In good ol' days, Widget wolud be declared as a field in Foobar, or maybe as a smart pointer if polymorphic behavior was needed, and it would be initialized in constructor: class Foobar { Widget widget; public: Foobar() : widget(blah blah blah) ...
I understand that O(n) describes an algorithm whose performance will grow linearly and in direct proportion to the size of the input data set. An example of this is a for loop: for n in 0.100 puts n end What does the O(m+n) and O(m*n) mean? I couldn't find any clear examples of this in the internet. Please provide e...
I'm working on a project that has me responsible for testing out some software that scrapes a web-page representing an input form, and generates a mobile friendly version of that page. This is particularly useful for form data, since not all websites have mobile-enabled browsers, and the aim of this project is to ultim...
I'm curious because I have read that once an array is declared it can not be changed. Maybe if I lay out my thoughts. Say, I have a cube with dimensions 5x5x5 and I have a viewport that can rotate the face of the cube to see object data in a area. Instead of slicing the image in flat planes, is it possible to have an ...
I'm trying to understand the way that GPLv2 works, and have a couple of questions. I'm going to describe a couple of scenarios, and want to know how GPL applies there. I make a web application that uses a GPLv2 library. I put this project in a public repository (github). The project calls functions from the library, b...
I have an event table that should store events (dt_start, dt_end, all_day,etc). I saw that .ical files stores dt_start and dt_end as the same day (without time) for an "all_day" event. Question: if I have an event on 2015.09.08 all day, how it should appear for a user that has a different timezone? Along two days? o...
What would be the best approach to maintain the dropdown lists for the whole application (like city, state etc) taking into account the SOLID principles and performance? Right now am loading the list values into a static property and using the same like public int DestCountry { get; set; } private string _CountryText;...
it's not a big programming problem, but I'm curious if it should be done better. So I have a config file which I'm reading via java.util.Properties class. When property is not present in a file getProperty() method returns null. I would like to throw an exception if any property is not present in config file. So how sh...
Where does the phrase "overload" come from? It's interesting to see the translation of the term in different languages (e.g. list of Wikipedia articles about overloading), some languages translate it directly (in the meaning of "to put too much weight on something"), but some languages don't translate it at all.
It's always been known that Disk operations are slow and we know the reasons why they are slow. So the question here is why do we have to wait for I/O or why is there such a thing as IOWait, etc.? I mean I've noticed that when you're doing some I/O tasks in the background, your computer basically gets a lot slower, I'...
My instructor once told me that I should not define a variable inside a loop, but I honestly still do not understand why. What are the disadvantages of that? Could any body explain that to me?
I have a complex object which routinely needs to compute a sub-object representing various aspects of the parent's state as a bundle. For example, imagine the object represents information about an aircraft and the sub-object is a summary of various key parameters of the aircraft at some particular time such as its hea...
Are there licensing ramifications to having GPLed code in a public git history, but not a released version of the distributed software? Could a repo owner be obliged to changing their licensing based on historical missteps? This seems like it could be an avenue to inject GPL into code for projects that may not hav...
I'm designing a distributed application, very basic for now. The idea is that once the application is active on all machines (about 5 vms), you can initiate a grep on all log files from all machines from any one machine. Generally, the steps would be: Launch the application on all machines All applications pause in a ...
Often when I'm writing a set of utility functions, I find myself wanting a function that applies some logic to multiple items, as well as a function that does the same with just a single item. There are a lot of potential solutions to this, but I always find myself flipping back and forth. I could write an exclusively...
What is the difference between O(N^2) and Θ(N^2)? I know that O is the upper bound and Θ is tight bound. Could someone explain me this concept with an example.
When I first learned about CORS and Same Origin Policy, I thought it was an honor system (enforced by browsers) to protect a website's resources from being stolen, bootstrapped, by other websites. But since then I've read things here and there that suggest it's to protect users, and I'm not quite sure how it does that ...
PHP is a mixed paradigm language, allowing to use and return non-object data types, such as arrays. I pose a question to try to clarify some guidelines for selection of arrays vs objects when deciding upon what programming construct to use in a particular situation. This is really a question about ways to encode data u...
I've had a dispute with a colleague about when to run JavaScript unit tests in a CI environment at one of two different times. Let's call the two parties PE (pro-early) and PL (pro-late). Early (against src) Running the tests against the source code right out of the version control system. PE says that we should run ...
I believe that DTO should be as dummy and easy as possible. However, after hint made by my friend, opportunity to validate data that is set in DTO sounds tempting. Let's have following example: //this class only holds bunch of objects from the future class FooFuture{ /** @var ArrayObject */ $collection; ...
In our deployment process for our services, besides unit and integration tests, we also have a little smoke test for our services. Mostly for verifying that the deployment went well, cloud services set up correctly with working connection strings and working domains. For most services this is quite easy. Make a request...
Working in Python, I've written a few utilities to assert pre-conditions and to re-interpret exceptions, and have found my code doesn't have so many branches. I've also tried to move other code path selection into maps, so depending upon data conditions, an appropriate object will be looked up to carry out the operatio...
So, I am part of a very large project which has, as yet, no unit testing (shudder!) and I want to introduce it. I plan on using Google Test and Google mocks. The code is large and unwieldy and suffers from "header spaghetti". If I wish, for simplicities sake, to test only a.cpp which calls only a single function in b.c...
I am designing a REST api backend that is meant to be consumed by a javascript front-end. I am not sure how to communicate server-side business logic errors (e.g. a user trying to retrieve his password with an unknown email, etc.) to the front-end. After setting a 40x status code on the response, I need to add further ...
I was wondering why isomorphic JS, like using reactjs in both client and server side increase first page load ? What is different from simple SPA applications ? In both cases we are loading the full content of the applications (in build.js or bundle.js for example). So what is different in both cases ?
Is there a difference between these two versions of code? foreach (var thing in things) { int i = thing.number; // code using 'i' // pay no attention to the uselessness of 'i' } int i; foreach (var thing in things) { i = thing.number; // code using 'i' } Or does the compiler not care? When I'm sp...
I'm trying to think of a better way to version control our website projects. Keep in mind I'm only a front-end dev so I don't have a profound knowledge of VCS. Workflows are changing, and past version control habits become obsolete. The main problem is there are 2 arrays of front-end files for each website. The dev env...
I am doing some research as to how most hardware accelerated GUI libraries work. I am actually only care about the rendering backends of them here. I am trying to figure out what would be the best way to try and write my own as a sort of side project. I am trying to go for ultimate performance here instead of overly fa...
I have what is probably an over-engineering question. I have some PHP code that logs messages to a file. We've been having a problem with the file having the wrong perms from time to time. While we're troubleshooting that, I am writing a work-around for that in the logging function, changing the unix perms and owners o...
Below I describe what I'm trying to do and how I think I will do it. What I'm hoping is that a design pattern exists for using one object to configure another. This would allow me to have a nice generic Job class rather than an ever-increasing list of Job subclasses. If there is such a design pattern, what's it called...
A significant portion of the application I work on every day consists of Javascript that outputs a lot of (what might as well be) Excel spreadsheet formulas. Yes, Excel is barely a Turing-complete language, but the formulas are more than complex enough to qualify as "code". They're not meant to be human-readable or hum...
I have an application that process portfolios. I must aggregate 8 years of returns of aproximatelly 8K securities. (about 2016 doubles (8 years of data) for 2 dates (for comparison) 4032 for 8K securities.) This is consuming aproximatelly 2GB of memory. I wonder if there is a better way of processing this other than ho...
In following the principle of testing only the exported functions on a package (using Go - or for others languages, the public functions on a class), I'm running into a scenario where related packages are causing the code base to be tested multiple times. For example, I have a Preprocessor, which calls a Parser package...
I am creating a little randomization library. One of the methods is similar to .NET's System.Random.Next(int start, int end). The thing is, I am not sure how to decide on whether the upperp bound should be inclusive or exclusive. While .NET's Random.Next has an exclusive upper bound, there are other frameworks and libr...
So I had to write some code related to splitting Bezier curves into parts. I read through several references and particularly referred this rather detailed one. The final code outcome is however around 20-30 LOC. But without having this kind of background, it would be really difficult for someone to figure out what th...
Problem: We have an int array[n]. We need to find all the pairs for which array[a] + array[b] = 0. The only algorithm I came up with so far has O(n^2) - tho most obious one. Is there a better way to do it?
When I was first taught Object Oriented principles, it was drilled into me that when using objects in a "hasA" relationship (or any similar situations where a helper object encapsulates a discrete smaller purpose in a bigger system), the owned class should not have awareness of it's greater environment, so, for example...
Normally, a Data Mapper maps data of one particular table. (Theoretically it should be communicating between Storage and a Domain Object, but its not possible in my case, so I am directly communicating with tables.) Table1Mappper > Table1 But if that table requires data to be joined from another table, then you are ...
I want to create a windows 10 universal to-do app with offline sync capability. So I checked out this tutorial which helped me to get started on the offline functionality. But I was wondering how should I design my Azure database to get data efficiently and moreover I also should have the ability to store images. So he...
Some developers work on code hardening. (protecting against errors, you can build with a stack protector for example). However, if you're trying to redo a strange someone else reports, or find possible problems with the code, the reverse could be useful. Are there well known ways to increase the chance an error in the ...
I have a page the allows a user to create a signature using a touch screen or mouse. The touch screen works fine in Chrome but not in IE. Most of the time IE does not 'detect' that I am using a touch screen. We detect touch like this: if ('ontouchstart' in window == false){ // rest of code } The canvas elem...
I'm so ridiculously frustrated with having to use DateTime values for data sets that are truly "just a day." Birthdays being the most-common example, but this comes up in business applications all the time. I've gotten used to just setting the Time part of "date-only" records to "noon" (which avoids the date ever chang...
I have 10 independent data structures that contain unsigned bytes and bit fields from different data sources. I am using C++, and was looking for a way to combine all these data structures into one data structure for the purpose of passing all the data around between different methods. For example I have an object that...
I am working on a ML project that will involve malware and I want to represent the statistics files used for training the classifier via StatsFile objects. However, I am wondering whether I should use a IStatsFile and subclass as such: IStatsFile TrainingMWStatsFile TrainingBWStatsFile TestingMWStatsFile TestingBWStats...
How is an Integration Point defined within the context of an application? I've heard about it in a programming course but couldn't grasp the concept in a way that I could distinguish an integration point among other parts of the software. The teacher in the course asked to make sure that software is responsive and sta...
I know according to open closed principle, something like class,interface,code.... should be unchanged when add new functions or contents, but is file also in this case? I was designing a game, the game have some monster information, and the game (in client side) may download or replace some file if there are new monst...
I am currently porting the class NumberRange from Java to C#. I am writing this constructor and I wonder whether I can call a constructor in itself. Something like this: public NumberRange(Double num1, Double num2) { if (num1 <= num2) { Min = num1; Max = num2; } else { Number...
Note: this question is different from Can a UML class diagram show two different relationships between two classes? which is about two relations of different type. I have a Menu class which contains: A bunch of children, which are instances of MenuItem class. An instance of a MenuItem class which corresponds to a very...
I have a helper project which I use in all the applications that I create. It contains some extension methods and a bunch of generic helper classes, controls etc. I update/extend the helper project from time to time. These are usually small and unrelated projects, and I am the only person working on all of them. I trie...
Let's take an example of a generic API endpoint that looks as follows: https://api.imgur.com/3/gallery/{section}/{sort}/{window}/{showViral}/{page} Conditions on this endpoint are as follows: Arguments are optional. Default values will be used if not provided. All the earlier arguments must be provided in order to us...
We are used to Node.js / Python / Insert X. Moving to a Java EE stack, it seems to me like all of the resources are 'press this button', 'do that' without any actual architectural explanation. For the time being I'm interested in answers to the following questions (I'm completely ignorant on the topic, so some of them ...
Regarding the fact that C in CSS stands for Cascade, so generally speaking rules described in one file can modify/subsitute rules in other files, can we claim that all project css files should be concatenated to a single file in most cases. Because browser still won't get all style computed till all rules will be take...
I run a website that is hosted on Microsoft Azure and I'd like to store users' profile pictures. Which storage solution would be better ? I'm aware of a few ways to do so : Store images as blobs in database (but I need to render it via a controller) Store images as base64 in database (but I need to render it via a con...
i am a hobby php-dev and have the following problem: i have a rar-file, whose header is damaged, therefor extracting is not fully possible. the contents are non-compressed, and can be read with eg. a hex-editor. the archive contains jpeg-files, but because of the damaged header, some of them are not extractable in winr...
I have 5 different websites that use exactly the same code, apart from they have an uploads folder with different contents (AKA images that aren't consistent through every site) and also a config file which has a few settings like whether this is a production environment, which database to use etc. My problem is I have...
"amortize" mean reduce or extinguish (a debt) by money regularly put aside. i.e. to pay off of debt with a fixed repayment schedule in regular installments over a period of time. In amortized analysis of algorithms, does "amortize" also mean to reduce something by something else regularly put aside?
I'm working on a big project for the first time and right now I'm using 15 dll's from different sources. Having all these dll's in my output directory together with my .exe is "polluting" that folder a lot. From most of these dll's I have the source code that I could copy into a single dll of my own reducing the amount...
If we have a strictly layered architecture, can we allow outside components to interact directly with the lower layeres? More specifically: In my lower layers, I am providing a service, and in the top most layer I have a layer called Applications which is basically various set of applications that can use that service...
The team I am working on is trying to do agile development with 2 week sprints. I think we must be doing something wrong however, as we have to work like madmen to get the features implemented in the 2 weeks, leaving barely a few hours at the end for a quick QA cycle and no time for documentation or writing unit tests...
I'm trying to get through one of the exercises in Okasaki's "Purely Functional Data Structures," where he presents a zeroless binary numbers as a structure for random-access list, and asks to 9.6 Show that lookup and update on element i now run in O(log i) time. "now" here contrasts zeroless representation with a pla...
git stash apply stash@{n} contains a number of hard to type characters and repeats some information. Is there a reason for repeating the stash and using the at-sign and braces instead of something easier to type, like git stash apply n, for instance?
I am considering adding a plugin system to a commercial project and I've found a Dr. Dobb's article that describes in detail with source code a plugin framework for C and C++. The article doesn't mention a license. Is is generally safe to use such source code in commercial software?
I have a REST API that could GET, POST, PUT, DELETE models. My problem is when I paginate that with ajax call combining with DELETE operations. My problem comes after few steps list one page list the following page (when i scoll down) I delete a row Problem. when I ask for the 3rd page, i miss a row, because, asking...
I'm working on a personal project to help me branch out and learn some new/different technologies. I'm a .NET programmer but I want to learn Ruby and how to develop Android apps. I have developed pieces already but need the whole system to tie together now. End Goal: I want to develop an Android app that will display g...
According to the book "Clean Code" on page 38, the following lines of code violate the single responsibility principle. However, I cannot understand how there are "multiple" reasons for it to change? public Money CalculatePay(Employee e) throws InvalidEmployeeType { switch (e.type) { case COMMISSIONED: ...
Why did C++ make any distinction between static globals (internal linkage) and symbols in an unnamed namespace (external linkage, but no way to refer to it from outside anyway), when introducing the latter? Are any of those reasons still valid, or are there new ones? Are there any places left where they are still di...
Problem? I have been looking at MVP implementation and process to design a good domain model (not anemic). It says that the domain model should have its own behavior and not being a simple data model (like DTO). In my case (my application), it turns out that controllers architecture is following the model architecture ...
I just read this excellent tutorial on OAuthv2 but am still missing some important concepts regarding authorization grants. I'm fundamentally not understanding the necessity for the two request/response cycles between client app and authorization server, where: First the user is redirected to the auth server during an...
Imagine a simple PHP application where an user can post notes and the other users can upvote or downvote them. We want to implement a system where each note has a different rating (normal, good, great ...) based on the number of upvotes and downvotes it has. My question is: When should I handle these rating changes? My...
Many programs are capable to "rewrite" on the same line, not in a STDOUT way. For example scp write the percentage or many installation programs will show you the nice rotating wheel. How it works?
It was my understanding that cookies are transferred with each subsequent http request, yet if I log in to a web application that uses cookie authentication, say on my browser, other applications on the same machine don't seem to send these previous cookies with their requests to the same address. Is my understanding o...
For those of you who have the good fortune not to work in a language with dynamic scope, let me give you a little refresher on how that works. Imagine a pseudo-language, called "RUBELLA", that behaves like this: function foo() { print(x); // not defined locally => uses whatever value `x` has in the calling context ...
This question is somewhat language-agnostic, but not completely, since Object Oriented Programming (OOP) is different in, for example, Java, which doesn't have first-class functions, than it is in Python. In other words, I feel less guilty for creating unnecessary classes in a language like Java, but I feel like there ...
I'm a volunteer for a non-profit organization and am helping them develop a free open source Android application that will be licensed under GPLv3. We are going to use the logo and some other graphics files from the organization and are wanting to use licensing of this artistic work to protect ourselves from anyone doi...
I am trying to build a PHP application using the Repository Pattern but I'm not sure how I should implement the save method. I have an abstract class called ItemRepository which have the following method: abstract class ItemRepository { public function save(Item $item); } Where Item also is an abstract class. Now ...
In C, for creating linked list we write: struct Node{ int data; struct Node* next; }; So, my understanding is "struct Node* next" is a pointer variable of "Node" datatype. But how does it point to the next node in a linked list?
Let's say you have some kind of data structure, which is persisted in some kind of database. For simplicity, let's call this data structure Person. You are now tasked to design a CRUD API, which allows other applications to create, read, update and delete Persons. For simplicity, let's assume that this API is accessed ...
I've been a rails developer for a bit now, and I've started to get into the MEAN stack through a tutorial. I kinda understand Angular and Node and the purposes they both serve, but I'm not sure I get express yet. Does rails do all of these things in the background? My understanding: Angular is does most of your views,...
I'm trying to migrate lagacy data to a new eCommerce system which I'm building myself and I have full control over (so I can modify it however I want). There is a product that came with a free gift for the first 100 customers. After that, it was just the regular product. Now the way that was handled in the old system w...
Mergesort is a divide and conquer algorithm and is O(log n) because the input is repeatedly halved. But shouldn't it be O(n) because even though the input is halved each loop, each input item needs to be iterated on to do the swapping in each halved array? This is essentially asymptotically O(n) in my mind. If possible...
for (Canvas canvas : list) { } NetBeans suggests me to use "functional operations": list.stream().forEach((canvas) -> { }); But why is this preferred? If anything, it is harder to read and understand. You are calling stream(), then forEach() using a lambda expression with parameter canvas. I don't see how is that any...
Name of data structure that's tree-like with multiple root nodes I stumbled upon someone's answer to a question regarding implementing a tree that has > 2 nodes above. I just wanted to get someone's thoughts on using a Forest Data Structure to implement a Family Genealogy Tree that consist of multiple nodes with 0-mult...
I had written a WCF based "chat/notification" system but I am questioning my decision if WCF is a good fit. I have an external 3rd party lib that calls my process when events arrive: public class Service { ScreenPopService _service; public void Start() { MyThirdPartyImports.RegisterUpdate(CallEvent...
We occasionally deploy our SSO system with some major changes. As much as we try to minimize it, on occasion we have require our users to delete all their "old" cookies. This is because their cookies refer to old session data from the previous SSO version. Is there are common way to handle this making it more seamless ...
This came up as part of a code review for a code segment which resembled this: auto somePikachu = GetMeAPikachu(); NT_ASSERT(somePikachu != nullptr); // this only fires on debug build somePikachu->ThunderBolt(); In my opinion that assert is redundant since if somePikachu is null it will crash anyway in the next line w...
I'm using source code from a code example that is licensed under the Apache 2.0 License in my program. Now I would like to publish that program and source code on GitHub using the MIT License. I've read the following in the license: You must cause any modified files to carry prominent notices stating that You changed...
I'm working on a command line interface text based game. I'm writing it in C but there are various ways in which I could refactor the code by using Objective-C: using NSDictionary to allow me to store data in Plists (easier to read/write because of the Foundation framework but much larger in size) instead of plain t...