Skip to content

Instantly share code, notes, and snippets.

View paulsmith's full-sized avatar
😀
Hi, friends

Paul Smith paulsmith

😀
Hi, friends
View GitHub Profile
@paulsmith
paulsmith / echo.go
Created January 12, 2011 06:09
A simple echo server testing a few interesting Go language features, goroutines and channels.
// $ 6g echo.go && 6l -o echo echo.6
// $ ./echo
//
// ~ in another terminal ~
//
// $ nc localhost 3540
package main
import (
@paulsmith
paulsmith / daemon.py
Created November 19, 2010 01:22
Library functions for daemonizing in the standard POSIX way, per Stevens et. al.
"""
Helpful utilities for running a standard POSIX daemon.
- daemonize() - creates a proper POSIX daemon
- already_running() - ensures a single instance of the daemon
- get_logger() - sets up logging to syslog for the daemon
- drop_privileges() - change user if started with superuser
Reference: Advanced Programming in the UNIX Environment, 2nd Ed.,
Stevens, pg. 426, 432, 454.
#!/bin/sh -e
#
# ~ liberty.sh ~
#
# Linux port of the Freedom network-disabling software for Mac & Win:
# http://macfreedom.com/
#
# It is a Linux version of beloved Mac/Win software, therefore it is
# appropriately obscure and hard to use (but free!).
#
#!/usr/bin/env python
import urllib, os, time, glob, urlparse, errno, sys, getpass, re
from xml.dom.minidom import parseString as parse
API_PATH = '/api/read'
MAX_NUM_PER_REQUEST = 50
class BadLogin(Exception): pass
def make_api_url(tumblr):
#!/usr/bin/env python
"""
Tallies up the geocoded tweets and geo-enabled users in your Twitter social graph / friend
timeline, at most for the last 3,200 friend tweets (as rate-limited by the Twitter API)
Prints some stats to stderr, the geocoded tweets in JSON format to stdout
I would execute it like so:
$ ./geo_tweet_stats.py username password | tee geotweets.json
#!/bin/bash
set -e -x
export DEBIAN_FRONTEND=noninteractive
apt-get update && apt-get install -y siege
siege -c 100 --time=10m --user-agent="Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.2pre) Gecko/20100207 Ubuntu/9.10 (karmic) Namoroka/3.6.2pre" http://ec2-174-129-96-143.compute-1.amazonaws.com/index.html
shutdown -h now
import urllib, re
from pprint import pprint as pp
from datetime import datetime, timedelta
from geopy.geocoders import Google
import MySQLdb
from time import sleep
bcpd_arc_url = "http://maps.baltimorepolice.org/servlet/com.esri.esrimap.Esrimap?ServiceName=BaltimorePolice&CustomService=Query&ClientVersion=3.1&Form=True&Encode=False"
districts={"Northwest":
FF 3.5
| Run | String(fn) | fn + "" |
|-----+-------------+-----------|
| 1 | 0.658 | 0.617 | (time in sec.)
| 2 | 0.666 | 0.617 |
| 3 | 0.651 | 0.61 |
| 4 | 0.651 | 0.611 |
| 5 | 0.653 | 0.621 |
|-----+-------------+-----------|
@paulsmith
paulsmith / markov.clj
Created November 9, 2009 20:56
Another toy Markov chain generator, this time in Clojure
(def state (ref {}))
(def nonword "\n")
(defn get-words
[]
(loop [words []]
(let [line (read-line)]
(if (nil? line)
words
@paulsmith
paulsmith / example_output.txt
Created November 3, 2009 16:24
A toy Markov chain generator, primed with magazine-length article text by The Nation's Chris Hayes
Rush Limbaugh all tore into him as nominee, could completely
alter the structure of her considerable enthusiasm into
persuading even the rare greater red horse that make solar cells,
a Ways and Means they are also, by and large ways, in gentler,
politer interactions with ministers and churches. That's really
how I first came into this thinking it was easy to surmise that
the mainstream of his shot-up airplane that paralyzed his right
arm paralyzed. Or the story of the world over, and scapegoating
the brown-skinned Other who is seeking an exemption in the
country--and board chair Hank Dittmar, an expert on ...