Skip to content

Instantly share code, notes, and snippets.

View ihower's full-sized avatar
🎯
Focusing

Wen-Tien Chang ihower

🎯
Focusing
View GitHub Profile
@ihower
ihower / gist:113
Created July 21, 2008 20:26
"fooooooooooooobar" => "f***************r"
nickname = 'ihower'
1.upto(nickname.length-2) { |i| nickname[i] = '*' }
nickname # 'i****r'
@ihower
ihower / gist:36968
Created December 17, 2008 06:39
your exact age
today = Date.today
birthday = Date.new(1986, 12,31)
overflow = ( today.month > birthday.month ||
( today.month == birthday.month && today.day >= birthday.day )
)? 0 : 1
age = today.year.to_i - birthday.year.to_i - overflow
@ihower
ihower / gist:46568
Created January 13, 2009 19:08
nth week
def nthweek( time )
time.strftime("%U").to_i
end
def get_time_by_nthweek(i, year = Time.now.year)
first_day = Time.mktime(year,1,1)
first_day - first_day.wday.days + i*7.days
end
def next_nthweek(i, year = Time.now.year)
(function($) {
$(document).ready(function() {
$('#bd').click(function(event) {
var target = $(event.target);
if (target.attr('rel') == 'external') {
if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) return true;
else {
var oWin = window.open(target.attr('href'), '_blank');
if (oWin) {
if (oWin.focus) oWin.focus();
# Helper
def grid_row( cols )
out = ""
cols.each do |col|
out << "<div class=\"grid_#{col[0]}\">#{col[1]}</div>"
end
return out
end
# HTML (from http://960.gs/ code example)
<div class="container_12">
<div class="grid_7 prefix_1">
<div class="grid_2 alpha">
<p>...</p>
</div>
<div class="grid_3">
<p>...</p>
</div>
class ApplicationController < ActionController::Base
before_filter :log_session
def log_session
logger.info("Session debug: #{ (session.cgi.cookies['_registrano_session']).to_yaml }")
logger.info("Cookie get: #{session.instance_variable_get("@data").to_yaml}")
end
MD5 test
# ruby
require 'digest/md5'
puts Digest::MD5.hexdigest( File.read('foobar.png') )
# php5
echo md5( file_get_contents('foobar.png') );
@ihower
ihower / gist:78473
Created March 13, 2009 07:47
Counting Black Friday
# http://www.geocities.com/calshing/dayofweek.htm
def get_week( year , month , day)
c = year.to_s[0, year.to_s.length-2 ].to_i
y = year.to_s[year.to_s.length-2,2]
a = (14-month)/12
y = y.to_i - a
m = month + 12*a - 2
y_div_4 = ( y == 0 )? 0 : (y/4)
SetEnv force-proxy-request-1.0 1
SetEnv proxy-nokeepalive 1
# Rewrite index to check for static
RewriteRule ^/$ /index.html [QSA]
# Rewrite to check for Rails cached page
RewriteRule ^([^.]+)$ $1.html [QSA]
# Redirect all non-static requests to cluster