Skip to content

Instantly share code, notes, and snippets.

View parano's full-sized avatar
🍱

Chaoyu parano

🍱
View GitHub Profile
@parano
parano / dom-like-parsing.rb
Created February 29, 2012 08:41
scrape jingdian
#!/usr/bin/ruby -w
require 'rexml/document'
include REXML
xmlfile = File.new("tour_treepath_area.xml")
xmldoc = Document.new(xmlfile)
root = xmldoc.root
#puts root.attributes["ver"]
@parano
parano / gist:44c086b3d09c329751f0
Last active October 1, 2015 06:28
multithread scrape
#!/usr/bin/ruby
# coding: utf-8
require 'uri'
#require 'iconv'
require 'open-uri'
require 'thread'
def scrape(from,to,n)
begin
@parano
parano / gist:181bcbf4046bab23a716
Last active October 1, 2015 05:28
scrape jingdina
#!/usr/bin/ruby
# coding: utf-8
require 'uri'
require 'iconv'
require 'open-uri'
if $0 == __FILE__
url = 'http://jingdian.tuniu.com/fengjing/'
num = 1
@parano
parano / gist:3ccaeeb5974564f8132d
Last active August 29, 2015 14:05
Ruby on Rails Controller - Allow Origin Header
class ApplicationController < ActionController::Base
before_filter :cors_set_access_control_header
# other staff
private
def cors_set_access_control_header
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
headers['Access-Control-Request-Method'] = '*'
@parano
parano / gist:10683720
Created April 14, 2014 21:23
Recursively delete all the '.DS_Store' files under current folder and its sub-folders
sudo find ./ -name ".DS_Store" -depth -exec rm -f {} \;
@parano
parano / gist:9518893
Created March 12, 2014 23:29
Sending Keystrokes to OS X via osascript, in Ruby
#!/usr/bin/ruby -w
def presskey(keycode)
system "osascript -e 'tell application \"System Events\" to key code #{keycode}'"
end
kVK_LeftArrow = 123
kVK_RightArrow = 124
kVK_DownArrow = 125
kVK_UpArrow = 126