Skip to content

Instantly share code, notes, and snippets.


Jonas Galvez galvez

View GitHub Profile
View github-source-font-change.user.js
// ==UserScript==
// @name github-source-font-change.user.js
// @description Script to change the source code viewer font in GitHub
// @include*
// @include*
// @include*
// ==/UserScript==
function change_font() {
var pres = document.getElementsByTagName('pre');
This is some skeleton code to building a RESTful API using 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.
View gist:57084
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:
View gist:57938
# 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 as artist_id, as artist_name from artists a where like %s;', (like1,))
likes1 = db.fetchall()
db.execute('select as artist_id, as artist_name from artists a where like %s;', (like2,))
likes2 = db.fetchall()
uniq_likes = uniq(likes1+likes2, 'artist_id')
View identification_tests
>>> URI = ""
>>> 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:
...'Cueio Lim\xc3\xa3o')
... with track_xml.album:
View gist:128840
jshash, an improved python dictionary.
basic functionality comes from's storage()
added support for the with-statement
if you're running python <2.6, you need to put
from __future__ import with_statement
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()
def instantiate(*args, **kargs):
View regioes_br_checkboxes_helper.rb
'Norte' => [
['Acre', 'AC'],
['Amazonas', 'AM'],
['Pará', 'PA'],
['Rondônia', 'RO'],
['Roraima', 'RR'],
['Tocantins', 'TO']
class TLSRelay(server.Relay):
def __init__(self, host='', 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)
# 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()]"