This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
Learn a variety of programming paradigms:
- Write a program in assembly language
#!/usr/local/bin/python | |
from flask import Flask, Blueprint | |
app = Flask(__name__) | |
bp = Blueprint(__name__, "bp") | |
@bp.route("/test") | |
def test(): | |
return "BP.test" |
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
Learn a variety of programming paradigms:
#!/usr/bin/env python2.7 | |
#coding: utf-8 | |
import gevent | |
import gevent.pool | |
class TestPool(object): | |
def __init__(self, maxsize=10): |
function textColor(bgColor) { | |
var r = bgColor.r * 255, | |
g = bgColor.g * 255, | |
b = bgColor.b * 255; | |
var yiq = (r * 299 + g * 587 + b * 114) / 1000; | |
return (yiq >= 128) ? 'black' : 'white'; | |
} |
# Looping per line of input | |
some | command | sequence | while read var1 var2; do | |
# something here | |
done | |
# Reading a file line by line | |
while read var1 var2 etc; do | |
perform --commands --with $var1 $var2 $etc | |
done < some-file.ext |
from flask import Flask, url_for | |
from werkzeug.serving import run_simple | |
from werkzeug.wsgi import DispatcherMiddleware | |
app = Flask(__name__) | |
app.config["APPLICATION_ROOT"] = "/abc/123" | |
@app.route("/") | |
def index(): |
{ | |
"name": "parse-user-agent", | |
"version": "0.0.1", | |
"private": true, | |
dependencies: { | |
"platform": "~1.1.0", | |
"split": "~0.3.0" | |
} | |
} |
# Via http://pydanny.com/jinja2-quick-load-function.html | |
from jinja2 import FileSystemLoader, Environment | |
def render_from_template(directory, template_name, **kwargs): | |
loader = FileSystemLoader(directory) | |
env = Environment(loader=loader) | |
template = env.get_template(template_name) | |
return template.render(**kwargs) |
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.
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:
Finarfin: Aye. That, in truth, none might e'er deny. Yet lettest thou not cease to bear in mind, that elders be but Eldar, e'en as their offspring, and subject no less than more unto equal passions, to the world's storms and the heart's disquiet, and to wrath, and inconstancy, even as to the over-mastering pride, that durst not yield concession of any, lest smallest surrender be presage to the all; and willfulness doth ever raise the cry of Willful! - as 'twere a mirrored shield to turn back just rebuke.
[with a sweeping gesture, looking at his sons even as he addresses her]
For hard indeed, and surpasseth measure, to be held unto reckoning by one subject, for fealty, and if 'tis so, how much more so when him that challengeth is child and student, younger in years, in knowing, and in deed, and holding all those - or so it seemeth - but from one's self, as a gem's light inwrought by the artisan; for so easily and swift do we forget, that neither earth, nor holy fire, are of our own sole making