Skip to content

Instantly share code, notes, and snippets.

@bakso
bakso / gist:4352283
Created December 21, 2012 11:33
前端计算价格区间时候的要用到的特定方法:舍弃后一位和增大前一位(一种自定义的toFixed方式)
/**
* 向下toFixed
* 例如: toFixedDown(0.407) == 0.40
* @param {Number} num 数值
* @param {Number} decimal 保留小数点后几位
* @return {Number}
*/
function toFixedDown(num, decimal){
var decimal = decimal || 2,
nstr = parseFloat(num)+'',
'use strict';
var through = require('through2'), //开发gulp插件必备的模块
Buffer = require('buffer').Buffer; //处理二进制buffer的时候有用
module.exports = function(opt){
/*
* gulp会将你通过诸如src('*/**/.js')获取的文件对象,传递到你返回的下面这个流对象里
* file对象可用属性:file.path、file.contents等
@bakso
bakso / surge.conf
Created October 29, 2015 05:25 — forked from soffchen/surge.conf
surge.conf
[General]
skip-proxy = 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12, 100.64.0.0/10, localhost, *.local
bypass-tun = 0.0.0.0/8, 1.0.0.0/9, 1.160.0.0/11, 1.192.0.0/11, 10.0.0.0/8, 14.0.0.0/11, 14.96.0.0/11, 14.128.0.0/11, 14.192.0.0/11, 27.0.0.0/10, 27.96.0.0/11, 27.128.0.0/9, 36.0.0.0/10, 36.96.0.0/11, 36.128.0.0/9, 39.0.0.0/11, 39.64.0.0/10, 39.128.0.0/10, 42.0.0.0/8, 43.224.0.0/11, 45.64.0.0/10, 47.64.0.0/10, 49.0.0.0/9, 49.128.0.0/11, 49.192.0.0/10, 54.192.0.0/11, 58.0.0.0/9, 58.128.0.0/11, 58.192.0.0/10, 59.32.0.0/11, 59.64.0.0/10, 59.128.0.0/9, 60.0.0.0/10, 60.160.0.0/11, 60.192.0.0/10, 61.0.0.0/10, 61.64.0.0/11, 61.128.0.0/10, 61.224.0.0/11, 100.64.0.0/10, 101.0.0.0/9, 101.128.0.0/11, 101.192.0.0/10, 103.0.0.0/10, 103.192.0.0/10, 106.0.0.0/9, 106.224.0.0/11, 110.0.0.0/7, 112.0.0.0/9, 112.128.0.0/11, 112.192.0.0/10, 113.0.0.0/9, 113.128.0.0/11, 113.192.0.0/10, 114.0.0.0/9, 114.128.0.0/11, 114.192.0.0/10, 115.0.0.0/8, 116.0.0.0/8, 117.0.0.0/9, 117.128.0.0/10, 118.0.0.0/11, 118.64.0.0/10, 118.128.0.0/9, 119.0.
# 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'
#
@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;
}
}
@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 / 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 / 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 / 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
}
}
}
ExpressionList
= e:Expression*
Expression
= ae:AssignExpression
/ we:WatchExpression
AssignExpression
= id: Identifier f: Factory "(" (params:ParameterList)? ")"