Skip to content

Instantly share code, notes, and snippets.

> console.log(Promise.toString())
function Promise() { [native code] }
undefined
> function Promise(execute) {
... this.then = execute;
... this.catch = function catch(handler) {
..... return this;
..... };
... }
... ;
@jido
jido / gist:c22947e171c7e76314d865686583c5a5
Created April 26, 2016 00:15
var Promise messes up the test
var mistigri = (function(){
/*
if (Promise === undefined)
{
console.log("Making a fake Promise");
var Promise = function Promise(execute) {
this.then = execute; // Mistigri always returns, even if it ran into problems
this.catch = function(onrej) {
return this;
@jido
jido / gist:1aa424dceb434da4e38973d0a2b7482c
Created April 23, 2016 16:07
The function that uses the callback
var handleAllIncludes = function handleAllIncludes(includes, config, rendered, size, finish) {
if (includes.work.length === 0)
{
if (finish !== undefined) finish(rendered);
return;
}
if (finish === undefined)
{
console.warn("Mistigri needs a callback - ignoring all includes");
return;
Configuration options
---
.
.
.
__reader__ : _function(string, function(string), function(Error))_
A function that reads a template and passes it to the first callback
when it is ready. The second callback can be used in case of error.
@jido
jido / dodo.js.test.html
Created August 25, 2011 09:47
The dodo object model: a Javascript adaptation
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"/>
<title>Test JS</title>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
<link rel="stylesheet" type="text/css" href=".css"/>
<script>
"use strict";
@jido
jido / gist:1129540
Created August 6, 2011 17:24
Javascript clone
// Does not exactly perform a clone, but all fields are same as original var
function clone(x) {
function Build() {};
Build.prototype = x;
return new Build;
}
@jido
jido / gist:1126681
Created August 5, 2011 00:43
How JS scoping messes with capture
var a = {};
a.foo = function() {
return "foo";
}
a.bar = function() {
return "bar";
}
@jido
jido / gist:1057053
Created June 30, 2011 19:50
Using closure and continuation-passing style in C
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
char* description;
} event;
typedef void (*fun)();
; I have this in my code
(defn fun [f, continuation] (-> f continuation)) ; pass f to continuation
; I want to change it to this
(defn fun [argc, f, continuation]
(continuation
(fn [& args]
(defn dodo*fork [coroutine, return]
(let [outcome (promise)]
(println "starting coroutine")
(future
(coroutine ; run in parallel
(fn [& args] (deliver outcome {:return args}))
(fn [e] (deliver outcome {:error e}))))
(println "returning blocking function")
(return
(fn wait [return, error]