Skip to content

Instantly share code, notes, and snippets.

View kennethreitz's full-sized avatar
🐍

Kenneth Reitz kennethreitz

🐍
View GitHub Profile
@kennethreitz
kennethreitz / helpers.py
Created March 9, 2010 22:12
Random Python helper functions
# encoding: utf-8
""" Python General Helpers
Copyright (c) 2010 Kenneth Reitz. Creative Commons Attribution 3.0 Lisense.
"""
import urllib, re, time
import paramiko
def enc(str):
@kennethreitz
kennethreitz / attrib.regex
Created March 11, 2010 20:46
Regex to match any html attribute, and its value.
attrib="[^"\r\n]*"
@kennethreitz
kennethreitz / current.jquery.js
Created March 23, 2010 14:17
jQuery: Find current path, and wrap in em's
$.fn.markCurrentLocation = function() {
var path = window.location.href
return this.each(function(){
var self = $(this);
var href = self.attr('href');
if(RegExp(href).test(path)){
self
.wrap('<em></em>')
}
})
@kennethreitz
kennethreitz / sups.jquery.js
Created March 23, 2010 14:17
jQuery script for sup-ing ordinals.
$.fn.orderedFigure = function() {
return this.each(function(){
var self = $(this);
var cont = self.html();
var cont2 = cont.replace(/(\d)(st|nd|rd|th)/g,'$1<sup>$2</sup>')
self.html(cont2);
})
};
@kennethreitz
kennethreitz / .htaccess
Created March 29, 2010 04:03
Apache htaccess for gzip compression
<IfModule mod_deflate.c>
SetOutputFilter DEFLATE
# file-types indicated will not be compressed
SetEnvIfNoCase Request_URI
\.(?:gif|jpe?g|png|rar|zip|pdf)$ no-gzip dont-vary
<IfModule mod_headers.c>
Header append Vary User-Agent
</IfModule>
</IfModule>
@kennethreitz
kennethreitz / crash-ie6.wp-plugin.php
Created March 31, 2010 16:25
WordPress Plugin that instantly crashes IE6
<?php
/*
Plugin Name: Crash IE 6
Plugin URI: http://gist.github.com/350532
Description: We'll take them by force.
Version: 0.1
Author: Kenneth Reitz
Author URI: http://kennethreitz.com/
Min WP Version: 2.0
Max WP Version: 3.5
@kennethreitz
kennethreitz / backup.php
Created April 5, 2010 07:27
mediatemple-to-s3.php
#!/usr/bin/env php
<?php
set_time_limit(0);
$nDays = 300; // How many days of backups to keep?
// MySQL variables
$bBackupMySQL = true; // Do you want to backup MySQL databases?
$mysql = '/usr/bin/mysql';
$mysqldump = '/usr/bin/mysqldump';
$mysql_server = 'xxxx.com';
$mysql_username = 'xxxx';
@kennethreitz
kennethreitz / dir.js
Created April 19, 2010 21:05
returns all known methods of given object.
function dir(o){
var keys = [];
for(var key in o){
keys.push(key);
}
return keys;
}
@kennethreitz
kennethreitz / slaughter-pyc.sh
Created April 21, 2010 01:17
Death to the bytecode!
find . -name "*.pyc" -exec rm '{}' ';'
sudo curl "http://gist.github.com/raw/372696/bffde4ea5cf23eebd8b0f4ee15708a0a9d0af7f5/ssh-copy-id" -o /usr/local/sbin/ssh-copy-id
sudo chmod +x /usr/local/sbin/ssh-copy-id