Skip to content

Instantly share code, notes, and snippets.

Avatar

Patrick Pelletier skinp

View GitHub Profile
@skinp
skinp / Vagrantfile
Created Jul 29, 2013
Vagrantfile supporting multiple providers (VirtualBox, AWS, LXC)
View Vagrantfile
# -*- 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 Jan 11, 2013
Python basic auth using urllib2
View basic_auth.py
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 Jan 10, 2013
Primitive file completion in python
View file_completion.py
#!/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 Dec 10, 2015
Enabling tab completion in default python interpreter
View python_tab_complete.md

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 Nov 2, 2012
Google reader star list
View google.py
#!/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 Sep 25, 2012
Setup git environment
View git-env-setup.sh
#!/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 Jun 18, 2012
Context manager to time python code...
View timing.py
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()
@skinp
skinp / ajax.js
Created Jun 15, 2012
Ajax function call
View ajax.js
function ajax(url, callback) {
var x = new XMLHttpRequest();
x.onreadystatechange = function(){
if (x.readyState == 4) {
callback(x.responseText);
}
};
x.open("GET", url);
x.send();
}
@skinp
skinp / genpass.py
Created May 8, 2012
Simple python password generator
View genpass.py
#!/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 / shell.py
Created Mar 30, 2012
Basic web shell in python
View shell.py
#!/usr/bin/env python
import cgi
import subprocess
import cgitb
cgitb.enable()
def run(command):
if not command:
You can’t perform that action at this time.