Skip to content

Instantly share code, notes, and snippets.

🐢

shunwen shunwen

🐢
Block or report user

Report or block shunwen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View pattern_i_dont_understand.rb
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
View poly_association_reference.rb
# 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)
@shunwen
shunwen / Dockerfile
Created May 21, 2014
Dockerfile Rails
View Dockerfile
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
@shunwen
shunwen / rename_files.sh
Created Oct 29, 2014
Rename *.conf to *.conf.erb
View rename_files.sh
for f in *.conf
do
mv ${f}{,.erb}
done
@shunwen
shunwen / .kitchen.yml
Created Dec 2, 2014
chef apache cookbook test
View .kitchen.yml
---
driver:
name: docker
socket: <%= ENV['DOCKER_HOST'] %>
provisioner:
name: chef_zero
platforms:
- name: ubuntu-14.04
View worker_skeleton.rb
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 / chop_dos_date_time.bat
Created Jul 23, 2012
Chop %date% and %time% into useful tokens
View chop_dos_date_time.bat
REM get date from MM/DD/YYYY
SET YEAR=%DATE:~6,4%
SET MONTH=%DATE:~0,2%
SET DAY=%DATE:~3,2%
SET DATENOW=%YEAR%%MONTH%%DAY%
REM get time from hh:mm:ss.ss
SET hh=%TIME:~0,2%
IF %hh% LSS 10 SET hh=0%hh:~1,1%
SET mm=%TIME:~3,2%
@shunwen
shunwen / test.py
Created Dec 25, 2012
Python local variable declared in for loop stays alive outside the loop.
View test.py
bar = [1,2,3]
for foo in bar:
foo = foo + 1
break
print foo
@shunwen
shunwen / default_value_in_lambda.rb
Created May 13, 2013
Use default value in lambda
View default_value_in_lambda.rb
lambda { |*args| (args.first || default) }
@shunwen
shunwen / visit_url.rb
Created Jun 23, 2013
How to visit an url in Ruby
View visit_url.rb
# Not suitble for production
require 'open-uri'
open('http://github.com')
require 'net/http'
require 'uri'
uri = URI.parse "http://github.com/"
response = Net::HTTP.get_response uri
# Use system call
You can’t perform that action at this time.