Skip to content

Instantly share code, notes, and snippets.

View kennethreitz's full-sized avatar
🐍

Kenneth Reitz kennethreitz

🐍
View GitHub Profile
@kennethreitz
kennethreitz / gist:1294570
Created October 18, 2011 03:54 — forked from Miserlou/gist:1294412
Posting JSON in Python without Requests Library
1 import urllib2
2 import json
221 def basic_authorization(user, password):
222 s = user + ":" + password
223 return "Basic " + s.encode("base64").rstrip()
224
225 def submit_pull_request(user, repo):
226 auth = (settings.username, settings.password)
227 url = 'https://api.github.com/repos/' + user + '/' + repo + '/pulls'
@kennethreitz
kennethreitz / git-hook-functions.sh
Created October 15, 2011 14:07 — forked from evilchili/git-hook-functions.sh
function library for git hooks & a post-receive hook for automatic branch building
#!/bin/bash
GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
if [ -z "$GIT_DIR" ]; then
echo >&2 "fatal: hooks/functions: GIT_DIR not set"
exit 1
fi
read oldrev newrev refname
@kennethreitz
kennethreitz / plumbing.md
Created September 19, 2011 18:41 — forked from schacon/plumbing.md
plumbing cheat sheet

the plumbing commands

  • rev-parse [something]

    • show the SHA of any weird git phrase
  • hash-object -w [file]

    • take any file or stdin and return a blob sha
  • ls-tree (-r) [sha]

  • show the entries of a git tree in the db

@kennethreitz
kennethreitz / oss.textile
Created September 2, 2011 11:28
Open Source Notes

Contributing to Open Source
=======

First Rule: You can find the time
- It doesn’t take much
- Weekends are good
- Find what other time you’re wasting
- Try something that’s not your day job

Second Rule: What to contribute to?

@kennethreitz
kennethreitz / link_header.py
Created July 24, 2011 22:12 — forked from mnot/link_header.py
link_header.py: HTTP Link header parsing
@kennethreitz
kennethreitz / background.html
Created July 22, 2011 05:38
Instapaper Chrome Extension
<script>
chrome.browserAction.onClicked.addListener(function(tab) {
var script = "function iprl5(){var d=document,z=d.createElement('scr'+'ipt'),b=d.body,l=d.location;try{if(!b)throw(0);d.title='(Saving...) '+d.title;z.setAttribute('src',l.protocol+'//www.instapaper.com/j/pUgLJLCrwjg0?u='+encodeURIComponent(l.href)+'&t='+(new Date().getTime()));b.appendChild(z);}catch(e){alert('Please wait until the page has loaded.');}}iprl5();void(0)"
chrome.tabs.executeScript(tab.id, {code: script});
});
</script>
@kennethreitz
kennethreitz / Procfile
Created July 9, 2011 01:53 — forked from pkqk/Procfile
Python on Heroku cedar stack
web: bin/python test-webapp.py
@kennethreitz
kennethreitz / phantom-jasmine-xunit.js
Created June 17, 2011 23:33 — forked from tmpvar/phantom-jasmine-xunit.js
xunit output from jasmine tests
if (phantom.state.length === 0) {
if (phantom.args.length !== 1) {
console.log('Usage: run-jasmine.js URL');
phantom.exit();
} else {
phantom.state = 'run-jasmine';
phantom.open(phantom.args[0]);
}
} else {
window.setInterval(function () {
@kennethreitz
kennethreitz / embed-sample.html
Created June 4, 2011 04:01 — forked from umbrae/embed-sample.html
Read Now + Read Later + Send to Kindle
<!--
rbdWrapper can take several data- attributes:
1. data-url : to specificy a specific URL to link to (useful for index pages)
2. data-text-color : the text color of "Read". 6 digit hex or "transparent"
3. data-bg-color : the bg color. 6 digit hex or "transparent"
4. data-show-send-to-kindle : 1 or 0, whether to show the "send to kindle" button or not.
5. data-show-read : 1 or 0, whether to show the read buttons or not.
A sample is like:
-->
@kennethreitz
kennethreitz / dump_and_restore_DBs.sh
Created April 23, 2011 21:23 — forked from unbracketed/dump_and_restore_DBs.sh
Recipes for dumping and restoring different databases, using different compression formats
#Dump
mysqldump db | gzip -c > db.sql.gz
pg_dump db | gzip -c > db.sql.gz
#use gzip --fast
#Restore
gunzip < db.sql.gz | mysql db
bunzip2 < db.sql.bz2 | mysql db