Weighted/Biased Random Number Generation with JavaScript based on Probability

weighted random post image

First of all what is weighted random ? Let’s say you have a list of items and you want to pick one of them randomly. Doing this seems easy as all that’s required is to write a little function that generates a random index referring to one of the items in the list. Sometimes plain randomness is not enough, we want random results that are biased or based on some probability. This is where a simple weighted random generation algorithm can be used.

Continue reading “Weighted/Biased Random Number Generation with JavaScript based on Probability”

Using Underscore.string for String Manipulations in JavaScript

Underscore.string is an excellent string manipulation library (or helper) for Javascript that can be used with or without the nifty Underscore.js library. It can be used client side in browsers or server side with Node.js.

Continue reading “Using Underscore.string for String Manipulations in JavaScript”

Using CoffeeScript over JavaScript in your Node.js Application or Module

If you’ve wanted to code your next Node.js app in CoffeeScript then it ain’t that hard. Since coffeescript is just a little language that compiles down to javascript it is pretty much compatible with node.js. Let’s take a look at some of the ways in which you can execute your node.js script (written in coffeescript).

Continue reading “Using CoffeeScript over JavaScript in your Node.js Application or Module”

Remote Web App JavaScript Debugging with JSConsole.com

jsconsole web app/page debugging

I’ve written a few posts on remote debugging before, using edge inspect and weinre. They’re definitely very good at the problem they try to solve but today I came across a new Javascript-only remote debugging tool (mobiles, desktops, laptops, etc.) called JSConsole and am loving it! It’s pretty amazing for what it does and is trivial to setup.

Continue reading “Remote Web App JavaScript Debugging with JSConsole.com”

How To Use Twitter OAuth with node-oauth in your Node.js / Express Application

I am building a Node.js application where I want the users to be able to signup with their twitter credentials rather than remembering another set of username/pasword. My framework of choice is Expressjs, so I’ll quickly show you how to authenticate the user with twitter’s oauth service in it.

Continue reading “How To Use Twitter OAuth with node-oauth in your Node.js / Express Application”

Scaling Your HTML5 Canvas to Fit Different ViewPorts (or Resolutions)

I am going to share a neat little trick that was learnt while working on an HTML5 game recently. The game is pretty much like our HTML5 Doodle Jump. We had to make sure that the game scales down very well on smaller devices like mobiles, ipads, tablets, etc. and in the process learnt a neat trick to scale the entire canvas across all devices consistently.
Continue reading “Scaling Your HTML5 Canvas to Fit Different ViewPorts (or Resolutions)”

Games Physics: Basics and Implementation of Predictive (or Continuous) Collision Detection

Few days ago, I wrote a post about why time based animations are better than frame based animations. However, in animations done as a function of time, some serious problems could arise. One of them is that your regular collision detection techniques might fail if the frame rate is lower than acceptable. Your object might pass through the walls or even fall through the floor!

Continue reading “Games Physics: Basics and Implementation of Predictive (or Continuous) Collision Detection”