Skip to content

Instantly share code, notes, and snippets.

@SoftwareDevPro
SoftwareDevPro / uuid.coffee
Created October 30, 2016 18:08
Creates a UUID and returns it.
# Filed under: uuid, id, random
###
a: placeholder
###
b = (a) ->
###
if the placeholder was passed, return a random number from 0 to 15 unless b
is 8, in which case a random number from 8 to 11 in hexadecimal or
@SoftwareDevPro
SoftwareDevPro / objectid.coffee
Created October 30, 2016 05:33
Implementation of hash code for the Object prototype
# Filed under: 140bytes, identifier, object, id, hashcode
# Gives every object a unique ID.
(() ->
Object.prototype.getHashCode = ((i) ->
i = 0
() ->
if this.h = this.h then this.h else i++
)()
@SoftwareDevPro
SoftwareDevPro / hsl2rgb.coffee
Created October 30, 2016 05:27
Takes a HSL (hue saturation, light) value and returns the RGB equivalent
# Filed under: color, convert, hsl, rgb
# Converts hue-saturation-lightness to red-green-blue color value.
###
@param a hue
@param b saturation
@param c lightness
###
hsl2rgb = (a, b, c) ->
@SoftwareDevPro
SoftwareDevPro / hex2rgb.coffee
Created October 30, 2016 05:24
Receives a hex string, and returns an array of R,G,B components
# Filed under: hex, color, rgb
# Converts a hex string to RGB.
###
@param a a "#xxxxxx" hex string,
###
hex2rgb = (a) ->
###
turn it into a number by taking the hexadecimal prefix and the
@SoftwareDevPro
SoftwareDevPro / 41bFib.coffee
Created October 30, 2016 04:19
Fibonacci sequence implemented in CoffeeScript
# Filed under: 140bytes, fibonacci, recursive
# calculate fibonacci (recursively)
fibonacci = (n) ->
if n > 1 then f(n - 1) + f(n - 2) else n