This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- shiny and exciting O(n log n) algorithm | |
-- the n parameter and the idea to use something like merge sort is from Bird | |
-- both of those things are really clever | |
join :: Ord a => Int -> [(a, Int)] -> [(a, Int)] -> [(a, Int)] | |
join 0 ax [] = ax -- n corresponds to length b, so if b is empty n = 0 | |
join n [] bx = bx | |
-- something like merge sort but slightly different | |
join n ax@((a, ac):as) bx@((b, bc):bs) | |
| a < b = (a, ac + n) : join n as bx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.List | |
-- import Debug.Trace | |
data Node a = DeadEnd a | |
| Passage a (Node a) | |
| Fork a (Node a) (Node a) | |
instance (Show a) => Show (Node a) where | |
show (DeadEnd a) = "DeadEnd " ++ show a | |
show (Passage a _) = "Passage " ++ show a | |
show (Fork a _ _) = "Fork " ++ show a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* requires substack/node-binary and dependencies (npm install binary) */ | |
/* also don't forget node.js */ | |
var net = require('net'); | |
var Binary = require('binary'); | |
exports.attach = function attach(server) { | |
if ('number' == typeof server) { | |
var port = server; | |
server = net.createServer(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var b = require('bindify') | |
// first make a function that does \ a b -> \ c -> b(a c) | |
var compose_2 = b(b, null | |
, Function.prototype.call | |
, b._1 | |
, b._wrap(b._this) | |
, nested_b(nested_b, null | |
, b._0 | |
, b._wrap(b._this) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
// works as a CLI similar to the browserify one, but prints a space-separated list of dependencies for the arguments you give. | |
// requires browserify (obviously), JSONStream and event-stream. | |
var JSONStream = require('JSONStream') | |
, child_process = require('child_process') | |
, path = require('path') | |
, es = require('event-stream') | |
var parser = JSONStream.parse([true]) | |
var cwd = process.cwd() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function router() { | |
function router(method, url) { | |
var r = get_routes(method), rl = r.length | |
for (var i = 0; i < rl; ++i) { | |
if (r[i].type == 'string') { | |
if (r[i].url == url) | |
return [[url], r[i].callback] } | |
else { | |
var route = r[i] | |
if (route.type == 'regexp') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form onsubmit="myAuth.login(), false"> | |
<input type="text" name="name" id="auth_name" autocomplete="on"> | |
<input type="password" name="password" id="auth_passwd" autocomplete="off"> | |
<input type="submit" value="Log In"> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// keeps track of connections to a http server and closes them when the server closes. | |
function LinkedList() { | |
this.start = null | |
this.end = null } | |
LinkedList.prototype.add = function(data) { | |
var ref = { data: data, next: null, prev: null } | |
if (!this.start) this.start = ref | |
if (this.end) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Warn when you're about to tweet "thanks to me" | |
// @namespace http://localhost/ | |
// @version 0.1 | |
// @description Add an alert whenever someone types "thanks to me" | |
// @match http://twitter.com/* | |
// @match https://twitter.com/* | |
// ==/UserScript== | |
(function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function RPS(noPlayers, proto) { | |
var obj = Object.create(proto || RPS.prototype) | |
obj.players = noPlayers | |
obj.score = {} | |
obj.moves = {} | |
for (var i = 0; i < noPlayers; i++) { | |
obj.score[i] = 0 | |
obj.moves[i] = [] } | |
return obj } |
OlderNewer