Skip to content

Instantly share code, notes, and snippets.

@quickredfox
quickredfox / dice.coffee
Created March 29, 2012 18:06
A seriously (if I may say so) kick-ass implementation of a dice notation reader in coffeescript.
##
A seriously (if I may say so) kick-ass implementation of a dice notation reader in coffeescript.
Careful, it evals code, keep your strings clean before feeding them to this baby! (and adds a "d" method to Number)
##
Number::d = ( v )->
[1..@].reduce ( a )->
a + ( Math.floor( Math.random()*v ) + 1 )
, 0
Dice = ( dice )->
HEXCHARS = '0123456789ABCDEF'.split('')
rgb2hex = (r,g,b)-> "##{byte2hex(r)}#{byte2hex(g)}#{byte2hex(b)}"
byte2hex = (n)-> String(HEXCHARS.substr((n >> 4) & 0x0F,1)) + HEXCHARS.substr(n & 0x0F,1)
hex2rgb = ( color )->
triplet = color.toLowerCase().replace /#/ , ''
rgb = []
if triplet.length is 6
rgb[0] = parseInt(triplet.substr(0,2), 16)
rgb[1] = parseInt(triplet.substr(2,2), 16)
rgb[2] = parseInt(triplet.substr(4,2), 16)
Cross-browser, time-zone-aware parsing via JavaScript:
var s = "Fri Apr 09 12:53:54 +0000 2010";
var date = new Date(
s.replace(/^\w+ (\w+) (\d+) ([\d:]+) \+0000 (\d+)$/,
"$1 $2 $4 $3 UTC"));
Tested on IE, Firefox, Safari, Chrome and Opera.
@quickredfox
quickredfox / word_to_rageface.json
Created April 26, 2012 19:17
Mapping of words to their "appropriate" rage face.
{"laughing":"http://s3.amazonaws.com/ragefaces/1304a2ba552f395b793a278dc6b232e1.png","funny":"http://s3.amazonaws.com/ragefaces/6bba77c8b9326aef8230886e16d66b0e.png","pftch":"http://s3.amazonaws.com/ragefaces/4f767454e72cef87d679c12823892356.png","victorious":"http://s3.amazonaws.com/ragefaces/b5140e11e5281ae31921bd53a39da08a.png","troll":"http://s3.amazonaws.com/ragefaces/0105be0f3197674f51bd013fbda84ecb.png","umad":"http://s3.amazonaws.com/ragefaces/fed47e7ffa874d01b771474d2eef1a60.png","trollface":"http://s3.amazonaws.com/ragefaces/1188b161991386e76f70a617220d95a6.png","problem":"http://s3.amazonaws.com/ragefaces/1188b161991386e76f70a617220d95a6.png","u jelly":"http://s3.amazonaws.com/ragefaces/1188b161991386e76f70a617220d95a6.png","jelly":"http://s3.amazonaws.com/ragefaces/1188b161991386e76f70a617220d95a6.png","fuck that":"http://s3.amazonaws.com/ragefaces/8874e57c4f330a8efe107b21aa2190ab.png","fuck":"http://s3.amazonaws.com/ragefaces/a3dc16a8264672738297dc924e36bbf7.png","fuckin":"http://s3.amazonaws.com
@quickredfox
quickredfox / express-server.coffee
Created May 2, 2012 14:11
my usual coffeescript expressjs preamble
FS = require 'fs'
express = require 'express'
joinPath = require( 'path' ).join
redis = require( 'redis' ).createClient()
RedisStore = require( 'connect-redis' )( express )
server = express.createServer()
fetcher = require './fetcher'
# create "temp dir"
try FS.mkdirSync( joinPath( __dirname, '..','tmp' ) , 0755 ) catch ignore
@quickredfox
quickredfox / chest.md
Created May 4, 2012 19:24
The Github Pirates' Chest
<!DOCTYPE html>
<html>
<head>
<title>Bootstrap-Plus, from Needium</title>
<link rel="stylesheet" href="/css/bootstrap-plus.css" type="text/css" media="screen" title="no title" charset="utf-8">
<style type="text/css" media="screen">
body{padding-top:40px;}
</style>
</head>
<body data-spy="scroll">
var TermGroup;
TermGroup = function(options) {
this.name = options.name || ("termgroup-" + (new Date().getTime()));
this.terms = options.terms || [];
this.toString = function() {
return this.terms.join();
};
this.toJSON = function() {
return this.terms;
@quickredfox
quickredfox / example.sh
Created June 12, 2012 21:36
list files and directories with absolute paths in linux/unix/osx terminal
# Use this for dirs:
ls -d -1 $PWD/**
# this for files:
ls -d -1 $PWD/*.*
# this for everything:
@quickredfox
quickredfox / capped-object.js
Created June 20, 2012 19:35
CappedObject for Nic
var CappedObject = function( limit ){
items = {};
length = 0 ;
this.put = function( string ) {
if( items[string] ) return string;
items[string] = string;
length++;
if( length > limit ){
delete items[ Object.keys( items )[0]];
length --;