Skip to content

Instantly share code, notes, and snippets.

"""
Simple forking echo server built with Python's SocketServer library. A more
Pythonic version of http://gist.github.com/203520, which itself was inspired
by http://tomayko.com/writings/unicorn-is-unix.
"""
import os
import SocketServer
class EchoHandler(SocketServer.StreamRequestHandler):
/* SOURCE: https://github.com/supereggbert/GLGE/blob/master/src/core/glge.js%20%20 */
fastHash=function(str){
var s1=0;var s2=0;var s3=0;var s4=0;var s5=0;var s6=0;
var c1=0;var c2=0;var c3=0;var c4=0;var c5=0;var c6=0;
var i=0;
var length=str.length;
str+="000000";
while(i<length){
c1=str.charCodeAt(i++);c2=str.charCodeAt(i++);c3=str.charCodeAt(i++);
@svieira
svieira / detatchableObservable.js
Created July 25, 2011 20:06
Knockout: Detatchable dependentObservable
// A dependentObservable that can be written to and reverted.
ko.detatchableDependentObservable = function(value, model) {
var root_value = typeof value === 'function' ? ko.dependentObservable(value, model) : ko.observable(value);
var public_value = ko.observable(root_value());
root_value.subscribe(function(value){
public_value(value);
});
var public_ = ko.dependentObservable({read: public_value, write: function(value){ public_.isConnected(false); public_value(value); }});
@svieira
svieira / argy.py
Created February 6, 2013 19:23 — forked from beala/argy.py
"""
Inspired by:
http://eli.thegreenplace.net/2009/08/29/co-routines-as-an-alternative-to-state-machines/
"""
def parse_args(target):
"""A generator that parses a stream of arguments one character at a time.
As soon as a flag, or flag value pair ("-a" or "-a value") is processed
the pair is sent off as a tuple to the 'target' generator.
#!/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:
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")
@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;
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 / 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.

(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.