Skip to content

Instantly share code, notes, and snippets.

View sikachu's full-sized avatar

Prem Sichanugrist sikachu

View GitHub Profile

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:

@sikachu
sikachu / quoting.applescript
Last active August 29, 2015 14:13
Green quoting for Colloquy
using terms from application "Colloquy"
on process outgoing chat message m
set messageBody to body of m as string
if messageBody starts with ">" then
set HTML of m to "<font color=\"green\">" & messageBody & "</font>"
end if
end process outgoing chat message
end using terms from
@sikachu
sikachu / test.rb
Last active August 29, 2015 14:14
Fetch vs []
require "benchmark/ips"
hash = Hash.new
Benchmark.ips do |x|
x.report("fetch") { x = hash.fetch(:foo, "bar") }
x.report("fetch block") { x = hash.fetch(:foo) { "bar" } }
x.report("[]") { x = hash[:foo] || "bar" }
end
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