Rails 3 提供了 match 方法供我们自定义 routes,然而我们要小心使用它以避免“跨站脚本攻击”(XSS Attack)。比如像这样的 routes:
注:(r3 代表 Rails 3,r4 代表 Rails 4)
# routes.rb| #!/usr/bin/env ruby | |
| require 'fileutils' | |
| require 'debugger' | |
| class Fixnum | |
| def to_surrogate_pair | |
| if self >= 0x10000 && self <= 0x10FFFF | |
| high = ((self - 0x10000) / 0x400).floor + 0xD800 | |
| low = ((self - 0x10000) % 0x400) + 0xDC00 |
| # coding=utf-8 | |
| __author__ = 'Vincent Ting' | |
| #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| __author__ = 'Vincent Ting' | |
| import cookielib | |
| import urllib2 |
| if [ -f "$rvm_path/scripts/rvm" ]; then | |
| source "$rvm_path/scripts/rvm" | |
| if [ -f ".rvmrc" ]; then | |
| source ".rvmrc" | |
| fi | |
| if [ -f ".ruby-version" ]; then | |
| rvm use `cat .ruby-version` | |
| fi |
| # 1. Make sure you have nginx sub module compiled in | |
| # nginx -V 2>&1 | grep --color=always '\-\-with\-http_sub_module' | |
| # 2. add two directives below at HTTP level | |
| # nginx.conf | |
| http { | |
| # ...... | |
| sub_filter '</head>' '<style type="text/css">html{ filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1); -webkit-filter: grayscale(100%); filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'><filter id=\'grayscale\'><feColorMatrix type=\'matrix\' values=\'0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\'/></filter></svg>#grayscale"); /* Firefox 10+, Firefox on Android */ |
| $ cat ~/.irbrc | |
| cat: /Users/pbarry/.irbrc: No such file or directory | |
| $ rails c | |
| Loading development environment (Rails 4.0.0) | |
| irb(main):001:0> Subscription.first | |
| Subscription Load (2.5ms) SELECT "subscriptions".* FROM "subscriptions" ORDER BY "subscriptions"."id" ASC LIMIT 1 | |
| => nil | |
| irb(main):002:0> puts ENV.keys.sort | |
| Apple_PubSub_Socket_Render | |
| Apple_Ubiquity_Message |
| <a href=""> | |
| <div class="cbCoorBox_e"> | |
| <img src="img/index/hanya.png" alt="合作机构"> | |
| </div> | |
| </a> |
| { | |
| 0: 'tench, Tinca tinca', | |
| 1: 'goldfish, Carassius auratus', | |
| 2: 'great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias', | |
| 3: 'tiger shark, Galeocerdo cuvieri', | |
| 4: 'hammerhead, hammerhead shark', | |
| 5: 'electric ray, crampfish, numbfish, torpedo', | |
| 6: 'stingray', | |
| 7: 'cock', | |
| 8: 'hen', |
| '''This script goes along the blog post | |
| "Building powerful image classification models using very little data" | |
| from blog.keras.io. | |
| It uses data that can be downloaded at: | |
| https://www.kaggle.com/c/dogs-vs-cats/data | |
| In our setup, we: | |
| - created a data/ folder | |
| - created train/ and validation/ subfolders inside data/ | |
| - created cats/ and dogs/ subfolders inside train/ and validation/ | |
| - put the cat pictures index 0-999 in data/train/cats |
| import React from 'react' | |
| import axios, { post } from 'axios'; | |
| class SimpleReactFileUpload extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state ={ | |
| file:null | |
| } |