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 SomeController < ApplicationController | |
# http://blog.jetthoughts.com/2010/12/22/allow-multiple-access-control-requests-for-rails/ | |
before_filter :set_access_control_headers | |
def show | |
@thing = Thing.find(params[:id]) | |
respond_to do |format| | |
format.html | |
format.json do | |
body = render_to_string(:locals => {:thing => @thing}) |
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
# ENV: | |
ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10.3.1] | |
pismo (0.6.2) | |
nokogiri (1.4.2) | |
... | |
>> require 'pismo' | |
=> true | |
# First method works: |
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
# in a large directory of pdf files | |
time find . -name "*.pdf" -exec md5 {} \; | |
... | |
real 0m4.773s | |
user 0m1.389s | |
sys 0m0.934s | |
time find . -name "*.pdf" | xargs md5 | |
... |
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
tell application "Terminal" | |
activate | |
end tell | |
tell application "Mail" | |
activate | |
end tell | |
tell application "gmail" | |
activate |
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
#bash function to retrieve the last 5 tweets from a user | |
#based on the Chirp hackathon project by @jf and @jazzychad | |
#hattip @gypak | |
last5tweets () | |
{ | |
dig +short TXT `dig +short TXT $1.timeline.twitter.viadns.org | tr -d \"` | tr -d \" | |
} | |
#usage: |
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
Liberation Mono, Lucidia Grande, Helvetica |
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
(defun mate-open-buffer () | |
"Open current file in TextMate" | |
(interactive) | |
(shell-command-to-string (concat "mate " buffer-file-name))) |
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
# From http://www.nitrxgen.net/factorialcalc.php | |
The resulting factorial of 4,000! is 12,674 digits long. | |
The result also contains 999 trailing zeroes (which constitutes to 7.88% of the whole number) | |
182880195151406501331474317557391904421737771073043921970645269542089597979731773648503702868704841073364430415692855717546724618615435573339426156179 | |
569967167452848315973174988187609374828049804195765129487206105589281297880978006205934295377053267406244538842850917439517567461444473623787224694361 | |
945759295799001142129733606589980739777146972612050486637259363374904040660979666371702540213488009442803422853559466496813162601634597438035771759033 | |
947331700768417647790821668911845293242300334141454978018325982185184065522570973925300245827389829191044067821687088714956035019058673999662987985348 | |
777479231791957914165044080548789747703086507071208788376249865760733404494148545783673833017157063581941274008498556040804733051968334824080794209642 |
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
# is this not already provided somewhere? | |
# even_distribution?([50,49,53]) => true | |
# even_distribution?(50,33,70]) => false | |
def even_distribution?(array, slack = 0.1) | |
exact_distribution = 1 / array.size.to_f | |
slack_val = exact_distribution * slack | |
ceil = exact_distribution + slack_val | |
floor = exact_distribution - slack_val | |
total = array.reduce{ |v,t| v + t }.to_f | |
array.each do |element| |