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
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 |
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
%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 |
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
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.") |
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
# 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) |
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
require 'rubygems' | |
require 'mechanize' | |
def process_links links_block | |
url_regex = /http:\/\/[^"\/\s]+/ | |
agent = Mechanize.new | |
clean_links = [] | |
possible_spam = [] |
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
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 |
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
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 |
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
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 |
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
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 |
OlderNewer