This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name github-source-font-change.user.js | |
// @description Script to change the source code viewer font in GitHub | |
// @include https://github.com/* | |
// @include http://github.com/* | |
// @include http://gist.github.com/* | |
// ==/UserScript== | |
function change_font() { | |
var pres = document.getElementsByTagName('pre'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is some skeleton code to building a RESTful API using | |
web.py 0.3, my own xmlbuilder library and cElementTree for | |
generating and parsing XML, respectively; and Python's | |
low-level MySQLdb library. | |
It shows some conventions that I've adopted which are really | |
not very mature yet. It will eventually evolve into a well | |
defined set of standards and practices and SQLAlchemy is | |
also likely to be thrown into the mix in the future. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re, os | |
path = r'C:\Home\OldMusic' | |
def get_files_out_of_subdirs(path): | |
base_level_len = len(path.split(os.path.sep)) | |
for n, d, files in os.walk(path): | |
n = n.split(os.path.sep) | |
top_level = (len(n) == base_level_len+1) | |
if top_level: top_level_dir = n | |
if not top_level: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ok, let's filter artist names based on bigram occurrence | |
bigrams = ss_vector[:6] | |
if len(bigrams) == 6: | |
like1 = '%%s%%s%%%s%' % (bigrams[0], bigrams[2], bigrams[4]) | |
like2 = '%%s%%s%%%s%' % (bigrams[1], bigrams[3], bigrams[5]) | |
db.execute('select a.id as artist_id, a.name as artist_name from artists a where a.name like %s;', (like1,)) | |
likes1 = db.fetchall() | |
db.execute('select a.id as artist_id, a.name as artist_name from artists a where a.name like %s;', (like2,)) | |
likes2 = db.fetchall() | |
uniq_likes = uniq(likes1+likes2, 'artist_id') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> URI = "http://api2.aupeo.com/v2/identification" | |
>>> h = httplib2.Http() | |
>>> h.add_credentials('jonas', '[secret]') | |
>>> headers = {'Content-Type': 'application/xml; charset=utf-8'} | |
>>> | |
>>> track_xml = xmlbuilder.builder(version='1.0', encoding='utf-8') | |
>>> with track_xml.track: | |
... with track_xml.artist: | |
... track_xml.name('Cueio Lim\xc3\xa3o') | |
... with track_xml.album: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
jshash, an improved python dictionary. | |
basic functionality comes from web.py's storage() | |
added support for the with-statement | |
if you're running python <2.6, you need to put | |
from __future__ import with_statement |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DBCursor(MySQLdb.cursors.DictCursor): | |
def lock_on_string(self, str, timeout=1000): | |
self.execute('select get_lock(%s, %s);', (str, timeout)) | |
return self.fetchone() | |
def unlock_on_string(str, timeout=1000): | |
self.execute('select release_lock(%s);', (str,)) | |
return self.fetchone() | |
@staticmethod | |
def instantiate(*args, **kargs): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REGIOES_BRASILEIRAS = { | |
'Norte' => [ | |
['Acre', 'AC'], | |
['Amapá','AP'], | |
['Amazonas', 'AM'], | |
['Pará', 'PA'], | |
['Rondônia', 'RO'], | |
['Roraima', 'RR'], | |
['Tocantins', 'TO'] | |
], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TLSRelay(server.Relay): | |
def __init__(self, host='127.0.0.1', port=25, debug=0, use_tls=False, auth={}): | |
self.use_tls = use_tls | |
self.auth = auth | |
self.hostname = host | |
self.port = port | |
self.debug = debug | |
def deliver(self, message, To=None, From=None): | |
relay_host = smtplib.SMTP(self.hostname, self.port) | |
relay_host.set_debuglevel(self.debug) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# little monstruosity i wrote, probably done with 10x fewer characters with sed | |
# and maybe 5x fewer characters with ruby, but python is still my native language :) | |
git status | grep \.svn | python -c "import re, sys; sys.stdout.write('\n'.join(set([res[0] for res in [re.findall('file:\s+(.*?\.svn)', line) for line in sys.stdin.readlines()] if len(res) > 0])));" | python -c "import os, sys; [os.system('git rm -rf %s' % line) for line in sys.stdin.readlines()]" |
OlderNewer