instruction stringlengths 34 36.1k |
|---|
I came up with a problem that's similar to the Set Cover problem but which I can't reduce down to any know problem. Does anyone have a good algorithm for solving this?
Given a set of elements U = {1, 2, ..., m} (the universe) and a collection S of n sets whose union equals the universe, what's the smallest sub-collecti... |
I have an interesting "real-world" combinatorial optimization problem that I need to solve programmatically, however I have yet been able to whiteboard a good strategy.
The task is similar to the Knapsack Problem except there are additional constraints.
The Rules are as Follows:
You must must fill a bag with weigh... |
So I'm developing an application which is using an IoC container. Now I need some helper methods for array manipulation like set, get, etc. I see two possible ways to go:
Using a class with static methods.
Using a class with non-static methods registered in the IoC container.
When using method 1, it will look somethi... |
I'd like to be able to identify duplicate jokes posted on a website. I can build up a reasonably large database of previously-posted jokes, and then I'd like to look at each new joke as it comes in and pick out the most "similar" jokes from the database and spit them out, in order, if my confidence that the new joke is... |
I am playing around with the date object, i made a function that generates a bunch of dates, and applies some function on each date.
For a month's worth, it is fine about 2.5ms on my pc, ff and chrome, but for a year's worth it is horribly slow, 17-50ms, not predictable at all.
This ofc got me thinking, what am I doing... |
class A {
int a;
int b;
A(int i,int z) {
a = i;
}
void abc() {
System.out.println("a is " + a);
System.out.println("b is " + b);
}
}
class B extends A {
int a = 55;
int b = 66;
B() {
super(14,13);
super.b = 99;
}
}
public class te... |
Here's a rough translation of a tweet by @xharaken.
"Space rays hit computers and mess up the bits in the memory" "hardware bugs mess up the bits in the memory" such things almost never happen, but they happen on a nearly daily basis when there are so many users using a software like [Google] Chrome. So the GC running... |
I was going through JBAKE code at
https://github.com/jbake-org/jbake/blob/master/src/main/java/org/jbake/app/Asset.java : 58
PFB the code.
Why are we sorting the array here?
if (assets != null) {
//TBD : Why is sorting required?
Arrays.sort(assets);
for (int i = 0; i < assets.length; i++) {... |
In the below visualisation,
There are two array objects(cars & bikes) that are created with below syntax,
var cars = new Array("Saab", "Volvo", "BMW");
var bikes = ["Honda", "Yamaha"];
whose [[Class]] property value is Array.
In addition, we also have Array.prototype, which is fully functional array, as shown below,
... |
I'm a beginner in Java and I have a question from the "Head First Java" book. In the book, the author creates a method that takes the number as String and then convert it into int. Why do I need to take the input as a string and convert it rather than directly take it as an int. Below is he screenshot that I'm talking ... |
I often see the follwing example when reading about MVC (example is in Java, but question adapts to all OOP languages):
class View{
JTextField tfName;
public String getTfNameText(){
return this.tfName.getText();
}
public void setTfNameText(String text){
this.tfName.setText(text);
}... |
Assuming I have this class (Java code only for the sake of example):
class Person {
private String name;
public void setName(String name) {
this.name = name;
}
}
When I write documentation for this application and/or in-code documentation, what should I use to refer to a particular symbol, whether... |
I have designed my own kind of vm, a sort of stack-register. It works by having a stack but instead of pushing and popping values, you simply store the values on the stack, and add together different addresses.
For example add would be #add addressTo, address1, address2. It might sound like a register machine, but ever... |
I kind of get what it means, but not enough to explain it by myself. Is a key concept when talking about the MVC pattern and it's giving me problems to explain that concept too.
|
If I was going to write a parser for HTTP, would I be able to assume the encoding of the HTTP headers and status line? Until I read the charset or encoding header, how could I tell what the encoding type was? I am given the impression that these lines will always be in ASCII.
I guess I am confused how HTTP handles var... |
I like having build numbers, just because it is cool. Please don't judge me :D.
However, I develop on two machines (one OS X and one Windows for portability checks). I have on both machines a script that automatically increases the build number every time I build the project. However, when doing changes on both machin... |
This is a very basic question but is something I've never completely understood and recently, when studying .NET Core and ASP.NET 5 I felt the need of a more complete understanding of the topic.
Reading the article Introduction to the Common Language Runtime (CLR) there we find the following piece of text:
Every progr... |
I've recently worked on a reusable network service class for a service-aggregator iOS app. This class should retry a failed request if it was caused by expired user token. Plus, this class will be used between multiple contractors, who will create the aggregated services.
Since the contractors might use different authe... |
I'm working on a class that represents an object with multiple representations - one is an XML type representation used by an automatic ordering system, the other is a POJO-based representation used by a monitoring tool.
The problem I'm running into is that I seem to have to make trade-off between encapsulating the obj... |
For the below code, that creates inheritance hierarchy,
function Animal(){
this.name = "Animal";
// toString is a function in the main Object that every
// object inherits from
this.toString = function() {
return "My name is : " + this.name;
};
}
function Rodent(){
this.name = "Rodent"... |
I understand that we should use %s to concatenate a string rather than + in Python.
I could do any of:
hello = "hello"
world = "world"
print hello + " " + world
print "%s %s" % (hello, world)
print "{} {}".format(hello, world)
print ' '.join([hello, world])
But why should I use anything other than the +? It's quicker... |
My book says that function overloading is not possible in python but it asks me questions like:
WAP to find out the volume of a cube,cuboid and cylinder using function overloading.
Do I have to involve decorators here?
How am I supposed to involve functional overloading in my program?
I saw a similar question where w... |
I'm doing market basket analysis. I have a set of transactions. Every transaction is a set of items that were bought. I then have a set of itemsets (i.e. a set of items) that I want to determine the support for. The support of an itemset is defined as the number of transactions of which the itemset is a subset. I'm onl... |
I've seen some programmers use this:
foreach (var item in items)
{
if (item.Field != null)
continue;
if (item.State != ItemStates.Deleted)
continue;
// code
}
instead of where I'd normally use:
foreach (var item in items.Where(i => i.Field != null && i.State != ItemStates.Deleted))
{
... |
Why does XmlWriter's create methods have output parameters?
For example (from MSDN)
public static XmlWriter Create(
StringBuilder output,
XmlWriterSettings settings
)
output
Type: System.Text.StringBuilder
The StringBuilder to which to write to.
Content written by the XmlWriter is appended to the Strin... |
Our company is in the process of converting a lot of manual business processes (and the associated institutional knowledge) into new enterprise software. The project is going really well, but as we proceed it is clear that there is a lot of confusion concerning terms and definitions on both the business and developmen... |
I'm working on a project at the moment, and we have the source code up in a private repository on Github, with each of us as a collaborator.
What we are unclear on is how to separate each of our work.
What I think we need to do is:
Each of us needs to fork the repository
When we are ready to push our code, we then sub... |
Until now, we have not had an application version strategy or version-ed our application. We are considering doing so with our next release. What are the minimum tasks necessary to transition to a version-ed application? Answers in the form of bullet points, not necessarily in chronological order would be sufficient. ... |
I am working on a REST service in which I am trying to come up with a JSON response that I am supposed to return back. Below is the design I am able to come up with in which each line is a response for each request so we have total three response for three request wrapped around an array.
In this I will pass HTTP Statu... |
Currently in my job im working with a lot of older php systems which don't follow normalised design patterns and are frankly, a mess.
As an ethical developer and someone who always strives to better what Im working on, but also keep within the budget of my employer and their clients, what are my obligations here?
Most... |
DBIx::Class is a popular Perl interface to any database that you can connect to through DBI. There is good documentation for its technical details, but scant information about its proper use (including the situations where you probably don't want it).
In many situations, people reach for it reflexively because they thi... |
First of I'm not sure if I chose the right name for my question, I'm not sure if
they are functional tests or integration ( or other ). I'm talking about tests which test (or it should) the app from a http request to database.
With simple controllers where they query the db for some data it's pretty easy to test them.... |
I have a list of integer pairs. The value of this list is the sum of the maximum values of each pair.
For
(0, 5) (20, 5) (6, 8)
the value would be
5 + 20 + 8 = 33
Given a list like this, I need to maximize its value. The only operation I can do is swap an element of a pair with another element of a different pair... |
I am doing a tech test for a job (Web Development) and in the test I need to get data from an API and there is this conditions for the server:
Focus on client-side (AngularJS)
nodeJS
The server must not serve dynamic pages
My question is: Should I call the API directly using Angular? Or I can get the data from API us... |
There seems to be a recent trend in JavaScript towards treating data structures as immutable. For example, if you need to change a single property of an object, better to just create a whole new object with the new property, and just copy over all the other properties from the old object, and let the old object be garb... |
I have a scenario where I have a Windows Store Application, there is a page with a search functionality, the user types names in a textbox and the app searches for names similar to the typed text.
Searching is done through calling a RESTful GET Api method. the call takes about 4 seconds to retrieve the results. This us... |
I am trying to understand how to properly store ordered information in a relational database.
An example:
Say I have a Playlist, consisting of Songs. Inside my Relational Database, I have a table of Playlists, containing some metadata (name, creator, etc). I also have a table called Songs, containing a the playlist_id,... |
So I'm using C# WPF and binding to a Model View to display states. The data that needs to be displayed is spread across a couple different classes. For instance I have a class that reads out digital IO values that need to be displayed on the main interface as red or green lights.
Is it better to simply pass the Model... |
Here is a question that I believe could be solved with some data mining and a sophisticated algorithm, but I don't quite know how. Any pointers as to what data sources to use and what algorithm to apply are welcome.
Background: I'm a Romanian-Hungarian who is expecting a baby with a Polish-Ukrainian and haven't quite s... |
I was wondering if somebody has done this, and to what success compared to the classic method of getting them to solve a problem as you watch on?
Any pointers on how to carry this out in an interview situation?
I was thinking about doing this for mid/senior candidates which should definitely have the technical knowledg... |
I'm working on a meanjs project. The user roles are set as an array:
roles = ['admin', 'user', 'manager'];
why not just set it like this?
role = 'admin'
Why is the convention of an array used rather than just setting a role value as a string?
|
I had a HUGE switch/case statement, which I converted to use a function dispatch table using an enum list for the index.
My colleague (who is doing a code review on this change) agreed that it should be broken down into several functions, but there was a later change that required that some parameters that weren't used... |
We're designing an application that is supposed to monitor a system for certain events, email interested parties to prompt them to take action when relevant and parse their replies.
The application is comprised of several threads that handle separate parts (one for monitoring the state and sending emails, another for p... |
Magento has a class called Varien_Object with a pattern I'm trying to identify. The pattern creates hidden data and allows access to it but the main difference between this and a normal facade is that methods are dynamically created to allow access to this data.
Here's a (very rough) example of pattern.
$vo = new Vari... |
We have the object
public class MyObject{
protected MyObject(){}
public string Property1 {get;private set;}
public string Property2 {get;private set;}
public string Property3 {get;private set;}
public string Property4 {get;private set;}
public string Property5 {get;private set;}
public stri... |
Pre: I am looking at a quite big PHP project developed by a company which we need to partly interact with while building a new webapp.
The whole application is developed in PHP 5.
Most of the classes in this project, and in particular all the classes that interact with the database, are declared abstract and contain o... |
The Apollo missions had technology no more complicated than a pocket calculator.
From link here, there's an information about Apollo Guidance Computer (AGC)
The on-board Apollo Guidance Computer (AGC) was about 1 cubic foot with 2K of 16-bit RAM and 36K of hard-wired core-rope memory with copper wires threaded or not... |
I am learning programming and often see the term "string literal" being used in various places. From the looks of it, it seems to be a synonym for "hard-coded string", but on another hand the term looks quite specific.
Is "string literal" always the same as "hard-coded string"?
|
I have been warned by my professor to avoid "false recursion", where a function behaves recursively, but does no useful recursive work.
I believe I understand recursion, but would like to double check.
I have written a short recursive sorting program that sorts (recursively I hope) the given array, ignoring the first ... |
Fortran II (1958) was recorded using line numbers, from what I can tell. For example, the first five columns of this IBM punch card are titled "statement number".
Punch card from a typical Fortran program. Arnold Reinhold (https://en.wikipedia.org/wiki/File:FortranCardPROJ039.agr.jpg)
Columns 1 to 5 may be used to w... |
I am trying to implement a activity tracking system in Ruby on Rails for an API only application.
I have a table named letter with information as follow :
id (primary key)
sender_id (foreign_key on contact)
receiver_id (foreign_key on user)
owner_id (foreign_key on user)
re (string)
status (enum { ON_HOLD , CLOSED , O... |
Using this Coursera's course about machine learning, I learned some things about supervised and unsupervised algorithms.
And from Wikipedia I've read that machine learning is "to get better performance/P at tasks/T with each task being done, that is experience/E".
Now, in those algorithms what I see is that they give ... |
In my python CS class at school, we were given a true or false question as follows.
A comparison function returns either True or False.
When originally answering I thought about two things. First, a function as follows (what I thought was a comparison function) returns true or false.
def comparison(valOne,valTwo):
... |
So I just launched my first "real" site that actually has a decent amount of interactions and whatnot. It's an ASP.net site with a SQL backend.
We've served 130k requests in the last 12 hours but 930 failed. Is this normal, bad, or "I should fire myself as a programmer" bad. While ideally this number would be 0, what'... |
I've been reading Scrum Guide and one part is missing for me.
What happens if Sprint Goal is not met at all?
Let's say the Sprint Goal is a big part of a functionality which cannot be broken into parts further so devs have, say 2 weeks (the Sprint duration) to accomplish it or not, but they fail to do it. What happens... |
I was reading the "Closures" section on the w3schools JavaScript tutorial and I don't understand how the last example works.
http://www.w3schools.com/js/js_function_closures.asp
The goal is to create a "private" variable counter that only the add function can manipulate. Here is the code:
<!DOCTYPE html>
<html>
<body>
... |
There is a parent class with a method which many children use but many children extend the method, what is the best way to extend it without violating DRY?
Here are my 2 current solutions:
1: The parent has a method which calls the reusable code which is relevant for all subclasses (do_this), then it calls a class spec... |
Say, I'm building a system that uses various complex algorithms (k means, mean shift, a few others), all of which are parameterized. I'm highlighting `uses', because the system is not just a thin layer around them; deep in its processing, these algorithms are instantiated and executed.
The 'dumb' parts of the system d... |
I need a function that will take the name of a town and return a specific range of numbers that is assigned to that town. I won't be using a database. The simplest way to do this is
//Pseudocode
public arr getTownNumbers(string town) {
switch (town)
case: "Pasadena"
arr["min"] = 183
... |
To copy something to the clipboard in Windows (at least in .NET as far as I know) it has to be done on a separate thread that is in STA Mode. One example I have used is this.
Thread thread = new Thread(() => Clipboard.SetText(s.Trim()));
thread.SetApartmentState(ApartmentState.STA); //Set the thread to STA
thread.Start... |
Please consider the following scenario:
There is an npm package named some-package.
There are a couple dozen known dependent npm packages that all depend on some-package.
I forked some-package and made a breaking change to its API.
I forked all dependent packages that I care about and updated them to use the modified... |
I have my own website that displays some data I get from webscraping. I run the webscraping script on my website host server. I just realized that maybe I'm accessing other websites too quickly through this script. For example, I just wrote a script that accessed 15 websites on the same domain in about a second. My ... |
I have read multiple websites on this topic but none of them gave me a 'good' solution for the problem I am having. The problem is described in the following (related) questions:
How do I couple the UI package with the rest of the system without too much coupling with classes inside the other packages (I am thinking o... |
Update/Clarification My client understands the need for their in-house testing and he/they always swears they will "do better" (i.e. do something) but it just doesn't happen. They don't have the budget for outside testing. I guess I am asking (vaguely, I acknowledge) about what could instill a "test early, test often, ... |
In my project, I have an abstract Cache class that allows me to populate a series of lists that globally persist throughout my application. These cache objects are thread-safe and can be manipulated as necessary, and allow for me to cut-down on the massive overhead of querying external third-party APIs directly. I've s... |
I'm writing a webpage with a simple header, nav, body and footer layout.
To style it, I wrote the following CSS:
.mainSideBar {
position: relative;
display: inline-block;
vertical-align: top;
width: 20%;
height: auto;
margin: 1%;
border: 1px groove darkgreen;
background-color: green;... |
I see a lot of classes that look like:
class Student extends Model {
public string major;
public string minor;
}
class Employee extends Model {
public string department;
public string building;
}
These kind of classes are mostly used to hold data. My question is, should these aliases for Model class e... |
I've never seen a programming language with conditional assignment targets, eg.:
// If (x == y), then var1 will be set to 1, else var2 will be set to 1
((x == y) ? var1 : var2) = 1
The target of the assignment is determined conditionally at run-time, in this case based on whether x == y.
It seems like it could be a ha... |
What's the best way to display complex objects in AngularJS in your opinion?
You have some data from a service used in multiple places in an app. You need to display multiple properties, each with a specific filter for that particular place.
I can name 3 different approaches, but I'm unsure on how to implement them.
Pl... |
A 2013 study of 93 open source Java programs (of varying size) found
that
While there is [no] huge opportunity to replace inheritance with composition (...), the opportunity is significant (median of 2% of
uses [of inheritance] are only internal reuse, and a further 22% are
only external or internal reuse). Our ... |
I have two classes C1 and C2. C1 has 2 methods and C2 has 3 methods each of complexity value 1. C2 inherits from C1. So, I know C2 has 2+3=5 methods in all. The question is, should I take C2 to have 5 methods while calculating the WMC for the classes?
I couldn't find any example or proof to justify or refute the claim.... |
I'm developing a desktop analytics application wrapped in Electron (that integrates with an external REST API), and am looking to use one of the WrapBootstrap themes to spruce it up.
I'm deciding between the MIT or Apache license for the project itself, which will be hosted on GitHub.
I'll be fronting the cost of the t... |
I am creating a java package which offers an API based on a pipeline pattern. That is I have a series of steps which can be plugged together in any combination provided their inputs match the Output of the step before. Initial source and final sink are fixed.
Unfortunately I have a step which feeds its output into two ... |
I am working with a system that is using NoSQL (Azure Table Storage) primarily to house its data. Unfortunately, the work also involves billing and medical records - meaning the data itself will need to be protected. That's fine, we can provide user access to the system, and encrypt that data over the wire and at rest ... |
I have a task, which is to scramble a single word, whose size is greater than 3 letters.
The scrambled word must not be equal to the original, and the first and last letters of the word must remain the same.
For example, the word stack, could give the one of the following results:
satck
scatk
stcak
sactk
etc
While ... |
Where I work we develop in C# .NET and I was looking a code that they have made (my job is to optimize it) but I saw something in particular:
Assuming that InterfaceDHO is an interface and ClassDHO is a class that implements InterfaceDHO.
Code:
InterfaceDHO in1;
ClassDHO cl1 = new ClassDHO();
in1 = cl1;
in1.METHODHER... |
I'm having trouble designing this role (or permission) based application, when it comes to figuring out how to handle actions that differ per use role.
For instance, our controller is App\ResourceController, and we will be editing the resource. There are 2 roles: admin and user. The admin is allowed to edit every field... |
There is an assembler that I am writing that is located within the file asm.c located in this repository. It uses the instruction set located in the specs file to produce an output binary. (The program that would run this binary has not yet been made - the beginning is located in main.c.) Using the example program name... |
I'm working on an existing code base and am trying to reduce a lot of duplication and gain some polymorphic behavior. Right now I have a type of domain object with an abstract base class and two (at the moment) subclasses. In our domain we have a need sometimes to create pdf documents of these objects and send them as ... |
I have used Git and Mercurial a bit over the past ten years and appreciate and prefer them, but most of my experience is with SVN. If it is decided within a corporate programming group that branching and merging are not to be done because they cause too many problems then what significant benefit remains for Git over ... |
I have a need to test output of my code before I send the output for PDF rendering.
Currently I have decided on a switch statement that does two different things depending on whether I am in production or in testing mode.
Render PDF with data that goes on PDF in a web browser. Nothing is returned to caller
Do not ren... |
I'm new to web applications development, specially when it comes to frontend, but as I understood, a typical structure for a big application would have a frontend php (or equivalent) layer calling the backend services and generating dynamic pages.
Now we're building a new site, and a colleague of mine insists on not ha... |
I am going to ask some random questions from hundreds of them to my users and the answers can be only "true" or "false". Then I am going to record those answers into my database and lastly I am going to compare those answers and find relations between them such as "User A" and "User B" have 20 answers in common and not... |
For years, I've been a great fan of putting licences on things shared online to make it easier for others to determine if and how they can reuse said things. Before GitHub began to gently 'push' its users to include LICENSE files with their repos, I didn't really know how to best do this with code – particularly code p... |
I found this link to count number of bits in a variable. I think it is pretty cool, but I can't figure out why it works. Can someone offer an explanation?
Here is the code
unsigned int v; // count the number of bits set in v
unsigned int c; // c accumulates the total bits set in v
for (c = 0; v; c++)
{
v &= v - 1; /... |
I have heard the story of how Douglas Mcllroy came up with the concept and how Ken Thompson implemented it in one night.
As far as I understand, pipe is a system call which shares a piece of memory between two processes where one process writes and other reads from.
As someone who is not a familiar with OS internals or... |
I've read these questions:
Understanding "programming to an interface"
What is the point of an interface?
Does it always make sense to "program to an interface" in Java?
I don't understand how to "program to an interface" if you are using methods in concrete classes that aren't part of the interface.
I realize the mo... |
I was discussing unit/integration testing with a colleague, and he made an interesting case against writing unit tests. I'm a big unit test (JUnit primarily) proponent, but am interested to hear others' takes, as he made some interesting points.
To sum up his points:
When major code changes occur (new set of POJOs, ma... |
So I'm comfortable programming in Python, I love the minimalist nature of the language. However, I haven't been exposed to any Django yet.
I do know html, css etc for web design but when making websites is it essentially doing either
1) The usual route: HTML, CSS,
or
2) Using Django
My understanding is that both the ab... |
Composite aggregates Part, Container contains Content, and Recorder records. Recorded are all very common relationships between classes in a class diagram. Creator suggests that the enclosing container or recorder class is a good candidate for the responsibility of creating the thing contained or recorded. Of course, ... |
I have been using GitHub for quite some time now and I usually used to push my feature-branches and then start a Pull Request which I myself merged. I found it helped me keep track of where I merged branches.
But recently I have been reading more and more about how Git works and I realised that I can use the merge-comm... |
This question is mainly talking about PHP, but I think it can be applicable to other languages as well. This is a question about code organization.
I have a friend who insists the best approach regarding organization to PHP programming is to have one file/class with all functions ever written inside it. He says it's si... |
I have an app and it stores data in shared preferences which can be easily changed using something like root explorer. So, how can I keep settings and be sure that user won't be able to edit them even with root access?
|
If I wrap in a class an object that has the dispose method I'll need to implement the dispose method in the class too?
For example I have a class which wraps an instance of SQLiteConnection, should I need to implement the dispose method to call the SQLiteConnection one?
|
I have a couple of classes with the following pattern that I am uncomfortable with. Is this the only way to do this, or are their other design patterns that would be more reliable.
public class MyClass1<T,K> where T: MyClass2<K>
{
...
public MyClass1(K param1) {...} // example of constructor, other constructors do not ... |
I've been coming across some interview questions that mention within the question "... given an integer x and a zero-indexed array..." Is it necessary to mention zero-indexed array? What languages support non-zero-indexed arrays? Is it possible with javascript?
|
I started PHP programming around 2002, when there were not that many frameworks around. Over the years, I developed my own PHP framework, which seems to be entirely different from any standard I come across.
I'll try to describe the framework that I created:
Basically it's an engine that builds an entire web-applicatio... |
I've started my own open source project, which is still in an early phase of development. I chose to use the MIT license for it.
However, I've read that the Apache license is better for large projects, and it's going to become a large project later. So, I plan to study the Apache license later, and consider it for my ... |
Should I include exceptions, like a TimeOutException or just general Exceptions, to a activity diagram?
For example: A activity diagram describing a client-server connection. Several exceptions can be thrown and in my software I use the Enterprise Library to handle/log it. Should I include the exception handling and if... |
I have a TCPClient class. It has several ClientEvents. Originally it followed the standard pattern
public delegate void ClientEvent(object sender, ClientEventArgs e);
Only TCPCLient uses this event. But I am pretty determined to keep things as standard as possible (all event based things I've seen use object sender). H... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.