Skip to content

Instantly share code, notes, and snippets.

View shey's full-sized avatar

Sheheryar Sewani shey

View GitHub Profile
-module(talk).
-compile(export_all).
%% call talk:start() to start the program
start() ->
Node = chomp(io:get_line('Which node do you want to talk to?')),
%%Registered process where all the magic happens:
register(me, spawn(?MODULE, receiving, [])),
register(them, spawn(?MODULE, sending, [list_to_atom(Node)])),
@shey
shey / gist:172997
Created August 22, 2009 22:04
IoC with Pinsor
#Example of IoC using Pinsor
import pinsor
class PowerfullEngine(object):
def __str__(self):
return "I am a V8"
class WeakEngine(object):
@shey
shey / bank.py
Created August 10, 2010 02:31 — forked from jessemiller/bank.py
Refactoring buliders using python dicts
class Account():
def __init__(self):
self.balance = 0
self.currency = 'CAD'
self.overdraft = False
def make_deposit(self, amount):
"""imagine a boat load of business logic that would make this useful"""
pass
[connection:main]
#RabbitMQ Setting
host = localhost
virtual_host = /
userid = guest
password = guest
[exchange:nasdaq]
durable = True
type = direct
class HandlerFactory {
HandlerFactory(billing_service, account_repo) {
this.billing = billing_service;
this.accounts = account_repo
}
public static Handler create_handler(var discriminator){
switch discriminator:
case 1: return type_a_handler(this.billing, this.accounts)
case 2: return type_b_handler(this.billing, this.accounts)
//implementation
create_handler(var billing_service, var account_repo, var discriminator){
switch discriminator:
case 1: return type_a_handler(billing_service, account_repo)
case 2: return type_b_handler(billing_service, account_repo)
}
//implementation
create_handler(var billing_service, var account_repo, var discriminator){
switch discriminator:
case 1: return type_a_handler(billing_service, account_repo)
case 2: return type_b_handler(billing_service, account_repo)
}
handler_factory = partial(
class HandlerFactory(object):
def __init__(self, billing_engine, accounts_repo):
self.engine = billing_engine
self.accounts = accounts_repo
def create_handler(self, discriminator):
if discriminator == 1:
return type1_handler(self.engine, self.accounts)
else:
return type2_handler(self.engine, self.accounts)
def create_handler(billing_engine, accounts_repo, discriminator):
if discriminator == 1:
return type1_handler(billing_engine, accounts_repo)
else:
return type2_handler(billing_engine, accounts_repo)
# "a" and "b" passed for illustrative purposes only,
# They represent the billing_engine, accounts_repo dependencies
get_handler = partial(
from pylons.decorators import decorator, get_pylons
def cache_control(**options):
def updated_headers(func, *args, **kwargs):
pylons = get_pylons(args)
if pylons:
del pylons.response.headers['Cache-Control']
del pylons.response.headers['Pragma']
pylons.response.cache_control = {'max-age': options['max_age'], 'public': True}
return func(*args, **kwargs)