Skip to content

Instantly share code, notes, and snippets.

import ast
from cStringIO import StringIO
import sys
INFSTR = '1e308'
def interleave(inter, f, seq):
seq = iter(seq)
try:
f(next(seq))
@Davis-Desormeaux
Davis-Desormeaux / monad-parser.cpp
Created November 26, 2012 10:23 — forked from splinterofchaos/monad-parser.cpp
Monadic parsing in C++
#include <memory>
#include <iostream>
#include <sstream>
#include <utility>
#include <algorithm>
#include <iterator>
struct sequence_tag {};
struct pointer_tag {};
@Davis-Desormeaux
Davis-Desormeaux / example.php
Created August 14, 2012 07:52 — forked from ah01/example.php
PHP Thread class with exit code support
<?php
require "thread.php";
function doSomething($res, $t) {
usleep($t);
exit($res);
}
$thread1 = new Thread('doSomething');
@Davis-Desormeaux
Davis-Desormeaux / Thread.php
Created August 14, 2012 07:52 — forked from Arbow/Thread.php
PHP Process Pool With Executor
<?php
//Found on http://www.alternateinterior.com/2007/05/multi-threading-strategies-in-php.html
//Modified by http://www.php-code.net
//Modified: add executor
class Thread {
var $pref ; // process reference
var $pipes; // stdio
var $buffer; // output buffer
var $output;
var $error;
/**
* Functional promise
*/
var Promise = (function createPromise(listeners, resolved) {
var self = this;
if (typeof listeners === 'undefined') {
listeners = [];
}
@Davis-Desormeaux
Davis-Desormeaux / gist:2440560
Created April 22, 2012 00:46
Dart Lotto Picker
// Dart code snippet to get next week's winning lottery numbers
// by taking a random guess...
// dartbit.com
final int out_of_nbs = 6; // Total numbers required to play.
final int number_max = 40; // NYC lotto game (Sweet Million)
//final int number_max = 49; // CAN lotto game (The Lotto 6/49)
/*
* Returns a random [int] between 1 and [int] 'max_inclusive'.
@Davis-Desormeaux
Davis-Desormeaux / dartIrcbot.dart
Created April 22, 2012 00:44
simple dart bot that joins irc.freenode.net/#dart
#import("dart:io");
#import("dart:utf");
class Bot {
Socket socket;
bool sendNick = true;
Bot() {
socket = new Socket("irc.freenode.net",6667);
socket.onError = (e) {
print("onError: ${e}");
@Davis-Desormeaux
Davis-Desormeaux / gist:2440544
Created April 22, 2012 00:41
Quick Dom Selector
function domSelect(element) {
var elm_type = element.substring(0, 1);
var _element = element.substring(1);
return elm_type != '.'
? elm_type != '#'
? document.getElementsByName(element) // Default to name.
: document.getElementById(_element) // By an id request.
: document.getElementsByClassName(_element) // By class request.
}
@Davis-Desormeaux
Davis-Desormeaux / parser.js
Created April 20, 2012 05:25 — forked from igstan/parser.js
JavaScript Monadic Parser Combinators
var bind = function (prev, bridge) {
return function (input) {
var result = prev(input);
return result.length === 0 ? result : bridge(result[0])(result[1]);
};
};
var result = function (a) {
return function (input) {
return [a, input];
@Davis-Desormeaux
Davis-Desormeaux / monad.js
Created April 20, 2012 04:16 — forked from liquidz/monad.js
monad.js: checking with rhino
// checking with rhino
(function(){
// MonadBase {{{
var MonadBase = function(){};
MonadBase.prototype.result = function(v){
return function(){ return v; };
};
MonadBase.prototype.bind = function(a, f){
return f(a());