Skip to content

Instantly share code, notes, and snippets.

#!/usr/local/bin/python
from flask import Flask, Blueprint
app = Flask(__name__)
bp = Blueprint(__name__, "bp")
@bp.route("/test")
def test():
return "BP.test"
#!/usr/bin/env python2.7
#coding: utf-8
import gevent
import gevent.pool
class TestPool(object):
def __init__(self, maxsize=10):
@svieira
svieira / color-contrast.js
Last active July 15, 2016 00:02
YIQ Method of calculating contrast
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';
}
@svieira
svieira / bash-tricks.sh
Last active March 20, 2024 06:08
Things you can do with bash
# 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
@svieira
svieira / app.py
Last active October 21, 2019 10:43
Example sub-mounted Flask application
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():
@svieira
svieira / package.json
Last active August 29, 2015 14:01
User-agent from the command line
{
"name": "parse-user-agent",
"version": "0.0.1",
"private": true,
dependencies: {
"platform": "~1.1.0",
"split": "~0.3.0"
}
}
@svieira
svieira / jinja_render.py
Created June 16, 2014 13:42
How to render a jinja template (standalone)
# 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)

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
@svieira
svieira / quotes.md
Last active October 6, 2015 14:31
Quotations

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