Skip to content

Instantly share code, notes, and snippets.

View klizhentas's full-sized avatar
Be kind

Alexander Klizhentas klizhentas

Be kind
View GitHub Profile
from time import time
from logging.config import fileConfig
from twisted.internet import epollreactor
epollreactor.install()
from flask import Flask, request
app = Flask(__name__)
fileConfig("logging.ini")
@klizhentas
klizhentas / twisted_flask
Created June 13, 2013 16:28
Twisted.wsgi + thread pool + flask
from time import time
from logging.config import fileConfig
from twisted.internet import epollreactor
epollreactor.install()
from flask import Flask, request
app = Flask(__name__)
fileConfig("logging.ini")
@klizhentas
klizhentas / dns-http
Created August 30, 2013 01:14
DNS server configurable via http
# http://notmysock.org/blog/hacks/a-twisted-dns-story.html
# http://blog.inneoin.org/2009/11/i-used-twisted-to-create-dns-server.html
# twistd -y dns.py
import socket
from twisted.internet import reactor
from twisted.names import dns
from twisted.names import client, server
from twisted.web.server import Site
import klein
@klizhentas
klizhentas / gist:6419458
Last active December 22, 2015 04:48
Twisted MX
from operator import attrgetter, itemgetter
from itertools import groupby, chain
from random import shuffle
from twisted.names.client import Resolver
from twisted.internet import defer
from twisted.python import log
def init(config):
R.resolver = Resolver(resolv='/etc/resolv.conf')
@klizhentas
klizhentas / gist:6528324
Created September 11, 2013 19:09
Counters with TTL
CREATE TABLE hits (
hit text PRIMARY KEY,
counter counter
) WITH COMPACT STORAGE;
UPDATE hits USING TTL 3600 SET counter = counter + 1 WHERE hit='api-call-some-hour';
@klizhentas
klizhentas / gist:6690608
Created September 24, 2013 20:17
Cassandra
:cluster_name => "Mailgun Tanks",
:initial_token => "",
:version => '1.2.5',
:user => "cassandra",
:jvm => {
:xms => 32,
:xmx => 512
},
:limits => {
:memlock => 'unlimited',
@klizhentas
klizhentas / aggregate.py
Created October 24, 2013 01:11
Aggregator that collects events from keen.io and flushes them in batches
"""Aggregates events in batches and flushes them after max batch size
have been achieved or certain amount of seconds has passed
"""
import logging
from threading import Lock
from datetime import datetime
log = logging.getLogger(__name__)
FLUSH_SECONDS = 3
@klizhentas
klizhentas / mongo
Created October 25, 2013 20:51
Mongo
from mailgun/base:latest
ENV DEBIAN_FRONTEND noninteractive
ENV MONGO_VERSION 2.4.5
ENV MONGO_PLATFORM linux-x86_64
ENV MONGO_DISTRO linux-x86_64-2.4.5
ENV MONGO_PORT 27016
ENV MONGO_DBPATH /var/mongodb
run wget http://fastdl.mongodb.org/linux/mongodb-$MONGO_DISTRO.tgz
from mailgun/base:latest
ENV DEBIAN_FRONTEND noninteractive
run apt-get install -y postgresql-9.1 postgresql-contrib-9.1
add . /src
run cp /src/*.conf /etc/postgresql/9.1/main/
run su postgres sh -c "/usr/lib/postgresql/9.1/bin/postgres --single -D /var/lib/postgresql/9.1/main -c config_file=/etc/postgresql/9.1/main/postgresql.conf" < /src/psql-init.sql
run su postgres sh -c "/usr/lib/postgresql/9.1/bin/postgres --single mg_dev -D /var/lib/postgresql/9.1/main -c config_file=/etc/postgresql/9.1/main/postgresql.conf" < /src/create-extension.sql
run su postgres sh -c "/usr/lib/postgresql/9.1/bin/postgres --single mg_test -D /var/lib/postgresql/9.1/main -c config_file=/etc/postgresql/9.1/main/postgresql.conf" < /src/create-extension.sql
from ubuntu:12.04
ENV DEBIAN_FRONTEND noninteractive
run apt-get -y install aptitude curl emacs wget net-tools less
# install Java 6
run wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F" http://download.oracle.com/otn-pub/java/jdk/6u45-b06/jdk-6u45-linux-x64.bin
run chmod u+x jdk-6u45-linux-x64.bin
run ./jdk-6u45-linux-x64.bin
run mv jdk1.6.0_45 /opt