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
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'; | |
} |
#!/usr/bin/env python2.7 | |
#coding: utf-8 | |
import gevent | |
import gevent.pool | |
class TestPool(object): | |
def __init__(self, maxsize=10): |
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/local/bin/python | |
from flask import Flask, Blueprint | |
app = Flask(__name__) | |
bp = Blueprint(__name__, "bp") | |
@bp.route("/test") | |
def test(): | |
return "BP.test" |
(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. |
gradient-with-fallback(fallback=none, gradient-args...) { | |
args = unquote(join(", ", gradient-args)) | |
fallback = typeof(fallback) == "string" ? unquote(fallback) : fallback | |
background: fallback | |
background-image: -vendor-linear-gradient(args) | |
background-image: linear-gradient(args) | |
} | |
.test { | |
gradient-with-fallback(#FFF 150px, #CCC 100%, fallback: top left repeat-y url("some/image.jpg")) |
/** | |
* Treat generators and coroutines the same | |
* This means we need to treat all generators | |
* as coroutines, rather than the other way around. | |
*/ | |
function *loggingDecorator(gen) { | |
let processed = gen.next(null); | |
while (!processed.done) { | |
console.log("INFO:", processed); | |
let unprocessed = yield processed.value; |
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: |