Skip to content

Instantly share code, notes, and snippets.

View richthegeek's full-sized avatar

Richard Lyon richthegeek

View GitHub Profile
@richthegeek
richthegeek / jquery.auto-load.js
Created March 19, 2012 00:08
Auto-load templates
var templates = window['templates'] = {}
$.get('assets/html', function(data) {
$('a[href*=html]', data).each(function() {
$.get('assets/html/' + $(this).attr('href'), function(data) {
_name = this.url.split('/').pop().split('.')
_name.pop()
path = templates
for (var i = 0; i < _name.length; i++) {
segment = _name[i]
@richthegeek
richthegeek / .htaccess
Created August 13, 2012 15:34
Automatic SASS/SCSS compilation with PHPSass and Apache2
Action compile-sass /git/phpsass/compile-apache.php
AddHandler compile-sass .sass .scss
@richthegeek
richthegeek / debug.coffee
Created September 27, 2012 21:55
Node debugging functions
global.debug = ( ) ->
tabs = ( n ) -> ( "\t" for i in [0...n] ).join( '' )
for i in [0...arguments.length]
arg = arguments[i]
type = get_type arg
# last arg is boolean? sleep if true
if ( i + 1 ) is arguments.length and type is 'Boolean'
if arg
@richthegeek
richthegeek / index.coffee
Created March 6, 2013 12:40
Modified builder-coffee which takes .coffee files directly from teh "scripts" directive of a component.json file.
fs = require( 'fs' )
CoffeeScript = require( 'coffee-script' )
module.exports = ( builder )->
builder.hook 'before scripts', ( pkg )->
if scripts = pkg.conf.scripts
ret_scripts = []
scripts.forEach (file) ->
@richthegeek
richthegeek / svg2png.sh
Created March 28, 2013 17:00
Script which converts all .svg files in the current directory into various size*color combinations. For example, "thing.svg" results in "pngs/black/16/thing.png" and "pngs/holo/256/thing.png" amongst others. Just customise sizes/colors/aliases in the script and then ./extract.sh
#!/bin/bash
sizes="16 24 32 64 128 256"
colors=("#000" "#33b5e3" "#808080")
names=("black" "holo" "grey")
count=${#names[@]}
for i in `seq 1 $count` ; do
name=${names[i - 1]}
@richthegeek
richthegeek / SassCache.php
Last active December 17, 2018 10:52
A simple caching wrapper for PHPSass - does not take into account changes in files referrred to from @include. Assumes that the PHPSass library is located in a directory at ./phpsass Assumes it can write to a directory called ./phpsass_cache, or create it.
<?php
function compileSass($filename, $cached = true) {
$cache_dir = './phpsass_cache';
# if cached, ensure we can write to the cache directory
if ($cached) {
if (!file_exists($cache_dir) && !mkdir($cache_dir)) {
throw 'SASS cache directory does not exist and cannot be created';
}
@richthegeek
richthegeek / deferredObject.coffee
Last active December 25, 2015 19:08
Allow lazy evaluation of a string, such that you can have asynchronous parts to an otherwise synchronous evaluation. For example, part of the object may need to be loaded from the database but you don't want the code to be written with callbacks.
Q = require 'q'
class DeferredObject
constructor: (data) ->
@data = data
for k, v of @data
@__defineGetter__ k, -> this.data[k]
defer: (key, getter) ->
@richthegeek
richthegeek / deferredRequest.coffee
Last active December 26, 2015 17:29
A wrapper around the "request" module which allows use of the promises style for dealing with the response.
Q = require 'q'
request = require 'request'
init = request.Request::init
request.Request::init = (options) ->
defer = Q.defer()
@on 'complete', defer.resolve
@on 'error', defer.reject
# copy over promise functions, except timeout.
@richthegeek
richthegeek / setup.sh
Created November 7, 2013 16:52
Install basic stuff to a fresh buntu server.
#!/bin/sh
apt-get update
apt-get dist-upgrade -y
apt-get install python-software-properties -y
# node
apt-add-repository ppa:chris-lea/node.js -y
# redis
@richthegeek
richthegeek / zxcvbn.js
Created January 23, 2015 12:53
Ignore this
var passwords = ['password','123456','12345678','1234','qwerty','12345','dragon','pussy','baseball','football','letmein','monkey','696969','abc123','mustang','michael','shadow','master','jennifer','111111','2000','jordan','superman','harley','1234567','fuckme','hunter','fuckyou','trustno1','ranger','buster','thomas','tigger','robert','soccer','fuck','batman','test','pass','killer','hockey','george','charlie','andrew','michelle','love','sunshine','jessica','asshole','6969','pepper','daniel','access','123456789','654321','joshua','maggie','starwars','silver','william','dallas','yankees','123123','ashley','666666','hello','amanda','orange','biteme','freedom','computer','sexy','thunder','nicole','ginger','heather','hammer','summer','corvette','taylor','fucker','austin','1111','merlin','matthew','121212','golfer','cheese','princess','martin','chelsea','patrick','richard','diamond','yellow','bigdog','secret','asdfgh','sparky','cowboy','camaro','anthony','matrix','falcon','iloveyou','bailey','guitar','jackson','purp