Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:
注:(r3 代表 Rails 3,r4 代表 Rails 4)
# routes.rb| require 'rubygems' | |
| require 'celluloid' | |
| class Waiter | |
| include Celluloid | |
| FORK_FREE = 0 | |
| FORK_USED = 1 | |
| attr_reader :philosophers | |
| attr_reader :forks | |
| attr_reader :eating |
| [ | |
| { | |
| name:"HTML5", | |
| uri:"http://www.w3.org/TR/html5/single-page.html", | |
| category:"markup" | |
| }, | |
| { | |
| name:"HTML 5.1", | |
| uri:"http://www.w3.org/TR/html51/single-page.html", | |
| category:"markup" |
| package main | |
| import ( | |
| "github.com/samuell/blow" | |
| "github.com/trustmaster/goflow" | |
| "runtime" | |
| ) | |
| const ( | |
| NUMTHREADS = 4 |
| // Just before switching jobs: | |
| // Add one of these. | |
| // Preferably into the same commit where you do a large merge. | |
| // | |
| // This started as a tweet with a joke of "C++ pro-tip: #define private public", | |
| // and then it quickly escalated into more and more evil suggestions. | |
| // I've tried to capture interesting suggestions here. | |
| // | |
| // Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_, | |
| // @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant, |
| /** | |
| The MIT License (MIT) | |
| Copyright (c) 2013 Jean Helou | |
| Permission is hereby granted, free of charge, to any person obtaining a copy | |
| of this software and associated documentation files (the "Software"), to deal | |
| in the Software without restriction, including without limitation the rights | |
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| copies of the Software, and to permit persons to whom the Software is |
| <snippet> | |
| <content><![CDATA[ | |
| assert.Equal(t, ${1:err}, nil) | |
| ]]></content> | |
| <!-- Optional: Set a tabTrigger to define how to trigger the snippet --> | |
| <tabTrigger>aerr</tabTrigger> | |
| <!-- Optional: Set a scope to limit where the snippet will trigger --> | |
| <scope>source.go</scope> | |
| </snippet> |
| package main | |
| import ( | |
| "bufio" | |
| "compress/gzip" | |
| "fmt" | |
| "io" | |
| "io/ioutil" | |
| "log" | |
| "net/http" |
| import ( | |
| "crypto/md5" | |
| "encoding/hex" | |
| ) | |
| func GetMD5Hash(text string) string { | |
| hasher := md5.New() | |
| hasher.Write([]byte(text)) | |
| return hex.EncodeToString(hasher.Sum(nil)) | |
| } |
| // alterkeys.c | |
| // http://osxbook.com | |
| // | |
| // Complile using the following command line: | |
| // gcc -Wall -o alterkeys alterkeys.c -framework ApplicationServices | |
| // | |
| // You need superuser privileges to create the event tap, unless accessibility | |
| // is enabled. To do so, select the "Enable access for assistive devices" | |
| // checkbox in the Universal Access system preference pane. |