Skip to content

Instantly share code, notes, and snippets.

View yangchenyun's full-sized avatar

Steven Yang yangchenyun

View GitHub Profile
@yangchenyun
yangchenyun / mock-test.coffee
Created July 29, 2012 16:40
test with mocks
describe "calculator", ->
it "should call the given method when parameter is valid", ->
# create mocks to
# 1. spy its behavior
# 2. verify the method call
# 3. stub the method return
#
mock = sinon.mock(sample)
mock.expects('minus').once().withArgs([1]).returns({})
@yangchenyun
yangchenyun / gist:3215393
Created July 31, 2012 09:23
vim settings to delete trailing spaces when saving files
" removing trailing spaces before saving
autocmd FileType c,cpp,java,php,coffee,javascript,ruby,python,yaml,sh autocmd BufWritePre <buffer> :%s/\s\+$//e
@yangchenyun
yangchenyun / database.yml
Created August 20, 2012 16:39
Rails Setup for using PostgreSQL
development:
adapter: postgresql
encoding: utf8
database: project_development
pool: 5
host: localhost
username:
password:
test: &TEST
@yangchenyun
yangchenyun / nginx.conf
Created August 23, 2012 19:10
genghis PHP Nginx Configuration File
server {
listen 80;
server_name genghis;
root /Users/yangchenyun/sites/genghis;
access_log /usr/local/var/log/nginx/genghis.access.log;
error_log /usr/local/var/log/nginx/genghis.error.log warn;
location / {
fastcgi_pass 127.0.0.1:9000;
@yangchenyun
yangchenyun / gist:3496677
Created August 28, 2012 09:48
github.com webhook sample
{
"pusher": {
"name": "none"
},
"repository": {
"name": ".vim",
"created_at": "2012-03-17T03:18:39-07:00",
"size": 484,
"has_wiki": true,
"watchers": 0,
@yangchenyun
yangchenyun / w2-packet-switching-what-is.md
Created October 16, 2012 18:13
calculator for end-to-end delay exercise

var c = 2 * Math.pow(10, 8); var l1 = 400 * 1000; var l2 = 200 * Math.pow(10, 6) * 1000; var p = 1600 * 8; // 1600 bytes var r1 = 2 * Math.pow(10, 6); var r2 = 64 * Math.pow(10, 3); var totalTime;

propagationDelay = function (c, l) { return l / c;

@yangchenyun
yangchenyun / w2-packet-switching-what-is.md
Created October 16, 2012 18:33
answers for data held in the pipe to London

var MB = Math.pow(2, 20); var Mb = Math.pow(10, 6); var roundTime = 90 / 1000;

bitToMB = function (bit) { return bit / (8 * MB) };

var totalBits = bitToMB(100 * Mb * roundTime)

@yangchenyun
yangchenyun / test.rb
Created December 9, 2012 14:30
examples to show module callback methods
# GistID: 4245259
module TestModule
# invoked when the module itself is extended by class
def self.extended(base)
puts "#{base} extended with #{self}"
end
# invoked when the mixined module or class is included in another module
# see below for more information
def append_features(base)
@yangchenyun
yangchenyun / active_support_concern_details.rb
Created December 9, 2012 15:02
detailed explaining what's happening with ActiveSupport::Concern
# GistID: 4245473
# Examine how ActiveSupport works
# https://github.com/rails/rails/blob/master/activesupport/lib/active_support/concern.rb#L110
module Foo
# @_dependencies is set to [] within Foo
# new class methods append_features and included is added to Foo
# they are triggered later by Bar
extend ActiveSupport::Concern
# forward the incoming http request to local port
server {
listen 80;
server_name dev.example.org *.dev.example.org;
access_log /var/log/nginx/dev-example-access.log;
error_log /var/log/nginx/dev-example-error.log;
root /home/yangchenyun/repositories/;