Skip to content

Instantly share code, notes, and snippets.

James Forbes JAForbes

Block or report user

Report or block JAForbes

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@JAForbes
JAForbes / readme.md
Last active Aug 4, 2018
A simple Javascript
View readme.md

Warning this is purely a thought experiment and will probably go nowhere. The language semantics will likely be incongruent and non-rigourous. Proceed at your own risk.

Philosophy

Javascript always wanted to be a functional language. But for historical, political and perhaps even sensible reasons, JS's original mission was never truly fulfilled.

But what if, we take JS and start removing things. We can remove mutation, remove variables, remove classes, remove variadic signatures, remove default arguments and on and on.

What if we go back to ES1 and re-evaluate a future unperturbed by corporate circumstance.

@JAForbes
JAForbes / index.js
Last active Jul 1, 2017
Non tagged tempalte literal SQL convenience function.
View index.js
const SQL = {
transform(xs){
return xs.reduce(function(p, x, i){
if( i % 2 == 0 && typeof x != 'string' ){
throw new TypeError('Expected a string at index '+i)
}
@JAForbes
JAForbes / index.js
Created Jul 1, 2017
pg-promise specific tagged template literal
View index.js
/* eslint-disable fp/no-rest-parameters, fp/no-throw */
const pg = require('pg-promise')
const Injectable = {
ensure: a =>
a.isInjectable
? a
: Injectable.Untrusted(a)
,Trusted: x => ({ trusted: true, x, isInjectable: true })
,Untrusted: x => ({ trusted: false, x, isInjectable: true })
@JAForbes
JAForbes / index.js
Last active Jul 14, 2017
Nominally Typed Maybe/Either + some combinators
View index.js
/* eslint-disable fp/no-mutation */
const $ = require('sanctuary-def')
const Sum = require('sum-type')($, { checkTypes: true, env: $.env }).Named
const a = $.TypeVariable('a')
const b = $.TypeVariable('b')
const T = (a, f) => f(a)
const I = x => x
@JAForbes
JAForbes / state-router.js
Last active Mar 25, 2017
An early concept for easily serializing state in the URL, and avoiding the pain and verbosity of action types.
View state-router.js
const {
lensPath
, view
, set
, concat
} = require('ramda')
const afterSilence = require('flyd/module/afterSilence')
const m = require('mithril')
@JAForbes
JAForbes / groups.sql
Last active Mar 22, 2017
Set up permission groups when an organization is created.
View groups.sql
with args as (
select
$[organization_id] as organization_Id
,$[user_id] as user_id
)
-- Create the new data
,role_permissions_agg as (
select gen_random_uuid() as role_id, * from (
@JAForbes
JAForbes / flagon.js
Created Mar 15, 2017
flagon v2 (return of the monoids)
View flagon.js
module.exports =
[
{ name: 'OR', op: (a,b) => a | b , empty: 0}
,{ name: 'XOR', op: (a,b) => a ^ b, empty: 0 }
,{ name: 'AND', op: (a,b) => a & b , empty: 1}
,{ name: 'LSHIFT', op: (a,b) => a << b, empty: 0 }
,{ name: 'RSHIFT', op: (a,b) => a >> b, empty: 0 }
]
.map(
({name, op, empty}) => ({
@JAForbes
JAForbes / request.js
Last active Mar 14, 2017
A wrapper around m.request that relies on partial application for convenient configuration.
View request.js
const R = require('ramda')
const m = require('mithril')
const p = R.pipe
/*
used as a default function for a bunch of situations
*/
const empty = R.always("")
function normalizeErrorFormat(e){
throw new Error(e.error)
View gist:918d2e4983630a7f4903679aac0c2afa
Name | New Server Per Request | Server Per Endpoint | Hosting |
-------|------------------------|---------------------|----------------------------------------------|
Lambda | Yes | Yes | Amazon |
Micro | No | Yes | Heroku, zeit/now, Google App Engine, ec2 etc |
Express| No | No | Heroku, zeit/now, Google App Engine, ec2 etc |
@JAForbes
JAForbes / autocomplete.ts
Created Sep 12, 2016
Mithril + TS wrapper around Awesomeplete
View autocomplete.ts
/* tslint:disable no-any */
declare var require : any;
/* tslint:enable no-any */
import Component from '../utils/component'
const m = require('mithril')
const Awesomplete = require('awesomplete')
const R = require('ramda')
/* tslint:disable */
You can’t perform that action at this time.