Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:
注:(r3 代表 Rails 3,r4 代表 Rails 4)
# routes.rb| #!/bin/bash | |
| # Pull this file down, make it executable and run it with sudo | |
| # wget https://gist.githubusercontent.com/bryanhunter/10380945/raw/build-erlang-17.0.sh | |
| # chmod u+x build-erlang-17.0.sh | |
| # sudo ./build-erlang-17.0.sh | |
| if [ $(id -u) != "0" ]; then | |
| echo "You must be the superuser to run this script" >&2 | |
| exit 1 | |
| fi |
| iex> use PipeInspect | |
| nil | |
| iex> "hello" |> String.reverse |> String.upcase |> String.downcase | |
| "olleh" | |
| "OLLEH" | |
| "olleh" |
| #!/bin/bash | |
| # Simple tcp server using netcat | |
| # - depending on the netcat version either use nc -l 5555 or nc -l -p 5555 | |
| # - verify with `telnet locahhost 5555` | |
| # - quit the telnet with `ctrl-]` and then type quit | |
| # - the while loop is there so reopen the port after a client has disconnected | |
| # - supports only one client at a time | |
| PORT=5555; | |
| while :; do nc -l -p $PORT | tee output.log; sleep 1; done |
| package main | |
| import ( | |
| "fmt" | |
| "log" | |
| "os" | |
| "runtime" | |
| "runtime/debug" | |
| "runtime/pprof" | |
| "strconv" |
| // Settings in here override those in "Default/Preferences.sublime-settings", | |
| // and are overridden in turn by file type specific settings. | |
| { | |
| "font_face": "Courier New", | |
| "font_size": 10, | |
| "ignored_packages": [] | |
| } |
| #!/usr/bin/env python | |
| # | |
| # Copyright 2012 Patrick Hetu <patrick.hetu@gmail.com> | |
| # | |
| # This program is free software: you can redistribute it and/or modify | |
| # it under the terms of the GNU General Public License as published by | |
| # the Free Software Foundation, either version 3 of the License, or | |
| # (at your option) any later version. | |
| # | |
| # This program is distributed in the hope that it will be useful, |
| class Settings < Settingslogic | |
| source "#{Rails.root}/config/application.yml" | |
| if Rails.env == 'development' | |
| namespace 'development-' + Socket.gethostname.gsub(/\W/, '-').gsub(/[-]{2,}/, '-') | |
| else | |
| namespace Rails.env | |
| end | |
| # load local settings |
| # yes, sometimes you need to do this. you get pilloried in a forum if you | |
| # ask about it, though! | |
| # this code taken from | |
| # http://wholemeal.co.nz/blog/2011/04/05/rendering-from-a-model-in-rails-3/ | |
| class MyModel < ActiveRecord::Base | |
| # Use the my_models/_my_model.txt.erb view to render this object as a string | |
| def to_s | |
| ActionView::Base.new(Rails.configuration.paths.app.views.first).render( |
| #!/bin/sh | |
| # | |
| # Script to prepare and restore full and incremental backups created with innobackupex-runner. | |
| # | |
| # This script is provided as-is; no liability can be accepted for use. | |
| # | |
| INNOBACKUPEX=innobackupex-1.5.1 | |
| INNOBACKUPEXFULL=/usr/bin/$INNOBACKUPEX | |
| TMPFILE="/tmp/innobackupex-restore.$$.tmp" |