Skip to content

Instantly share code, notes, and snippets.

View yolio2003's full-sized avatar
🎯
Focusing

monkeytao yolio2003

🎯
Focusing
View GitHub Profile
@nightscape
nightscape / sexp.peg
Created August 16, 2012 18:27
S-Expression grammar for PEG.js
/*
* Grammar to generate an S-Expressions parser for Javascript using http://pegjs.majda.cz/
*/
start
= expression*
integer "integer"
= digits:[0-9]+ { return parseInt(digits.join(""), 10); }
@bshamric
bshamric / cache.js
Last active January 24, 2021 12:08
I like phantomjs, but it doesn't directly support getting images from webpages without requesting them separately like in casperjs. I went through QTNetworking code in the phantomjs repo until I figured out where the cache was. To use this, have all three files in the same directory. Then modify test.js for whatever you need. Call phantom js wit…
var fs = require('fs');
//this is the path that QTNetwork classes uses for caching files for it's http client
//the path should be the one that has 16 folders labeled 0,1,2,3,...,F
exports.cachePath = '/path/to/phantomjs/cache/data/folder';
//this is the extension used for files in the cache path
exports.cacheExtension = "d";
//the resources that are to be saved
@nightire
nightire / Changes in Rails 4_1.md
Last active April 21, 2025 07:25
拥抱 Rails 4 —— 详述 Rails 4 的新变化

Routes

小心地使用 Match(Rails 3 已实现)

Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:

注:(r3 代表 Rails 3,r4 代表 Rails 4)

# routes.rb
@BrendanEich
BrendanEich / gist:5753666
Created June 11, 2013 00:36
ES6 version of Peter Norvig's Sudoku solver originally written in Python
// XXX should be standard (and named clone, after Java?)
Object.prototype.copy = function () {
let o = {}
for (let i in this)
o[i] = this[i]
return o
}
// Containment testing for arrays and strings that should be coherent with their iterator.
Array.prototype.contains = String.prototype.contains = function (e) {
@oklai
oklai / README.md
Last active January 9, 2019 10:11
TCTicketScript - 火车票自动查询工具

TCTicketScript

TCTicketScript是一段浏览器脚本,帮你自动查询火车票余票。

如何使用

  1. 请使用Chrome浏览器;
  2. 拖拽这个链接到你的书签栏,抢票工具,拷贝下面的代码;
javascript:var QPscript=document.createElement('script');QPscript.src='https://gist.github.com/oklai/6533698/raw/4c29378caebcc0fe9c80f2592f0951846ece1e04/TCTicketScript.js';document.body.appendChild(QPscript);
@iwillwen
iwillwen / app.js
Last active December 30, 2015 19:08
webjs example
var web = require('webjs');
var redis = require('redis');
var client = redis.createClient();
// webjs style
web.run(process.argv[2] || 8080)
.config({
'views': __dirname + '/views',
'view engine': 'ejs', // jade, etc.

Javascript #router. Features:

  • Just 70 lines of code.
  • Router scope can be bound to any object (default window); just change first parameter
  • Triggers custom DOM (Level 2) events on window.document.
  • IE 9+, FF, and Webkit based browsers [Tested only in Chrome and FF].
define('mods/xss',function(require,exports,module){
/**
* 过滤XSS攻击
*
* @author 老雷<[email protected]>
*/
/*
* 默认HTML标签白名单
* 标签名=>属性列表
@staltz
staltz / introrx.md
Last active May 9, 2025 12:50
The introduction to Reactive Programming you've been missing
@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
}