Skip to content

Instantly share code, notes, and snippets.

View lanrion's full-sized avatar
🎯
Focusing

lanrion lanrion

🎯
Focusing
  • guǎng zhōu
View GitHub Profile

Routes

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

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

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

# routes.rb

Capybara

save_and_open_page

Matchers

have_button(locator)
data:text/html, <style type="text/css">#e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div id="e"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("e");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script>

Getting started

First add your twitter username and password. Then server.rb and once it's started open websocket.html in your browser. You should see some tweets appear. If not take a look at the javascript console.

require 'rubygems'
require 'eventmachine'
children = []
Signal.trap('SIGINT') do
EventMachine.next_tick { EventMachine.stop_event_loop }
end
Signal.trap('EXIT') do
@lanrion
lanrion / 360buy.rb
Created January 23, 2013 09:57 — forked from mimosz/.gitignore
# -*- encoding: utf-8 -*-
require 'mini_magick'
require 'rtesseract'
require 'nokogiri'
require 'nestful'
require 'csv'
require 'pp'
class Buy360
def initialize(url='')
@lanrion
lanrion / 360buy.rb
Created November 4, 2012 15:55 — forked from mimosz/.gitignore
京东商品价格解析
# -*- encoding: utf-8 -*-
require 'mini_magick'
require 'rtesseract'
require 'nokogiri'
require 'nestful'
require 'csv'
require 'pp'
class Buy360
def initialize(url='')
@lanrion
lanrion / OPML
Created May 27, 2012 14:14 — forked from hooopo/OPML
opml.xml
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>Google 阅读器中 Hooopo 的订阅</title>
</head>
<body>
<outline text="(未知标题)" title="(未知标题)" type="rss"
xmlUrl="http://thoughtrails.com/feeds.atom" htmlUrl="http://thoughtrails.com"/>
<outline text="(未知标题)" title="(未知标题)" type="rss"
xmlUrl="http://confreaks.net/feeds2.feedburner.com/confreaks-general" htmlUrl="http://www.google.com/reader/view/feed%2Fhttp%3A%2F%2Fconfreaks.net%2Ffeeds2.feedburner.com%2Fconfreaks-general"/>
@lanrion
lanrion / OPML
Created May 27, 2012 14:10 — forked from hooopo/OPML
opml.xml
<?xml version="1.0" encoding="UTF-8"?>
<opml version="1.0">
<head>
<title>Google 阅读器中 Hooopo 的订阅</title>
</head>
<body>
<outline text="(未知标题)" title="(未知标题)" type="rss"
xmlUrl="http://thoughtrails.com/feeds.atom" htmlUrl="http://thoughtrails.com"/>
<outline text="(未知标题)" title="(未知标题)" type="rss"
xmlUrl="http://confreaks.net/feeds2.feedburner.com/confreaks-general" htmlUrl="http://www.google.com/reader/view/feed%2Fhttp%3A%2F%2Fconfreaks.net%2Ffeeds2.feedburner.com%2Fconfreaks-general"/>