Skip to content

Instantly share code, notes, and snippets.

View lerouxb's full-sized avatar

Le Roux Bodenstein lerouxb

View GitHub Profile
module.exports = reqr = (path, m) ->
before = new Date()
if m
ret = m.require path
else
ret = require path
ms = new Date - before
if m
relative = m.filename.replace __dirname, ''
p = "#{path} from .#{relative}"
@lerouxb
lerouxb / teensy_osx.txt
Last active August 29, 2015 14:04
Some notes I took while getting the teensy version of micropython to build on OSX
* update README.md to mention "make deploy" and not "make upload"
* update README.md to link to wiki page
* update Makefile to include `pwd` in -path (see below)
* update README.md with build instructions for OSX:
(I'm probably missing some things because I've built some things before, but
those are all probably fairly standard "build toolchain" packages.)
@lerouxb
lerouxb / slugify.coffee
Created May 2, 2014 09:23
Turn names/titles/whatever into url/filename-friendly bits.
slugify = (title) ->
title
.toLowerCase()
.replace(/\ /g, '-') # spaces to dashes
.replace(/[^\w-]+/g, '') # remove anything that's not ascii A-Za-z0-9
.replace(/[-]+/g, '-') # remove consecutive dashes
@lerouxb
lerouxb / parseurl.coffee
Last active August 29, 2015 14:00
Parse a URL and querystring.
# This could be used as a client-side polyfill for node.js's url.parse()
parseURL = (url, parseQuery) ->
# http://stackoverflow.com/questions/736513/how-do-i-parse-a-url-into-hostname-and-path-in-javascript
parser = document.createElement('a')
parser.href = url
parsed =
protocol: parser.protocol
host: parser.host
hostname: parser.hostname
@lerouxb
lerouxb / contrast.coffee
Last active February 17, 2022 12:35
The W3C's suggested color contrast algorithm
# http://www.w3.org/TR/AERT#color-contrast
getBrightness = (rgb) ->
sum = parseInt(rgb[0])*299 + parseInt(rgb[1])*587 + parseInt(rgb[2])*114
brightness = Math.round(sum / 1000) # 0 (dark) to 255 (light)
colorDifference = (a, b) ->
max = Math.max
min = Math.min
d0 = max(a[0], b[0]) - min(a[0], b[0])
@lerouxb
lerouxb / hiLux.markdown
Created April 8, 2014 14:52
A Pen by Le Roux Bodenstein.
@lerouxb
lerouxb / flood.sh
Created August 15, 2013 14:55
Fill up the temp file system with trollfaces.
#!/bin/bash
while :
do
echo "Press [CTRL+C] to stop.."
curl -i -F image=@trollface.png http://127.0.0.1:3000/
done
@lerouxb
lerouxb / db.coffee
Created August 7, 2013 14:36
convenience methods for working with postgres in node.js
pg = require 'pg'
executeSQL = module.exports.executeSQL = (sql, params, callback) ->
# for executing sql outside of transactions
throw new Error "DATABASE_URL not set" unless process.env.DATABASE_URL
pg.connect process.env.DATABASE_URL, (err, client, done) ->
return callback(err) if err
client.query sql, params, (err, result) ->
done(client) # gets called regardless
return callback err, result
# extract the weight and style from a google font variant string
splitVariant = (variant) ->
weight = 'normal'
style = 'normal'
unless variant == 'regular'
if variant == 'italic'
style = 'italic'
else
weight = variant[..2]
italic = variant[3..]
@lerouxb
lerouxb / gist:4051170
Created November 10, 2012 13:59
nodesque
info: Creating snapshot 0.0.1-5
info Uploading: [ ] 0%
info: Updating app nko3-nodesque
info: Activating snapshot 0.0.1-5 for nko3-nodesque
info: Starting app nko3-nodesque
error: Error running command deploy
error: Nodejitsu Error (500): Internal Server Error
error: There was an error while attempting to deploy the app
error:
error: Rackspace Error (404): Item not found