Skip to content

Instantly share code, notes, and snippets.

View galvez's full-sized avatar

Jonas Galvez galvez

View GitHub Profile
var div = $('<div/>', {
id: 'example',
css: {
height: '100px',
width: '100px',
color: 'blue',
backgroundColor: 'green'
},
click: function() {
$(this).css('backgroundColor', 'red');
// 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;
}
};
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;
}
}
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAyoM5qaqZCLSYoB5IIH4uDMOR8VF2NPqc9pd2gMQYZKoc9pNlcBClfz9ZwT92TZejgG7EqHy/LYRY4w2Fp7y3im6zhGvMgcysUfRKUv6wViZDkEoOrVJl8eJAhuwugVGtkuE7kkq37+IcEjoUmMg53KCbrkW8tRiJz4c62MT49U5m5T08hyFsGoZl4QEEwJ1VQmDKuD4YMK9ekbWEafr7NKMgUXW5iKEKnCtiwtPI6z6/QYzW9Ci2gPkgvJERfBBdjYI1DCvFJI13rJ+kJLatXkMtjm2eBxec5eIAMuClBnV1sxcOnvGgJnd4BIrXAGTRAkxpvj4zWxDKu4i0+foElQ== jonas@celine
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);
}
// Simple D3-based square graph generator
// To display accomplished pomodoros in each weekday
// Used in hire.jonasgalvez.com.br
function shuffle(array) {
// https://github.com/coolaj86/knuth-shuffle
var currentIndex = array.length, temporaryValue, randomIndex ;
while (0 !== currentIndex) {
# 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)
@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/
"""
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 / __init__.py
Created November 30, 2010 17:50
Bootstrap code for a fabfile module that automatically loads all .py files and makes all pre-loaded libraries available to them
from __future__ import with_statement
from fabric.api import *
from code import interact
import os
import sys
import time
APP_ROOT = os.path.abspath(os.path.dirname(__file__))