Skip to content

Instantly share code, notes, and snippets.

View sundarj's full-sized avatar

Sundar Joshi sundarj

View GitHub Profile
@sundarj
sundarj / index.html
Last active August 29, 2015 14:21 — forked from anonymous/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>nest.key</title>
</head>
<body>
<script id="jsbin-javascript">
(function(window){
nest.request('/bts/api/post', {
'content-type': 'application/json; charset=utf-8',
'accept': 'application/json'
}).post(values, function() {
console.log(this.responseText);
});
@sundarj
sundarj / harmony-pubsub.js
Last active August 29, 2015 14:27
pub-sub pattern implemented with Harmony Proxies.
//const Proxy = require('harmony-proxy');
function Publisher() {
this.subscribers = [];
var self = this;
this.public = new Proxy({}, {
get: function (target, name) {
return target[name];
},
set: function (target, name, value) {
@sundarj
sundarj / Tabula.js
Last active August 29, 2015 14:27
Terminal-style table generator
function Tabula(init) {
this.fields = init.fields;
this.values = init.values;
function maxFieldLength(values, fields) {
return values.map(function(value, index) {
return Math.max(value.length, fields[index % fields.length].length);
}).map(function(value, index, full) {
return Math.max(value, full[index + full.length/2]);
@sundarj
sundarj / some-package.json
Last active August 29, 2015 14:28
Idea for a possible config setup
{
"name": "some app",
"version": "1.2.0",
"description": "i do a neat thing sometimes",
"main": "start.js",
"dependencies": {
"sequelize": "~1.3.7"
},
"devDependencies": {
"promise": "~7.0.1",
@sundarj
sundarj / keymap.js
Last active May 22, 2016 19:58
keymap[keycode] = keyname
// eslint-disable-next-line max-len
const keymap = [ '', '', '', 'CANCEL', '', '', 'HELP', '', 'BACK_SPACE', 'TAB', '', '', 'CLEAR', 'ENTER', 'RETURN', '', 'SHIFT', 'CONTROL', 'ALT', 'PAUSE', 'CAPS_LOCK', 'KANA', 'EISU', 'JUNJA', 'FINAL', 'HANJA', '', 'ESCAPE', 'CONVERT', 'NONCONVERT', 'ACCEPT', 'MODECHANGE', 'SPACE', 'PAGE_UP', 'PAGE_DOWN', 'END', 'HOME', 'LEFT', 'UP', 'RIGHT', 'DOWN', 'SELECT', 'PRINT', 'EXECUTE', 'PRINTSCREEN', 'INSERT', 'DELETE', '', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'COLON', 'SEMICOLON', 'LESS_THAN', 'EQUALS', 'GREATER_THAN', 'QUESTION_MARK', 'AT', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'WIN', '', 'CONTEXT_MENU', '', 'SLEEP', 'NUMPAD0', 'NUMPAD1', 'NUMPAD2', 'NUMPAD3', 'NUMPAD4', 'NUMPAD5', 'NUMPAD6', 'NUMPAD7', 'NUMPAD8', 'NUMPAD9', 'MULTIPLY', 'ADD', 'SEPARATOR', 'SUBTRACT', 'DECIMAL', 'DIVIDE', 'F1', 'F2', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12', 'F13', 'F14
@sundarj
sundarj / Machine.js
Last active August 27, 2015 16:36
JS State Machine
function Machine() {
this.states = [];
this.current = null;
this.verbose = false;
}
Machine.prototype.advance = function (input) {
function next(pass) {
this.current = this.states.filter(function (state) {
return state.name === this.current.to
}, this).pop();
<:import src="some/path">, <:include src="some/path">
imports the file under some/path into the current file
<:self>, <:this>, <:i>
these are placeholder elements, that indicate where the template's content should be put (in case you want anything before or after)
<:if condition>
start if statement
<:else>
start else statement
<:endif>, <:fi>
end if/else statement
@sundarj
sundarj / html.pegjs
Last active September 19, 2015 20:40
Simple HTML parser - supports quoted and unquoted attributes, text, elements (both open and close), comments
document = (html / text / comment)+
html = markup:(open document? close?) {
return {
type: 'element',
content: markup
}
}
open = '<' tn:tagname attrs:attribute* '/'? '>'
var currentToken, tokens;
function nextToken() {
return tokens.next().value;
}
function express(precedence) {
var token = currentToken;
currentToken = nextToken();