This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object::go = (...funcs)->fold (|>), this, funcs | |
[1 to 10].go do | |
filter odd | |
map (^ 2) | |
fold1 (+) | |
#=>165 | |
#compare: | |
[1 to 10] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require \http .create-server (req,res)-> | |
status = | |
| req.url is '/' => 200 | |
| otherwise => 503 | |
res.write-head status,"Service Unavailable" { | |
"Content-Type": "application/json; charset=UTF-8" | |
"Connection": "close" | |
"X-Powered-By": "PHP/5.3.10-1ubuntu3.4" | |
"Server": "Apache/2.2.22 (Ubuntu)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs = require \fs | |
http = require \http | |
global.options = JSON.parse fs.read-file-sync "importio-webui/options.json" \utf8 | |
console.log options | |
http.create-server (req,res)-> | |
if req.url == /_mlt$/ | |
res.write-head 404 "Not Found" | |
# lol jetty 404 | |
res.end """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http = require \http | |
http.create-server (req,res)-> | |
opts = { | |
host: "api.import.io" | |
port: 80 | |
req.method | |
path: req.url | |
req.headers | |
} | |
req.pipe http.request opts, (response)-> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -XPOST 'http://importio.uservoice.com/api/v1/tickets.json?client=83JT0Uy7WDJAUv4aHiohQw' -d '{"email":"[email protected]","ticket":{"subject":"TEST TICKET IGNORE ME","message":"lorem","attachments":[{"name":"test.txt","content_type":"text/plain","data":"aGVsbG8gd29ybGQ="}]}}' -H "Content-Type: application/json" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const co = require('co'), | |
fs = require('fs'), | |
curry = require('prelude-ls').curry; | |
var read = curry(fs.readFile()); | |
co(function* () { | |
var a = yield read('.gitignore','utf8'); | |
var b = yield read('Makefile','utf8'); | |
var c = yield read('package.json','utf8'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# semigroup | |
Readable::concat = (b)-> | |
a = this | |
new class extends Readable | |
-> | |
super ... | |
@read-from = a | |
_read: (size)-> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Readable.of = (body)-> | |
new class extends Readable | |
offset: 0 | |
_read: (size)-> | |
@push body.slice @offset,@offset+size-1 | |
@offset += size-1 | |
if @offset > body.length then return @push null # end the Readable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Readable::chain = (f)-> | |
orig = this | |
new class extends Readable | |
_read: (size)-> | |
if (orig.read size)? | |
if ((f that)read size)? | |
@push that | |
else @push "" | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# applicative derived from monad | |
Readable::ap = (m)-> | |
@chain (f)-> | |
m.map f | |
# functor derived from monad | |
Readable::map = (f)-> | |
@chain (a)~> | |
Readable.of f a |
OlderNewer