Skip to content

Instantly share code, notes, and snippets.

@snowmantw
snowmantw / gist:8708553
Created January 30, 2014 13:43
Promises and map/reduce
// Use a Promise-based library to do IO.
var http = require("q-io/http")
,noop = new Promise(()=>{})
,prepare =
(str)=> http.read('http://www.example.com/' + str)
.then((res)=> res.body.toString())
,makeQuery =
(strs)=> strs.map((str)=> prepare(str))
@snowmantw
snowmantw / gist:8708585
Created January 30, 2014 13:44
Haskell and map/reduce
{-# LANGUAGE UnicodeSyntax #-}
-- Pardon me. Crying for the missing lambda charater on the keybord.
-- Let's construct queries from SQL statements.
makeQueries strs = map λstr → prepare conn str
doQuery qrys = foldl (λresults query → results >> query) (return ()) qrys
-- Do query and get results.
let stmts = [ "INSERT INTO Articles ('Functional JavaScript')"
, "INSERT INTO Gecko VALUES ('30.a1')"
@snowmantw
snowmantw / gist:9106619
Created February 20, 2014 03:29
Use Promise without defer
t = (new Promise((s, f) => {console.log('>>',s); setTimeout(s, 6000)}))
.then(()=>{console.log('step #2');})
// The Promise constructor would receive two resolver, and call it inside the wrappered asynchrous function to trigger the next steps.
a = (D = {}, S = Init)=>(D = {d1}, S = Sa)=>(D = {d2}, S = Sb)=> doTransfer()
a()
a()()
a()()()
a()()()() ... doTransfer()
1: K = a()
if ('function' === typeof K)
goto 1
gaiatest --restart --type=b2g --app=b2gdesktop --binary=/home/cltbld/b2g/b2g-bin --profile=/home/cltbld/gaia/profile --testvars=/home/cltbld/testvars.json /home/cltbld/gaia/tests/python/gaia-ui-tests/gaiatest/tests/functional/lockscreen/test_lockscreen_unlock_to_emergency_call_screen.py
{
"acknowledged_risks": true,
"skip_warning": true,
"settings": {},
"carrier":{
"phone_number": "",
"country": "",
"network": ""
},
"imei": "",
@snowmantw
snowmantw / gist:06fce8d3db93dbad45b6
Created August 23, 2014 16:23
Promise.then test: parallel or sequently.
var k = new Promise((r) => {r()});
var s = () => { return new Promise((r) => { setTimeout(()=> {console.log(1); r()}, 3000) })}
var g = () => { return new Promise((r) => { setTimeout(()=> {console.log(1); r()}, 3000) })}
k.then(s).then(g) // sequently
// parallel
k.then(s)
k.then(g)
// because it should be:
" set up pathogen, https://github.com/tpope/vim-pathogen
filetype on " without this vim emits a zero exit status, later, because of :ft off
filetype off
call pathogen#infect()
filetype plugin indent on
colorscheme advantage
" don't bother with vi compatibility
set nocompatible
export PS1="\[\033[1;32m\]`hostname`\[\033[0m\] \[\033[1;35m\]\u\[\033[0m\]:\[\033[1;33m\]\w\[\033[0m\]$ "
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad
@snowmantw
snowmantw / gist:b12b7a844b61f01fc672
Last active August 29, 2015 14:20
A hack to run Raptor with Marionette
'use strict';
marionette('LockScreen media playback tests', function() {
var LockScreenMediaPlaybackActions, actions;
var LockScreenMediaPlaybackChecks, checks;
var FakeMusic = require('./lib/media_playback_fake_music.js');
var fakeMusicInfo = new FakeMusic();
var apps = {};
apps[fakeMusicInfo.origin] = fakeMusicInfo.path;
var client = marionette.client({
prefs: {