Instantly share code, notes, and snippets.

View eyetv_xmltv_grabber.rb
#!/usr/bin/env ruby
# SweDB XMLTV Grabber for EyeTV
# by Henrik Nyh <> under the MIT License.
# Configure the list of channels below and run this script as a cron job, e.g.
# 0 */12 * * * ruby /path/to/this/script.rb
View gist:27428
require 'net/http'
require 'digest/md5'
# Is there a Gravatar for this email?
def gravatar?(email)
hash = Digest::MD5.hexdigest(email.to_s.downcase)
response ='', 80).request_head("/avatar/#{hash}?size=1&default=.")
response.code != '302'
View Ensure Image Extension.scpt
on adding folder items to myFolder after receiving myFiles
repeat with myFile in myFiles
set myPath to (POSIX path of myFile)
set myType to do shell script "file --mime-type -br " & (quoted form of myPath)
if myType is "image/jpeg" and myPath does not end with ".jpg" and myPath does not end with ".jpeg" then
set newExtension to ".jpg"
else if myType is "image/gif" and myPath does not end with ".gif" then
set newExtension to ".gif"
View unsimple_format.rb
# From Rails
def simple_format(text, html_options={})
start_tag = '<p>'
text = text.to_s.dup
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
text.gsub!(/\n\n+/, "</p>\n\n#{start_tag}") # 2+ newline -> paragraph
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
text.insert 0, start_tag
text << "</p>"
View init.rb
Merb::BootLoader.before_app_loads do
# This will get executed after dependencies have been loaded but before your app's classes have loaded.
require 'config/settings'
View .bashrc
# username@Machine ~/dev/dir[master]$ # clean working directory
# username@Machine ~/dev/dir[master*]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/[\1$(parse_git_dirty)]/"
View rails_ext.rb
module ActiveSupport::Inflector
# Parameterize "Foo's and Charles's bar" into "foos-and-charles-bar"
# instead of into "foo-s-and-charles-s-bar".
def parameterize_with_apostrophe_removal(string, sep = '-')
string = string.dup
string.gsub!(%r{s's\b}i, 's')
string.gsub!(%{'}, "")
parameterize_without_apostrophe_removal(string, sep)
ssh hyper "osascript -e 'tell app \"iTunes\" to back track'"
View .irbrc
# Provides "ri", history survives restart etc
require 'rubygems'
require 'wirble'
# Show rails root in script/console prompt
require 'irb/completion'
View httpd-vhosts.conf
# Make Apache with enabled mod_proxy forward
# to for use in local Rails development.
<VirtualHost *:80>
RewriteEngine on
RewriteRule /(.*) http://localhost:3000/$1 [P]