Skip to content

Instantly share code, notes, and snippets.

View oinopion's full-sized avatar

Tomek Paczkowski oinopion

View GitHub Profile
@oinopion
oinopion / books.py
Created February 15, 2014 18:52
Random PR
import json
import random
closeds = json.load(open('closed.json'))
opens = json.load(open('open.json'))
def today(pr):
return pr['created_at'].startswith('2014-02-15')
prs = [p for p in (opens+closeds) if today(p)]
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
# multi_accept on;
}
@oinopion
oinopion / gunicorn.sh
Created December 15, 2011 11:39
Simple wrapper (used mostly in supervisord)
#!/bin/bash
# This script is a wrapper around gunicorn
# It provides clean interface for starting stopping app server
PROJECT_NAME=photon
HOME_DIR=/home/photon
RELEASE_DIR=$HOME_DIR/releases/current
GUNICORN_BIN=$HOME_DIR/bin/gunicorn_django
GUNICORN_PID=$HOME_DIR/pids/gunicorn.pid
# encoding: utf-8
def fib_gen():
a, b = 1, 1
while True:
yield a
a, b = b, a+b
def get_values(iterator, n):
l = []
for i in range(n):
# encoding: utf-8
def fib_gen():
a, b = 1, 1
while True:
yield a
a, b = b, a+b
def get_values(iterator, n):
l = []
for i in range(n):
@oinopion
oinopion / registry.py
Created February 2, 2012 00:02
Simple Dependency Injection with decorators
# encoding: utf-8
"""
Dependency injection made simple
@requires('stores')
class Action(object):
self.stores = None
@provides('stores')
class InMemoryStores(Stores):
(cascade) % ./manage.py syncdb
Creating tables ...
Creating table ticket_a
Creating table ticket_b
Creating table ticket_c
Installing custom SQL ...
Installing indexes ...
No fixtures found.
(cascade) % ./manage.py shell
Python 2.7.2 (default, Jan 17 2012, 23:42:54)
@oinopion
oinopion / utils.py
Created February 29, 2012 13:02
Render dict from Django model
def render_dict(pattern, data):
"""Render Django model to dict (helps in rendering JSON)"""
out = {}
for item in pattern:
if isinstance(item, basestring):
attr = manager_getattr(data, item)
out[item] = attr
elif isinstance(item, dict):
for subitem, subpattern in item.items():
attr = manager_getattr(data, subitem)
package gchat
import "log"
import "net"
import "bufio"
import "fmt"
func Serve() {
fmt.Println("Start server on port 2000")
l, err := net.Listen("tcp", ":2000")
@oinopion
oinopion / output
Last active December 13, 2015 20:38
TASK: [debug msg="/home/$user/13-02-17--15-23-58"] *********************
ok: [192.168.60.2]
TASK: [pause seconds=5] *********************
(^C-c = continue early, ^C-a = abort)
[192.168.60.2]
Pausing for 5 seconds
ok: [192.168.60.2]
TASK: [debug msg="/home/$user/13-02-17--15-24-04"] *********************