Skip to content

Instantly share code, notes, and snippets.

var BLOCKSIZE = 500;
var dataset = []; // Assuming, of course, that there's something in here..
var renderActions = [];
for (var i=0; i<dataset.length; i+= BLOCKSIZE) {
renderActions.push((function(offset) {
return function(callback) {
//
Sequencer = function(lambdas) {
var self = this;
this.start = function() {
this.next();
}
this.next = function() {
if (lambdas.length != 0) {
@michiel
michiel / example-sequence-10k.js
Created February 9, 2011 22:00
Run 10000 async calls through a sequencer
//
// Example #1 : sequence 10000 async calls
//
function sequence(arr) {
var self = function() {
arr.length && arr.shift()(self);
}
self();
@michiel
michiel / example-sequence-10k-in-blocks-of-500.js
Created February 9, 2011 22:02
Run 10000 async calls through a sequencer in blocks of 500
//
// Example #2 : sequence 10000 async calls in blocks of 500 using a collector
//
function sequence(arr) {
var self = function() {
arr.length && arr.shift()(self);
}
self();
}
@michiel
michiel / example-10k-sequence-pipeline.js
Created February 10, 2011 17:04
Run 10000 async calls through a pipeline'd sequencer
//
// Example #3 : sequence 10000 async calls in a pipeline, with max 500 open
//
function pipeline(arr, maxOpenCalls, finalCallback) {
var openCalls = 0;
function callback() {
if (--openCalls < maxOpenCalls) {
@michiel
michiel / sequencer.coffee
Created May 17, 2011 13:33
Sequencer in coffeescript
sequence = (arr) ->
self = ->
if arr.length then arr.shift() self
self()
async = (callback) ->
console.log "Calling callback after 1s"
setTimeout callback, 1000
sequence [async, async, async]
@michiel
michiel / cors-nginx.conf
Created July 5, 2011 10:41
Wide-open CORS config for nginx
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
@michiel
michiel / multisort.js
Created April 2, 2012 21:56
Some sorting
//
// Ex. sort on attrs = [
// ["Name", "asc"],
// ["Description, "desc"]
// ]
//
// This is how we do just one column,
//
// function sortOn(objs, attr, order) {
// return objs.sort(
@michiel
michiel / sortingx.coffee
Last active October 2, 2015 17:48
some sorting in coffeescript
sort = (objs, attrs) ->
dojo.map(
(dojo.map objs, (obj) ->
arr = [obj]
dojo.forEach attrs, (attr) ->
arr.push obj.get(attr)
arr
).sort(
(attrsA, attrsB) ->
i = 1
package main
import (
"log"
"io"
"os"
"crypto/tls"
"strings"
"net"
"flag"