Skip to content

Instantly share code, notes, and snippets.

View swang's full-sized avatar

Shuan Wang swang

  • San Francisco, CA
View GitHub Profile
D, [2009-02-02 14:34:22 #3582] DEBUG -- : Rendering template: errors/not_found_404
W, [2009-02-02 14:34:22 #3582] WARN -- : http://localhost:3000/ not found.
D, [2009-02-02 14:34:22 #3582] DEBUG -- : /Library/Ruby/Gems/1.8/gems/waves-0.8.2/lib/runtime/request.rb:63:in `not_found'
D, [2009-02-02 14:34:22 #3582] DEBUG -- : /Library/Ruby/Gems/1.8/gems/waves-0.8.2/lib/runtime/response_mixin.rb:31:in `send'
D, [2009-02-02 14:34:22 #3582] DEBUG -- : /Library/Ruby/Gems/1.8/gems/waves-0.8.2/lib/runtime/response_mixin.rb:31:in `not_found'
D, [2009-02-02 14:34:22 #3582] DEBUG -- : /Library/Ruby/Gems/1.8/gems/waves-0.8.2/lib/resources/mixin.rb:120:in `__instance_exec_13288380'
D, [2009-02-02 14:34:22 #3582] DEBUG -- : /Library/Ruby/Gems/1.8/gems/functor-0.5.1/lib/object.rb:11:in `send'
D, [2009-02-02 14:34:22 #3582] DEBUG -- : /Library/Ruby/Gems/1.8/gems/functor-0.5.1/lib/object.rb:11:in `instance_exec'
D, [2009-02-02 14:34:22 #3582] DEBUG -- : /Library/Ruby/Gems/1.8/gems/functor-0.5
@swang
swang / iTunes_cleanup.rb
Created November 28, 2011 18:12
Cleans up music files in iTunes library (for Windows) that no longer exist (file moved or deleted).
require "win32ole"
itunes = WIN32OLE.new('iTunes.Application')
library = itunes.LibraryPlaylist
tracks = library.Tracks
c = 1
while (c < tracks.count )
if (tracks[c].Location == "" && tracks[c].BitRate > 0)
#puts tracks[c].Location + " " + tracks[c].Artist + " : " + tracks[c].Name
tracks[c].delete
else
@swang
swang / everyday_im_knuth_shuffling.rb
Created January 11, 2012 07:21
everyday i'm knuth shuffling.
def everyday_im_knuth_shuffling( arr_list )
(arr_list.length-1).downto(0).each {|i|
n = rand(i + 1)
# swap
tmp = arr_list[n]
arr_list[n] = arr_list[i]
arr_list[i] = tmp
}
arr_list
end
@swang
swang / gist:2642784
Created May 9, 2012 07:51
Command to verify private keys work in plink for git
& 'C:\Program Files (x86)\PuTTY\plink.exe' -agent -v -i <location of .ppk file> [email protected]
@swang
swang / gist:2670326
Created May 13, 2012 02:22
Caesar Cipher Snippet
def caesar_encrypt(str,sft=0)
atoz = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
str.upcase.tr( atoz, atoz[sft..-1]+atoz[0..(sft-1)])
end
def caesar_decrypt(str,sft=0)
atoz = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
str.upcase.tr( atoz[sft..-1]+atoz[0..(sft-1)], atoz)
end
@swang
swang / gist:2778902
Created May 24, 2012 01:27
Basic/quick search/replace regexp to add comments to top of javascript functions
Search for: (^\s+)(function [a-zA-Z]+)\(
Replace with: $1/*\n\n$1$2\n\n$1input: \n$1output: \n\n$1*/\n$1$2(
Generates:
/*
function testFunction
input:
@swang
swang / gist:2866992
Created June 4, 2012 07:39
Snippet of code for pace of a basketball game.
# quarter = what quarter
# mins_left
# secs_left: whatever the timer in the game says. So if its 4th quarter, with 3:23 left to play means you play mins = 3, secs = 23
# team1_score: score of team #1
# team2_score: score of team #2
# goal: how many points team1 + team2 are suppose to make.
def pace(quarter, mins_left, secs_left = 0, team1_score, team2_score, goal)
total_time = 48*60 # 48 minutes in a game
@swang
swang / gist:2879170
Created June 6, 2012 00:49
vim stuff
:set tabstop=2
:set shiftwidth=2
:set expandtab
:set number
@swang
swang / gist:3094273
Created July 11, 2012 22:47
grep non-svn files
# grep while excluding .svn directories if your grep version <= 2.5.1 and does not have exclude-dir
grep -Iir --exclude="*\.svn*" "<pattern>" *
@swang
swang / kill coffee
Created October 10, 2012 00:08
Snippet to kill excessive node watch :|
# 'xargs kill -9' after making sure you're not killing anything other than node
ps aux | grep "node" | grep -v "grep node" | cut -c 16-20