Skip to content

Instantly share code, notes, and snippets.

View galvez's full-sized avatar

Jonas Galvez galvez

View GitHub Profile
// ==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 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.
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:
# 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')
>>> 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:
'''
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
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):
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)
@galvez
galvez / gist:263457
Created December 25, 2009 01:39 — forked from leandro/gist:263095
#!/bin/bash
# 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
#
// jQuery.fn.or
//
// $('.dont-exist').or('.does-exist') //=> [.does-exist];
// $('.does-exist').or('.dont-exist') //=> [.does-exist];
$.fn.extend({
or: function(selector, context) {
if ($(this).length > 0) {
return $(this);
} else {