Skip to content

Instantly share code, notes, and snippets.

View parano's full-sized avatar
🍱

Chaoyu parano

🍱
View GitHub Profile
@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
@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: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: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: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 / 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:9c7290220a230b82de37
Created April 19, 2013 04:59
use peterson method to implement semaphore
/*
* =====================================================================================
*
* Filename: mutex_semaphore.c
*
* Description: use peterson method to implement semaphore
*
* Version: 1.0
* Created: 04/16/2013 03:27:04 PM
* Revision: none
#!/bin/ruby
require 'RMagick'
include Magick
animation = ImageList.new(*Dir["*.png"])
animation.delay = 10
animation.write("animated.gif")
@parano
parano / gist:9653676
Created March 19, 2014 23:19
Send random arrow keys using ruby, Mac OS X only
#!/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
We can make this file beautiful and searchable if this error is corrected: It looks like row 7 should actually have 7 columns, instead of 4. in line 6.
reporting_campaign,da😄te,group,cre*&ative,type,na^$%me,valu()e
Belsomra-Q1-2016,2016-02-08,desktop,Always Awake? | Get The Information You Need To | Help Aid Your Insomnia Symptoms. | www.help-treat-insomnia.com,metric,Clicks,0
Belsomra-Q1-2016,2016-02-08,desktop,Always Awake? | Get The Information You Need To | Help Aid Your Insomnia Symptoms. | www.help-treat-insomnia.com,metric,Impressions,15
Belsomra-Q1-2016,2016-02-08,desktop,Can't Sleep At Night? | Find Answers To Common Questions &amp; | Learn About A Treatment Option Here | www.help-treat-insomnia.com,metric,Clicks,0
Belsomra-Q1-2016,2016-02-08,desktop,Can't Sleep At Night? | Find Answers To Common Questions &amp; | Learn About A Treatment Option Here | www.help-treat-insomnia.com,metric,Impressions,6
Belsomra-Q1-2016,2016-02-08,desktop,Can't Sleep At Night? | Find Information About Insomnia | &amp; A Treatment Option Today. | www.help-treat-insomnia.com,metric,Clicks,0
Belsomra-Q1-2016,2016-02-08,desktop,Can't Sleep At Night? | Find Information About