Skip to content

Instantly share code, notes, and snippets.

Avatar

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 https://github.com/*
// @include http://github.com/*
// @include http://gist.github.com/*
// ==/UserScript==
function change_font() {
var pres = document.getElementsByTagName('pre');
View README
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.
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 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')
View identification_tests
>>> 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:
View gist:128840
'''
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
View dbutils.py
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):
View regioes_br_checkboxes_helper.rb
REGIOES_BRASILEIRAS = {
'Norte' => [
['Acre', 'AC'],
['Amapá','AP'],
['Amazonas', 'AM'],
['Pará', 'PA'],
['Rondônia', 'RO'],
['Roraima', 'RR'],
['Tocantins', 'TO']
],
View tlsrelay.py
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)
View remove_all_svn_dirs.sh
# 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()]"
You can’t perform that action at this time.