Skip to content

Instantly share code, notes, and snippets.

View sikachu's full-sized avatar

Prem Sichanugrist sikachu

View GitHub Profile
puts "Hello world :)"
#!/bin/sh -e
### BEGIN INIT INFO
# Provides: starling
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop starling server
### END INIT INFO
#
# starling This init.d script is used to start starling.
# It basically just calls starling.
@sikachu
sikachu / comtoon.rb
Created December 9, 2008 13:38
Collect data from Comtoom.com, store in /data folder, then create rss.xml file to be used as a feed
require 'rubygems'
require 'hpricot'
require 'iconv'
require 'time'
require 'builder'
require 'active_support/ordered_hash'
include ActiveSupport
THAI_MONTHS = [nil] + %w(มกราคม กุมภาพันธ์ มีนาคม เมษายน พฤษภาคม มิถุนายน กรกฎาคม สิงหาคม กันยายน ตุลาคม พฤษจิกายน ธันวาคม)
@sikachu
sikachu / string_format_with_strftime_extension.rb
Created July 3, 2009 06:07
Provide an extension for String's % method to call time#strftime if given argument is a Time object
# string_format_with_strftime_extension.rb
#
# Provide extension for String's % method to call Time%strftime when given argument
# is a Time object. So we can do <tt>"%d/%m/%Y" % Time.now</tt> and get the same
# result as <tt>Time.now.strftime "%d/%m/%Y"</tt>
#
# Put this file in #{RAILS_ROOT}/config/initializers so it will be automatically loaded.
class String
alias_method :format_without_strftime_extension, :%
@sikachu
sikachu / .bash_profile
Created August 11, 2009 05:19
automatically open .tmproj file with textmate if exists, or open the whole folder if there's no file name
e() {
TMPROJ=`ls -1 *.tmproj 2>/dev/null`
if [ ! $TMPROJ = "" ]; then
osascript -e "tell application \"TextMate\"
open \"${PWD}/${TMPROJ}\"
activate
end tell"
else if [ "$1" = "" ]; then
mate "."
else
@sikachu
sikachu / captcha.rb
Created December 22, 2009 04:55
Generate 4 characters captcha based on given string
require 'rubygems'
require 'active_support'
numbers = "%04d" % rand(9999)
available_colors = %w(#FF0080 #0080FF #408000 #FF8000 #FF6666 #6666FF #FF6FCF #800080 #FFCC66 #0000FF #FF0000)
colors = available_colors.shuffle[0,5]
y_points = [rand(10) + 20, rand(20), rand(20) + 30, rand(10) + 25, rand(20) + 15, rand(20) + 20]
`convert -size 135x50 xc:white \
-fill "#{colors[0]}" -stroke "#{colors[0]}" -strokewidth 1 -family TimesNewRoman -pointsize #{rand(25) + 25} \
def set_cookie(request, options)
if request.cookie_jar[@key] != options[:value] || !options[:expires].nil?
request.cookie_jar[@key] = options
end
end
" Highlight Ruby 1.8.x hash rocket
" This will prevent you to ever write it again
highlight ObsoleteHashRocket ctermbg=red guibg=red
au ColorScheme * highlight ObsoleteHashRocket guibg=red
au BufEnter * match ObsoleteHashRocket /=>/
au InsertEnter * match ObsoleteHashRocket /=>/
au InsertLeave * match ObsoleteHashRocket /=>/
@sikachu
sikachu / benchmark.rb
Created December 5, 2011 01:47
Compare between not define a method in subclass and define a method in subclass and call #super
require 'benchmark'
class A0
def foo
true
end
end
(1..1000).each do |n|
eval <<-RUBY
@sikachu
sikachu / gist:1760830
Created February 7, 2012 17:25
Check validity of the gem package
tar xzfO {package}.gem metadata.gz | gzcat | grep -q '\- =' && echo "Invalid"