Skip to content

Instantly share code, notes, and snippets.

View richthegeek's full-sized avatar

Richard Lyon richthegeek

View GitHub Profile
let type = process.argv[2];
if (type !== 'minor' && type !== 'major' && type !== 'patch') {
console.error('Specify major/minor/patch as the first argument');
process.exit(1)
}
let file = process.cwd() + '/package.json';
let package = require(file);
const Model = require('sequelize').Model;
class User extends Model {
columns: {
id: {
autoIncrement: true,
primaryKey: true,
type: Model.DataTypes.INTEGER(10)
},
@richthegeek
richthegeek / hmac.java
Last active August 29, 2015 14:26
Veoo Subscriber API HMAC generation
private static String toHexString(byte[] bytes) {
Formatter formatter = new Formatter();
for (byte b : bytes) {
formatter.format("%02x", b);
}
return formatter.toString();
}
public static String generateHMAC(String path, String body, String key) throws SignatureException, NoSuchAlgorithmException, InvalidKeyException {
SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), "HmacSHA1");
@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
@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 / 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 / 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 / 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 / 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 / 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) ->