Skip to content

Instantly share code, notes, and snippets.

View nelix's full-sized avatar
🎯
Focusing

Nathan Hutchision nelix

🎯
Focusing
View GitHub Profile
@bendc
bendc / functional-utils.js
Last active July 15, 2025 04:33
A set of pure ES2015 functions aimed to make functional JavaScript more idiomatic.
// array utils
// =================================================================================================
const combine = (...arrays) => [].concat(...arrays);
const compact = arr => arr.filter(Boolean);
const contains = (() => Array.prototype.includes
? (arr, value) => arr.includes(value)
: (arr, value) => arr.some(el => el === value)
@mattdesl
mattdesl / debugger.js
Last active December 30, 2015 03:53
bug with setScriptSource ?
var Chrome = require('chrome-remote-interface')
Chrome({
chooseTab: function(tabs) {
var idx = 0
tabs.forEach(function(tab, i) {
if (tab.url === 'http://localhost:9966/')
idx = i
})
return idx
"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});
@jlongster
jlongster / forms-with-react.js
Last active May 8, 2017 14:15
higher-order form components w/react
// Simple wrapper to use bootstrap's grid system to position elements side-by-side
var VerticalFieldsElement = React.createClass({
render: function() {
return dom.div(
{ className: 'clearfix' },
React.Children.map(this.props.children, function(child) {
if(!child) {
return child;
}
@threepointone
threepointone / index.js
Last active March 22, 2016 10:17
time travel with disto
import {Dis} from 'disto';
import {photo} from 'disto/record';
let {register, dispatch, lock, unlock} = new Dis();
let store = photo(register({x: 0}, o => ({x: o.x+1}))); // simple increments
store.subscribe(o => console.log(o.x)); // 0
let t1 = store.snapshot();
dispatch('xyz'); // 1
@acdlite
acdlite / flux.js
Last active October 7, 2021 17:19
A Redux-like Flux implementation in <75 lines of code
/**
* Basic proof of concept.
* - Hot reloadable
* - Stateless stores
* - Stores and action creators interoperable with Redux.
*/
import React, { Component } from 'react';
export default function dispatch(store, atom, action) {
@threepointone
threepointone / sto.js
Created July 28, 2015 07:12
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({
/*
* Top-level error handler for async functions.
*/
async function errorWrap(cb, ...args) {
try {
await cb(...args);
} catch(err) {
if (err.stack) {
// `Error` object
console.log(err.stack);
var Immutable = require('devtools/client/shared/vendor/seamless-immutable');
var gentest = require('devtools/client/shared/vendor/gentest');
var types = gentest.types;
function maybe(type) {
return types.oneOf([type, types.constantly(null)]);
}
var foo = function () {
@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