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
#!/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") |
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
:$ ./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 | |
:$ |
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
# 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 |
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
# 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 |
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
# Allows usage of the following syntax: | |
# Model.find :conditions => {:field => NotNull} | |
class NotNullClass | |
def map(*a, &b) | |
[].map(*a, &b) | |
end | |
def empty? | |
true |
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 href="hi">hi</a> |
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
#!/usr/bin/env ruby | |
require "rubygems" | |
require "dexterous" | |
require "pp" | |
file = ARGV.shift | |
unless file | |
puts "Usage: #{$0} FILE ID [ID2, ...]" | |
exit 1 |
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
#!/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+)/ |
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
set terminal gif | |
set xdata time | |
set timefmt "%s" | |
plot "out.txt" using 1:3, "out.txt" using 1:2 |
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
jQuery("textarea[maxlength]").change(function(){ | |
var len = parseInt(jQuery(this).attr("maxlength")); | |
var text = jQuery(this).val().substr(0, len); | |
jQuery(this).val(text); | |
}); |
OlderNewer