Skip to content

Instantly share code, notes, and snippets.

View bjoerge's full-sized avatar

Bjørge Næss bjoerge

View GitHub Profile
@bjoerge
bjoerge / rxjs-autocomplete.js
Last active August 29, 2015 14:12
Minimal rxjs autocomplete impl
// Based on https://github.com/Reactive-Extensions/RxJS/tree/master/examples/autocomplete
var Rx = require("rx-dom");
var querystring = require("querystring");
var jsonp = require("jsonp");
function searchWikipedia(term) {
return new Promise((resolve, reject) => {
var params = querystring.stringify({
@bjoerge
bjoerge / index.js
Created January 9, 2015 09:40
requirebin sketch
var EventEmitter = require("events").EventEmitter;
function PathEmitter() {
window.addEventListener('popstate', this._emitNavigate.bind(this));
EventEmitter.call(this);
}
PathEmitter.prototype = new EventEmitter();
PathEmitter.prototype._emitNavigate = function _emitNavigate() {
@bjoerge
bjoerge / nodeswitch.sh
Created January 14, 2015 10:24
Switch between io.js and node.js on OSX
alias useio='ln -sf /usr/local/bin/iojs /usr/local/bin/node && node -v'
alias usenode='(brew unlink node && brew link --overwrite node) > /dev/null && node -v'
@bjoerge
bjoerge / index.js
Created January 27, 2015 18:59
requirebin sketch
var concat = require('concat-stream');
function parseCSV(file) {
var parser = csvParse({
delimiter: ',',
auto_parse: true,
columns: true
});
return new Promise(function(resolve, reject) {
.playerContainer {
position: relative;
}
.playerContainer object {
height: 100%;
left: 0;
top: 0;
position: absolute;
width: 100%;
@bjoerge
bjoerge / parse.js
Created March 26, 2015 19:14
Parse CSV into objects with RxJS
const Rx = require('rx');
const csv = require('csv-parse');
const fs = require('fs');
Rx.Node.fromReadableStream(fs.createReadStream('file.csv').pipe(csv()))
.skip(1)
.withLatestFrom(rows.take(1), (row, header) => {
// Map header[i] => row[i]
return row.reduce((rowObj, cell, i) => {
rowObj[header[i]] = cell;
@bjoerge
bjoerge / skip-single-keys.js
Created April 29, 2015 14:11
Recursively skip keys with no siblings
const assert = require("assert");
function skipSingleKeys(obj) {
if (obj === null || typeof obj !== 'object') {
return obj;
}
const keys = Object.keys(obj);
if (keys.length == 1) {
return skipSingleKeys(obj[keys[0]]);
}
@bjoerge
bjoerge / .gitignore
Last active October 13, 2015 10:12
heidrun-logger
.DS_Store
npm-debug.log
node_modules
@bjoerge
bjoerge / README.md
Last active January 13, 2016 15:41
Minimalistic pubsub

Minimalistic pubsub

function pubsubber() {
  const subscribers = []
  return {
    subscribe,
    once,
    publish
 }
@bjoerge
bjoerge / syncUrl.js
Last active January 31, 2016 15:00
An require('url') replacement which keeps its properties in sync and supports a custom query parser/stringifier
import url from 'url'
export default Object.assign(configure(), configure)
function configure({qsImpl} = {}) {
return {
parse(urlToParse) {
return Object.assign(createUrlObject({qsImpl}), {
href: urlToParse
})