Skip to content

Instantly share code, notes, and snippets.

@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 -*-
@konstantint
konstantint / spawn.cpp
Created November 14, 2014 17:28
Example of communication with a subprocess via stdin/stdout
//
// Example of communication with a subprocess via stdin/stdout
// Author: Konstantin Tretyakov
// License: MIT
//
#include <ext/stdio_filebuf.h> // NB: Specific to libstdc++
#include <sys/wait.h>
#include <unistd.h>
#include <iostream>
# 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
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 / 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 / earlystopping_mnist.py
Last active August 30, 2020 00:20
Early Stopping Experiment with MNIST
# Early Stopping Experiment with MNIST
# http://fouryears.eu/2017/12/05/the-mystery-of-early-stopping/
#
# Code adapted from: https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py
# By: Konstantin Tretyakov
# License: MIT
import keras
from keras.datasets import mnist
from keras.models import Sequential
@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
@konstantint
konstantint / Program.cs
Last active October 27, 2022 15:36
A program for adding ten numbers
// Source code for the post:
// https://www.quora.com/Can-you-write-a-program-for-adding-10-numbers/answer/Konstantin-Tretyakov
// http://fouryears.eu/2018/03/17/a-program-for-adding-10-numbers/
//
// Runs with the following config.xml:
// <Config>
// <InputProvider class="Enterprise.NumberSequenceProvider"/>
// <OutputConsumer class="Enterprise.PeanoNumberPrinter"/>
// <Solution class="Enterprise.TenNumberAddingSolution">
// <Strategy class="Enterprise.AdditionStrategy"/>