Skip to content

Instantly share code, notes, and snippets.

View MaxMorais's full-sized avatar
🏢
Building TechMax Soluções

Maxwell Morais MaxMorais

🏢
Building TechMax Soluções
View GitHub Profile
import lxml.etree
def pprint(elem):
print lxml.etree.tostring(elem, pretty_print=True)
class Bind(object):
def __init__(self, path, converter=None, first=False):
'''
path -- xpath to select elements
converter -- run result through converter
first -- return only first element instead of a list of elements
@mumrah
mumrah / websocketserver.py
Created August 7, 2010 17:01
Simple WebSockets in Python
import time
import struct
import socket
import hashlib
import sys
from select import select
import re
import logging
from threading import Thread
import signal
@TheNicholasNick
TheNicholasNick / ishikawa_sha1.js
Created November 25, 2010 01:19
Takanori Ishikawa's JavaScript implementation of the Secure Hash Algorithm 1 (SHA1)
/*
* The JavaScript implementation of the Secure Hash Algorithm 1
*
* Copyright (c) 2008 Takanori Ishikawa <takanori.ishikawa@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
@jbpotonnier
jbpotonnier / gtranslate.py
Created February 12, 2011 18:56
Translate between french and english using google api
# -*- coding: iso-8859-15 -*-
import Tkinter as tkinter
import urllib2, urllib
import json
TRANSLATE_URL = 'http://ajax.googleapis.com/ajax/services/language/translate'
TO_ENGLISH = 'fr|en'
TO_FRENCH = 'en|fr'
@gagarine
gagarine / mysql_multiple_import.bash
Created February 24, 2011 22:34
Import multiple sql file in a mysql database
#!/bin/bash
db=$1
user=$2
passwd=$3
if [ "$db" = "" ]; then
echo "Usage: $0 db_name user password"
exit 1
fi
clear
for sql_file in *.sql; do
var TinyORM = (function(options) {
/* a hash containing all the available models */
var Models = {};
var connection = null;
var config = _.extend({
/* The name of the database which Ti will open. The local db is located at:
~/Library/Application Support/iPhone Simulator/4.2/Applications/APP_ID/Library/Application Support/database/dbname
*/
dbname: 'add.db',
@ederwander
ederwander / gist:1342497
Created November 6, 2011 05:01
Accessing the Google Speech API + Python
# Copyright (c) 2011, Eng Eder de Souza
# ___ _ _ ___
# | __|__| |___ _ _ __| |___ / __| ___ _ _ _____ _
# | _|/ _` / -_) '_| / _` / -_) \__ \/ _ \ || |_ / _` |
# |___\__,_\___|_| \__,_\___| |___/\___/\_,_/__\__,_|
#Accessing the Google API for speech recognition!
#Open a file type Wav to speech recognition
#This source does not require any external programs to perform audio conversions :-)
#http://ederwander.wordpress.com/2011/11/06/accessing-the-google-speech-api-python/
#Eng Eder de Souza
@glenrobertson
glenrobertson / white_noise_image.py
Created April 3, 2012 00:05
get PIL white noise image
from PIL import Image
def get_white_noise_image(width, height):
pil_map = Image.new("RGBA", (width, height), 255)
random_grid = map(lambda x: (
int(random.random() * 256),
int(random.random() * 256),
int(random.random() * 256)
), [0] * width * height)
pil_map.putdata(random_grid)
@lsbardel
lsbardel / async.py
Created May 8, 2012 16:15
A micro-asyncronous script derived from twisted
'''A micro-asyncronous script derived from twisted.'''
import sys
import traceback
from collections import deque
__all__ = ['Deferred', 'MultiDeferred']
def iterdata(stream):
@rmehta
rmehta / gist:3866677
Created October 10, 2012 16:20
client event trigger example
// add a trigger on field "custom_field1"
cur_frm.cscript.custom_field1 = function(doc, cdt, cdn) {
// update a new field "custom_field3"
doc.custom_field3 = flt(doc.custom_field1)*flt(doc.custom_field2)/1000;
// refresh in form
refresh_field('custom_field3');
}