Skip to content

Instantly share code, notes, and snippets.

View lawrencejones's full-sized avatar

Lawrence Jones lawrencejones

View GitHub Profile
# Configure default remote server for dredd tests
REMOTE = 'http://localhost:55000'
desc 'Runs dredd to verify API matches the apiary docs'
task 'dredd', [], async: true, ->
title "Running dredd on ./apiary.apib with #{REMOTE} remote"
log 'Reading Imperial credentials from ~/.imp'
try [user, pass] =
fs.readFileSync("#{process.env.HOME}/.imp", 'utf8').split '\n'
catch err
# /api/courses/year/cid
num = /^\d+$/
nonWhitespace = /^[^\s\t\r\n]$/
nonEmpty = /[^\s\t\r\n]+/
any = /.*/
cateRes =
/^https:\/\/cate\.doc\.ic\.ac\.uk\/showfile\.cgi\?key=(\d{4,4}):\d+:\d+::(NOTES|SPECS):\w+$/
discussion =
@lawrencejones
lawrencejones / agg.coffee
Last active March 15, 2019 19:00
Projection generator for mongodb
_ = require 'underscore'
# Given an array of elements ELEM and a matching KEY value,
# will build the apprpriate projection to generate sortable
# weights for a mongo aggregator.
#
# ELEM: An array of values upon which to match against KEY
# KEY: The document field key to match against
# I: Default 0, index into array at which to begin
#
@lawrencejones
lawrencejones / README.md
Last active August 29, 2015 14:03
A very crappy git hour calculator. Buggy as hell, but works with before/after flags also

git-hours

Relies on the git_time_extractor gem, which can be installed with gem install git git_time_extractor.

Example usage...

$ git-hours --after 06/20/2014
Lawrence Jones: 38.8hrs
@lawrencejones
lawrencejones / npm-deps.litcoffee
Last active August 29, 2015 14:04
A small coffeescript that generates a template dependencies manifest by searching through globbed coffee files

NPM Dependency Generator

Simple detection of used npm packages by searching files for require mentions. Will output JSON dependencies for a quick copy-paste.

Helpers

fs = require 'fs'
@lawrencejones
lawrencejones / arduino.c
Created July 22, 2014 15:15
Variadic function to enable easy writing to serial char device on an arduino
#include <cstdarg.h>
void writeValues(int count, ...)
{
/* Declare variadic args */
va_list ap;
va_start(ap, count);
Serial.print("#S|SAVEDATA|[");
@lawrencejones
lawrencejones / filter.litcoffee
Last active August 29, 2015 14:04
Small CSV filtering script, experimenting with promises

CSV Processor

Small script to help process data from a CSV file. Messaround with promises also.

First part of script is just helpers- skip to Start Filtering to see the body.

fs = require 'fs'
_  = require 'underscore'
Q  = require 'q'
#!/bin/sh
cat $1 \
| grep -B 3 -E "Translation of Javascript" \
| grep "<dd>/" \
| sed "s/<dd>\(.*\)<\/dd>/\\1/g" \
| tr -s " "
{ User } = require('sesquis/app/models/user')
{ StripeConnection } = require('sesquis/app/etc/stripe_connection')
{ CARDS } = require('sesquis/spec/seeds/stripe/stripe')
describe 'Stripe', ->
resetAndExposeUser = ->
before resetDatabase
@lawrencejones
lawrencejones / parentMapping.json
Created October 10, 2014 17:27
Mapping of Imperial parents to their DoC children
[
{
"parents": [
{
"id": "sjc113",
"fname": "Samuel",
"lname": "Coope",
"year": 2
},
{