Skip to content

Instantly share code, notes, and snippets.

View briandoll's full-sized avatar
😎
Helping companies market and sell more software

Brian Doll briandoll

😎
Helping companies market and sell more software
View GitHub Profile
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})
# 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:
# 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
...
tell application "Terminal"
activate
end tell
tell application "Mail"
activate
end tell
tell application "gmail"
activate
#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:
Liberation Mono, Lucidia Grande, Helvetica
(defun mate-open-buffer ()
"Open current file in TextMate"
(interactive)
(shell-command-to-string (concat "mate " buffer-file-name)))
# 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
#!/bin/bash
# domainavailable
# Fast, domain name checker to use from the shell
# Use globs for real fun:
# domainavailable blah{1..3}.{com,net,org,co.uk}
# Inspired by foca / giles:
# http://gilesbowkett.blogspot.com/2009/02/simple-bash-domain-availability.html
trap 'exit 1' INT TERM EXIT
# 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|