Skip to content

Instantly share code, notes, and snippets.

task :test do
["git clone git://github.com/radiant/radiant-reorder-extension.git vendor/extensions/reorder",
"rake radiant:extensions:reorder:migrate",
"rake radiant:extensions:reorder:update"].each do |command|
begin
sh( command )
rescue Exception => e
puts e
puts "FAIl!"
exit
@gunn
gunn / ruby_viz.rb
Created November 27, 2009 04:11
Crude ruby/IRB visualizer tool
%w[rubygems graphviz rbosa irb].each { |g| require g }
puts "==RubyViz==
For exploring the ruby language, draws a graph of ruby objects as they are instantiated.
Usage:
declare a top level instance-variable then set attributes one it
Example:
@dog = Object.new
def common_words the_words
prohibited = %w{i is about an and are as be by come de en this for from}
the_result = the_words.gsub(/[^a-z ]/i, "").split(" ").inject(Hash.new(0)) do |hash, w|
hash[w] += 1 if !prohibited.include?(w)
hash
end
the_result.sort{ |a,b| b[1] <=> a[1] }.first(10).map{|a,b| a }.join(", ")
end
p common_words("This is some text. This is some text. Slash development costs.")
# flash / restfulx doesn't like 422 error codes. if it's fxml, return 200s instead of 422s
require 'rack/utils'
class CleanFxmlResponseMiddleware
def initialize(app)
@app = app
end
def call(env)
@gunn
gunn / spam_link_checker.rb
Created February 16, 2010 11:25
Radiant wiki spam cleaner
@gunn
gunn / simple_authentication.rb
Created August 1, 2010 09:12
Simple Authentication demo for IRC user
USER_ID, PASSWORD = "zara", "pass123"
before_filter :admin?, :only => [ :edit, :delete ]
def admin?
@is_admin ||= authenticate_or_request_with_http_basic do |id, password|
id == USER_ID && password == PASSWORD
end
end
@gunn
gunn / custom_xml.rb
Created August 19, 2010 08:48
Custom xml demo for IRC user
def custom_xml hash
Builder::XmlMarkup.new(:indent => 2).tags do |tag|
hash.each do |key, val|
tag.tag! key do |v|
v.value val
end
end
end
end
@gunn
gunn / convert_to_haml.rake
Created August 19, 2010 22:42
Hamlize all views
require 'haml'
require 'haml/exec'
namespace :haml do
task :convert do
Dir.glob("app/views/**/*.html.erb").each do |html|
puts html + "..."
Haml::Exec::HTML2Haml.new([html, html.gsub(/\.erb$/, ".haml")]).process_result
File.delete(html)
end
@gunn
gunn / close_tags.rb
Created November 8, 2010 11:39
Nokogiri can be used to fix html
require "rubygems"
require 'nokogiri'
doc = Nokogiri::HTML.parse(<<-eohtml)
<html>
<head>
<title>Hello World</title>
<body>
<h1>This is an awesome document</h1>
<p>
@gunn
gunn / application_helper.rb
Created November 17, 2010 02:45
Helper to load from Google CDN but with fallbacks
def javascript_fallback primary, fallback, test
html = javascript_include_tag( primary )
html << "\n" << content_tag(:script, :type => "text/javascript") do
%Q{
if (#{test}) {
document.write(unescape("%3Cscript src='#{fallback}' type='text/javascript'%3E%3C/script%3E"));
}
}.gsub(/^ {6}/, '')
end
html