View logreg.py
with pm.Model() as m: | |
pi = data.partner_id.astype('category').cat.codes.values | |
ii = data.item_id.astype('category').cat.codes.values | |
# [rest of priors here] | |
item_sigma = pm.Exponential('item_sigma', 1) | |
b_item = pm.Normal('b_item', 0, item_sigma, shape=ii.nunique()) | |
p = pm.math.invlogit( | |
a |
View andrews-spinner-2.py
with pm.Model() as m2: | |
p = pm.Dirichlet('p', np.ones(8) / 8., shape=8, | |
testval=np.ones(8) / 8.) | |
N = pm.Bound(pm.Poisson, lower=data.sum())('N', mu=8*mean_) | |
succ = pm.Multinomial('succ', n=N, p=p, observed=data) | |
m2.name = 'm2' | |
m2.trace = pm.sample(5000, tune=5000, chains=2) |
View quotient_se.py
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 |
View extract_decorators_xml.py
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): |
View post_json_request.js
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(); |
View same.py
def same(i): | |
a = next(i) | |
return _same(a, i) | |
def _same(a, i): | |
try: | |
b = next(i) | |
except StopIteration: | |
return True |
View scrapy_large_start_urls.py
with open('init_links.csv', 'r') as f: | |
init_links = f.read().split('\n') | |
class LargeSpider(scrapy.Spider): | |
start_urls = init_links |
View gist:8932942
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$ |
View redis.inspector.py
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 |
View decimal_date_json_handlers.py
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) |
NewerOlder