Skip to content

Instantly share code, notes, and snippets.

@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.
@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); }});
/* 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++);
"""
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):
"""
Simple preforking echo server in Python.
Python port of http://tomayko.com/writings/unicorn-is-unix.
"""
import os
import sys
import socket
/*!
* JavaScript preload() function
* Preload images, CSS and JavaScript files without executing them
* Script by Stoyan Stefanov – http://www.phpied.com/preload-cssjavascript-without-execution/
* Slightly rewritten by Mathias Bynens – http://mathiasbynens.be/
* Demo: http://mathiasbynens.be/demo/javascript-preload
*/
function preload(arr) {
var i = arr.length,
@svieira
svieira / details.js
Created December 7, 2010 18:48 — forked from remy/details.js
/**
* Note that this script is intended to be included at the *end* of the document, before </body>
*/
(function (window, document) {
if ('open' in document.createElement('details')) return;
// made global by myself to be reused elsewhere
var addEvent = (function () {
if (document.addEventListener) {
return function (el, type, fn) {
@svieira
svieira / object.js
Created December 7, 2010 18:31 — forked from joemccann/object.js
/*!
* JavaScript Core Object v0.53
*
* Licensed under the new BSD License.
* Copyright 2008-2009, Bram Stein
* All rights reserved.
*/
(function() {
function getInternalType(value) {
return Object.prototype.toString.apply(value);
@svieira
svieira / gist:726944
Created December 3, 2010 13:23 — forked from remy/gist:350433
if (!window.localStorage || !window.sessionStorage) (function () {
var Storage = function (type) {
function createCookie(name, value, days) {
var date, expires;
if (days) {
date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
expires = "; expires="+date.toGMTString();
@svieira
svieira / gist:726943
Created December 3, 2010 13:22 — forked from remy/gist:726930
if (!sessionStorage && JSON) {
sessionStorage = (function () {
var data = window.name ? JSON.parse(window.name) : {};
return {
clear: function () {
data = {};
window.name = '';
},
getItem: function (key) {