Discover gists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a:link { color: blue; } | |
a:visited { color: purple; } | |
a:hover { color: purple; } | |
a:active { color: red; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% content_for('body') do %> | |
<% form_view :outlet => true, :tag => 'table', :class =>'form' do %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stmt = dbm.prepare "INSERT OR REPLACE INTO items VALUES ( ?, ?, ? );" | |
begin | |
items.each do |item| | |
stmt.execute(*item) | |
end | |
ensure | |
stmt.close rescue nil | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scope 'merb-gen' do | |
# do merb-gen stuff here | |
end | |
scope 'monkey' do | |
# do monkey stuff here | |
end | |
[ew[ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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."); | |
}) | |
}); |