Skip to content

Instantly share code, notes, and snippets.

View psobot's full-sized avatar

Peter Sobot psobot

View GitHub Profile
@psobot
psobot / ontarioPostalCode.php
Created February 1, 2011 21:41
Detects the validity of an Ontario postal code.
<?php
function isOntarioPostalCode($string){
return preg_match("%[PKLNM]\d[ABCEGHJKLMNPRSTVWXYZ]( )?\d[ABCEGHJKLMNPRSTVWXYZ]\d%i"), $string);
}
?>
@psobot
psobot / excluded_sources.txt
Last active January 26, 2018 14:41
"The Street Preacher" - hyper-local twitter bot
<a href="http://foursquare.com" rel="nofollow">foursquare</a>
<a href="http://instagram.com" rel="nofollow">Instagram</a>
@psobot
psobot / jobmine_parse.rb
Created January 16, 2012 01:43
Jobmine MySQL Dumper
# Jobmine Data Parser v0.1
# Peter Sobot, January 15, 2012
#
# Takes in a Jobmine search result dump (i.e.: "ps.xls" which is actually HTML)
# puts it all into a DB for easy self-searching and fun
#
# Assumed table system:
#
# CREATE TABLE `jobs` (
@psobot
psobot / exceptionthread.py
Created April 14, 2012 19:05
Exception-Raising Thread
import Queue
import threading
import sys
__author__ = 'psobot'
class ExceptionThread(threading.Thread):
def __init__(self, *args, **kwargs):
threading.Thread.__init__(self, *args, **kwargs)
self.__status_queue = Queue.Queue()
@psobot
psobot / lame.py
Created April 14, 2012 19:34
Asynchronous MP3 encoding in Python
from Queue import Queue
import subprocess
import threading
import traceback
import logging
import time
log = logging.getLogger(__name__)
"""
@psobot
psobot / randomthumbs.rb
Created April 22, 2012 00:49
Random Image Thumbnailer
# Hacky random image thumbnailer.
# by Peter Sobot, April 21, 2012
# Based heavily on code by Michael Macias
# (https://gist.github.com/a54cd41137b678935c91)
require 'rmagick'
images = Dir.glob(ARGV[0] ? ARGV[0]
: '-default-input-paths-')
output_dir = (ARGV[1] ? ARGV[1]
@psobot
psobot / example.nginx.conf
Created May 9, 2012 03:35
API proxying with nginx
proxy_cache_path /tmp/recipe_cache levels=1:2 keys_zone=RECIPE:64m inactive=3600m max_size=360m;
# Yada yada yada...
server {
# Yada yada yada, more in here...
location ^~ /recipes {
rewrite ^/recipes\??(.*) /recipes?key={your_private_api_key_here}&$1 break;
@psobot
psobot / multiprocesscallback.py
Created May 13, 2012 20:28
Cross-process Python Callbacks
"""
multiprocesscallback.py, by Peter Sobot (psobot.com), May 13, 2012
Handles callback functions in classes that have member functions that
are executed in a different process. A crazy experiment in Python
magic that breaks a lot of rules.
Do not use in production, for any reason. (Although I do.)
If your class takes in a callback, like so:
@psobot
psobot / roundingdict.py
Created June 1, 2012 04:11
Rounded Dictionary Access in Python
class RoundingDict(dict):
def __getitem__(self, key):
if key in self:
return dict.__getitem__(self, key)
try:
values = [abs(x - key) for x in self.keys()]
return self.values()[values.index(min(values))]
except (TypeError, ValueError):
raise KeyError(key)
@psobot
psobot / fmod.py
Created July 8, 2012 18:35
Binary File Change Monitor in Python
"""
Detect exactly which bytes have changed in a file.
Useful for binary reverse engineering:
- Start script
- Save file from program, changing one attribute
- See which byte(s) have changed
"""
import os
import traceback