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
@jkrems
jkrems / Vagrantfile
Created July 27, 2012 08:03
Simple vagrant setup with debian and puppet
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
# Map NFS uid/gid to current user. This can be used to create a
# user inside the VM with matching uid/gid which makes file access
# a lot easier.
config.nfs.map_uid = Process.uid
config.nfs.map_gid = Process.gid
@jkrems
jkrems / stream.json
Created March 31, 2013 01:09
Blocked in DE? But why?! :(
{
"items": [
{
"id": "WdrXcikNdQU",
"kind": "youtube#video",
"snippet": {
"publishedAt": "2013-03-05T02:04:29.000Z",
"title": "International TableTop Day Live Stream - pt. 2 on March 30th!",
"description": "Join Wil Wheaton and friends from 3pm Pacific to 7pm Pacific as they play awesome games like SMASH UP, STAR TREK CATAN, and 7 WONDERS. Stream goes live ON March 30th.\n\nWant to participate in #TableTopDay? Go to TableTopDay.com and check out the events in your area going on all day."
},
@jkrems
jkrems / util.js
Last active December 21, 2015 14:09
Transparent function and generator proxy
var toString$ = Object.prototype.toString;
// Ported from angular.js
var COMMENTS_PATTERN = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg,
ARGS_PATTERN = /^function\s*(\*)?\s*[^\(]*\(\s*([^\)]*)\)/m,
ARG_PATTERN = /^\s*(_?)(\S+?)\1\s*$/;
module.exports = {
isGenerator: function isGenerator(obj) {
return toString$.call(obj).slice(8, -1) === 'Generator';
@jkrems
jkrems / intend.js
Created December 4, 2013 22:03
Clarity of intend
function getUser(id) {
// implementation unknown
}
function getUserName(id) {
// is getUser(id) returning Promise[String]? String? - both work fine
return when(when(id, getUser), function(user) {
return user.name;
});
}
@jkrems
jkrems / cjsify.js
Last active December 31, 2015 11:59
POC commonjs everywhere grunt task
'use strict';
var DESC = 'Generate bundle from commonjs-everywhere';
var escodegenFormat = {
indent: {
style: ' ',
base: 0
},
renumber: true,
// 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 / README.md
Last active August 11, 2017 09:07
Weird crashes when the tty init is moved out of main().

Works as expected:

gcc tty_crash.cc -I deps/libuv/include -L deps/libuv/out/Debug -luv && ./a.out

Crashes with various errors, bus errors/segmentation faults/SIGABRT:

gcc tty_crash.cc -I deps/libuv/include -L deps/libuv/out/Debug -luv -D CRASHING && ./a.out