Skip to content

Instantly share code, notes, and snippets.

View shunwen's full-sized avatar
🐢

shunwen shunwen

🐢
View GitHub Profile
// XPath CheatSheet
// To test XPath in your Chrome Debugger: $x('/html/body')
// http://www.jittuu.com/2012/2/14/Testing-XPath-In-Chrome/
// 0. XPath Examples.
// More: http://xpath.alephzarro.com/content/cheatsheet.html
'//hr[@class="edge" and position()=1]' // every first hr of 'edge' class
def foo
some_function(true, { :before => {a: 1},
:after => {b: 2} })
call_block { do_something }
end
def bar
case @var
when 1
print [1..42]
@shunwen
shunwen / ssl_puma.sh
Created June 24, 2017 03:17 — forked from tadast/ssl_puma.sh
localhost SSL with puma
# 1) Create your private key (any password will do, we remove it below)
$ cd ~/.ssh
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@shunwen
shunwen / worker_skeleton.rb
Created January 13, 2015 07:50
Worker skeleton
class TestWorker
def startup
# Change process name
$PROGRAM_NAME = "HL7 - noop working..."
# Create pid file
File.open("tmp/pids/workers.pid", "a") {|f| f.puts Process.pid }
# Go daemon and disconnect from STDOUT/STDERR
@shunwen
shunwen / .kitchen.yml
Created December 2, 2014 03:21
chef apache cookbook test
---
driver:
name: docker
socket: <%= ENV['DOCKER_HOST'] %>
provisioner:
name: chef_zero
platforms:
- name: ubuntu-14.04
@shunwen
shunwen / rename_files.sh
Created October 29, 2014 08:36
Rename *.conf to *.conf.erb
for f in *.conf
do
mv ${f}{,.erb}
done
require 'flickraw'
require 'mini_magick'
require 'parallel'
def get_photo_urls_from_photoset(flickr, photoset_id)
total_pages = nil
current_page = 1
urls = []
opts = {
photoset_id: photoset_id,
@shunwen
shunwen / Dockerfile
Created May 21, 2014 13:56
Dockerfile Rails
FROM ubuntu:14.04
MAINTAINER Shunwen Hsiao, "https://github.com/shunwen"
RUN apt-get update
RUN apt-get install -qy git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common vim
RUN apt-get clean
# Install nodejs for js runtime
RUN add-apt-repository ppa:chris-lea/node.js
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.1.1'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
class Foo
def self.do_something *args
new(args).do_something
end
def initialize *args
# set instance variables
@var1 = args[0]
# and so on
end