Skip to content

Instantly share code, notes, and snippets.

@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';
}
#!/usr/bin/env python2.7
#coding: utf-8
import gevent
import gevent.pool
class TestPool(object):
def __init__(self, maxsize=10):
#!/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.
@svieira
svieira / README.md
Last active December 25, 2015 00:09
If things are ugly, you may want another font.

Explaination

These characters are all characters that can look similar - I use this to test monspace fonts for legibility.

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"))
@svieira
svieira / generatorsAsCoroutines.js
Last active December 22, 2015 11:29
Possible reasons for wanting generator expressions to be generators / coroutines rather than simply iterable iterators. In response to questions from Dominic Denicola in http://domenic.me/2013/09/06/es6-iterators-generators-and-iterables/
/**
* 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: