language-agnostic

Quicker if-statement: if `variable` is "value" or "value"

Hey! How can you compare against multiple possibilities in one argument? Example: if ((integer == 2) || (integer == 5)) if ((string == "hello") || (string == "dolly)) Would save me a lot of code if you could write that like this: if (integer == (2 || 5)) if (string == ("hello" || "dolly")) ...

What's the term for the part of the URL after the question mark?

http://www.example.com?foo What's the term for the foo part of the URL? ...

Get name of day from month, year, and day.

Does anyone know a way to convert a month, year, and day into the day's name for any year? Example: function convert(day, year, month) ... return "Monday" end Thanks in advance! ...

what is the main feature of stack?

what is the main feature of stack compare to arrays ...

Is it possible to share public code through heroku like I can with Github?

On Github, I can send a page link with a file of code. Does Heroku have the same functionality, or do I have to have them clone the project and added as a collaborator to do that? ...

which data structure is used in most popular databases?

i want to know which data structure(AVL, B-Tree, etc...) is used in most popular relational databases. and also in what way the data structure is superior than other in-class data structures? if possible a small comparison could help me a lot! thanks in advance! ...

Reading In A File While It's Being Changed

I'm curious what happens in this scenero. Suppose I open a file for reading, and begin reading the contents in a loop. Like this: $fp = fopen('test.txt', 'r'); while(!feof($fp)) { fread($fp, 1024); } fclose($fp); What happens if another process starts appending to the file while I'm reading it? ...

Is this considered a model or a view object?

My application downloads images from the web and encloses them in custom Image objects. Using my Image class I can extract particular data from the images. That data is eventually presented to the user. With the model-view-controller paradigm in mind, can my Image class be considered a model class or a view class? ...

Cryptographically secure additive hash function

I am working on a Fountain Code based file transfer system. In this system blocks of data are downloaded, combined with an xor function. I want to verify the blocks as they arrive. What I need is a cryptographically secure hash function which has the property: Hash(A) ^ Hash(B) == Hash(A ^ B) does such a thing exist? Note: The data b...

What's the meaning and use of "res" in function arguments?

Hi, here's a short question that my googling failed to deliver any clues on. It seems to be pretty commonplace to use the word "res" for one of the indexes in function arguments. Its existence appears to be agnostic to whatever programming language you look at. What does it stand for? A simple guess would be, "resource", perhaps? If th...

Find all chordless cycles in an undirected graph

How to find all chordless cycles in an undirected graph? For example, given the graph 0 --- 1 | | \ | | \ 4 --- 3 - 2 the algorithm should return 1-2-3 and 0-1-3-4, but never 0-1-2-3-4. (Note: [1] This question is not the same as small cycle finding in a planar graph because the graph is not necessarily planar. [2] I have...

Type conversion when iterating over a collection of super-type. Alternatives?

This is quite a common problem I run into. Let's hear your solutions. I'm going to use an Employee-managing application as an example:- We've got some entity classes, some of which implement a particular interface. public interface IEmployee { ... } public interface IRecievesBonus { int Amount { get; } } public class Manager : IEmploye...

Given an R,G,B triplet and a factor F, how do I calculate a “watermark” version of the color?

I have an (R, G, B) triplet, where each color is between 0.0 and 1.0 . Given a factor F (0.0 means the original color and 1.0 means white), I want to calculate a new triplet that is the “watermarked” version of the color. I use the following expression (pseudo-code): for each c in R, G, B: new_c ← c + F × (1 - c) This produces so...

How do you log how many hours you have spent on a project?

How do you log how many hours you've spent on a project? Something more reliable (and accurate) than just watching the clock. ...

Suggest MVC frameworks that do not use controller base classes.

pseudo-code: class SomeController { def myAction(){ // controler is an property passed via ctor controller.redirect(toWhereever) } } // another variant class AnotherController { def myAction(controller){ // controler is an method argument controller.redirect(toWhereever) } } Any suggestions? ...

Possible to unit test code that wasn't initially design to be tested, without changing any code?

Is it generally accepted that you cannot test code unless the code is setup to be tested? A hypothetical bit of code: public void QueueOrder(SalesOrder order) { if (order.Date < DateTime.Now-20) throw new Exception("Order is too old to be processed"); ... } Some would consider refactoring it into: protected DateTime M...

What algorithm should I use to zoom a graph or map smoothly?

I have a graph, generated by a function, and it zooms itself in and out automatically, depending on the value of the function. I already have the graphing tools and I can display any x,y,width,height at high resolution. I tried just snapping to the right spot: x = target_x y = target_y width = target_width height = target_height But...

Reading hexadecimal values in English

I've been reading hexadecimal on a digit by digit basis for many years and am now fed up with translating hex values for numbers requiring more than 16 bits into English. Does a more elegant form of translating hexadecimal to English exist? In English, a simple system exists for converting decimal values to English. Decimal 10 is Engli...

DRY without having single code?

i want to not repeat myself (DRY), but i cannot have a single piece of code. For example here is code repeated 3 times with the same bug: class StarWars : Movie { //Calculate "base ^ exponent" public float Power(float base, float exponent) { return (base * exponent); } } class Customer: Object { //Calculate "base ^...

Code Golf: DNA Sequences

Let's give the GMO guys something to cry about: Goal: Generate a sequence of DNA base pairs (A, T, G or C), 78 pairs long (not a big gene...), terminated by a newline, and print it. Rules: The lines must be exactly 78 characters long with a terminating newline, and while the program can give the same result if invoked twice in a row, i...