Skip to content

Instantly share code, notes, and snippets.

// do as self.isany()
self.isa = function(/* args */) {
if (arguments.length > 0) {
// Prepare arguments and constructors
var args = Array.prototype.slice.call(arguments), // args provide an .isany() feature; could do in sep method
makers = [] //: list
ypcmc02106:pages dyoder$ irb
>> load 'startup.rb'
=> true
>> with
ArgumentError: wrong number of arguments (0 for 1)
from (irb):2:in `with'
from (irb):2
self.eq = function(other) {
// Is self equal to other?
if (self.length !== other.length) return 0
var equal = 1
for (var i=0; i<self.length; i++) {
if (self[i] !== other[i])
equal = 0
}
return equal
}
self.istypeof = function(other) {
// Is self the same type as other?
}
self.isany = function(types) {
// take nums, chars, lists and maybe args
// can't see any reason to take hashes
}
self.same = function(other) {
// Is self other?
if (no(other)) return self
return self === other
}
if (results = Parser.new.parse).nil?
# parse failure
else
# displaying help info and exiting is a valid execution method
execute_with_options results
end
@oliyoung
oliyoung / gist:1975
Created July 24, 2008 00:55
form helper to display tags from acts_as_taggable_on
class ActionView::Helpers::FormBuilder
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::FormTagHelper
def tag_list(method, options={})
return false unless options[:tags]
links = options[:tags].map do |tag|
link_to_function( tag.to_s, "toggle_tag('#{tag}', '#{@object.class.to_s.downcase}_#{method.to_s.pluralize.downcase}')", :class => ["tag", (@object.send(method).map(&:name).include?(tag.to_s) ? "selected" : "")].compact.join(" "), :id => tag )
end
@oliyoung
oliyoung / gist:1976
Created July 24, 2008 00:57
convert a string into a URL safe slug
class String
def to_param
self.downcase.strip.gsub(/[\/ ]+/, "-").gsub(/[^a-z0-9\-\_]+/i, "").gsub(/\-+/,"-")
end
end
@oliyoung
oliyoung / gist:1977
Created July 24, 2008 01:01
Capistrano deploy script with mongrel specifics
set :application, "application.url.com"
set :repository, "http://svn.#{application}/trunk/"
set :runner, ENV['LOGNAME']
set :deploy_to, "/var/www/#{application}"
role :app, application
role :web, application
role :db, application, :primary => true
task :after_update_code, :roles => :app do
run "ln -s #{deploy_to}/shared/system/mongrel_cluster.yml #{release_path}/config/mongrel_cluster.yml"
@oliyoung
oliyoung / gist:1978
Created July 24, 2008 01:02
show an animated gif whenever an AJAX called is made
Ajax.Responders.register({
onCreate: function() {
if($('busy') && Ajax.activeRequestCount>0)
Effect.Appear('busy',{duration:0.5,queue:'end'});
},
onComplete: function() {
if($('busy') && Ajax.activeRequestCount==0)
Effect.Fade('busy',{duration:0.5,queue:'end'});
}
});