Skip to content

Instantly share code, notes, and snippets.

View ssoroka's full-sized avatar
👾

Steven Soroka ssoroka

👾
View GitHub Profile
@ssoroka
ssoroka / Gemfile
Created February 16, 2011 20:10
A default Gemfile with most of the stuff I use in every project.
# Use "bundle install --path vendor/bundler"
source :rubygems
gem 'mysql'
gem 'rails', '~> 3.0' # rails 3!
gem 'hoptoad_notifier'
gem 'app_settings', :git => 'git://github.com/ssoroka/app_settings.git'
gem 'ignore_nil' # eg: ignore_nil { user.account.config.name.strip }
gem 'less'
@ssoroka
ssoroka / speller.rb
Created February 13, 2011 03:38
spelling game in 18 lines of ruby
dictionary = File.read('/usr/share/dict/words').split("\n")
dictionary = dictionary.select { |word|
word.length > 3 && word.length < 7
}
word_picked = dictionary[rand(dictionary.size)]
system %(say "#{word_picked}")
@ssoroka
ssoroka / prevent_doubleclick.js
Created January 13, 2011 17:03
Prevent a link with .prevent_doubleclick class from being clicked more than once every 10 seconds; avoids multiple link submits
function do_nothing() {
return false;
}
// prevent a second click for 10 seconds. :)
$('.prevent_doubleclick').live('click', function(e) {
$(e.target).click(do_nothing);
setTimeout(function(){
$(e.target).unbind('click', do_nothing);
}, 10000);
40+ newbie rails mistakes
themes:
Build for failure
expect services to be slow
expect services to be unavailable
Build so components can be easily replaced
Build so code can be easily reused
mistakes:
INSTALLER_VERSION = "1.2.1"
=begin
Contact Info:
Tim Hunter, [email protected], http://rmagick.rubyforge.org
Usage:
See the README.rtf file that accompanies this script.
# truncates html text to the desired text length.
# Like the Rails _truncate_ helper but doesn't break HTML tags or entities.
#
# accepts options:
# :link_to => url
def truncate_html(text, max_length = 400, options = {})
return text if text.blank?
elipsis = '&hellip;'
tag_delimiter_count = 0
in_html_entity = false
#!/usr/bin/env ruby
def test1
begin
raise Exception.new("worked1")
rescue Exception => e
puts "caught exception1"
end
end
# renders public/400.html on requests that do not supply expected parameters.
module ValidateRequestParameters
# accept_only :string, :for => [:first_name, :last_name]
# accept_only :number, :for => :age
# accept_only :hash, :for => :categories
# accept_only :boolean, :for => :wants_newsletter
# accept_only String::VALID_POSTAL, :for => :postal_code
# accept_only /\d{3}\-\d{4}/, :for => :phone
module ClassMethods
def accept_only(param_type, options)
######### bin/task_runner.rb ##########
# USAGE:
#
# ruby task_runner.rb run -- start the daemon and stay on top
# ruby task_runner.rb start -- start the daemon and stay on top
# ruby task_runner.rb stop stop all instances of the application
# ruby task_runner.rb restart stop all instances and restart them afterwards
require 'rubygems'
have_library: checking for GeoIP_new() in -lGeoIP... -------------------- no
"gcc -o conftest -I. -I/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/universal-darwin9.0 -I. -arch ppc -arch i386 -Os -pipe -fno-common conftest.c -L"." -L"/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib" -L. -arch ppc -arch i386 -lruby -lGeoIP -lpthread -ldl -lm "
conftest.c: In function ‘t’:
conftest.c:3: error: ‘GeoIP_new’ undeclared (first use in this function)
conftest.c:3: error: (Each undeclared identifier is reported only once
conftest.c:3: error: for each function it appears in.)
conftest.c: In function ‘t’:
conftest.c:3: error: ‘GeoIP_new’ undeclared (first use in this function)
conftest.c:3: error: (Each undeclared identifier is reported only once