Skip to content

Instantly share code, notes, and snippets.

@mattmanning
mattmanning / pi.rb
Created August 6, 2012 20:30
Estimate pi using random points and the distance formula
#!/usr/bin/env ruby
#
# Estimate pi using 1 random point:
# ./pi.rb 1
#
# Estimate pi using 1000 random points:
# ./pi.rb 1000
class Point
def initialize
class Array
def inc(val)
map {|e| e + val}
end
end
def add1(arr, val, n)
case n <=> 0
when 0
arr.inc(val)
Dear Matt,
Thank you for contacting Online Support.
Go Daddy is the world’s largest domain name registrar with more than 50 million domain names in our portfolio. Go Daddy has a full time presence in Washington D.C. and takes an active role in Congressional and legislative proposals.
Included in Go Daddy’s legislative efforts is the Stop Online Piracy Act (SOPA). We are currently reviewing the most recent legislative proposal and continue to educate ourselves on the many facets of SOPA. We look forward to working with Congress to refine legislative language about this issue when appropriate.
To review Go Daddy's statement on the matter, you can read this article:
@mattmanning
mattmanning / gist:1430691
Created December 4, 2011 17:02
Fixing Apachebench on OS X Lion
If you're getting this error trying to use ApacheBench on OS X Lion:
Benchmarking mwmanning.com (be patient)...apr_socket_recv: Connection reset by peer (54)
You need to download the latest beta version of Apache and rebuild ab. Here's how (assuming you have homebrew installed).
brew install pcre
tar xzvf httpd-2.3.15-beta.tar.gz
cd httpd-2.3.15-beta
./configure
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0L8ZLq6XbWgDJFTk5RE+hvGKCPHk7OuAME666HgeoG1uBYpUOu9W9OTOoUpSVA1fEsT9v1Q5y39gPoExGknqLEKm7DWQ8j8gITLI9u/pN5W6Mk8n9WzSbn0e9iymjdO7SyUH5y2V+vWjlAeb9RfSY+cpcVpfdVdQ+SaoOGRtr90pGO6Lgun5z2Kh+bgN2D0flQ4uVF+akG2FRZjUL74Slmdgqnji6SODBXemyAsKLx2dLkYVuVHmDYIkFoqDEqxQQ0H0d7oVYp82tsQgm/Q0znVAnZ/Kw18POuUu5hdbsQ5OVA+mhf8KoylAD6Doe2BDi39vJqOZ3U20q0OV2/a6cQ== matthew@redhouse.local
@mattmanning
mattmanning / gist:1165497
Created August 23, 2011 15:41
bundler unicode
-----> Heroku receiving push
-----> Ruby/Rails app detected
-----> Detected Rails is not set to serve static_assets
Installing rails3_serve_static_assets... done
-----> Configure Rails 3 to disable x-sendfile
Installing rails3_disable_x_sendfile... done
-----> Configure Rails to log to stdout
Installing rails_log_stdout... done
-----> Gemfile detected, running Bundler version 1.0.7
Unresolved dependencies detected; Installing...
Should see something like this:
>> Rails.cache
=> #<ActiveSupport::Cache::DalliStore:0x7f43ecf2e900 @data=#<Dalli::Client:0x7f43ece7be90 @ring=nil, @options={:expires_in=>0}, @servers=["mc5.ec2.northscale.net"]>, @middleware=ActiveSupport::Cache::Strategy::LocalCache, @thread_local_key=:active_support_cache_dalli_store_local_cache_69964857439360, @options={}>
Seeing this:
>> Rails.cache
=> <#ActiveSupport::Cache::MemoryStore entries=2, size=8, options={}>
@mattmanning
mattmanning / gist:989923
Created May 24, 2011 22:41
Heroku deploy failure on Cedar with 'include Rake::DSL' in Rakefile
[~/sendgrid-example] git push heroku master
Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 367 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
-----> Heroku receiving push
-----> Rails app detected
-----> Installing dependencies using Bundler version 1.1.pre.1
@mattmanning
mattmanning / gist:989933
Created May 24, 2011 22:47
Cedar rake db:migrate failure without 'include Rake::DSL'
[~/sendgrid-example] heroku run rake db:migrate
Running rake db:migrate attached to terminal... up, run.11
rake aborted!
undefined method `task' for #<SendgridExample::Application:0x000000034ab980>
(See full trace by running task with --trace)
require 'addressable/uri'
def remove_query_param(url, param)
uri = Addressable::URI.parse(url)
params = uri.query_values
params.delete(param)
uri.query_values = params
uri.to_s
end