Skip to content

Instantly share code, notes, and snippets.

@svieira
svieira / springer-free-maths-books.md
Created December 28, 2015 16:19 — forked from bishboria/springer-free-maths-books.md
Springer have made a bunch of maths books available for free, here are the direct links

Abstraction Suggestions

Summary: use good/established messaging patterns like Enterprise Integration Patterns. Don't make up your own. Don't expose transport implementation details to your application.

Broker

As much as possible, I prefer to hide Rabbit's implementation details from my application. In .Net we have a Broker abstraction that can communicate through a lot of different transports (rabbit just happens to be our preferred one). The broker allows us to expose a very simple API which is basically:

  • publish
  • request
  • start/stop subscription
#!/usr/bin/env python2.7
#coding: utf-8
import gevent
import gevent.pool
class TestPool(object):
def __init__(self, maxsize=10):
(function b() {
//The file goes through heuristics that turn object properties into
//a hash table
//run with
//d8 --enable-natives-syntax prop_heuristics.js
//Note that even if object has fast properties, there are still 2 kinds of
//fast properties (in and out of object) and only one of them is even faster.
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")
#!/usr/bin/env python
"""
Tail-Recursion helper in Python.
Inspired by the trampoline function at
http://jasonmbaker.com/tail-recursion-in-python-using-pysistence
Tail-recursive functions return calls to tail-recursive functions
(themselves, most of the time). For example, this is tail-recursive:
@svieira
svieira / argy.py
Created February 6, 2013 19:23 — forked from beala/argy.py
"""
Inspired by:
http://eli.thegreenplace.net/2009/08/29/co-routines-as-an-alternative-to-state-machines/
"""
def parse_args(target):
"""A generator that parses a stream of arguments one character at a time.
As soon as a flag, or flag value pair ("-a" or "-a value") is processed
the pair is sent off as a tuple to the 'target' generator.
"""
Simple forking echo server built with Python's SocketServer library. A more
Pythonic version of http://gist.github.com/203520, which itself was inspired
by http://tomayko.com/writings/unicorn-is-unix.
"""
import os
import SocketServer
class EchoHandler(SocketServer.StreamRequestHandler):
"""
Simple preforking echo server in Python.
Python port of http://tomayko.com/writings/unicorn-is-unix.
"""
import os
import sys
import socket