Skip to content

Instantly share code, notes, and snippets.

View refractalize's full-sized avatar

Tim Macfarlane refractalize

View GitHub Profile
@refractalize
refractalize / ls.pogo
Created September 23, 2012 12:12
Pogo's async operator, `!`
fs = require 'fs'
filenames = fs.readdir! '.'
stats = [f <- filenames, size = fs.stat (f)!.size, {filename = f, size = size}]
for each @(stat) in (stats)
console.log "#(stat.filename): #(stat.size)"
console.log ()
@refractalize
refractalize / gist:3778560
Created September 24, 2012 21:37
Async operator works in pogo REPL
zap ~ λ pogo
> fs = require 'fs', nil
undefined
> fs.read file! 'stuff.txt' 'utf-8'
Error: ENOENT, open 'stuff.txt'
> fs.write file! 'stuff.txt' 'contents of stuff.txt'
undefined
> fs.read file! 'stuff.txt' 'utf-8'
'contents of stuff.txt'
> yay!
@refractalize
refractalize / continuations.pogo
Created October 15, 2012 21:58
Continuations in Pogoscript
exports.current (callback) =
continuation () =
callback (nil, continuation)
callback (nil, continuation)
@refractalize
refractalize / coroutines.pogo
Created October 25, 2012 20:02
Coroutines in Pogo
last yield continuation = nil
last result continuation = nil
yield (n, yield continuation) =
last yield continuation = yield continuation
last result continuation (nil, n)
coroutine (block) =
run (result continuation) =
last result continuation = result continuation
@refractalize
refractalize / myapp.js
Created December 11, 2012 00:27
How to bootstrap AngularJS with mock dependencies, in unit tests...
// your app
myapp = angular.module('myapp', []);
myapp.directive('userView', function () {...});
myapp.factory('userApi', function () {...});

Having a wee bit o trouble with the async paradigm?

pogoscript has a calling convention for async functions, taken from the Node.js fs module, many other libraries use it, but not all. The callback is called like this:

callback(error, result);

So

fs.readFile(filename, function (error, result) { ... });
@refractalize
refractalize / index.html
Created May 29, 2013 09:07
cursor smoke
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style type="text/css">
@-webkit-keyframes rotate-1 {
from {
-webkit-transform: rotate(0deg) scale(0.4, 0.4);
@refractalize
refractalize / syncasync.pogo
Created October 10, 2013 08:48
How to make functions both synchronous and asynchronous at the same time. The caller decides.
function (f) is asynchronous =
r/function(.*continuation)/.test (f.to string ())
ensure (b) is asynchronous =
if (function (b) is asynchronous)
b
else
@(args, ..., cont)
try
cont (nil, b (args, ...))
@refractalize
refractalize / device.rb
Last active December 29, 2015 02:29
Timing and Retry for Selenium
require 'selenium-webdriver'
require 'ap'
class Scope
def find type, query
Element.new self, type, query
end
def where(name, &predicate)
Where.new self, name, predicate
@refractalize
refractalize / rethinkdb-pogo-repl.md
Last active August 29, 2015 13:57
Mucking around with rethinkdb and the pogoscript REPL

Mucking around with rethinkdb and the pogoscript REPL:

> r = require 'rethinkdb'
[snip]
> connection = r.connect {}!
[snip]
> r.tableCreate 'bobo'.run (connection)!
{ created: 1 }
> r.table 'bobo'.insert {name = 'haha'}.run (connection)!

{ deleted: 0,