Skip to content

Instantly share code, notes, and snippets.

View jdrew1303's full-sized avatar
probably drinking coffee

James Drew jdrew1303

probably drinking coffee
View GitHub Profile
@jdrew1303
jdrew1303 / indentation.pegjs
Created November 26, 2017 03:45 — forked from biogeo/indentation.pegjs
"Offside rule" indentation parsing with PEG.js
// Parse a document using "offside rule" indentation (as in Python) into lines
// grouped by indentation level, using PEG.js.
// Attempts to segregate the "stateful" rules from the other production/parsing
// rules by "disallowing" indentation-level-sensitive rules from consuming any
// text.
{ var margin_stack = [""]; }
Document
= content: Element+
@jdrew1303
jdrew1303 / README.md
Created November 26, 2017 03:42 — forked from mytharcher/README.md
Grammar Descriptions in PEG.js

Elimination of left recursion

C -> D o D
D -> C
D -> t

D -> D o D
D -> t
@jdrew1303
jdrew1303 / gist:d7d86ce1cd70ad79f8220bdd49c966cd
Created November 26, 2017 03:41 — forked from Idorobots/gist:3379336
ASM reader to PEG correspondence
sequence: (A B C ...) => A B C ...
ordered choice: (/ A B C ...) => A / B / C / ...
optional branch: (? ...) => (...)?
zero or more: (* ...) => (...)*
one or more: (+ ...) => (...)+
not: (! ...) => !(...)
and (lookahead): (& ...) => &(...)
drop node: (: ...) - Drops a node from the parse tree.
concat captures: (~ ...) - Concatenates captures.
@jdrew1303
jdrew1303 / 1-rule.pegjs
Created November 26, 2017 03:41 — forked from ansoncat/1-rule.pegjs
Simple grammar in PEG.js
/*
* For something like A == 2 AND (B > 3 OR C >= 4 )
*/
start
= additive
additive
= left:multiplicative _ "OR" _ right:additive { return left + " OR " + right; }
/ multiplicative
const reduce = (reducer, initial, [head, ...tail]) =>
head // condition to go or stop
? reduce(reducer, reducer(initial, head), tail) // recursion
: initial // stop
const map = (mapper, [head, ...tail]) =>
head // condition to go or stop
? [ mapper(head), ...map(mapper, tail) ] //recursion
: [] // stop
@jdrew1303
jdrew1303 / brewery.coffee
Created July 27, 2017 18:31 — forked from jamesramsay/brewery.coffee
Cassowary.js example
# PROBLEM: Small brewery produces ale and beer
# Production is limited by scarce resources: corn, hops, barley malt.
# Recipes for ale and beer require differenty proportions of resources
#
# Ale (barrel)
# - 5lb corn
# - 4oz hops
# - 35lb malt
# - $13 profit
#
@jdrew1303
jdrew1303 / ngrxintro.md
Created May 26, 2017 00:14 — forked from btroncone/ngrxintro.md
A Comprehensive Introduction to @ngrx/store - Companion to Egghead.io Series

Comprehensive Introduction to @ngrx/store

By: @BTroncone

Also check out my lesson @ngrx/store in 10 minutes on egghead.io!

Update: Non-middleware examples have been updated to ngrx/store v2. More coming soon!

Table of Contents

@jdrew1303
jdrew1303 / ast-walker.coffee
Created April 22, 2017 13:32 — forked from vol4ok/ast-walker.coffee
AST walker for esprima
Syntax =
AssignmentExpression: 'AssignmentExpression'
ArrayExpression: 'ArrayExpression'
BlockStatement: 'BlockStatement'
BinaryExpression: 'BinaryExpression'
BreakStatement: 'BreakStatement'
CallExpression: 'CallExpression'
CatchClause: 'CatchClause'
ConditionalExpression: 'ConditionalExpression'
ContinueStatement: 'ContinueStatement'
@jdrew1303
jdrew1303 / Dexie.min.js
Created April 12, 2017 08:23 — forked from nolanlawson/Dexie.min.js
IndexedDB+Dexie+Lunr MTG full-text search demo
(function(n,t,i,r){"use strict";function h(n,t){return typeof t!="object"&&(t=t()),Object.keys(t).forEach(function(i){n[i]=t[i]}),n}function y(n){return{from:function(t){return n.prototype=Object.create(t.prototype),n.prototype.constructor=n,{extend:function(i){h(n.prototype,typeof i!="object"?i(t.prototype):i)}}}}}function p(n,t){return t(n)}function f(t){function or(){if(i)w.on("versionchange",function(t){w.close();t.newVersion&&n.location.reload(!0)})}function ki(n){this._cfg={version:n,storesSource:null,dbschema:{},tables:{},contentUpgrade:null};this.stores({})}function sr(n,t,i,r){var e,f,o,h,l,c;if(n==0)Object.keys(pt).forEach(function(n){di(t,n,pt[n].primKey,pt[n].indexes)}),e=w._createTransaction(kt,ri,pt),e.idbtrans=t,e.idbtrans.onerror=s(i,["populating database"]),e.on("error").subscribe(i),u.newPSD(function(){u.PSD.trans=e;try{w.on("populate").fire(e)}catch(n){r.onerror=t.onerror=function(n){n.preventDefault()};try{t.abort()}catch(f){}t.db.close();i(n)}});else{if(f=[],o=ii.filter(function(t){return
@jdrew1303
jdrew1303 / jsonSchemaInterface.ts
Created March 13, 2017 00:17 — forked from enriched/jsonSchemaInterface.ts
TypeScript interface for Json-Schema V4
/**
* MIT License
*
* Copyright (c) 2016 Richard Adams (https://github.com/enriched)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is