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 | |
# Finds all files in app directory that have CRLF line endings | |
# and converts them to LF line endings by removing all of the CR (\r) characters. | |
files = %x{find app -exec file {} \\; | grep CRLF}.map{|s| s.gsub(/:.*$/, '').strip} | |
files.each do |f| | |
puts "Processing #{f}" | |
system "tr -d '\\r' < #{f} > #{f}.new" | |
system "mv #{f}.new #{f}" | |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> | |
<head> | |
<title>semicolon</title> | |
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.6.0/build/logger/assets/logger.css"/> | |
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.6.0/build/yuitest/assets/testlogger.css"/> | |
<script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/yahoo-dom-event/yahoo-dom-event.js"></script> | |
<script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/logger/logger-min.js"></script> | |
<script type="text/javascript" src="http://yui.yahooapis.com/2.6.0/build/yuitest/yuitest-min.js"></script> |
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 'curb' | |
require 'webrat' | |
Webrat.configure { |config| config.mode = :mechanize } | |
session = Webrat.session_class.new | |
session.visit "http://en.oreilly.com/rails2009/public/schedule/proceedings" | |
session.dom.search(".en_session_downloads a").each do |link| | |
url = URI.escape(link['href']) |
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
#!/bin/sh | |
# clear Leopard font cache | |
# http://www.macworld.com/article/139383/2009/03/fontcacheclear.html | |
atsutil databases -removeUser | |
atsutil server -shutdown | |
atsutil server -ping |
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
#!/bin/ruby | |
def combine_mp3_files(final_mp3) | |
`rm #{final_mp3}` | |
Dir.glob("*.mp3").sort.each do |file| | |
puts "#{file}" | |
`cat "#{file}" >> #{final_mp3}` | |
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
class AjaxController < ApplicationController | |
def handle_checkbox | |
render :text => "You entered: #{params[:my_input]}" | |
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
#!/usr/bin/env ruby | |
require 'nokogiri' | |
xml = <<XML_END | |
<?xml version="1.0"?> | |
<root><this><document><is>truncated | |
XML_END | |
puts "Original:" | |
puts xml |
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
(defn calculate-pi | |
"Calculates Pi using the approximation 4 * (1 - 1/3 + 1/5 - 1/7 + …)" | |
[iterations] | |
(* 4.0 (reduce + (map eval (partition 2 (interleave (cycle '(+ -)) (map #(/ 1.0 %) (take iterations (filter odd? (iterate inc 1)))))))))) | |
(println "calculated pi =" (calculate-pi 100000)) | |
(println "Math.PI =" (. Math PI)) |
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
(defn calculate-pi | |
"Calculates Pi using the approximation 4 * (1 - 1/3 + 1/5 - 1/7 + ...)" | |
[iterations] | |
(let [odd-numbers (filter odd? (iterate inc 1))] | |
(* 4.0 | |
(apply + (map / (cycle [1.0 -1.0]) (take iterations odd-numbers)))))) | |
(println "calculated pi =" (calculate-pi 100000)) | |
(println "Math/PI =" Math/PI) |
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
class ApplicationController < ActionController::Base | |
protect_from_forgery | |
def admin_only! | |
if user_signed_in? | |
unless current_user.admin? | |
flash[:error] = "The feature you attempted to use is restricted to admins only." | |
redirect_to root_url | |
end | |
else |
OlderNewer