Skip to content

Instantly share code, notes, and snippets.

@jjb
jjb / 1. code.rb
Created May 13, 2012 05:56
Usage of Timeout#timeout
require 'timeout'
begin
Timeout.timeout(1) do
# spending time doing, say, an IO operation accross the network
sleep 2
end
rescue
puts "Getting the big file took too long. Try again later."
end
# TODO: write blog posts
@jjb
jjb / gist:2347804
Created April 10, 2012 01:30
How to build the pg gem on os x with macports

First, install your preferred version of postgres

sudo port install posgresql84

Now you have psql84 available, which rolls right off your fingers. Even better, your pg_config is buried in a postgresql84 namespace. Fix both of these with:

sudo port select --set postgresql postgresql84

Now you can intall the gem

@jjb
jjb / 1update.md
Last active May 8, 2020 05:44
How to install ruby 1.9.3 on OS X with macports
@jjb
jjb / gist:1771190
Created February 8, 2012 17:12 — forked from trevorturk/gist:1756760
Bare minimum html5 template
<!DOCTYPE html>
<head>
<title>title</title>
</head>
<body>
<p>body</p>
</body>
foo = 1
[2].each{|foo| }
# in ruby 1.8, foo in this scope is now 2
# in ruby 1.9, foo stays as it was before the block, 1. hooray!
@jjb
jjb / gist:1262562
Created October 4, 2011 19:35
WHOIS spam
➔ whois apple.com
Whois Server Version 2.0
Domain names in the .com and .net domains can now be registered
with many different competing registrars. Go to http://www.internic.net
for detailed information.
APPLE.COM.WWW.BEYONDWHOIS.COM
APPLE.COM.WAS.PWNED.BY.M1CROSOFT.COM
@jjb
jjb / gist:996510
Created May 28, 2011 02:00
How to set the certificate file for Net::HTTP library-wide

In my previous post I described how to securely acquire the Mozilla list of root certificates and convert them to a form usable by curl and various libraries which don't ship with them.

Next, I want to point Net:HTTP at this file library-wide, so that it is used by all invocations of methods accessing https resources (in particular, Kernel#open, which in ruby 1.8.7 does not have a ca_file option and is therefore unusable with https). I hunted around the ruby standard library for a couple hours and came up with this:

require 'open-uri'
require 'net/https'

module Net
 class HTTP
@jjb
jjb / gist:996292
Created May 27, 2011 22:11
How to securely acquire the Mozilla root certificate bundle for use with curl, Net::HTTP, etc.

If you want to use curl or net-http/open-uri to access https resources, you will often (always?) get an error, because they don't have the large number of root certificates installed that web browsers have.

You can manually install the root certs, but first you have to get them from somewhere. This article gives a nice description of how to do that. The source of the cert files it points to is hosted by the curl project, who kindly provide it in the .pem format.

problem: Sadly, ironically, and comically, it's not possible to access that file via https! Luckily, the awesome curl project does provide us with the script that they use to produce the file, so we can do it securely ourselves. Here's how.

  1. git clone https://github.com/bagder/curl.git
  2. cd curl/lib
  3. edit mk-ca-bundle.pl and change:
@jjb
jjb / gist:950975
Created May 1, 2011 23:16
Using whenever with capistrano and bundler in multiple environments
We couldn’t find that file to show.