Skip to content

Instantly share code, notes, and snippets.

View skinp's full-sized avatar

Patrick Pelletier skinp

View GitHub Profile
@skinp
skinp / shell.py
Created March 30, 2012 16:49
Basic web shell in python
#!/usr/bin/env python
import cgi
import subprocess
import cgitb
cgitb.enable()
def run(command):
if not command:
@skinp
skinp / tailf.py
Created March 30, 2012 15:24
Tail -f implementation in python
import time
def tailf(filename):
f = open(filename, 'r')
f.seek(0,2)
while True:
line = f.readline()
if not line:
time.sleep(0.1)
continue
@skinp
skinp / genpass.py
Created May 8, 2012 13:53
Simple python password generator
#!/usr/bin/env python
# genpass.py
# Random password generation
# author: Patrick Pelletier
import md5
import random
def genpass(len=20):
''' generates a random password based on the md5 of a random float '''
@skinp
skinp / Vagrantfile
Created July 29, 2013 01:14
Vagrantfile supporting multiple providers (VirtualBox, AWS, LXC)
# -*- mode: ruby -*-
# vi: set ft=ruby :
BOX_NAME = ENV['BOX_NAME'] || "ubuntu"
BOX_URI = ENV['BOX_URI'] || "http://files.vagrantup.com/precise32.box"
AWS_REGION = ENV['AWS_REGION'] || "us-east-1"
AWS_AMI = ENV['AWS_AMI'] || "ami-23d9a94a"
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
@skinp
skinp / basic_auth.py
Created January 11, 2013 02:15
Python basic auth using urllib2
import urllib2, base64
request = urllib2.Request("http://api.url")
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
result = urllib2.urlopen(request)
@skinp
skinp / file_completion.py
Created January 10, 2013 21:13
Primitive file completion in python
#!/usr/bin/env python
import readline
import glob
def complete(text, state):
for file in glob.glob(text+"*"):
if not state:
return file
else:
state -= 1
@skinp
skinp / python_tab_complete.md
Last active December 10, 2015 22:48
Enabling tab completion in default python interpreter

Add this to your PYTHONSTARTUP (~/.pythonrc.py) file:

try:
    import readline
except ImportError:
    print "Module readline not available."
else:
    import rlcompleter
 readline.parse_and_bind("tab: complete")
@skinp
skinp / google.py
Created November 2, 2012 20:38
Google reader star list
#!/usr/bin/env python
import urllib
import urllib2
import getpass
from xml.dom import minidom
class Grua:
def __init__(self, username, password):
@skinp
skinp / git-env-setup.sh
Created September 25, 2012 18:54
Setup git environment
#!/bin/bash
if [ $# -ne 2 ]
then
echo "Usage: $0 <name> <email>"
exit 1
fi
git config --global user.name $1
git config --global user.email $2
@skinp
skinp / timing.py
Created June 18, 2012 14:19
Context manager to time python code...
from timeit import default_timer
class Timer(object):
def __init__(self, verbose=False):
self.verbose = verbose
self.timer = default_timer
def __enter__(self):
self.start = self.timer()