Skip to content

Instantly share code, notes, and snippets.

View swanson's full-sized avatar
😈

matt swanson swanson

😈
View GitHub Profile
window.onload = function() {
var s = new io.Socket(null, {port: 3000});
s.connect();
s.on('message', function(data) {
if (data['type'] == 'add') {
$("#announcements").append(
'<div id=' + data['id'] +'>' + data['payload'] + '</div>'
);
}
//Good! (well, better at least...)
app.get('/edit', function(req, res){
var stored_items = [];
//pull some data out of mongo
Announcement.fetch_active().all(function(results) {
for (i in results) {
stored_items.push(results[i].body);
}
//Bad!
app.get('/edit', function(req, res){
var stored_items = [];
//pull some data out of mongo
Announcement.fetch_active().all(function(results) {
for (i in results) {
stored_items.push(results[i].body);
}
});
@swanson
swanson / directions.py
Created November 11, 2010 03:24
MapQuest API Turn-by-turn script
#!/usr/bin/env python
# MapQuest API Turn-by-turn script
#
# Generates driving directions from a starting location
# to a series of destinations in a CSV, used to print
# maps for volunteers delivering food to the less-fortunate
#
# CSV format - place in a file named `list.csv`
# Name, Street, Zipcode, Phone, Count
@swanson
swanson / _config.yml
Created February 1, 2011 01:48
Deploying Sintra+Jekyll to Heroku using Rack
pygments: true
source: ./_posts
destination: ./blog
@swanson
swanson / ghettohub.sh
Created March 9, 2011 01:12
ghetto repository language classified
matt@nigiri:~$ sloccount $GIT_REPO_DIR 2>/dev/null | grep '%' | head -n 1 | cut -d : -f 1
#doesnt work on javascript since LOC scripts havent been updated since like 2004
@swanson
swanson / .bashrc
Created March 9, 2011 01:25
auto activate virtualenv in python git repos only
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
# Automatically activate Git projects' virtual environments based on the
# directory name of the project. Virtual environment name can be overridden
# by placing a .venv file in the project root with a virtualenv name in it
function workon_cwd {
# Check that this is a Git repo
GIT_DIR=`git rev-parse --git-dir 2> /dev/null`
if [ $? == 0 ]; then
from argparse import ArgumentParser
import re
from datetime import date
p = ArgumentParser(description='Generate a jeykll blog post template')
p.add_argument('title', help='title of the post, generates slug')
p.add_argument('category', help='category (e.g blog, writeup)')
args = p.parse_args()
template = '''---
layout title published categories
post
Hackers Guide to Purdue Computer Engineering
false
blog

#Contents ##Introduction

@swanson
swanson / blobs.json
Created July 10, 2011 00:09
github v3 api digging
GET https://api.github.com/repos/swanson/swanson.github.com/git/blobs/957e6b4efb22fa921d0e6b17a1fbf46788c97ed3
HTTP/1.1 200 OK
Server: nginx/1.0.4
Date: Sun, 10 Jul 2011 00:08:16 GMT
Content-Type: application/json
Connection: keep-alive
Status: 200 OK
X-RateLimit-Limit: 5000
X-RateLimit-Remaining: 4988