Skip to content

Instantly share code, notes, and snippets.

View sikachu's full-sized avatar

Prem Sichanugrist sikachu

View GitHub Profile
@sikachu
sikachu / clean.rb
Created April 27, 2012 22:41
Cleanup stupid Safari bookmark duplication
require 'rubygems'
require 'nokogiri'
lines = File.open("Safari Bookmarks.html").readlines
urls = []
output = []
lines.each do |line|
if line =~ %r(<DT><A HREF="(.+)">.+</A>$)
@sikachu
sikachu / gist:2648731
Created May 9, 2012 20:51
Fat Radio URL
http://radio1.serverradio.net:8012/
@sikachu
sikachu / down_wwdc_2012.rb
Created June 11, 2012 20:47
Download "WWDC 2012" from apple. http://events.apple.com.edgesuite.net/126pihbedvcoihbefvbhjkbvsefbg/event/index.html This script is based on previous Apple Special Event download script: https://gist.github.com/1997591
#!/usr/bin/env ruby
require 'open-uri'
size_hash = {"720p" => "6540", "720i" => "4540", "540p" => "2540", "540i" => "1840", "360p" => "1240", "360i" => "0640", "360is" => "0440", "224p" => "0240"}
if ["--help", "help", "-h"].include?(ARGV[0]) || ARGV.size < 1
puts "Usage: #{File.basename __FILE__} ( #{size_hash.keys.join(' | ')} )"
exit 0
end
@sikachu
sikachu / gist:3057373
Created July 6, 2012 00:53
window.it from Jasmine monkeypatched to show error if test is not implemented.
window.it = (desc, func) ->
if func?
jasmine.getEnv().it(desc, func)
else
jasmine.getEnv().it desc, ->
throw "test is undefined"
class User
has_many :topics
has_many :posts, through: topics
end
class Topic
belongs_to :user
has_many :posts
end
Benchmark.bmbm do |x|
x.report('start_with?') { 10_000.times { "fooo".start_with?('foo') }}
x.report('regexp') { 10_000.times { "fooo" =~ /^foo/ }}
end
@sikachu
sikachu / 01_function.zsh
Last active December 13, 2015 21:58
Open up the browser and create a new pull request
gpr() {
current_branch=`git rev-parse --abbrev-ref HEAD`
if [[ $1 != '' ]]; then
upstream=$1
else
upstream='master'
fi
origin_username=`git remote -v | grep 'origin.\+fetch' | sed "s/^.*github.com[\/:]\(.*\)\/\(.*\)\.git.*$/\1/"`
origin_repository=`git remote -v | grep 'origin.\+fetch' | sed "s/^.*github.com[\/:]\(.*\)\/\(.*\)\.git.*$/\2/"`
if [[ `git remote | grep sikachu` != '' ]]; then
@sikachu
sikachu / gist:4982127
Created February 19, 2013 00:54
calling object's method in method definition in Ruby
irb(main):001:0> class Foo
irb(main):002:1> def initialize(a, b = a.to_s)
irb(main):003:2> puts [a, b].inspect
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> Foo.new 1
[1, "1"]
=> #<Foo:0x007f973d9ca410>
@sikachu
sikachu / gist:7014735
Last active December 25, 2015 17:39
Get rid of libxml2 version mismatch when running Nokogiri
# Note: This assume that you're using libxml2 from Homebrew, which is keg-only.
# Run this command:
$ bundle config build.nokogiri --with-xml2-include=/usr/local/opt/libxml2/include/libxml2 --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xslt-dir=/usr/local/opt
# Remove and rebundle. You use Bundler, right?
$ yes | gem uninstall nokogiri --force
$ bundle

Keybase proof

I hereby claim:

  • I am sikachu on github.
  • I am sikachu (https://keybase.io/sikachu) on keybase.
  • I have a public key whose fingerprint is 7270 8199 79B1 6AD7 0571 6B7B 889C 472F 2DA2 8377

To claim this, I am signing this object: