Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://web-device.oss-cn-hangzhou.aliyuncs.com/aliyun-iot-device-sdk.min.js?00001"></script>
</head>
<body>
<script>
@bakso
bakso / gist:1e73f4794bda7297d6d3c6f2487a22bd
Last active September 20, 2017 06:35
super proxy pass
var http = require('http'),
httpProxy = require('http-proxy');
var url = require('url');
var proxy = httpProxy.createProxyServer({});
proxy.on('proxyReq', function(proxyReq, req, res, options) {
proxyReq.setHeader('host', req.query.host);
});
var server = http.createServer(function(req, res) {
{
function buildBinaryExpression(op, left, right) {
return {
type: 'BinaryExpression',
operator: op,
left: left,
right: right
}
}
}
ExpressionList
= e:Expression*
Expression
= ae:AssignExpression
/ we:WatchExpression
AssignExpression
= id: Identifier f: Factory "(" (params:ParameterList)? ")"
@bakso
bakso / rpn.pegjs.wrong
Created January 10, 2017 07:48
rpn peg.js wrong version
{
function buildBinaryExpression(op, left, right) {
return {
type: 'BinaryExpression',
operator: op,
left: left,
right: right
}
}
}
@bakso
bakso / indentation-based.pegjs
Created August 10, 2016 06:19 — forked from dmajda/indentation-based.pegjs
Simple intentation-based language PEG.js grammar
/*
* Simple Intentation-Based Language PEG.js Grammar
* ================================================
*
* Describes a simple indentation-based language. A program in this language is
* a possibly empty list of the following statements:
*
* * S (simple)
*
* Consists of the letter "S".
@bakso
bakso / caculator.pegjs
Created July 25, 2016 02:22
Caculator modified from pegjs online example
Expression
= head:Term tail:(_ ("+" / "-") _ Term)* {
var result = head, i;
for (i = 0; i < tail.length; i++) {
if (tail[i][1] === "+") { result += tail[i][3]; }
if (tail[i][1] === "-") { result -= tail[i][3]; }
}
return result;
@bakso
bakso / caculator.js
Last active July 24, 2016 15:00
Caculator implement by lexer and parser
'use strict'
const EOF = "EOF"
class Lexer {
constructor(input) {
this.input = input
this.index = -1
this.currentChar = null
this.step()
}
@bakso
bakso / json.pegjs
Last active July 22, 2016 15:03
json.pegjs
{
function mix(origin, target){
var origin = origin || {};
for (var i in target) {
origin[i] = target[i];
}
return origin;
}
}
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to make opened Markdown files always be soft wrapped:
#
# path = require 'path'
#