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
roomrate | |
======== | |
{ | |
'city': 'Berlin', | |
'hotel': 'Hilton', | |
'date': '2013-08-09' | |
'room_type': 'single', | |
'occupancy': 2, | |
'avail_count': 13, | |
'booked_count': 4, |
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
def echo_public(): | |
def nested(): | |
print public_ | |
public_ = 5 | |
nested() | |
echo_public() |
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, dumps, JSONEncoder | |
from decimal import Decimal | |
import datetime | |
class Encoder(JSONEncoder): | |
def default(self, obj): | |
if isinstance(obj, Decimal): | |
return '__decimal__' + str(obj) |
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
import redis | |
pool = redis.ConnectionPool(host='localhost', port=6633) | |
red = redis.StrictRedis(connection_pool = pool) | |
from datetime import datetime, timedelta | |
from decimal import Decimal | |
import time | |
import calendar | |
from json import dumps, loads |
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
CREATE OR REPLACE FUNCTION trigger_notify() | |
RETURNS trigger AS | |
$BODY$ | |
BEGIN | |
IF NEW.state = 'pending' THEN | |
EXECUTE 'NOTIFY tickets_pending'||NEW.id::text; | |
RETURN NULL; | |
END IF; | |
END; | |
$BODY$ |
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
with open('init_links.csv', 'r') as f: | |
init_links = f.read().split('\n') | |
class LargeSpider(scrapy.Spider): | |
start_urls = init_links |
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
def same(i): | |
a = next(i) | |
return _same(a, i) | |
def _same(a, i): | |
try: | |
b = next(i) | |
except StopIteration: | |
return True |
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
f = document.createElement('form'); | |
document.body.appendChild(f); | |
f.action = "http://makstat.stat.gov.mk/PXWeb/api/v1/mk/MakStat/InfOpstestvo/DelovniSubjekti/175_InfOpst_Mk_09EntDSL_mk.px"; | |
f.method = 'POST'; | |
f.enctype = "application/json"; | |
// how to set request body? | |
f.submit(); |
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
def extractattr(attr_name): | |
def _decorator(fc): | |
def wrapped(*args, **kwargs): | |
ellist = fc(*args, **kwargs) | |
return [el.attrib[attr_name] for el in ellist] | |
return wrapped | |
return _decorator | |
def extracttext(fc): | |
def wrapped(*args, **kwargs): |
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 scipy import stats | |
import numpy as np | |
def interval_zscore(alpha=0.95): | |
""" | |
Return a zscore corresponding with a confidence interval | |
(e.g., for alpha=0.95, returns 1.96) | |
:param: alpha: float, the width of the confidence interval, default is 0.95 |