Skip to content

Instantly share code, notes, and snippets.

@trey
trey / gist:2976
Created July 28, 2008 22:32
LOVE/HATE
a:link { color: blue; }
a:visited { color: purple; }
a:hover { color: purple; }
a:active { color: red; }
<% content_for('body') do %>
<% form_view :outlet => true, :tag => 'table', :class =>'form' do %>
@ktsugita
ktsugita / tai64.rb
Created July 28, 2008 23:43
tai64.rb
# tai64.rb
# http://cr.yp.to/libtai/tai64.html
class Time
TAI64_REGEX = Regexp.new(/(?:^\@)?([0-9a-fA-F]{16})/)
TAI64N_REGEX = Regexp.new(/#{TAI64_REGEX}([0-9a-fA-F]{8})/)
def self.tai64(str, leapseconds=10)
if match = TAI64N_REGEX.match(str).to_a.values_at(1)
tai64 = match[0].hex - 2**62 - leapseconds
return Time.at(tai64)
@ishikawa
ishikawa / sqlite_insert_or_replace.rb
Created July 29, 2008 00:41
SQLite INSERT or REPLACE
stmt = dbm.prepare "INSERT OR REPLACE INTO items VALUES ( ?, ?, ? );"
begin
items.each do |item|
stmt.execute(*item)
end
ensure
stmt.close rescue nil
end
scope 'merb-gen' do
# do merb-gen stuff here
end
scope 'monkey' do
# do monkey stuff here
end
[ew[
@ishikawa
ishikawa / simple_array_shuffle.rb
Created July 29, 2008 01:05
Ruby: Random sort an array
# Random sort an array (via http://d.hatena.ne.jp/tanakaBox/20070512/1178915094)
# Not perfect, but simple.
# Usage:
# >> (1..10).to_a.shuffle
# => [1, 3, 2, 5, 9, 7, 6, 8, 4, 10]
class Array
def shuffle() self.to_a.shuffle!; end
def shuffle!() self.sort! { rand(3) - 1 }; end
end
#python or ruby - turns out it doesn't matter
inc = random(0,2*pi)
az = random(0,2*pi)
dist = random(5,80)
cx = dist * cos(az)
cy = dist * sin(az)
sh = (cy/80)*0.6
x = 350 + (250+cx)*cos(inc)
y = 350 + (250+cx)*sin(inc)
z = cy
r.match(:domain => "admin") do |admin|
admin.match("/users").to(:controller => "admin/users")
end
r.match(:domain => "site") do |site|
site.match("/users").to(:controller => "site/users")
end
# l33t regular expression for matching URLs
# thanks @ Alex Payne of Twitter for providing this
# http://groups.google.com/group/twitter-development-talk/browse_thread/thread/369d81c2010f16a8#msg_eb0409891c5e18e3
%r{(<\w+.*?>|[^=!:'"/]|^)((?:https?://)|(?:www\.))([-\w]+(?:\.[-\w]+)*(?::\d+)?(?:/(?:(?:[~\w\+%-]|(?:[,.;@:][^\s$]))+)?)*(?:\?[\w\+%&=.;:-]+)?(?:\#[\w\-\.]*)?)([[:punct:]]|\s|<|$)}x
// This version works
$('#account_info_form').submit(function() {
$.facebox(function() {
$("#account_info_form").ajaxSubmit(function(respText, statusText) {
if (statusText == "success")
$.facebox("Account Information successfully update");
else
$.facebox("Failed to update Account Information.");
})
});