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):
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)
View gist:263457
# ddiff: Improved diff for directories
# ---------------------------------------------------------------------------------
# This is useful for creating a diff file between two directories.
# It's built upon the tradicional diff program.
# With a difference: it will create diff files for each file present only in the first directory.
# So, for given dirs A and B:
# full-diff A B
View jquery.or.js
// jQuery.fn.or
// $('.dont-exist').or('.does-exist') //=> [.does-exist];
// $('.does-exist').or('.dont-exist') //=> [.does-exist];
or: function(selector, context) {
if ($(this).length > 0) {
return $(this);
} else {
You can’t perform that action at this time.