Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
#
# This script generates RESTful scaffolds from your pre-existing models.
# Copyright 2008 Kyle Maxwell, available under the MIT licence.
#
require "rubygems"
require "active_support"
content = File.read(File.dirname(__FILE__) + "/db/schema.rb").split("create_table")
:$ ./script/generate scaffold user
The name 'User' is either already used in your application or reserved by Ruby on Rails.
Please choose an alternative and run this generator again.
Suggestions:
exploiter
drug user
substance abuser
:$
# Put in initializers
#
# Usage:
# class Foo < ActiveRecord::Base
# finds_by :bar
# end
#
# foo = Foo.create(:bar => "omg")
# found = Foo.find "omg"
# assert_equal foo.id, found.id
# Encapsulates the pattern where you want your menus to
# reflect what page you are on.
#
module ApplicationHelper
def nav_to(name, opts = {}, html = {})
if url_for(opts.merge(:only_path => true)) == request.request_uri
tag("a", {:class => "current"}.merge(html), open = true) + name + "</a>"
else
link_to(name, opts, html)
end
# Allows usage of the following syntax:
# Model.find :conditions => {:field => NotNull}
class NotNullClass
def map(*a, &b)
[].map(*a, &b)
end
def empty?
true
<a href="hi">hi</a>
#!/usr/bin/env ruby
require "rubygems"
require "dexterous"
require "pp"
file = ARGV.shift
unless file
puts "Usage: #{$0} FILE ID [ID2, ...]"
exit 1
#!/usr/bin/env ruby
#
# Example:
# $: git log --numstat -w --summary --date=iso | this.rb
# <timestamp> <added> <deleted>
#
require "time"
DATE = /^Date:(.*)/
DIFF = /^(\d+)\s+(\d+)/
set terminal gif
set xdata time
set timefmt "%s"
plot "out.txt" using 1:3, "out.txt" using 1:2
jQuery("textarea[maxlength]").change(function(){
var len = parseInt(jQuery(this).attr("maxlength"));
var text = jQuery(this).val().substr(0, len);
jQuery(this).val(text);
});