Skip to content

Instantly share code, notes, and snippets.

@laughinghan
laughinghan / schedule.php
Created August 25, 2010 16:01
Better Schedule Search for Berkeley
<?php
/*
* schedule.php
*
*
* Created by Jay on 12/4/09, based on Han's Better Schedule Search.
* Gift-Economy license. See en.wikipedia.org/wiki/Gift_economy
*
*/
@laughinghan
laughinghan / MathQuill Toolbar
Created April 15, 2011 07:39
Experimental MathQuill Toolbar
<!DOCTYPE html>
<html>
<head>
<title>MathQuill Toolbar Demo</title>
<!--script type="text/javascript" src="mathquill/vendor/jquery.min.js"></script>
<script type="text/javascript" src="mathquill/build/mathquill.js"></script-->
<link rel="stylesheet" href="http://mathquill.com/mathquill.css">
function parseTable(tbl) {
return tbl.find('tbody tr').map(function () {
return $(this).find('td').map(function () {
return $.trim($(this).text());
}).get().join('\t');
}).get().join('\n');
}
var i = 0, page = 1, pages = 1;
(function loop() {
while (!addresses[i]) {
@laughinghan
laughinghan / merge.js
Created June 15, 2011 06:06
merge.js
#!/usr/local/bin/node
var fs = require('fs');
var data = fs.readFileSync(process.argv[2]);
var target = fs.readFileSync(process.argv[3]);
var lines = (data+'').split('\n');
var rows = (target+'').split('\n');
var row = 0;
/**
* Join
* Joins async callbacks with arguments concatenated.
* Usage:
* var join = new Join;
* getScore (angel, buffy, join());
* getNextMatch (angel, join());
* recordVisitAndGetInfo (angel, buffy, join());
* join.after = function(score, next, vinfo) {
if (this.score > 0.9 && ! this.vinfo.last_visit) {
@laughinghan
laughinghan / minimap.js
Created July 21, 2011 03:03
Minimap of a web page
javascript:
var minimap = document.body.cloneNode(true);
[].forEach.call(minimap.getElementsByTagName('a'), function(link) {
link.href = 'javascript:;';
});
minimap.style.position = 'fixed';
minimap.style.webkitTransform = 'scale(.1)';
document.body.appendChild(minimap);
minimap.style.top = minimap.offsetHeight*-.45+'px';
minimap.style.right = minimap.offsetWidth*-.45+'px';
@laughinghan
laughinghan / heroku-ready_django_startproject.sh
Created September 7, 2011 08:51 — forked from tkopczuk/create_django_heroku_project.sh
Create a new Heroku-ready Django project
#!/bin/sh
PROJECT_NAME=$1
if [ -z "$PROJECT_NAME" ]; then
echo "Usage: heroku-ready_django_startproject.sh projectname"
exit
fi
mkdir $PROJECT_NAME
@laughinghan
laughinghan / PyClass.js
Created March 10, 2012 06:33
Python-style classes in JavaScript
//because why not?
//please don't actually use this. Please use idiomatic JavaScript classes or a very thin class layer like github.com/jayferd/pjs
/*
Usage:
var Cat = PyClass({
__init__: function(self, name) {
self.name = name;
},
chase: function(self, prey) {
@laughinghan
laughinghan / 22_name_scores.py
Created June 11, 2012 16:19
Sexy, sexy Project Euler Problem 22 "Name Scores" Solution
import string
def name_scores():
inputfile = open('./Downloads/names.txt')
inputstring = inputfile.read()
stringlist = inputstring.split(',')
strlst = []
for smallstring in stringlist:
strlst.append(smallstring[1:-1])
//timestamp: [time difference from previous] message
34: [34µs] about to do this.each (jQuery.fn.each)
62: [28µs] entered this.each, about to do .attr and MathElement[] lookup
118: [56µs] done, there is a block!
122: [4µs] got cursor, about to do cursor.clearSelection()
130: [8µs] did cursor.clearSelection(), about to do block.renderLatex(latex)
139: [9µs] got jQ, about to empty except for textarea
554: [415µs] emptied jQ, about to delete children from edit tree
566: [12µs] appending cursor
795: [229µs] appended cursor, this.cursor.writeLatex()