instruction stringlengths 34 19.9k |
|---|
I have a value between 0 and 8000 and I want this number to resolve to another number between 0 and 2000. I could just divide it by 4 but I have a special need here.
For values above 4000 I want the mapped value to be biased towards the 2000. But for values lower than 4000 I want the mapped value to be biased towards 0... |
I'm trying to develop a minimal MP3 player with some cool but light features. It is so simple that it doesn't matter if it is console application or not.
Since my purpose is to consume the sources as small as possible which one should I pick?
Extra info: I will be using a single textbox if it's going to be an applicati... |
Take for example the following:
public interface IManager
{
void AddItem(CollectionItem item);
void RemoveItem(CollectionItem item);
}
public interface IManagerCustomCollection
{
ManagerCollection Systems;
}
Is it usually more preferable to create a collection, and allow the consumer to operate directl... |
the title says it all. I'm still a university student studying IT. Whenever I'm doing coding, I will frequently look back on codes that I've done before or looking for codes online or on reference book on how to do certain task like using classes, HTML stuffs and such. Is this behaviour acceptable on working place or d... |
I don't know how to organize my code. Right now I just dumped everything in MainPage for testing. But what is the proper way to handle getting data from REST web service in Windows Phone 8? I have multiple pages that need to utilize the data that is returned.
/// <summary>
/// State information for our BeginGetR... |
I saw many RoR developers use command line to interact with interfaces and to deploy their web applications. Is that necessary step to earn for asp.net developer?
|
I'm trying to get to grips with unit testing.
Say we have a die which can has a default number of sides equal to 6 (but can be 4, 5 sided etc.):
import random
class Die():
def __init__(self, sides=6):
self._sides = sides
def roll(self):
return random.randint(1, self._sides)
Would the following... |
In order to convert e.g. a python object to json you would use a serializer. As far as I understand it, serialization leaves the possibility to change the converted object back to the original.
Where does the term serialization come from/why is the process called serialization?
|
I want to model simple objects as functions, to see where the pure functional approach gets me. Let's say my object is a person. There is some function that returns me a new person, but instead of just some data structure, it returns me a function that represents the person. I'm having difficulties to see what this fun... |
A few days ago, I appeared in an interview in a software company for .net developer. There I was asked the following question:
If we close browser window without getting logout, what will happen when
we provide same URL in the browser?
My answer was that user will be able to view the home page with login details in... |
I'm reading about eventual consistency in couchDB. I'm somewhat confused by the term and its consequences on an application.
Let's say I'm building a distributed e-commerce website where monetary transactions are critical. There could be online auctions running and people bidding on them in real time.
Will using a even... |
When choosing a title for a new issue, there are several grammatical options to choose from. Here are four different options for an example issue I just made up:
Descriptive: "Newlines are not stripped when multi-line headers are parsed"
Imperative - negative: "Avoid leaving newlines when parsing multi-line headers"
I... |
There is a rule in writing: When you break a section into subsections, typically it should have more than one subsection. This goes back to the old high school composition rules: if you have an A. section you also need a B. section.
To check a chapter of a book I'm writing in LaTeX I do this:
$ egrep -h '^\\(chapter|(s... |
I'm thinking about something I've read in a book: "A well designed system is a testable system" and I'm wondering why it is so.
Certainly, a system that is much tested is probably well designed. Build from the ground up on test-first principles and assuming basic competence, it is hard to imagine a very bad design.
But... |
In many languages there are libraries, either built into the language itself or built separately outside of the language, which allow information to be taken from the operating system at some level. Examples are metadata about a file, current memory usage and the OS version itself.
How is this information generally acc... |
I'm working with a new senior programmer who has almost the same amount of experience as me. He his own project to work on -- but I have to make sure he does not mess things up.
Now, how can I monitor him since he's not junior?
Do I examine his code? Cons of this are that I am not as deep into project as himself so i... |
We have a pretty complex project with 100 or so classes, multiple custom elements, etc. We have a new senior programmer who will work on this project.
How should we approach the task of introducing the senior programmer to the project? How can we make sure the programmer does not break some other feature while fixing ... |
We are a team of programmers and are employing a new person who will be a project manager only. Our project are only programming ones and we are not sure how to decide who will be the best for project manager.
Shall we find a senior programmer from our programming field?
Or we must find a regular guy (economics or man... |
Okay, it sounds odd, but the code is very simple and explains the situation well.
public virtual async Task RemoveFromRoleAsync(AzureTableUser user, string role)
{
AssertNotDisposed();
var roles = await GetRolesForUser(user);
roles.Roles = RemoveRoles(roles.Roles, role);
await Run(TableOperation.Repla... |
In the code sample below the Rental object is using Movie's fields to do a switch statement. Martin says : this is a bad idea but he does not give any deeper explanation as to why ?
Of course, you can say that this means a lot of coupling between Movie and Rental, or that Movie is badly encapsulated but those are just... |
Hello I am trying to use the alienTile problem described at www.alientiles.com using the A* algorithm but I cannot find any good heuristic function so far.
In alien tiles you have a board with NxN tiles, all colored red. By clicking on a tile, all tiles in the same row and column advance by a color, the color order be... |
I am not very educated on this topic of programming so I am seeking any advice/knowledge. I am coding a web app in PHP, and this particular task requires updating the display after the server has new information available. So, one seemingly-bad solution is to have a repeating AJAX request that spams the server on an in... |
While I think how to direct the future development:
Mini-introduction
As a fixed rule, I start with SOA (and REST as protocol) then I work on the interfaces (and that interface is a customer of my service, and usually is a separate project). I assume my deviation is because I'm first of all a back-end developer (with p... |
In a team of developers, how do you get the developers to feel pride in their code and write good code (I realize this is subjective and everyone is different, but there is a point when I write code that i can say, this is a good piece of code that I am happy to show off).
To often I hear we have no time to write good ... |
Is there a standard pattern in OOP to kind of "atomically" update a pair of objects, like a pair of bank accounts on a transaction?
I would like to have somehow a single public method exposed that does it all at once, but can only come up with ways of doing it by making two calls of public methods to update objects sep... |
What is a "variable"/data type?
How does a compiler / interpreter handle types?
My specific concern has to do with the different types in lower and higher level languages. For instance in Python, as list is really flexible. You can just define it and put in at runtime whatever you want.
ints
floats
strings
sets
even... |
For example, like:
The inaugural International Olympiad in Frogleaping is being held in Australia in 2013 and you are determined to win. While you want nothing to do with such slimy, jumpy creatures, you plan to enter a frog-like robot that you know will be faster than all the other organic entrants.
The IOF takes pla... |
I analyzed my algorithm and I deduced that in the best case it requires n^3 iterations while in the worst case it requires n^4 iterations. Then I asserted that my algorithm is in \Omega(n^3) and in \BigO(n^4). Is this assertion correct and useful?
(sorry for the format but I'm not able to add LaTeX text, so if you can ... |
In some articles and books that I read, I some time see the term 'Bootstrapping'. For example I see this sentence "Bootstrapping X.JS" in angular js document: http://docs.angularjs.org/tutorial/step_00
Bootstrapping AngularJS apps automatically using the ngApp directive is very easy and suitable for most cases. In adv... |
I'm writing a Jersey 1.9 JAX-RS application. I have to use 1.9 because it's the only supported version.
I'm trying to decide if there is any benefit to using EJBs as my Jersey Resources, rather than POJOs.
My Resources are strictly for my REST API; they delegate to my business service EJB as soon as the domain translat... |
I've used both webapp2 + GAE for python and a number of Java/JEE webapp frameworks. The python WSGI framework could keep users logged in while I redeploy the app while none of the Java web framework that I tried could do it. If I redeploy, users of the Java webapp will get logged out but if I use GAE for python then a ... |
I need your help how to implement it nice and well. It's quite a simple problem. I can solve it but I need help on how to do that better.
My class has logic working using three parameters. It gets them from another class. The problem is:
the first parameter is enum (it's required)
the second parameter is another enum... |
This concept is unclear with me.
I have worked on several frameworks for an instance Spring. To implement a feature we always implement some interfaces provided by the framework.
For an instance if I have to create a custom scope in Spring, my class implements a org.springframework.beans.factory.config.Scope interface.... |
In most Java code, I see people declare Java objects like this:
Map<String, String> hashMap = new HashMap<>();
List<String> list = new ArrayList<>();
instead of:
HashMap<String, String> hashMap = new HashMap<>();
ArrayList<String> list = new ArrayList<>();
Why is there a preference to define the Java object using the... |
My primary language is statically typed (Java). In Java, you have to return a single type from every method. For example, you can't have a method that conditionally returns a String or conditionally returns an Integer. But in JavaScript, for example, this is very possible.
In a statically typed language I get why th... |
I'm not sure I understand what all fall under the disconnected context scenarios in EF (See this and this). This link says use Web API or WCF services to avoid the complexities of disconnected tier EF solutions.
Here's my understanding. If I create a new DbContext, get some entities, pass it to another process/machine ... |
I always see standard Order classes implemented with a "Status" property, but I don't feel comfortable with that. Isn't the status a property of the fulfillment process instead of the order itself? What about orders that can be subject to different fulfillment processes?
|
I realize that there are already a couple of questions about this, but they mostly are about if you should bring code to the interview, which is not the case here.
I have a job interview (at a startup) coming up next week and they requested to bring some code to the interview. I have two smaller open-source projects an... |
I'd like to ask you about one simple thing. I have class A that do something (for example counts something ). There is also one class B that handle some parameters to this class (class A is member of class B). Class B calls one method of class A that does something and writes value to database.
Class A uses parameters ... |
I'm programming a graph object which can be in either a mutable or immutable state. In both states, it has a get method, but only in the mutable state is the set method allowed. The transition occurs when one invokes a method compress which optimizes the storage of the graph.
How do I deal with the fact that some metho... |
I'm trying to find the best way to process about 20,000 lines of a statute in text format into HTML so that it can be displayed and manipulated in a granular fashion, i.e. by clause. The format is essentially a nested list like (a)(1)(A)(i)(II)(aa) and is fairly consistent. Each clause begins with a new line and is enc... |
The question is about typehinting of the role interfaces.
The code example has two DataMappers which typehint the interface they need in the constructor,
FooDataMapper type hints the Preparable interface. Because it dependens on it and no other method from the dependency.
In the other mapper, BarDataMapper i replaced ... |
What are a few ways constants and enums are dealt with when creating an API Client? I'm writing a client in python for our API and I've hit a sticking point with this. We use a lot of mappings to numbers (to save space) and I was wondering what the best technique is. I can hard code them into the client, but if a ne... |
I am working on some code right now that involves processing user requests. Each request requires going through an approval. When a request is made, one or more records are created on the database recording what the request entails. Then a ticket is created and placed on the approver's work queue.
For a typical request... |
At this point, I'm not much of a programmer, solid html/css, familiar with JS but not a programmer by any means. I'm looking to pick up whatever is necessary for an upcoming project.
I need to build an online image repository that will host around 15k photos. Those photos will need to have user entered data associated... |
I'm encountering a common issue in PHP (and most other languages) at the moment, where systems I'm designing need to be updated in multiple places to add new features, whereas I would like to have a core, where I can add new features, plugin's etc without having to touch the core code.
An example would be a a navigati... |
Our knowledge domain involves people walking over a pressure-recording plate with their bare feet. We do image recognition which results in objects of the 'Foot' class, if a human foot is recognized in the sensor data.
There are several calculations that must be performed on the foot's data.
Now, which API would be be... |
Can we say that Java or C# are OO languages with a unified inheritance tree/unified type system?
By unified inheritance tree/unified type system I mean that every class derives implicitly or explicitly from one single type? Are there any object oriented language that do not follow that concept?
|
I'm working on 300K line C/C++ Windows application that is spread across 23 different Eclipse projects (approximately one third for Qt interface, one third for DLLs and one third for static libraries).
I have complained to the project manager that it's cumbersome to work with so many different projects for one single ... |
We're using Git as our DVCS and we're about to start to do a clean up (never done before in this team) of files that are not necessary (not part of the sources) from our products.
This is done in two ways:
removing the product files from the repo and adding them to the ignore list.
deleting dead code
According to W... |
I have an IP network and want to automatically find a free IP address to provision a new server. Due to frequent server additions/removals the used IPs might be quite fragmented over the whole address space. To effectively check if an IP is free I have to ping and ask the DNS system, which is considered expensive. So I... |
For a while now I have been considering the formatting of sass files to maximise their usability by other coders and I think that this would be perfect place to get some feedback on the rules I try to apply when writing a sass file. I am specifically interested in the usability of the source code as it is created and m... |
I have adopted some jQuery code that has like 20 event-captures that look like this
// used on menu#edit
$('.show-headers-only-toggle').on('click',function(){
arc_eh.menu_edit.show_headers_only_toggle.call(this);
});
that call a method that does the functionality. This is the only place that this method is c... |
I've always had this question and I think it is time to settle the answer, is it a heavy load to do this :
public Rect Bounds
{
get
{
var Top = (_targetPosition + _translationY) - _size / 2.0f;
return new Rect(callOutStarMargin, Top, _size, _size);
}
}
as ... |
Imagine you want to set up a minimalist e-commerce website for a "lemonade stall". You only have two products - a large glass of lemonade OR a small glass of lemonade (always either/or; never both). You want people to select, to pay, to enjoy - that fast, that simple, and with no other distracting features/options offe... |
I'm having trouble coming up with a suitable way to navigate through a set of star coordinates in the Equatorial Coordinate System. My goal is to display those which are within a given range of horizontal coordinates. The display is square with about 10 degrees "length" in each direction.
I thought about binning the st... |
While preparing SQL introductory material, I've ended asking myself about the line of thought followed by a developer when writing a query. I believe it could be too valuable from a beginner's point of view.
Let me illustrate the subject with an example. For the sake of brevity, I won't include the database schema, hop... |
After college I worked at one company for 6 months, and I've just now joined another one, bringing the grand total in my career so far to two.
So the first company had a few hundred thousand lines of code, maybe, across a couple hundred files. There was absolutely no introduction to where to start learning the organiza... |
I am starting to work on a new commercial software project that may use elements of "open source" code.
I have been instructed to ensure that I only use code which is licensed for commercial use and although we may decide to make it open source in the future it should be required to be open source.
So this clearly proh... |
I am facing a conceptual development methodology problem that I was hoping you could help me with. Firstly, a little bit of background.
Background
The project I am developing is a niche application that contains a database of information, and the target audience for my application are private individuals on the lower-e... |
I'm building a large, editable data table with angular, and I'm trying to figure out what the best practice is.
The table will be a couple of hundred rows, with a couple of dozen columns, so upwards of 2000 cells. Each cell needs to be editable inline.
My first thought was to have directives at the cell level, so it wo... |
The answer in this question suggests creating a ServletUtilities class to handle text conversion between Java strings and XML text.
Generally when you create a JEE web application you put together a
class that handles general conversions like this in a class named
ServletUtilities.
I did a bit of a google for Se... |
I am just starting out my programming career and I have a chance to bid on a freelance job. I have looked over the specifications for the app and believe I am capable of meeting the requirements satisfactorily. I have worked on a team developing 2 different apps for the same platform , as well as one app I wrote for a ... |
Assume you have two variables a and b, and you need to swap them, and for whatever reason, making a temporary variable for storage is not an option. This is the algorithm in pseudocode
a ← a XOR b
b ← a XOR b
a ← a XOR b
Based on examples I can see that this does work.
But, why does it work?
More specifically, how wa... |
I am currently working on a software project that performs compression and indexing on video surveillance footage. The compression works by splitting background and foreground objects, then saving the background as a static image, and the foreground as a sprite.
Recently, I have embarked on reviewing some of the class... |
I am starting my first project in OpenGL/GLSL and I was wondering, how do you work with code of shaders?
Because it needs to be const char and syntax higlighting shows everything in the same color (as string) and so its difficult to navigate in code.
const char *shader = ..."void main()\n"...;
Do you edit the code a... |
First a note, I thought maybe this question belonged in the database exchange, but I think it is more broadly related to a programming solution as a whole than to databases. Will move to database exchange if people think thats the best one.
I was wondering when a database table should have a created and updated timesta... |
I was suggested to put my question here, so I'm doing so ;)
I need a common interface which represents some specific behavior:
public interface Contract(){
public void methodA();
public void methodB();
// and so on...
}
The problem is, that in order to fulfill this behavior, implementation can be totally stat... |
Fail-fast seems like a right way since it simplifies bug detection. But it's a harm for performance cause of multiple checking the same thing at several levels of the system.
Simple example.
There is a function that input parameters must be not null. And there is function wrapping it, that also await the same parameter... |
Let's say I have a method DoTheThing() which requires the precondition-check CanTheThingBeDone() to return true. The latter method is time consuming as it accesses the database.
I'm finding it hard to find a perfect way to perform the precondition check effectively (i.e. once) while maintaining both readability and AP... |
I appreciate a lot the new Java 8 features about lambdas and default methods interfaces. Yet, I still get bored with checked exceptions. For instance, if I just want to list all the visible fields of an object I would like to simply write this:
Arrays.asList(p.getClass().getFields()).forEach(
f -> System.ou... |
Here is my situation. I have implemented the accepted .NET 4.0 answer in this question, which is working.
However, my codebase is quite large and as responsible for this code I've started getting inquiries regarding this solution. I've been asked if there are no easier ways of accomplishing the same thing, and if there... |
I often use enum types in my code with a switch to apply logic to each type. In these cases it's important that each enum has code implemented.
For example;
public enum eERROR
{
REQUIRED,
DUPLICATE,
UNKNOWN,
MISSING_VALUE
}
public void Error(eERROR pError)
{
switch (pError)
{
case eERRO... |
I have a very simple question that baffles me for a long time. I am dealing with networks and databases so a lot of data I am dealing with are 32-bit and 64-bit counters (unsigned), 32-bit and 64-bit identification ids (also do not have meaningful mapping for sign). I am practically never deal with any real word matter... |
I am writing a script that does something to a text file (what it does is irrelevant for my question though). So before I do something to the file I want to check if the file exists. I can do this, no problem, but the issue is more that of aesthetics.
Here is my code, implementing the same thing in two different ways.
... |
I am working on a Chen ERD to model our organizations merchandise. Our central entity is a Style. We have supplemental entities of Color and Season.
I am defining our assortment as the relationship between these three entities, and this relationship itself will have attributes and is defined by the three entities w... |
I have a discount service that gets called if certain conditions are met. I need to write test cases to check if the discount service is called. My doubt is checking if the discount service is NOT called for type 4 and 5 is a valid test case scenario.
public void ApplyDiscount(int typeId, double amount)
{
if(typeId ... |
Suppose I have an interface declaring the following method signature:
SearchResults SearchProducts(string type, string filter, string anotherFilter);
Inside a concrete implementation of this, I instantiate a helper class (call it QueryBuilder), built to ease the construction of strongly-typed search queries for the sp... |
When creating my object I pass it an array of a row from my database.
(everything in the array we will need, disregarding unnecessary elements at sql query level)
When I need to access certain array elements from within my class, I do so like
$this->row['element']
However, As I continue development, I sometimes forget... |
I have a web service. Right now, I have passwords stored in plain text in a MySQL table on my server. I know this isn't the best practice, and that is why I am working on it.
Why should passwords be encrypted if they are being stored in a secure database? I realize that if someone hacks in to my database they will get ... |
Why is repeating yourself by writing tests so highly encouraged?
It seems that tests basically express the same thing as the code, and hence is a duplicate (in concept, not implementation) of the code. Wouldn't the ultimate target of DRY include elimination of all test code?
|
In our company we do usability test at the end of each Sprint. Many times we discover that the users don't like the implemented feature, so we either completely change it or scrap it in the next Sprint.
However if we start doing potentially shippable product, thus fixing all bugs, running a lot of tests, preparing docu... |
For a project planning I have an initial period, lets call it PPStart-PPEnd.
The planning is associated with a project. This also has a period PrjStart-PrjEnd. PrjStart and PrjEnd are fixed, and can be unbound, i.e. the project start time or end time are not defined.
PPStart-PPEnd should be adjusted so that people can ... |
The only unit tests tactic I'm familiar with is comparing against golden data _ a predefined set of input data for which output is known (preferably including corner cases).
I cannot think of any other reasonable way of unit testing. Trying to unit test using arbitrary input data is (at least) as difficult as writing t... |
I've just been involved in a debate regarding semantics of how to define approaches to the software development lifecycle.
As far as I have been concerned, waterfall and agile are not methodologies, they are vaguely defined approaches/models. The definition of a methodology being a set of tools and techniques used to e... |
In a webapp, I have a scenario where I need some kind of global context (Static like) for few variables, for the current thread only.
If there are 3 different concurrent users, then I expect three corresponding global context variable for the 3 separate threads/sessions.
Using a Static variable makes its scope global... |
I have been asked to be the SCM (Software Configuration Manager) in my company. I've read online documentation to learn what SCM is, what SCM does, etc.
Currently, the company works with a version control system (Bazaar), so the software is versioned correctly, but there are old programs that are not well versioned (so... |
Suppose in a manufacturing environment, there are certain stock materials available for use in a product. For example, there are only a few different sizes of copper tube, each having a specific thickness and diameter combination. For the purposes of clean and minimal code as well as the ability to control the availabl... |
In my app, I use a widget with a loading spinner to signify that a network request is waiting.
On failure, there will be another view which contains a failure message and a "Reload" button.
My question is, since both of these views/widgets will ALWAYS be used together (either one or the other will be shown - or neither... |
First, I know there are lot of answers about MVC but I need some more-specific ansewer based on my probably wrong understanding of MVC.
I've already read this very good answer (Explain Model View Controller) but I still need some clarification.
I need to understand if I've understood how MVC works because I'm using it ... |
When do you want (on purpose) to coerce type in JavaScript? I mean, beyond comparing strings and numbers, when does it benefit something you're building?
Examples of type coercion:
"The answer is " + 42
//=> "The answer is 42"
"37" - 7
//=> 30
"37" + 7
//=> "377"
var foo = [0];
console.log(foo == foo);
//=> true
... |
I have moved to a new job and code base (been doing C#, .NET, Windows Forms, etc. for last four years) and I have been on this for three months until today. During these three months I caught up with parts of the language and syntax that I didn't know before (MVVM, Silverlight, some advanced stuff in .NET like Action, ... |
So I'm working on a software product where we have a number of fields that the customer can leave blank, some of which are numeric. To persist these in the database we use nullable columns. Easy peasy.
I'm considering the utility of an object oriented domain model and one thing that bugs me is the issue of nullable fie... |
This is a very broad question, and I'm just looking for a pointer in the right direction more than a specific answer, but it's something I've always wondered and never known.
Lets say I have a program that I wrote, and I put it on a server. Then, I write an android app that I want to use to control that program (give i... |
I'll write this in PHP (where this thought originated), but this is generic to any object-orientated language. Basically, this is an addition to abstract classes that defines the implementation of its subclasses. Obviously, this could never go into interfaces because it defines how classes will be implemented, an immed... |
Lets say we have an abstract class called BaseSwitch, inherited by concrete implementations Switch A and Switch B, Each Switch representing a real-life switch (A telephony tool which among its responsibilities is writing CDR; all data records of calls hitting the switch).
Each Switch in real life writes CDR in a differ... |
In objective C, classes are objects, but what object owns the class objects?
I am trying to get as detailed an understanding of iOS programming as I can, and this question popped into my head, so I decided I should know the answer.
|
I am implementing an ecommerce database. This is slightly different than most as the 'products' that are for sale are for services provided. For example a user (vendor) of the system may define a service to 'wash your car'.
Table: Services
--------------------------------------------------
| ID (pk) | Title ... |
I have a very large in memory node tree and need to traverse the tree. Passing the returned values of each child node to their parent node. This has to be done until all the nodes have their data bubble up to the root node.
Traversal works like this.
private Data Execute(Node pNode)
{
Data[] values = new Data[pNode... |
Assuming a list of elements is sorted in ascending order, we search sequentially from the first element comparing the target to successive elements either until we find the target (succeed) or until the current element is greater than the target or we reach the end of the list (fail).
Is Short Sequential Search ever m... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.