language-agnostic

Converting mathematical formula into an programmatic algorithm

I'm working on converting a mathematical formula into a program. This formula is called as optimal pricing policy for perishable products. I've seen this in an article and it is called Karush-Kuhn-Tucker condition. Somehow I lost all my maths skills and unable to understand the formula explained in that. I'm able to understand how to com...

Subtle software security bugs in webapps

Im doing research on the capabilities of static analysis and at the moment I'm in the process of gathering code-snippets which contain subtle vulnerabilities. By that I mean not the obvious XSS and SQLI, but more subtle ones like below: $url = htmlspecialchars($_GET["url"]); echo "<a href=$url>Click here to continue</a>"; $url = htmls...

What are sessions? How do they work?

I am just beginning to start learning web application development, using python. I am coming across the terms 'cookies' and 'sessions'. I understand cookies in that they store some info in a key value pair on the browser. But I have a little confusion regarding sessions, in a session too we store data in a cookie on the user's browser. ...

Is there a gentle hash function tutorial?

Embarrassingly, picking a hash function (say, for hashing strings, or sets of integers, etc.) is still magic to me: take some prime numbers here, magic constants there, do some bit shifting, modulo something, and done. Is there a nice, gentle and approachable tutorial about creating hash functions? ...

Are both csrf tokens and captcha needed?

Can someone confirm this: do I need to provide both a CSRF token and a Captcha in a submission form, or do the two more or less serve the same function (one can be used instead of the other)? ...

Unusual code bugs

I've been reading Wikipedia articles about unusual bugs. I'm particularly interested in Schrödinbugs and Heisenbugs: Schrödinbug A schrödinbug is a bug that manifests only after someone reading source code or using the program in an unusual way notices that it never should have worked in the first place, at which point the program p...

Map and min-heap for better speed

Can a map and a min-heap used together give better amortized time that either on their own? Let's suppose I have a project where I need to track several items. These items have an expiration time and a unique id: class Item { ID uid; Time expiration; }; For this example, both Time and ID are primitive integral data types. I need ...

Removal of every 'kth' person from a circle. Find the last remaining person.

As part of a recent job application I was asked to code a solution to this problem. Given, n = number of people standing in a circle. k = number of people to count over each time Each person is given a unique (incrementing) id. Starting with the first person (the lowest id), they begin counting from 1 to k. The person at k is t...

Accessing system resources through a web page

Hi all, Is it possible to access system resources via a web page? Specifically I would be interested in accessing system calls in order to put the computer into standby or sleep. At this point, I am language-independent. I would imagine that some sort of special access would need to be granted before anything of this nature occurs. ...

Delete and return in a single verb?

Imagine a function that deletes a cookie and returns its value. What would you call it if you have to use a single verb? I called it clear but I'm not very fond of the name. ...

Programmatically extracting slides as images from a Powerpoint presentation (.PPT)

Given a Powerpoint presentation in .ppt format, what is the best way to programmatically and using only open source software extract an image representation (in say .jpg or .png) of each slide in the presentation? The application will run in a Linux server environment, so installing Microsoft Office or Keynote is not an option. The fun...

Changing Active Directory user password

How can I change an Active Directory user password using Directory Services without knowing old password? ...

Is there a function that takes two values, lets f(x,y) == f(y,x), and the output is otherwise unique?

Hi, I am wondering if there is a way to generate a key based on the relationship between two entities in a way that the key for relationship a->b is the same as the key for relationship b->a. Desirably this would be a hash function which takes either relationship member but generates the same output regardless of the order the members ...

get month name from month number and vise versa

I start with c# syntax to get month name from month number, System.Globalization.DateTimeFormatInfo mfi = new System.Globalization.DateTimeFormatInfo(); string strMonthName = mfi.GetMonthName(8); and for abbrevated month name i use string strMonthName = mfi.GetAbbreviatedMonthNa...

How should I format this piece of code?

Here are two ways of calling callscript (in pseudocode): using duplicate calls if flag == true flag = false callscript flag = true else callscript endif using an extra variable flag2 = flag flag = false callscript flag = flag2 conditions I have to make sure is that flag is false when the script is cal...

How to use Dependency Injection without breaking encapsulation?

How can i perform dependency injection without breaking encapsulation? Using a Dependency Injection example from Wikipedia: public Car { public float getSpeed(); } Note: Other methods and properties (e.g. PushBrake(), PushGas(), SetWheelPosition() ) omitted for clarity This works well; you don't know how my object implem...

Developing using pre-release dev tools

We're developing a web site. One of the development tools we're using has an alpha release available of its next version which includes a number of features which we really want to use (ie they'd save us from having to implement thousands of lines to do pretty much exactly the same thing anyway). I've done some initial evaluations on it...

How to unit-test private code without refactoring to separate class?

Assume i have a private routine that performs some calculation: private function TCar.Speed: float { Result = m_furlogs * 23; } But now i want to begin testing this calculation more thoroughly, so i refactor it out to a separate function: public function TCar.Speed: float { Result = CalculateSpeed(m_furlogs); } private functio...

Why should you ever have to care whether an object reference is an interface or a class?

I often seem to run into the discussion of whether or not to apply some sort of prefix/suffix convention to interface type names, typically adding "I" to the beginning of the name. Personally I'm in the camp that advocates no prefix, but that's not what this question is about. Rather, it's about one of the arguments I often hear in that...

Funniest technical explanation?

Every so often I get asked for an explanation for some programming-related bit of jargon. Sometimes, if I know the person who's asking will get the joke, I make up the answer. For example, today the word "blitting" crept into an email thread and one of the S&M folk replied, Not too sure what "blitting" is; a technical term perhaps ...