Skip to content

Instantly share code, notes, and snippets.

@ddgromit
ddgromit / fisheryates.coffee
Created March 8, 2011 01:56
CoffeeScript Implementation of the Fisher-Yates array sorting algorithm
# Adapted from the javascript implementation at http://sedition.com/perl/javascript-fy.html
# Randomizes the order of elements in the passed in array in place.
fisherYates = (arr) ->
i = arr.length;
if i == 0 then return false
while --i
j = Math.floor(Math.random() * (i+1))
tempi = arr[i]
@abachman
abachman / color.coffee
Created September 13, 2012 18:11
color modifications in coffeescript
# rgb <-> hsl algorithms from
# http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript
Colors =
#
# Converts an RGB color value to HSL. Conversion formula
# adapted from http://en.wikipedia.org/wiki/HSL_color_space.
# Assumes r, g, and b are contained in the set [0, 255] and
# returns h, s, and l in the set [0, 1].
#
@fupslot
fupslot / gist:5015897
Created February 22, 2013 19:23
Javascript: Convert base64 to a Blob
function dataURItoBlob(dataURI, callback) {
// convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this
var byteString = atob(dataURI.split(',')[1]);
// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0]
// write the bytes of the string to an ArrayBuffer
var ab = new ArrayBuffer(byteString.length);