Skip to content

Instantly share code, notes, and snippets.

View jeremyBanks's full-sized avatar

Jeremy Banks jeremyBanks

  • Canada
  • 02:28 (UTC -04:00)
View GitHub Profile
@jeremyBanks
jeremyBanks / stack.c
Created September 15, 2008 22:25
[2010-01] me being thrilled upon discovering alloca
//&>/dev/null;x="${0%.*}";[ ! "$x" -ot "$0" ]||(rm -f "$x";cc -o "$x" "$0")&&"$x" $*;exit
// http://stackoverflow.com/questions/31937/what-is-your-favourite-non-standard-c-library-function#32064
#include <stdio.h>
#include <alloca.h>
int main(int argc, char* argv[]) {
char* myString = alloca(sizeof(char) * 5);
myString[0] = 'H';
myString[1] = 'e';
@jeremyBanks
jeremyBanks / gist:10970
Created September 16, 2008 01:18
[2010-01] simple example using scp from python
#!/usr/bin/env python
# encoding: utf-8
from __future__ import with_statement
import sys
import subprocess
def scp(source, server, path = ""):
return not subprocess.Popen(["scp", source, "%s:%s" % (server, path)]).wait()
def main(*args):
@jeremyBanks
jeremyBanks / sudoku.py
Created September 16, 2008 18:07
A hopefully decent Sudoku solver in Python.
#!/usr/bin/env python3.0
import sys
gridStringFormat = """\
%s %s %s | %s %s %s | %s %s %s
%s %s %s | %s %s %s | %s %s %s
%s %s %s | %s %s %s | %s %s %s
-------+-------+-------
%s %s %s | %s %s %s | %s %s %s
%s %s %s | %s %s %s | %s %s %s
@jeremyBanks
jeremyBanks / example.c
Created September 16, 2008 18:53
[2010-01] looking at scanf, i guess
//&>/dev/null;x="${0%.*}";[ ! "$x" -ot "$0" ]||(rm -f "$x";cc -o "$x" "$0")&&"$x" $*;exit
#import <stdio.h>
int main(int argc, char* argv[]) {
int i;
double d;
scanf("%d", &i);
printf("i = %d, d = %lf\n", i, d);
@jeremyBanks
jeremyBanks / profile.txt
Created September 18, 2008 00:25
[2010-01] an old (shitty?) PS1 I had. you should probably use the built-in one, now that it has it
export PS1="\W\$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ # \1/' -e \"s/(no branch)/\$(git rev-parse --short HEAD 2> /dev/null)…/\") \$ "
This requires a call to git-branch and to git-rev-parse for every shell
prompt to be displayed. This did not result in a noticeable delay for
me, your milage may vary. If we're in a git repository it adds a hash
sign and the name of the current branch to the prompt. If we're not at
the head of the branch, it displays the short form of the HEAD's SHA.
~ $ cd src
src $ cd blog
@jeremyBanks
jeremyBanks / installPytho.bash
Created September 19, 2008 04:55
[2010-01] a script downloading python from svn, they're moving off that
#!/bin/bash
version="${1:-"3.0"}"
release="${2:-"rc1"}"
repository="http://svn.python.org/projects/python/r${version//./}"
directory="python$version$release"
NUL="/dev/null"
if python$version --version &> "$NUL"; then
#!/usr/bin/env python
# encoding: utf-8
from __future__ import division, with_statement
import sys
class Foo(object):
def bar(self, counter=[0]):
counter[0] += 1
print("Counter is %i" % counter[0])
@jeremyBanks
jeremyBanks / post.md
Created November 13, 2008 05:59
a facebook comment to josh that was over the character limit

I want the Canon EOS 50D, which was released at the end of August. The body's MSRP is 1300 USD, so we'd need a few hundred minimum on top of that for glass.

This is why I never bought a nice camera before—the models below this just seem so weak by comparison.

On the other hand, we could probably get two of the 1000Ds for the same price as one of these.

Or we could go for a 400D, since they're no longer front-of-the line, we might actually be able to afford one.

Wow, you can get a refurb'ed body for $400 from Future Shop. I don't really think a camera is something I would want to get refurbished, but it's something to look at.

@jeremyBanks
jeremyBanks / numberwords.py
Created November 23, 2008 06:52
[2010-01] i meant to code golf numbers to words but failed
#!/usr/bin/env python
# encoding: utf-8
from __future__ import division, with_statement
import sys
# http://stackoverflow.com/questions/309884/code-golf-number-to-words
# http://en.wikipedia.org/wiki/Long_and_short_scales
"""Converts numbers to words using the English short scale."""
@jeremyBanks
jeremyBanks / logon.bat
Created December 9, 2008 16:57
[2010-01] trying windows "shebang" for python
C:\Python26\python.exe -x logon.bat & exit
# There, this can act as the windows equivilent of a shebang, I guess.
print("Hello world")