Skip to content

Instantly share code, notes, and snippets.

View jeremyBanks's full-sized avatar

Jeremy Banks jeremyBanks

  • Canada
  • 21:31 (UTC -04:00)
View GitHub Profile
Does this work?
Gonna twitter this and see if I see anything.
Foo.
Bar.
=== (Alleged) ORIGINAL CODE ===
d = (: d_0 = 0; t = 0; v = 0
: d_0 + t * v)()
`print` d(t=3, v=3, d_0=1)
`print` d(t=1, v=2)
`print` d(d_0=4)
=== TRANSLATED CODE ===
@jeremyBanks
jeremyBanks / loop-breaking.py
Created October 15, 2010 02:55
A simple way to have a loop break with an outer loop in Python.
for x in range(5):
for y in range(10):
if x * y > 20:
print x, y
break # breaks both loops!
else:
continue
break
# Prints "3 7", and nothing else.
This is an
%a(href="http://www.google.com/") example
\.
produces
This is an
<a href="http://www.google.com/">example</a>
.
@jeremyBanks
jeremyBanks / gist:811900
Created February 4, 2011 22:27
ecmascript deferred interface
Deferred(value?, greedy=false)
.state = "unresolved" | "resolved" | "rejected"
.done(handlerz)
.fail(handlerz)
.then(doneHandlerz failHandlerz, progressHandlerz)
.on (doneHandlerz, failHandlerz, progressHandlerz)
.resolve (value)
.reject (args...)
@jeremyBanks
jeremyBanks / pdf-meta.bash
Created February 28, 2011 02:25
A script for quickly editing PDF metadata with pdftk and TextMate.
#!/usr/bin/env bash
subject="$1"
name="$(basename "$subject")"
path="$(dirname "$subject")"
tmp_new="$path/__tmp_new_$name"
tmp_meta="$path/__tmp_meta_$name.txt"
echo "Dumping metadata..." &&
pdftk "$subject" dump_data > "$tmp_meta" &&
echo "Opening metadata..." &&
@jeremyBanks
jeremyBanks / cover.jpg
Created May 15, 2011 14:01
FanFiction.net Audiobook Generator
cover.jpg
package main
import "fmt"
func MergeChannels(a chan int, b chan int) chan int {
// Merges two channels of sorted ints.
output := make(chan int)
go func() {
@jeremyBanks
jeremyBanks / answer.md
Created July 14, 2011 21:34
sqlite3 name escaping in Python (re: Stack Overflow question #6514274)

Putting up a bounty didn't produce a solution to this, so I've spent a while figuring out the best one I could. I don't have any source confirming that this is the correct way to do it, so use at your own risk.

Solution

To convert any string into a SQLite identifier:

  • Ensure the string can be encoded as UTF-8.
  • Ensure the string does not include any NUL characters.
  • Replace all " with "".
  • Wrap the entire thing in double quotes.
db.transaction("customers").objectStore("customers").get("444-44-4444").onsuccess = function(event) {
alert("Name for SSN 444-44-4444 is " + event.target.result.name);
};