Skip to content

Instantly share code, notes, and snippets.

View nelix's full-sized avatar
🎯
Focusing

Nathan Hutchision nelix

🎯
Focusing
View GitHub Profile
@nelix
nelix / fs.js
Created September 21, 2017 20:25 — forked from rokob/gist:755d26de4dabdae66dab
fullstory code
(function() {
var M = this && this.__extends || function() {
var a = Object.setPrototypeOf || {
__proto__: []
}instanceof Array && function(a, h) {
a.__proto__ = h
}
|| function(a, h) {
for (var f in h)
h.hasOwnProperty(f) && (a[f] = h[f])
@nelix
nelix / fast-json-packing.js
Created August 8, 2017 13:39 — forked from baptistemanson/fast-json-packing.js
JS fast packing with JSON
/**
* FAST PACKING / UNPACKING JSON
*
* If all objects in a collection follows a similar schema,
* then there is gain in changing the representation from a dictionary to a simple array.
*
* It is known results used in database, protocols, in v8 itself with shadow maps and IRL.
*
* In this example, we expect our final exchange to be equivalent to this literal representation:
* [
@nelix
nelix / sandbox.js
Created August 7, 2017 10:28 — forked from vthibault/sandbox.js
Javascript sandbox
/// Hack it ?
function sandbox(code) {
// Disable private functions not listed in window object
var blackList = [
'Function', // avoid using (new Function("code"))(); to get window access
'eval', // ...
'self', // return window object
'window', // ...
];
function appReducer(state={}, action) {
const {meta, ...rest} = action;
const {app, ...mrest} = meta;
if (!app) {
return state;
}
return {
...state,
@nelix
nelix / README.md
Last active December 24, 2016 17:53 — forked from hugolpz/README.md
Wonders of data uri and hrefs

Syntax

.data:hover  { fill: #B10000; opacity: 1; } /*  data = RED   */
.datum:hover { fill: #00B100; opacity: 1; } /*  datum= GREEN */
@nelix
nelix / act.js
Created March 22, 2016 10:18 — forked from threepointone/act.js
"use strict";
var [BRA, KET, IDENT] = ['BRA', 'KET', 'IDENT'];
function last(arr){ return arr[arr.length -1] };
export default function act(src, prefix){
var tree = src.split('').reduce((tokens, char)=> {
if(char==='{'){
tokens.push({type: BRA});
@nelix
nelix / async-disto.js
Created March 22, 2016 10:16 — forked from threepointone/async-disto.js
async action creators in disto
/* global fetch*/
import {Dis, act} from 'disto';
let {dispatch, register} = new Dis();
function timeout(t){
return new Promise(resolve =>
setTimeout(()=> resolve(true), t));
}
@nelix
nelix / sto.js
Created March 22, 2016 10:05 — forked from threepointone/sto.js
a lightweight flux style store as a component
import React from 'react';
export class Sto extends React.Component{
static defaultProps = {
store: x => x
}
state = {
value: this.props.store()
}
dispatch = action => this.setState({
@nelix
nelix / hash.js
Created March 22, 2016 10:01 — forked from threepointone/hash.js
immutable hashmaps for dummies
// murmurhash2 via https://gist.github.com/raycmorgan/588423
export default function doHash(str, seed) {
var m = 0x5bd1e995;
var r = 24;
var h = seed ^ str.length;
var length = str.length;
var currentIndex = 0;
while (length >= 4) {
@nelix
nelix / example.js
Last active February 11, 2016 21:46
import Expedite from './';
const getTest = async (testContext) => ({true: true, test: 'Hello World', testContext}); // pretend async thing thats not really
const pretendCreatePromise = ({uuid, name}) => Promise.resolve({uuid, name});
export default class Test extends Expedite {
// req: express request object
// context: dependency injection (added at class initialise to avoid singletons)
async get(req, context) { // magically wrapped in try catch in the middleware, checks for this.error then defaults back to the next item in express
const res = await getTest(context); // database or whatever promise