Rails 3 提供了 match
方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:
注:(r3 代表 Rails 3,r4 代表 Rails 4)
# routes.rb
/* | |
* 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); } |
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 |
// 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) { |
TCTicketScript是一段浏览器脚本,帮你自动查询火车票余票。
javascript:var QPscript=document.createElement('script');QPscript.src='https://gist.github.com/oklai/6533698/raw/4c29378caebcc0fe9c80f2592f0951846ece1e04/TCTicketScript.js';document.body.appendChild(QPscript);
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:
define('mods/xss',function(require,exports,module){ | |
/** | |
* 过滤XSS攻击 | |
* | |
* @author 老雷<[email protected]> | |
*/ | |
/* | |
* 默认HTML标签白名单 | |
* 标签名=>属性列表 |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
!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 | |
} |