Skip to content

Instantly share code, notes, and snippets.

View bs1180's full-sized avatar

Ben Smith bs1180

  • Vienna, Austria
View GitHub Profile
If you can see this, you're viewing a Github gist.
@bs1180
bs1180 / jolt-gist.js
Last active August 29, 2015 14:21 — forked from kaplas/jolt-gist.js
function notEmpty(val) {
return !_.isEmpty(val);
}
function valueAndValidFrom(observable, validator) {
validator = validator || notEmpty;
return {
valueS: observable.filter(validator),
validS: observable.map(validator)
};

Implementing TodoFRP in JavaScript

FRP to me means building your app by transforming values over time, from the input to the current state to the display.

This implementation is based on a the [graphics][1] library and is heavily inspired by [Elm][2]

A full implementation of TodoFRP can be found [online at Raynos/graphics example server][3]

Moving away from MVC

// Event capturing for Mithril.js
// Demo here: http://jsfiddle.net/barney/vsw8r3Lh/
m.capture = function capturingEventHandler( eventName, handler ){
function bindCapturingHandler( element ){
element.addEventListener( eventName, handler, true );
}
return function config( element, init ){
if( !init ) bindCapturingHandler( element );
};
@bs1180
bs1180 / firebase-utils.coffee
Last active August 29, 2015 14:27 — forked from tlrobinson/firebase-utils.coffee
Higher-level classes for synchronizing a nested Firebase ref, FirebaseEventEmitter and FirebaseImmutable. Work in progress.
Firebase = require "firebase"
Immutable = require "immutable"
{ EventEmitter } = require "events"
# Recursively listens to Firebase ref for modifications and emits "add",
# "change", and "remove" events with a path and value (except for "remove")
class FirebaseEventEmitter extends EventEmitter
constructor: (url) ->
EventEmitter.call(@)
@bs1180
bs1180 / form.js
Last active September 4, 2015 14:02
Dynamic forms in redux-form
export default class FormWrapper {
render () {
const Form = makeForm(['name', 'age', 'sex']);
return (
<div>
<Form />
</div>
@bs1180
bs1180 / accounting.sql
Created January 21, 2016 08:41 — forked from NYKevin/accounting.sql
Basic double-entry bookkeeping system, for PostgreSQL.
CREATE TABLE accounts(
id serial PRIMARY KEY,
name VARCHAR(256) NOT NULL
);
CREATE TABLE entries(
id serial PRIMARY KEY,
description VARCHAR(1024) NOT NULL,
amount NUMERIC(20, 2) NOT NULL CHECK (amount > 0.0),
-- Every entry is a credit to one account...
// define libraries you would need
var oauth = require('oauth')
var AWS = require('aws-sdk')
var cuid = require('cuid')
// define your OAuth-application credentials
var twitterConsumerKey = 'xxxxxxxxxxxxxxxxxxxx'
var twitterConsumerSecret = 'xxxxxxxxxxxxxxxxxxxx'
// ensure AWS is requesting the nearest region
@bs1180
bs1180 / gist:13d40a96c2f7c3c9848b
Created March 13, 2016 09:55
How to get an array of requested field names from graphQL query
import { simplifyAST } from 'graphql-sequelize'
const parseFields = (ast) => {
let s = simplifyAST(ast[0])
return Object.keys(s.fields)
}
// and then in use:
accounts: {
type: new GraphQLList(accountType),
@bs1180
bs1180 / list.js
Last active April 17, 2016 18:51
List Component
import React, { Component, PropTypes } from 'react'
import {dataConnect} from 'relate-js';
import { Link } from 'react-router'
const data = (
null,
null,
(props) => ({
fragments: {
viewer: {