Skip to content

Instantly share code, notes, and snippets.

View oinopion's full-sized avatar

Tomek Paczkowski oinopion

View GitHub Profile
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"] *********************
TASK: [aasdfasds] *********************
ok: [192.168.60.2] => {"msg": "$home/13-02-17--19-36-28"}
TASK: [pause seconds=2] *********************
(^C-c = continue early, ^C-a = abort)
[192.168.60.2]
Pausing for 2 seconds
ok: [192.168.60.2] => {"changed": false, "delta": 2, "rc": 0, "start": "2013-02-17 19:36:28.635563", "stderr": "", "stdout": "Paused for 2.0 seconds", "stop": "2013-02-17 19:36:30.635935"}
TASK: [aasdfasd] *********************