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
#!/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!).
#
@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.
@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 (
ctrl-z
bg
touch /tmp/stdout
touch /tmp/stderr
gdb -p $!
# In GDB
p dup2(open("/tmp/stdout", 1), 1)
p dup2(open("/tmp/stderr", 1), 2)
@paulsmith
paulsmith / Rationale.md
Created July 11, 2011 03:35 — forked from leegao/Rationale.md
JIT for dummies: JIT compiling RPN in python

If you don't care about the explanation, scroll down to find the code, it's 50 some odd lines and written by someone who doesn't know any better. You have been warned.

What it does

This is a very simple proof of concept jitting RPN calculator implemented in python. Basically, it takes the source code, tokenizes it via whitespace, and asks itself one simple question: am I looking at a number or not?

First, let's talk about the underlying program flow. Pretend that you are a shoe connoisseur with a tiny desk. You may only have two individual shoes on that desk at any one time, but should you ever purchase a new one or get harassed by an unruly shoe salesman without realizing that you have the power to say no (or even maybe?), you can always sweep aside one of the two shoes on the desk (the one on the right, because you're a lefty and you feel that the left side is always superior) onto the messy floor, put the other shoe on the right hand side, and then place your newly acquired shoe in

@paulsmith
paulsmith / verbatim_templatetag.py
Created October 25, 2011 19:03 — forked from ericflo/verbatim_templatetag.py
verbatim Django template tag
"""
jQuery templates use constructs like:
{{if condition}} print something{{/if}}
This, of course, completely screws up Django templates,
because Django thinks {{ and }} mean something.
Wrap {% verbatim %} and {% endverbatim %} around those
blocks of jQuery templates and this will try its best
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7zYI1ymIOIRLheIC+/H8xb6Qnc4Kx5w9ofnouIHu1GIhQIlBwNpCZ8EPf85YnixDSwAeIAn/0Ve5b0nxhGERza6QgdiEQcYZSn4r8BjpZrcCUWCPdhi5tjqeHAbUNSOf/I8NLrEvY4ogwmFSYsNrDqE74JhkVSompDrQswor+btJTYavxV5cJN9BINGB5HLtynsDrchoKZ1VnCfVXfgUA9o3Bk+JnKubO4qxw9R0bp/1eJstJys3B1krr9Jn8YIZ7NzPxYUjH53h9QzbwuaYYbWuo+xHAYtsjil5STl7MbSgCMvTvnGdfxo7qiCoezqZMeW5fnJ5gZcncRoXd94TF paulsmith@formax.local
@paulsmith
paulsmith / mayoremanuel-tweets-20120223.txt
Created February 24, 2012 01:50
@mayoremanuel started tweeting again, around 8pm ET
# Decoded from the original reversed ASCII-encoded binary tweets
crl,carl,crl
Idremofyrwrld
thsonesalmstgone
thycameallatonce
ovrwhlmngforce
evrythngdisapprd
brthingfire
timedrgons!
@paulsmith
paulsmith / .bashrc
Created May 31, 2012 20:13
The least user-friendly version of `Freedom' I could come up with
# ~/.bashrc
# Freedom!
freedom () {
sed '/# FREEDOM/{n;s/^#//;}' < /etc/hosts > /tmp/hosts.$$ &&
sudo mv /tmp/hosts.$$ /etc/hosts
}
disable-freedom () {
sed '/# FREEDOM/{n;s/^[^#]/#&/;}' < /etc/hosts > /tmp/hosts.$$ &&
@paulsmith
paulsmith / markov.go
Created August 16, 2012 13:55
Markov chain generator in Go
// Markov chain generator
// Builds chain from stdin, outputs n generated words to stdout
package main
import (
"bufio"
"flag"
"fmt"
"io"
"log"