Generate a Gravatar URL with Ruby
To get a Gravatar you need to hash an email address with the MD5 algorithm.
MD5 is a part of the Ruby standard library. Rails loads it by default, but otherwise you will have to require it yourself.
This is a simple implementation.
Gravatar su...
Written by Sean Behan on 04/11/2014
Extract Domain Names From Links in Text with Postgres and a Single SQL Query
This query and pattern will return urls in text all within a single SQL query.
select substring(column_name from '.*://([^/]*)') as domain_name from table_name;
And here it is in a larger query, say for retrieving page view counts for referrers.
...
Written by Sean Behan on 11/23/2013
Python String Format Precision of Float
You can use string interpolation in combination with a dictionary for simple formatting.
print "My name is %(name)s and I have $%(change)0.2f in change in my pocket!" % { 'name': 'Sean', 'change': 00.23 }
# My name is Sean and I have $0.23 in chang...
Written by Sean Behan on 11/20/2013
How To Install Pyscopg2 Python Postgres Driver on Mac OSX with Homebrew, Postgres.app and VirtualEnv
You might have to append the path of the Postgres.app bin directory to your path in order to install the Python driver for Posgres.
export PATH=$PATH:/Applications/Postgres.app/Contents/MacOS/bin
To find the location of the application try this
...
Written by Sean Behan on 11/19/2013
A Ruby Regex for Removing Links and Images from Text
r = /https?:\/\/[\S]+/i
you_string.gsub(r, '')
Here's the rubular regex to play around with yourself http://rubular.com/r/SRKkYrW4IJ
Written by Sean Behan on 11/14/2013
How To Fix ActiveRecord::ConnectionTimeoutError with Sinatra
If you get this error message
ActiveRecord::ConnectionTimeoutError could not obtain a database connection within 5.000 seconds (waited 5.001 seconds)
Try closing the connection after each request using "after" in Sintara.
# app.rb
after { A...
Written by Sean Behan on 11/09/2013
Open Files in TextMate 2 with A Single Click
To open files with a single click from the file browser inside of TextMate 2 run this command from the terminal
defaults write com.macromates.TextMate.preview fileBrowserSingleClickToOpen -bool true
And to turn it off
defaults write com.macro...
Written by Sean Behan on 11/04/2013
How to Create A Unix Timestamp or the Epoch in Python
It's a little convoluted. Seeing as it's a pretty common thing you use when programming computers one might think that there would be a quick and easy method for it. But from what I can tell there isn't. So here is a snippet that will give you a *nix Epoc...
Written by Sean Behan on 11/02/2013
Roll Your Own Session Based Flash Messaging w/ Sinatra
Session based flash messages are fairly common in web apps. They work well when you have a temporary status to report back to the user, such as successfully saving a form.
If you use Rails it comes with the Framework. If you are using Sinatra there ar...
Written by Sean Behan on 11/01/2013