Skip to content

Instantly share code, notes, and snippets.

View jorgebastida's full-sized avatar

Jorge Bastida jorgebastida

View GitHub Profile
@jorgebastida
jorgebastida / Blizzard Wow Blue Post
Created November 29, 2010 15:17
Using lxml, parse a wow blizzard forum to discover blue posts
# encoding: utf-8
import urllib
from lxml.html import fromstring
URL = 'http://eu.battle.net/wow/es/forum/975481/'
def is_blue_post(element):
return len(element.getparent().cssselect('.blizzard_icon')) > 0
if __name__ == '__main__':
>>> a = "Ciudad south=Enolmu east=Dixu west=Dodala north=Trololo"
>>> dict([direction.split('=') for direction in a.split()[1:]])
{'west': 'Dodala', 'east': 'Dixu', 'north': 'Trololo', 'south': 'Enolmu'}
@jorgebastida
jorgebastida / gist:1023399
Created June 13, 2011 18:41
Tuenti ejercicio 1
import re
OPERADORES = {'^=': lambda x,y: x+y,
'^@': lambda x,y: x-y,
'^#': lambda x,y: x*y}
OP_RE = r'(\^\=|\^\@|\^\#) (\-?\d+)( \-?\d+)?\$'
def componer(op):
return '%s$' % ' '.join(op)
@jorgebastida
jorgebastida / ipdb.sublime-snippet
Created June 15, 2011 08:42
Sublime text 2 ipdb snippet - import ipdb; ipdb.set.trace()
<snippet>
<content><![CDATA[import ipdb; ipdb.set_trace()]]></content>
<tabTrigger>ipdb</tabTrigger>
<scope>source.python</scope>
<description>ipdb</description>
</snippet>
@jorgebastida
jorgebastida / gist:1129856
Created August 6, 2011 22:59
Distribute an amount among n users.
from decimal import Decimal
def distribute(amount, n, decimals=2):
"""
Distribute an amount among n users.
* Returns a list of Decimals.
>>> allocate(0.02, 3)
[Decimal('0.01'), Decimal('0.01'), Decimal('0.0')]
@jorgebastida
jorgebastida / gist:1221680
Created September 16, 2011 09:37
My .gitconfig
# My .gitconfig
# C&P from http://cheat.errtheblog.com/s/git
[user]
name = NAME
email = EMAIL
[color]
ui = auto
@jorgebastida
jorgebastida / gist:1886036
Created February 22, 2012 17:01
Get credit card type by number
import re
def credit_card_type(number):
"""
Return a string that represents the type of the credit card number.
Criteria:
AMEX: Starts with 34 or 37 and the length 15.
MASTERCARD: Starts with 51-55 and the length is 16.
@jorgebastida
jorgebastida / search.py
Created April 13, 2012 09:44 — forked from javisantana/search.py
search like a real hacker
#index is like this
index = [
('content indexed', object_id),
('test string', 1),
...
]
def _search(q):
if q:
q = q.lower()
@jorgebastida
jorgebastida / index.html
Created April 22, 2012 15:28
Step 01 -> 02 First template
tweets = [
{'user_name':'jorgebastida', 'message': 'Hello world!', 'timestamp': datetime.now()},
{'user_name':'jaimeirurzun', 'message': 'I like ponies :D', 'timestamp': datetime.now()},
{'user_name':'jorgebastida', 'message': 'Django rulezzzzz', 'timestamp': datetime.now()}
]
# Project Page: https://github.com/jorgebastida/glue
# command
glue glyphicons/ out --ignore-filename-paddings --namespace= --crop --padding=5 --order=height
# output png
http://dl.dropbox.com/u/567726/glyphicons.png