Skip to content

Instantly share code, notes, and snippets.

@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 / 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
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.
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)
@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 )->
@quickredfox
quickredfox / dirty-sandboxing.js
Created March 16, 2012 17:31
dirty sandboxing
var callForJS = $.ajax( {
complete: function( jqXhr ){
var unsafeResponse = jqXhr.responseText
, empty = {};
new Function( '', jqXhr.responseText ).call( empty ) // empty object as scope
}
} );
// Safer, if you want to restrict access to some globals
@quickredfox
quickredfox / example.js
Created February 23, 2012 15:17
JSON.lookup() # find things in JSON collections
var json;
json = [
{
foo: {
bar: ['ka', 'boom']
}
}, {
foo: {
bar: ['sna', 'fu']
@quickredfox
quickredfox / cheery.js
Created February 10, 2012 23:20
Problem I cannot solve, should be simple math for someone...
function oscillator(low, high, inc) {
// basic test for illegal parameters
if (low > high || inc < 0 || 2 * (high - low) < inc)
return function() { return NaN; };
var curr = low;
return function() {
var ret = curr;
curr += inc;
@quickredfox
quickredfox / mentions.json
Created January 25, 2012 15:19
/bad-ass-coffee-co/entries/mentions.json
{
"hits": [],
"total_pages": 3,
"total": 72,
"count": 25,
"entries": [{
"mention_in_reply_to_screen_name": "BadAssCoffeeRC",
"fetcher_type": "TwitterApiMention",
"pid": "mentions-twitter:3824990225",
"created_at": 1327367066,
@quickredfox
quickredfox / bootstraped-tumblr-theme.html
Created November 17, 2011 23:16
bootstrap tumblr theme for quickredthought.tumblr.com
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>{Title}</title>
<link rel='icon' href='{Favicon}'>
<link rel='shortcut icon' href='{Favicon}'>
<link rel='alternate' type='application/rss+xml' href='{RSS}'>
<meta name='description' content='{MetaDescription}'>
<meta name='color:Link' content='#6699cc'>