Skip to content

Instantly share code, notes, and snippets.

function LiveWatcher(watch_posts, watch_users) {
var self = this;
var _oldListener;
function newListener(d) {
var el = document.createElement('div');
el.innerHTML = JSON.parse(d.data).data;
var post_id = parseInt(el.childNodes[0].getAttribute("data-post_id"));
var user_login = el.childNodes[0].getAttribute("data-user_login");
@konstantint
konstantint / gist:3911953
Created October 18, 2012 13:50
Python: Namespace package __init__.py
# Namespace package
try:
__import__('pkg_resources').declare_namespace(__name__)
except ImportError:
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
@konstantint
konstantint / gist:3914476
Created October 18, 2012 20:08
Buildout: Boilerplate buildout.cfg
[buildout]
# Egg names
project-eggs =
# my-module
# Egg directories
#develop =
# my-module
# Build parts (add develop eggs if needed)
@konstantint
konstantint / gist:3952876
Created October 25, 2012 14:31
Python: UTF-8 encoding specifier
# -*- coding: utf-8 -*-
# Recreational computational human bananology.
# Copyright (c) 2015, Konstantin Tretyakov
# http://fouryears.eu/2015/04/12/two-bananas-make-a-human/
# ------------------------ Imports and utility functions ---------------- #
import gzip
import csv
import urllib
from ucscgenome import Genome
from Bio import SeqIO
@konstantint
konstantint / paul_and_simon_sort.py
Created July 25, 2017 13:58
Paul and Simon Sort
# "Paul-and-Simon sort"
# http://fouryears.eu/2017/07/25/sorting-in-linear-time/
# http://www-wjp.cs.uni-saarland.de/publikationen/PS80.pdf
#
# Copyright 2017, Konstantin Tretyakov
# License: MIT
from math import log2, ceil
def paul_and_simon_sort(a):
@konstantint
konstantint / fig5.py
Created March 6, 2018 21:42
Secrets of Spring Motion - Figure 5
# Figure 5 from http://fouryears.eu/2016/11/17/the-secrets-of-spring-motion/
# Intended to be run from a Jupyter notebook cell
%pylab inline
g = 9.18
k = 2.0 * 8
L = 1.0
m = 1.0/9
# Executable transcript of https://www.digitalocean.com/community/tutorials/how-to-set-up-an-openvpn-server-on-ubuntu-16-04
sudo apt update
sudo apt install -y openvpn easy-rsa python
make-cadir ~/openvpn-ca
cd ~/openvpn-ca
cat <<EOT >> vars
# New values
export KEY_COUNTRY="EE"
export KEY_PROVINCE="Some Province"
@konstantint
konstantint / dsw-1.py
Created December 2, 2018 02:45
The Data Science Workflow blogpost, code snippet 1
import sqlalchemy as sa
import pandas as pd
e = sa.create_engine("sqlite:///raw_data.sqlite")
pd.read_csv("raw_data.csv").to_sql("raw_data", e)
@konstantint
konstantint / dsw-2.sql
Created December 2, 2018 02:50
The Data Science Workflow post, snippet 2
select
s.Key
v1.AverageTimeSpent,
v1.NumberOfClicks,
v2.Country
v3.Purchase as Target
from vw_TrainSample s
left join vw_BehaviourFeatures v1 on v1.Key = s.Key
left join vw_ProfileFeatures v2 on v2.Key = s.Key
left join vw_TargetFeatures v3 on v3.Key = s.Key