This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// add an element to a tree | |
var add_elem = function(tree, value) { | |
if(tree === null) { | |
return { | |
data: value, | |
left: null, | |
right: null | |
}; | |
} | |
if(value <= tree.data) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY: run | |
run: | |
python manage.py runserver | |
.PHONY: clean | |
clean: | |
@find ./ -name "*.pyc" -exec rm -f {} \; | |
@find ./ -name "*~" -exec rm -f {} \; | |
@find ./ -name "__pycache__" -exec rm -f {} \; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(lambda n: dict(zip(['impar', 'par'], [filter(lambda x: x != False, map(lambda x: x if x % 2 else False, range(n))), filter(lambda x: x != False, map(lambda x: x if not x % 2 else False, range(n)))])))(10) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from datetime import datetime | |
from json import loads | |
from time import gmtime, mktime, strptime | |
# LevelDict é um wrapper usando dicionário para LevelDB | |
# https://github.com/maurobaraldi/leveldict | |
from leveldict import LevelJsonDict | |
from requests import get |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class dict_to_obj(dict): | |
def __getattr__(self, name): | |
if name in self: | |
return self[name] | |
else: | |
raise AttributeError("No such attribute: " + name) | |
def __setattr__(self, name, value): | |
self[name] = value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from json import loads | |
from collections import namedtuple | |
def json_to_obj(data): | |
def hook(d): | |
return namedtuple('obj', d.keys())(*d.values()) | |
return json.loads(data, object_hook=hook) | |
>>> json_data = '{"lastUpdate": 1435608300000, "type": "stock", "timeOffSet": -10800000, "total": 5, "data": [{"date": 1428289200000, "high": 5.11, "price": 5.05, "open": 5.05, "low": 5.01}, {"date": 1427943600000, "high": 5.05, "price": 5, "open": 4.93, "low": 4.88}, {"date": 1427857200000, "high": 5.07, "price": 4.91, "open": 5.01, "low": 4.91}, {"date": 1427770800000, "high": 5.14, "price": 4.97, "open": 5.1, "low": 4.97}, {"date": 1427684400000, "high": 5.24, "price": 5.12, "open": 5.18, "low": 5.12}], "today": 1435697531409}' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Abstract Methods and Interfaces in Python | |
# Interfaces are templates for classes with commont attributes to new classes | |
from abc import ABCMeta, abstractmethod | |
class Shape(object): | |
__metaclass__ = ABCMeta |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from timer import Timer | |
from stack import Stack as S | |
from stack_optimized import Stack as SO | |
with Timer() as tstack: | |
st = S(100) | |
(st.push(i) for i in range(100, 200)) | |
(st.pop() for i in range(99)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from http://stackoverflow.com/a/4256130/841339 | |
String.prototype.format = function() { | |
var formatted = this; | |
for (var i = 0; i < arguments.length; i++) { | |
var regexp = new RegExp('\\{'+i+'\\}', 'gi'); | |
formatted = formatted.replace(regexp, arguments[i]); | |
} | |
return formatted; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib2 import urlopen | |
from re import findall, search | |
base_url = "http://link.springer.com" | |
links = [] | |
for i in xrange(1, 13): | |
index = base_url + '/search/page/%d?facet-series="136"&facet-content-type="Book"&showAll=false' % i | |
links.extend(findall('<a class="title" href="(.*?)"', urlopen(index).read())) |