Skip to content

Instantly share code, notes, and snippets.

View lawrencejones's full-sized avatar

Lawrence Jones lawrencejones

View GitHub Profile
expect = (a,b) ->
[a,b] = [a.join(), b.join()]
if a != b
console.log """
Expect failed!
[#{a}] != [#{b}] """
else console.log "PASS! [#{a}]"
# Preprocesses P to generate list of occurances of suffixs within
# the pattern.
@lawrencejones
lawrencejones / merge.coffee
Created April 15, 2014 21:41
Implementation of a merge sort
PASSED = 0
check_sorted = (was, now) ->
if !now.reduce ((a,c,i) -> a && (!now[i+1]? || now[i] < now[i+1])), true
throw new Error """\n
Was: [#{was}]
Now: [#{now}]\n"""
else
++PASSED
@lawrencejones
lawrencejones / interleave.coffee
Last active August 29, 2015 14:00
Permutation generator. An example of how to divide tasks and facilitate real concurrency using Node's child_process libraries.
# Calculates time interval between start and end, formatted as
# 17928 -> 17s 928ms
timeElapsed = (start, end) ->
diff = end - start
"#{Math.floor(diff/1000)}s #{Math.floor(diff%1000)}m"
# Helpers for the permute function
arrayExcept = (A, idx) ->
(A = A[0..]).splice idx, 1; A
@lawrencejones
lawrencejones / coins.coffee
Last active August 29, 2015 14:00
Example of dynamic programming problem
# Simply rounds to four digits
dp = (num) ->
Math.round(10000*num)/10000
# Calculates empirical probability of
lazyCheck = (P, k) ->
RUNS = 500000
avg = 0
for i in [1..RUNS]
heads = P.reduce(((a,c) ->
@lawrencejones
lawrencejones / seq.coffee
Last active August 29, 2015 14:00
LCS algorithm making use of dynamic programming
# Making comparisons between two DNA sequences can become a hard computational
# problem, due to the inexact definition of organic similarity.
#
# When making comparisons between two sequences, a useful definition of
# similarity is the largest subsequence present within both sequences, where a
# subsequence is defined as such...
#
# Given X = { X1, X2, ..., Xm }
# and Z = { Z1, Z2, ..., Xk }...
#
var Track = (function() {
function Track(title, artist) {
this.title = title || 'Untitled';
this.artist = artist || 'Unknown';
}
Track.prototype.toString = function() {
return this.title + ',\t\t' + this.artist;
};
# Given a list V of item values, and W of item weights, where item i
# has value V[i] and weight W[i], find the optimal selection of i to
# sure fill the knapsack of capcity k with fractions of items.
#
# The values are required to be sorted by descending order of value
# per pound, in order to enable a greedy choice.
#
# The sort incurs a cost of O(n log(n)), assuming efficient merge
# sort.
#
> module Ex3FunctionsCodeGenerator where
> import Ex3FunctionsTypes
> import Data.List
-----------------------------------------------------------
Solution for Compilers exercise 3
Paul Kelly Imperial College London 2009
-----------------------------------------------------------
Fill in the gaps...
Anonymous UUID: 9DA07A69-940A-DF72-455D-54DAD821BB68
Wed May 21 22:44:27 2014
panic(cpu 0 caller 0xffffff7fa336bfb0): "GPU Panic: [<None>] 3 0 a0 d9 9 8 0 3 : NVRM[0/1:0:0]: Read Error 0x00000144: CFG 0xffffffff 0xffffffff 0xffffffff, BAR0 0x102c00000 0xffffff81f8d94000 0x0e7150a2, D0, P2/4\n"@/SourceCache/AppleGraphicsControl/AppleGraphicsControl-3.4.35/src/AppleMuxControl/kext/GPUPanic.cpp:127
Backtrace (CPU 0), Frame : Return Address
0xffffff81e307cbe0 : 0xffffff8020e22fa9
0xffffff81e307cc60 : 0xffffff7fa336bfb0
0xffffff81e307cd30 : 0xffffff7fa185a22c
0xffffff81e307cdf0 : 0xffffff7fa1924106
0xffffff81e307ce30 : 0xffffff7fa1b47e54
@lawrencejones
lawrencejones / Jakefile.coffee
Last active August 29, 2015 14:01
Jakefile deployment script
#!/usr/bin/env coffee
# vi: set foldmethod=marker
fs = require 'fs'
path = require 'path'
sSplitter = require 'stream-splitter'
$q = require 'q'
coffee = require 'coffee-script'
spawn = (require 'child_process').spawn
exec = (require 'child_process').exec