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

Keybase proof

I hereby claim:

  • I am jkrems on github.
  • I am jkrems (https://keybase.io/jkrems) on keybase.
  • I have a public key whose fingerprint is D289 A52C 5FD8 2339 0E33 1D9B 24E9 38F4 69EE 83D5

To claim this, I am signing this object:

@jkrems
jkrems / fun.js
Created December 10, 2014 05:17
What could go wrong..?
import * as assert from 'assert';
import { MY_FLAG } from './trust';
assert.ok(MY_FLAG === 1);
setTimeout(function() {
try {
assert.ok(MY_FLAG === 1);
} catch (err) {
console.log('Just ES6 things.');
}
@jkrems
jkrems / generators.md
Last active February 24, 2020 19:09
Generators Are Like Arrays

In all the discussions about ES6 one thing is bugging me. I'm picking one random comment here from this io.js issue but it's something that comes up over and over again:

There's sentiment from one group that Node should have full support for Promises. While at the same time another group wants generator syntax support (e.g. var f = yield fs.stat(...)).

People keep putting generators, callbacks, co, thunks, control flow libraries, and promises into one bucket. If you read that list and you think "well, they are all kind of doing the same thing", then this is to you.

@jkrems
jkrems / shrinkwrap.md
Last active August 29, 2015 14:05
State of `npm shrinkwrap`
@jkrems
jkrems / cached-call.js
Last active August 29, 2015 14:05
gofer-blog
var entityId = 'xy';
var loadEntity = cached.deferred(_.partial(myService.fetch, '/entity/' + entityId));
cached('myService').getOrElse(entityId, loadEntity, function(err, entity) {
// 80% of time this works every time
});
@jkrems
jkrems / react-rendering.js
Created July 19, 2014 04:53
quinn: Page rendering using React
'use strict';
var http = require('http');
var React = require('react');
var $ = React.DOM;
var _ = require('lodash');
var respond = require('quinn-respond');
var resolveDeep = require('resolve-deep');
var Promise = require('bluebird');
@jkrems
jkrems / safe-map.js
Created July 1, 2014 17:02
Safe object/dictionary in JavaScript
/* jshint node:true, esnext:true */
'use strict';
// Run: node --harmony_proxies --harmony-collections safe-map.js
function createSafeObject(props) {
if (typeof props !== 'object' || props === null) {
props = {};
}
@jkrems
jkrems / my-module.js
Last active August 29, 2015 14:02
How to write ES6 modules
export function each() {}
export function map() {}
export function reduce() {}
export function isEmpty() {}
export function extend() {}
@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": "[email protected]",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.0.0.tgz"
@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';