Skip to content

Instantly share code, notes, and snippets.

View chunpu's full-sized avatar
🎯
Focusing

chunpu chunpu

🎯
Focusing
  • 360
  • China
View GitHub Profile
var tokenRules = [
['number', /^\d+/],
['space', /^ +/],
'+', '-', '*', '/'
]
var str = '1 + 2 * 3 + 33 / 3'
function lex(str, tokenRules) {
var tokens = []
var tokenRules = [
['number', /^\d+/],
['space', /^ +/],
'+', '-', '*', '/'
]
var str = '1 + 2 * 3 + 33 / 3'
function lex(str, tokenRules) {
var tokens = []
<script type='x' id='markdown'>
title
===
> blockquote
code
code2
### head
<script type='x' id='markdown'>
title
===
> blockquote
code
code2
### head
@chunpu
chunpu / socks.js
Created June 24, 2014 11:21
useful socks!
// copy from https://github.com/gvangool/node-socks
// it is useful but shit code style
// save and one day pretty it
var net = require('net'),
util = require('util'),
log = function(args) {
//console.log(args);
},
info = console.info,
errorLog = console.error,
@chunpu
chunpu / jquery-animate.js
Last active August 29, 2015 14:04
jQuery css3 animate, if browser support css3 transition, use it. (ps: however, the performance is not obvious improved, and it is not in promise queue, so just for simplest situation)
!function($, doc) {
if (!$ || !$.fn) return
var css3 = function() {
var style = doc.body.style
var test = ['transition', 'webkitTransition', 'MozTransition', 'msTransition']
for (var i = 0, x; x = test[i++];) {
if (x in style) {
return x
}
@chunpu
chunpu / demo.lua
Created August 14, 2014 07:57
a koa style lua sample
-- koa style downstream and upstream
local thread1 = coroutine.create(function(down)
print('thread1-down')
coroutine.yield(down)
print('thread1-up')
end)
local thread2 = coroutine.create(function(down)
print('thread2-down')
!function(fn) {
window.$ = fn()
}(function() {
var $ = function(selector, context) {
return new $.fn.init(selector, context)
}
// var
@chunpu
chunpu / debug.as
Created October 24, 2014 05:58
copy TJ's debug to as3
package {
import flash.external.ExternalInterface;
public class Log {
public static var logs:Array = [];
private static const INHERIT:String = 'color:inherit';
private static const PREFIX:String = '';
private static const LS_KEY:String = 'debug';
@chunpu
chunpu / macYear.js
Created July 14, 2016 06:17
get mac version with year
// https://browser.primatelabs.com/mac-benchmarks
Object.keys($('#mac32').find('tr').map(function() {return $(this).find('.name a').text()}).toArray().map(function(x) {return (/\w+ \d{4}/.exec(x) || [])[0]}).filter(function(x) {return x}).reduce(function(prev, val, key) {prev[val] = 1; return prev}, {})).map(function(x) {return x.split(' ')}).sort(function(x, y) {return x[1] - y[1]}).map(function(arr) {return arr[1] + ' ' + arr[0]}).join('\n')