Skip to content

Instantly share code, notes, and snippets.

View galvez's full-sized avatar

Jonas Galvez galvez

View GitHub Profile
def try_sending_email():
import os, smtplib, mimetypes
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Encoders import encode_base64
gmail_user = '[user]@gmail.com'
gmail_password = '[password]'
recipient = '[recipient]'
msg = MIMEMultipart()
@galvez
galvez / 2010-10-02-14-00-test-migration.py
Created October 2, 2010 17:45
A minimalist Python migration management script based on Fabric and sqlwitch
# 2010-10-02 14h00
# Update created field in user_prefs table
def migrate(db):
with db.select('user_id, created', from_='users'):
all_users = db.fetchall()
for user in all_users:
with db.update('user_prefs') as obj:
obj.created = user['created']
db.where('user_id = %s', user['user_id'])
@galvez
galvez / gexport.py
Created October 1, 2010 14:54 — forked from mnot/gexport.py
#!/usr/bin/env python
"""\
gexport.py
Export Google Docs to a local directory.
Requires the GData Python client library:
http://code.google.com/p/gdata-python-client/
"""
# sqlwitch tries to give you just the right amount of abstraction for fast MySQL-based web applications.
# Avoid complex and memory hungry ORM libraries while keeping your code easy to maintain:
def get_db_handler(db_auth):
conn = MySQLdb.connect(**db_auth)
cursor = conn.cursor(MySQLdb.cursors.DictCursor)
conn.set_character_set('utf8')
cursor.execute('set names utf8;')
cursor.execute('set character_set_connection = utf8;')
return sqlwitch(cursor, conn)
create_random_id = function(len) {
var id = '', i = Math.ceil(len/2);
with(Math) while(i--)
id += (floor(random()*(256-16))+16).toString(16);
return id.substr(0, len);
}
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyoM5qaqZCLSYoB5IIH4uDMOR8VF2NPqc9pd2gMQYZKoc9pNlcBClfz9ZwT92TZejgG7EqHy/LYRY4w2Fp7y3im6zhGvMgcysUfRKUv6wViZDkEoOrVJl8eJAhuwugVGtkuE7kkq37+IcEjoUmMg53KCbrkW8tRiJz4c62MT49U5m5T08hyFsGoZl4QEEwJ1VQmDKuD4YMK9ekbWEafr7NKMgUXW5iKEKnCtiwtPI6z6/QYzW9Ci2gPkgvJERfBBdjYI1DCvFJI13rJ+kJLatXkMtjm2eBxec5eIAMuClBnV1sxcOnvGgJnd4BIrXAGTRAkxpvj4zWxDKu4i0+foElQ== jonas@celine
utils = {
subset_of: function(arr) {
for(var i = arr.length, d = {}; i--;) d[arr[i]] = 1;
var p, before = 0, after = 0;
for(p in d) before++;
for(i = this.length; i--;) d[this[i]] = 1;
for(p in d) after++;
return after == before;
}
}
// I wonder if there's anything like this already (there probably is)
Tag = function(name, content) {
this.name = name;
if(typeof content == 'function') {
this.content = content.call(null, this).toString();
} else {
this.content = content;
}
};
var div = $('<div/>', {
id: 'example',
css: {
height: '100px',
width: '100px',
color: 'blue',
backgroundColor: 'green'
},
click: function() {
$(this).css('backgroundColor', 'red');
// 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 {