Skip to content

Instantly share code, notes, and snippets.

@tnrn9b
tnrn9b / custom.src.js
Created June 15, 2017 06:42
built using the assembler
'use strict';
(function(root, factory) {
if (typeof module === 'object' && module.exports) {
module.exports = root.document ?
factory(root) :
factory;
} else {
root.Highcharts = factory(root);
}
}(typeof window !== 'undefined' ? window : this, function(win) {

Promises vs Eventual Values

A few times on Twitter, I've complained that Promises are a poor conceptual stand-in for Eventual Values.

A colleague of mine pointed out that I tweet this or something like it every few months. He's correct, I do.

The responses usually flow in saying something to the effect of "Well,

@tnrn9b
tnrn9b / interop.md
Created June 11, 2017 22:18 — forked from domenic/interop.md
`module.exports =` and ES6 Module Interop in Node.js

module.exports = and ES6 Module Interop in Node.js

The question: how can we use ES6 modules in Node.js, where modules-as-functions is very common? That is, given a future in which V8 supports ES6 modules:

  • How can authors of function-modules convert to ES6 export syntax, without breaking consumers that do require("function-module")()?
  • How can consumers of function-modules use ES6 import syntax, while not demanding that the module author rewrites his code to ES6 export?

@wycats showed me a solution. It involves hooking into the loader API to do some rewriting, and using a distinguished name for the single export.

This is me eating crow for lots of false statements I've made all over Twitter today. Here it goes.

"use strict";
exports.queryAll = function(conn, sql, args, cb) {
var allRows = [];
conn.execute(sql, args, {
resultSet: true
}, function(err, result) {
if (err) return cb(err);
function fetch() {
@tnrn9b
tnrn9b / js-ajax-php-json-return.html
Created April 18, 2017 23:50 — forked from jonsuh/js-ajax-php-json-return.html
jQuery AJAX Call to PHP Script with JSON Return
<div class="the-return">
[HTML is replaced when successful.]
</div>
<?php
// this script was created by Akbar Taufiq Herlangga (Software Engineer at Qiscus)
// this script was created for the Qiscus TechTalk #35 - Build Your Own MVC Framework
//////////////////////////////////////////////////////////////////////
//////////////////////////// M O D E L ///////////////////////////////
<?php
use Illuminate\Support\Arr;
function array_multi_search(array $array, $key)
{
if (!is_string($key)) {
return false;
}
@tnrn9b
tnrn9b / groupBy.php
Created April 17, 2017 04:49 — forked from petemcfarlane/groupBy.php
php implementation of groupBy, which takes an array and a callback
<?php
$groupBy = function (array $items, callable $cb) {
return array_reduce($items, function ($acc, $item) use ($cb) {
$key = $cb($item);
$acc[$key][] = $item;
return $acc;
}, []);
};
@tnrn9b
tnrn9b / graph.hs
Created March 9, 2017 04:53 — forked from YoEight/graph.hs
Stream based Graph processing example in Haskell
module Graph where
import qualified Data.Map as M
import qualified Data.Set as S
data Vertex v =
Vertex
{ vertexId :: Int
, vertexValue :: v
}
@tnrn9b
tnrn9b / BuildGraph.hs
Created March 9, 2017 04:01 — forked from AndrasKovacs/BuildGraph.hs
Graph building code for SO question. See link in source.
-- http://stackoverflow.com/questions/24278006/need-advice-on-optimising-haskell-data-processing/
-- http://stackoverflow.com/questions/24344440/optimising-haskell-data-processing-part-ii
-- ****************** "Normal" version *****************************
import Data.Vector (Vector)
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as BS
import qualified Data.IntSet as IS