Skip to content

Instantly share code, notes, and snippets.

View jkrems's full-sized avatar
Modules. Modules everywhere.

Jan Olaf Martin jkrems

Modules. Modules everywhere.
View GitHub Profile
// 1. Variable declaration
def myValue = 'value, immutable';
def myObjectValue = { a: 10 };
myObjectValue.b = 20; // TypeError
myObjectValue.a = 12; // TypeError
def myArrayValue = [ 10, 20 ];
myArrayValue.slice(1); // is okay, slice is pure
myArrayValue.pop(); // TypeError
myArrayValue.splice(); // TypeError
@jkrems
jkrems / server.js
Created March 7, 2014 23:13
Number doubling service
'use strict';
var net = require('net');
var LineInputStream = require('line-input-stream');
var END_MESSAGE = new Buffer("Thank you for using the nodejs doubling service\n");
var server = net.createServer(function(socket) {
var processLine = function(line) {
if (line.trimRight() === 'end') {
@jkrems
jkrems / report.txt
Created March 21, 2014 04:59
CSON with wrong indentation
> CSON.parse('a: 2\n b: 3\n c: 4')
Error: Syntax error on line 3: indentation is ambiguous
1 : a: 2
2 : b: 3
3 : c: 4
^ :~~^
at Preprocessor.Preprocessor.consumeIndentation (/Users/jankrems/Projects/itier/libs/cson-safe/node_modules/coffee-script-redux/lib/preprocessor.js:155:17)
at Preprocessor.Preprocessor.process (/Users/jankrems/Projects/itier/libs/cson-safe/node_modules/coffee-script-redux/lib/preprocessor.js:190:14)
at Function.Preprocessor.Preprocessor.process (/Users/jankrems/Projects/itier/libs/cson-safe/node_modules/coffee-script-redux/lib/preprocessor.js:22:38)
at Object.CoffeeScript.parse (/Users/jankrems/Projects/itier/libs/cson-safe/node_modules/coffee-script-redux/lib/module.js:47:35)
@jkrems
jkrems / target.js
Last active August 29, 2015 13:57
Spidernode demo
Stream.pipe = async function(source, target) {
let chunk;
// source.read() will throw if there's an error
// reading data
while (chunk = source.read()) {
target.write(await chunk);
}
// .end will throw when there were errors
return target.end();
};
@jkrems
jkrems / syntax.fs
Last active August 29, 2015 14:00
A more functional syntax..?
let dispatch req = Http.OK (sprintf! "Hello, %s" req.url)
let server = Http.Server port: 8000, dispatch
// OR:
let server = Http.Server { port: 8000 }, dispatch
// OR:
let server = Http.Server { port: 8000, dispatch: dispatch }
async {
let socket = await server.socket; // alternative: *server.socket
@jkrems
jkrems / straight.ml
Created April 27, 2014 05:19
First OCaml program
type id = string
type binop = Plus | Minus | Times | Div
type stm = CompoundStm of stm * stm
| AssignStm of id * exp
| PrintStm of exp list
and exp = IdExp of id
| NumExp of int
@jkrems
jkrems / promise-repl.js
Created May 15, 2014 05:14
Promise aware node.js repl
var vm = require('vm');
function fancyPromiseEval(code, context, file, cb) {
var err, result, script;
// first, create the Script object to check the syntax
try {
script = vm.createScript(code, {
filename: file,
displayErrors: false
});
} catch (e) {
@jkrems
jkrems / let.compiled.js
Created June 14, 2014 18:06
What traceur does to your code; compiled via `traceur --block-binding true --module let.js --out let.compiled.js`
System.register("let", [], function() {
"use strict";
var __moduleName = "let";
{
try {
throw undefined;
} catch (x) {
x = 10;
}
}
@jkrems
jkrems / html-handler.jsx
Last active August 29, 2015 14:02
Example of responding with an html page / fragment in quinn
/**
* @jsx React.DOM
*/
'use strict';
import {resolve} from 'bluebird';
import React from 'react';
import {getParam} from 'quinn'; // actually should be 'quinn-router'
import respond from 'quinn-respond';
@jkrems
jkrems / npm-ls.json
Created June 22, 2014 01:55
mocha dependencies
{
"name": "mocha",
"version": "1.20.1",
"from": "mocha@^1.20.1",
"resolved": "https://registry.npmjs.org/mocha/-/mocha-1.20.1.tgz",
"dependencies": {
"commander": {
"version": "2.0.0",
"from": "commander@2.0.0",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.0.0.tgz"