How do you simulate a dice? In javascript, It would be

function dice() {
  return Math.floor(Math.random() * 6) + 1
}

So how about biased dices, for example returns 1 in probability 1/4, returns 2 in probability 1/9, and so on?

If you get an interest in this, read this article.

Tags: algorithms

"The moon from earth is about 24.3px wide, for example. The Eiffel Tower from a mile away is about 550.5px tall. That means that when you do “{ width: 24.3px }” in CSS 2.1, you’re making something as wide as the moon looks to be."

Antipodean: CSS px is an Angular Measurement

Edit: In CSS3, 1px=1/96in.

Tags:

What is internet? He says Internet is not just a technology, but a set of ground rules which enables us to build network. The network has no global control.

Tags: Internet

Three boys had drifted for 51 days without fish gears.

Tags:

They tune language rather than their code. They created translator (HipHop) which converts PHP into C++. To debug generated code, they wrote another interpreter for them (HPHPi). HPHPi is painfully slow, so they wrote virtual machine to run them (HPHPVM).

Tags: PHP Facebook

Several stories from frazzled and overworked programmers.

My favorite story is this.

This scene is familiar to all game developers: It’s the day we’re sending out the gold candidate for our Xbox 1 game. The whole team is playtesting the game all day long, making sure everything looks good. It’s fun, it’s solid, it’s definitely a go in our minds.

In the afternoon, we make the last build with the last few game-balancing tweaks, and do one last playthrough session when disaster strikes: The game crashes hard! We all run to our workstations, fire up the debugger, and try to figure out what’s going on. It’s not something trivial, like an assert, or even something moderately hard to track down, like a divide by zero. It looks like memory is garbage in a few places, but the memory reporting comes out clean. What’s going on?

One dinner and many hours later, our dreams of getting out on time shattered, we manage to track it down to one data file being loaded in with the wrong data. The wrong data? How’s that possible? Our resource system boiled down every asset to a 64-bit identifier made out of the CRC32 of the full filename and the CRC32 of all the data contents. That was also our way of collapsing identical resource files into a single one in the game. With tens of thousands of files, and two years of development, we never had a conflict. Never.

Until now, that is.

It turns out that one of the innocent tweaks the designers had checked in that afternoon made it so a text file had the exact same filename and data CRC as another resource file, even though they were completely different!

Our hearts sank to our feet when we recognized the problem. There’s no way we could change the resource indexing system in such a short period of time. Even if we pulled an all-nighter, there was no way to know for sure that everything would be stable in the morning.

Then, as quickly as despair swept over us, we realized how we could fix this on time for the gold candidate release. We opened up the text file responsible for the conflict, added a space at the end, and saved it. We looked at each other with huge grins on our faces and said:

“Ship it!”

– Noel Llopis

Tags: programming

Beautiful. (via The 40th birthday of—maybe—the first microprocessor, the Intel 4004)

Tags:

Makes me want to try a Windows 8 phone…

Tags:

Awesome.

Tags:

Tags: