instruction stringlengths 34 36.1k |
|---|
I found in different places on the internet how to turn a Binary Search Tree into an AVL tree in O(nlog(n)). I was wondering how can this be done in O(n) (as the worst case limit). It kinda seems possible with right rotations but I just don't know how to implement it exactly. Any idea is welcomed.
|
I'm writing classes that "must be used in a specific way" (I guess all classes must...).
For example, I create the fooManager class, which requires a call to, say, Initialize(string,string). And, to push the example a little further, the class would be useless if we don't listen to its ThisHappened action.
My point is,... |
I've been reading around trying to understand multiple dispatching, and why it's so special.
On Wikipedia I came across this simple example:
(defmethod collide-with ((x asteroid) (y asteroid))
;; deal with asteroid hitting asteroid
)
(defmethod collide-with ((x asteroid) (y spaceship))
;; deal with asteroid ... |
I'm having trouble modelling a relationship in DDD. I have four entities:
Claim - defines access to a Service.
Service - a web service. A Service has many Claims and can belong to any number of Teams.
Role - contains a collection of Claims from any number of Services. Roles always belong to a Team.
Team - contains a c... |
In general, domain events are used to make a notification, when something has happened to entity, but is it okay - from perspective of ddd - to use domain events to make a notification, when entity reach a some specific state? For example "PersonIsValidToDoSomethingEvent" or "PersonHasReachedSomeStateEvent"?
|
Background
I am thinking about designing a (GoF/behavioral) command-pattern interface. I may decide to call this thing ICommand. I am thinking that I would have some sort of a queue containing a bunch of command-interface objects. I would like to exercise the queue, calling the interface method Execute for each of the... |
Kind of a functional programming newbie question here:
I've been reading the transcripts of some of Rich Hickey's talks, and in several of his more well-known ones, he recommends using queues as an alternative to having functions call one another. (E.g. in Design, Composition and Performance and in Simple Made Easy.)
... |
I'm attempting to write an algorithm that calculates the distance between vertebrae. The text parser already works perfectly in picking out vertebral references (cervical 6, c-6, c6, c six, cervical six).
It currently references a linear string array, and matches Vertebrae to their index, and then subtracts Min from Ma... |
RFC 2119 defines several terms, including MUST, SHOULD, and MAY, for use in standards documents, particularly those relating to networking protocols such as IP and HTTP. These terms are widely used in RFCs to describe the requirement level of individual items in a specification (e.g. "the server MUST do X" or "the cli... |
There are some datagrids I had quick look into:
Angular UI Grid
ag-Grid, one more link
Kendo UI Grid
Also, previously I had a very small experience with MySQL.
What are the differences between (a) datagrids, as given above and (b) databases like MySQL, with enduser-oriented frondend added to them?
|
Using Visual Studio 2015 update 2, creating a new ASP.NET 4.x application, the default .Net "Target framework version" is 4.5.
Is it a mistake to bump this to 4.6? I did my own research, and I am unclear.
It seems to me, that if .Net 4.6.1 is the newest, it should be the default. It is not. And it almost feels like th... |
I've come across a method that requires a parameter that implements IEnumerable and is of a certain type like this:
public myMethod (IEnumerable<HttpPostedFileBase> myParameter) {
....
}
Why do this at all? Why not just implement the IEnumerable interface for HttpPostedFileBase and require the param... |
Would I be using REST or would my app be considered RESTful if I was using the Google Volley library to connect to a database on localhost?
|
I'm working on a small website with a handful of other coders. Most of us don't have professional experience in software development.
The website is to be run from a local server, and it has a database and python web apps. Currently, all the development happens on the server through ssh. For instance, I ssh into the se... |
In a very simplistic way, I understand:
"Compilation" = "Pre-processing" + "Parsing" + "Linking" + "Executable"
All the macros and other such pre-processing directives are taken care at the "Pre-processing" stage itself.
Suppose, if we have several macros in source code, then will they cause any significant time in p... |
I was wondering how one should write comments in code. I mean, should a comment be a descriptive of what is done in code, like :
//we have got array, now we iterate over it.
code to iterate array
or should it be telling what we should do here. like an order, like :
//we have got array, iterate over it.
code to itera... |
Consider I have some codes that use different logic for some special case, e.g.:
bool compareRatio(unsigned int a,unsigned int b,unsigned int x,unsigned int y){
if(x==0){
return false;
}else if(y==0){
return true;
}else{
return (float)a/x<(float)b/y;
}
}
and to eliminate special... |
I've seen a number of answers (1, 2, 3) where they state that storage is cheap. So when designing a DB structure, it shouldn't be a main concern, or at least it doesn't rank very high in the list of concerns. What troubles me is that although storing data is very cheap, moving it around, transferring it between DB and ... |
Well, I am having two keys and 3 values for that. Say key1,key2,value1,value2,value3. In future may the values can be increased like value4, value5 so on.
I need to get the values(value1,value2,value3) either by key1 or key2. The key1 will be unique, and key2 is not.
Currently, I am using ENUM for this configuration as... |
Is there any good reason to supply a 32-bit version along with a 64-bit version of any software targeted at modern desktop machines, running modern 64-bit operating systems on 64-bit hardware?
It seems that 64-bit software would be more efficient, allow for higher memory usage if needed, etc. Apple even uses 64-bit pro... |
In Java you could return a list that cannot be modified by the caller by doing return Collections.unmodifiableList(list).
Should the method name indicate that it's returning an unmodifiable list? That could prevent clients of my class from attempting to add or remove objects from the list.
|
I would like to implement interprocess communication between an Ubuntu Linux 15.10 mono 4.1.2 C# recorder client and Ubuntu Linux 15.10 mono 4.1.2 C# video server using a C++ mutex class and C++ event class which harnesses pthreads, shm_open and mmap.
The recorder client and video server reside on the same Ubuntu Lin... |
I have a folder containing about 9,000 JPEG photos (about 30Gb), which I want to archive with some sort of compression. I understand that compressing JPEGs is not normally very effective, but these photos are frames of a timelapse, so there is a huge amount of commonality between most of the images. Am I likely to ge... |
I have written a new shiny Todo service with my favorite front-end and back-end framework. To minimize coupling I return data in some standard format like JSON or Protobuf and leave it up to the client to interpret and display it in a way it feels suitable.
The user can select multiple items which on selection should s... |
Given a starting point A and an end point E, I need an algorithm to determine the minimum transit route in a city that passes through all points (A, B, C, D, E) and is the fastest possible. I know I can represent this problem in a graph, but I'm not sure which algorithm to use in this situation.
I was thinking of using... |
We are designing a system based on independent microservices (connected via a RabbitMq bus). The code will (for the first components at least) be written in python (both python2 and python3). We have already a monolith application implementing some of the business logic, which we want to refactor as microservices, and ... |
I'm a bit confused how to use version control with Unity, especially with objects such as scenes or prefabs that are not just code.
We had an issue recently when my colleague and I were working on different parts of the same scene. which resulted in conflicts, branching and merging galore.
In the end my revision was o... |
Suppose we have a set of binary trees with their inorder and preorder traversals given and where no tree is a subtree of another tree in the given set.
Now another binary tree Q is given.
Find whether it can be formed by joining the binary trees from the given set(while joining each tree in the set should be considere... |
There are two modules A and B using the same DB. A imports B as a JAR. I read that messaging patterns can replace the tightly coupled solution of using a shared DB but I am not sure which message pattern I can use.
A high level solution that indicates how we can stop using the shared DB, would be great.
Adding more det... |
I'm in the process of redesigning a portion of my ASP.NET MVC application. I'm currently using Entity Framework 6.1 code first approach.
I've been reading as of late that (Correct me if I'm wrong, I don't know much about DBs): Joins are expensive; we should keep our database normalized and with the least queries execut... |
When I have a string of unknown size and I create an char array to hold this string.
I do something like this:
#define LINE_END "\r\n"
int line_end_size = strlen(LINE_END);
char line[]="Hello! world.";
int line_size=strlen(line);
int test_line_size=line_size+line_end_size;
char *test_line = malloc(test_line_size);
st... |
In ASP.Net MVC, the classic (synchronous) way to write an action method is to return ActionResult. More recently, the ability to perform action methods asynchronously was added, by allowing action methods to return Task<ActionResult>.
I have read https://msdn.microsoft.com/en-us/magazine/dn802603.aspx which explains t... |
In OOP languages, programs can define static methods that can generate objects with different parameters (including subclassed or pre-generated objects), but they are not as commonly used because we also have constructors that can take parameters, even though constructors are forced to synchronously return a single ins... |
Are there any good examples of non-Singleton PHP PDO Dbfactory or connection classes people can point me in the direction, or perhaps even briefly illustrate.
I am interested in learning both support of persistent connections as well as multiple instantiation. Right now, mostly I am finding Singleton use examples.
My g... |
I have recently been exposed to Docker and found it to be an excellent tool for making production deployments very less risky that what I was used to (coming from an embedded world, embedded as "Linux ported on custom arm PCB-s with complete system images cross-build").
However, I've soon experienced that building Dock... |
Is it still relevant?
Instead of
var result = new List<int>();
for (var i = 0; i < prev.Count; ++i)
{
result.Add(prev[i] * 2);
}
where the result.Add, prev[i], and * 2 instructions are executed 10 times (and then all their subinstructions, plus the instruction overhead for calling a subroutine)...
What about in a ... |
We've got talking about branching and forking in Git and a teammate asked if there's something like that in TFVC (hereafter referred to as TFS). I explained that there is, although it's managed differently (shelfsets, branching, cloning, workspacing). In the end, we couldn't figure out the exact relation between these ... |
A cursory glance at C#, Java, and other languages indicates this is not a feature that's required. I tried searching for justification for this maybe from a language design team or blog, but I haven't found anything that explains why such a type is ignored.
My current best guess is applications that use big integers wo... |
I'm working on a huge application and we got some serious troubles regarding the performance of the software. I don't want to bother you with too many details, so in short:
in one JVM runs the GUI (JavaFX)
in another JVM runs the logic
the two JVMs communicate with eachother over socket (for fast transmissions) and ht... |
Software rots. Or at least ages. Software development methodologies may slow down this process, but eventually almost any software system becomes so hard to maintain that a reimplementation is inevitable.
But what is that thing that gets worse with time called? Integrity? Cohesion? Entropy? The amount of technical debt... |
We have shipped our application. Now we have to do internationalization of the application shipping to 15 countries each country its own branded site.
We have many email templates and landing pages that need to get themed/branded e.g. color for header/buttons/icons, master images and logos etc...
As a developer I do no... |
I'm building a DLL and in my public headers I have this:
(definitions are in .cpp but for clarity I show them in .hpp here)
ObjectTag.hpp:
class API_DLL ObjectTag {
public:
ObjectTag() : mUUID(UIDGenerator::Generate()) {
}
uuid getUUID() {
return mUUID;
}
private:
uuid mUUID;
};
Texture.h... |
I'm trying to write a bit of code in Brainfuck, but I stumbled into some problems.
That got me wondering how Brainfuck is Turing complete, as I understand it Turing complete means a language or machine can calculate any function.
What got me wondering how, is that I have not been able to find or come up with a way of f... |
Firstly, a note on the app I'm about to discuss: It's quite large, on the order of magnitude of a service app like Airbnb -- i.e., it's not just a static web page, it is a full web application. It's in the early stages of development.
Here's the question:
I'm about to begin a rigorous dive into front-end dev and want t... |
When I have a lot of data that needs to be validated, should I create a new class for the sole purpose of validation or should I stick with in-method validation?
My particular example contemplates a tournament and a event/category class: Tournament and Event, which models a sport tournament and each tournament has one ... |
I have two different implementations for retrieving posts from the users someone is following and I want to know which one you would recommend using. First I'l show you the tables, and then the two implementations.
post table
id (PK)| poster_id (FK) | value | created_on
repost table - necessary for both implementatio... |
I don't know where else to ask this.
I have an Android app I want to release on the store, and I want to charge a low fee for it. But if part of my application uses code I did not write (i.e. code I've added as a dependency to my Gradle file, found through a project's Github page) under the Apache 2.0 license, am I not... |
I'm working on a small personal project that involves a user entering a password that would then allow them to view a text file that would otherwise be encrypted.
I'm having trouble wrapping my head around storing the password somewhere so that the program can authenticate that it has been entered correctly If I can't... |
The Situation:
I have 68GB of data that is conceptually realized as a 3D matrix of 8-bit values with dimension 4096*4096*4096.
I need to access multiple sections of this data for processing in a time critical setting (multiple as in sequential one after another). Each section would be approximately 50MB in size.
The se... |
This question is to understand the pros & cons for keeping the DAO's with the service or as a separate package being consumed by the services.
Consider a micro-service architecture. Let's say I have 5 different
services which constitute a System. Then there is a Database (MySQL or
Amazon DynamoDB) which these serv... |
Most of time while writing loops I usually write wrong boundary conditions(eg: wrong outcome) or my assumptions about loop terminations are wrong(eg: infinitely running loop). Although I got my assumptions correct after some trial and error but I got too frustrated because of the lack of correct computing model in my h... |
We're working on a commercial software product that uses partial syntax from 3rd party open source alternatives but none of the code from these. For example, the open source alternative have a static class DoSomeThing with a member RunNow() and we have the exact same method but none of the other members of the static c... |
In a recent homework assignment I ended up calling my functions in an ugly way uglyReceipt(cashParser(cashInput())) the program itself worked perfectly but I still felt like I was doing something wrong.
Is calling functions like this bad practice and if so: What should I be doing instead?
|
We have a requirement from our UK client in which he wants us to comply to Disability Discrimination Act of 1995 while developing the iOS app. I tried to search about it on Internet but most of the information is available on compliance by websites. I think that it might be related to supporting accessibility in our ap... |
Given for example this code:
for(int i=1;i<n;i++)
for(int j=1; j < sqrt(i); j++)
foo(); //foo takes constant time
can someone explain to me how to calculate the computational complexity ("Big O") of this kind of program?
|
I just spent a long, miserable week debugging a stack-overflow in a C++/Qt application. The fundamental problem was that I had a function that accepted a callback, and in certain cases the callback was triggered (in another function) before the original function returned. In this case, the callback happened to cause an... |
A coworker and I have a disagreement about where the cache for a webserver should go. We currently have it implemented as a global (static) in-process cache, which I don't agree with. I think the cache should be offloaded into another server using something like redis. I've always been under the impression that global ... |
The basic idea is to have some animated widgets that sit in a container, quite similar to Qt (the only actual difference is that my widgets are animated).
The animation is in some cases dependent on the current "time" (e.g. frame number) and it has some "events". To better explain this, let's take for example a line. T... |
I am about to publish an Android app project I would like to do it using GPLv3 license to avoid it being used in proprietary projects for now.
If I change my mind in the future, since I am the project owner, may I later relicense it to Apache 2.0?
|
I'm trying to understand big O with the bitwise operations. I have 2 functions those are solving the same question from different perspective.
num1BitsSecondSolution starts to shift the number right until number is 0. So Complexity looks like = O(width(n)) but how could I notate width ?
num1BitsThirdSolution it is mor... |
I understand that any language worth its salt can encode a Finite state machine. My question is the opposite, is it possible to convert an arbitrary piece of code ( say in C ) to a functionally equivalent Finite State Machine ?
for example if I have a piece of code with a couple of llvm basic blocks (loops, branches e... |
I have a requirement for a service that does the following.
Take a block of text and identify the server names in it (by name or ip address). So given:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec libero felis, accumsan in nunc id, lacinia rutrum libero. Server1 Praesent iaculis consequat est quis e... |
I have N matrices (n × m) and items to place in each one (n · m). The same items are repeated randomly for each matrix. When one item is placed in (i, j), for the following matrices the item cannot be placed in the same row or column.
For example:
A 3 × 3 matrix is repeated 3 times. We have 9 items (A, B, …, I). In t... |
I have a REST API that I want to model in a class so I can access the properties using the dot notation (JS list notation). I explicately defined the properties on my class using the @property tags over the known properties of the returned JSON, but since I am modelling a 3rd part API, I need a way to also dynamically... |
Is it a good/bad practice to add a "boolean meaning" to other fields?
For instance, let's say I'm modeling events, that might be recurring or not. I can have:
A boolean column that holds if the event is recurring
An integer column that holds the repetition interval
Or
Just the integer column for the repetition inter... |
I came across Passwordless which uses email/SMS to allow the user to login. Is this mechanism widely used? What are the advantages/disadvantages of using such mechanism? I'm asking because I haven't seen any applications that use the mechanism.
|
I've read that Hindley-Milner does not work with type systems that have subclasses, and there are other type system features that also do not work well with it. Go currently has only very limited type inference in the := operator. But Go does not have subclasses in the traditional sense, only interfaces which look very... |
Perhaps I am getting something wrong here but I had a conversation today that left me perplex.
I hear a lot about nodejs not having threads.
but that's not entirely true, right?
The precise phrasing is - you cannot spawn (or manage) threads in nodejs.
Threads are being managed for you.
The underlying implementation... |
In Graham Hutton's book "Programming in Haskell", he defines a function to be polymorphic, if its type "contains one or more type variables". He then defines a function to be overloaded, if its type "contains one or more class constraints".
From these definitions, my question is, "can a function be polymorphic and over... |
Imagine that you are starting to work in a project with a group of people. You want to share your code and the full configuration files of CMake, Qt IDE configuration. So you if you want to test or develop, you just need to clone te repo, make and run.
This is a big project, so it has many modules and import some libra... |
I have a number of applications that share the same data in the same database. To try and minimize redundancy of code the Data Access Layer is a shared project. This prevents each project from needing to re-code it's own data access, but this also creates a big pain point. When one team needs to update the data layer, ... |
An App I'm working on is kinda like an appear-as-you-touch piano.
Using AudioKit and the gesture recognizing I have my app set up to:
make a new button appear when the user touches the screen
(Essentially, I have my ViewController.swift which makes new CircularKeys every time the user taps.)
turn on an oscillator an... |
Lets say we have a large project which is split across multuple repos. We have something like
shared-functionality-repo
GUI-repo
REST-server-repo
supporting-framework-we-plan-to-release-seperate-repo
Communication-library-for-3-parties-repo
etc...
During a spring one of these repos, maybe the third party comms, is not... |
In my current work, we have some Java EE applications and we use exceptions and exception mappers to deal with user errors, i.e. that can't be dealt with in the frontend.
We usually reply with a 400, and make the frontend show a "pretty" message for the user.
Problem is: those exceptions count as errors in our APM (New... |
This question relates to the question here, but I'll generalise it so that you can answer effectively without reading all of that.
Context:
Imagine you had a large set of data greater than your available RAM that was partitioned in to chunks.
(Sized such that access was efficiently processed by virtual memory managers... |
Let's pick a relation database table (say an audit table) with high write rate. We can display 100 records at a time. But as a user don't want to see some the records on page 1 on page 2 when a couple more new records are added.
I thought about caching, but we can only keep so much on a cache server like memcache or re... |
I'm working on a WebForms application that has several pages. Each page currently loads JQuery in a script tag in the head. A colleague I'm working with insists this is WET code and a violation of the DRY principle since each page has to load JQuery individually. He suggests that the site should be refactored as a s... |
My job and my personal interests often have me writing parsing code, that is, code that converts from an input string written in a given formal language to a tree of model objects.
I come from a C language background, and the strategy to do so in C is pretty straightforward:
struct my_object *parse(const char *input);
... |
Are there terms that are used to describe what kind of command line program you are programming based on how the program is designed to interact with the user?
For example, I can write a program that
a.) gets invoked from the command line with optional parameters, executes, and then immediately returns control back to ... |
I am planning the implementation of a Pipeline pattern as seen in this MSDN article. This is a WPF application for which I need to monitor progress of each stage of the pipeline in order to display it in the GUI.
Is it okay to implement each stage of a Pipeline with a BackgroundWorker? If not then why and what is/are t... |
Running a ray tracing program as a single thread on an iMac quad-core processor the CPU utilisation is 12%. OK so one of the Intel hyper-threads has been 100% allocated to the process. When GCD is used the program completes in a quarter of the time, but is consuming more than 90% of the processor availability. It would... |
I often encounter the following program while programming. There is a "partial" solution to a problem, which provides all the functionality that is necessary, but the documentation explaining said functionality and the behaviour of the solution is very dense and esoteric. Then, there is a "full" solution, which provide... |
Problem
Given a set of applications "A[]" with execution cost "Ex" ,Arrival Time "t", Resource requirements "R" and the system having free resources "Fr", calculate the finishing time of all of the applications.
Important Restrictions
Every application will try to execute in parallel given that the following conditio... |
What criteria does one consider when choosing which data formats a library for doing some machine learning task should support for reading/writing tabular (i.e. non-hierarchical) data? I found a similar question on what language to write a general-purpose ML library in, but not one for data formats. I have a number of ... |
I have a simple REST application with a single controller. The application needs to fetch data from a Database, convert it to JSON and return this to the caller.
I need to decide what layers I should use. This is what I have so far:
Presentation layer: Contains the Controller which uses a Delegate that in turn calls a ... |
Currently working on a system which allows users to upload data files, which we then "clean" (i.e. process in various ways). Speed of processing and return to the user is an important consideration, so we want to do this as fast as possible.
The original plan was that once the user had uploaded the file, we would read ... |
I want to practice web programming on my Ubuntu virtual machine. I want to learn both server side web development using Java/J2EE and client side coding (HTML/CSS/JavaScript) .
I heard that we need Apache HTTP for serving static pages and Apache Tomcat for running Java servlets pages.
I want to install both of them on ... |
Assuming some pthread_cond_t condvar; properly initialized with pthread_cond_init am I allowed to pthread_cond_broadcast it without any mutex locked and thread blocked with pthread_cond_timedwait on it?
I tend to understand that it is possible (with a well defined "no-op" behavior), but I am not entirely sure. This is ... |
We are planning to build a web application which will consume data from an internal REST API that centralizes all of our "core" business data. For matter of demonstration, let's say this API exposes data for a very large Products database. So an example of our web application using the API would be:
A View that lists a... |
I am building a REST API and intent to use rate limiting (using the leaky bucket algorithm) as a way to protect against crawling and enumeration. The API will be consumed by a Mobile/Tablet App (installed on many devices) and server-to-server clients (some in-house, some external).
Allowing users to install the app on... |
Let assume that we have a main() function in which we call a createDirectory() function.
In Python for instance, the code would be:
def main():
# Do some stuff
createDirectory(myPath)
# Do some more stuff
To re-use our created directory, I can see at least two ways:
either the createDirectory() function r... |
I have a class, Customer which has some basic properties on it such as firstname, surname, email, dateofbirth. I have written another class called CustomerValidation which currently has one public method and three private methods. The public method is:
public bool ValidateCustomer(Customer customer)
This method calls t... |
I've two commands in my View Model and one of them is initialized using lazy loading and other using eager loading.
Which approach is good to go? Should I use lazy loading or eager for both?
View Model:
public class LoginPageViewModel : MvxViewModel
{
public LoginPageViewModel()
{
InitializeCommands();
... |
I am trying to build a framework of objects where the main actors can be interchanged freely. At the moment I've done this by creating an abstract base class that all of my actors can be derived from. A key reason for using an abstract class over an interface was there there is a very small bit of common code that all ... |
I'd like to know about licenses in Python program distributions. This is the scenario: let's say one would distribute a Python program for Windows, created with PyInstaller as a single executable file, which bundles Python 3.5 (with Tkinter libraries for the GUI) and some packages, downloaded with pip. The packages are... |
This is a test design question. I have a class 'handler' that accepts a 'validator' that checks some business logic on what's passed to the handler.
I made the unit tests for the validator and now I'm writing the test for the handler. Obviously I want to make sure that the validator is called when the handler does its... |
Question
I am looking for definitions and differences of the following terms in software development:
Modules
Plugins
Extensions
I want to understand these terms in a general sense, not tied to any specific software or platform. For example, what are the characteristics and purposes of each term? How do they relate t... |
On languages such as Haskell, most datatypes have instances which allow their values to be used as keys of structures such as Maps. JavaScript has reasonably fast maps, there called objects, but those only accept string keys. Is there any conceptual issue, or anything else to be worried of, in using JSON strings as key... |
We are wanting to implement an API to be used internally and externally and add it to our solutions.
Some environment notes:
We are currently using VS2013, .Net 4.5, EF5, SQL2008, MVC4, C#, and asp.net membership.
We looked into using the new Web Api 2.2 template that comes with VS2015 that uses OWIN.
This appeared to ... |
Is there a way to make Java interfaces only implementable by classes of a special type?
So for instance, I have a class Foo and an interface Bar. Only subclasses of Foo should be able to implement Bar. Is this possible?
(This would be useful if subclasses of Foo are the only classes that need to implement Bar. Other cl... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.