Skip to content

Instantly share code, notes, and snippets.

View jpinnix's full-sized avatar

Jeremy Pinnix jpinnix

View GitHub Profile
#!/usr/bin/env ruby
require 'net/imap'
# Source server connection info.
SOURCE_HOST = 'mail.example.com'
SOURCE_PORT = 143
SOURCE_SSL = false
SOURCE_USER = 'username'
SOURCE_PASS = 'password'
@jpinnix
jpinnix / remove_textile_and_html_helper.rb
Created October 29, 2008 01:13
Remove textile and HTML
def remove_textile_and_html(text)
textilize(text).gsub(/<\/?[^>]*>/, "")
end
class Foo
def bar
"test"
end
end
@jpinnix
jpinnix / .irbrc
Created March 12, 2009 18:37
.irbrc with wirble
# load libraries
require 'rubygems'
require 'wirble'
require 'pp'
alias q exit
# Easily print methods local to an object's class
class Object
def local_methods
class Test::Unit::TestCase
def self.should_have_default_scope(scope_call, find_options = nil)
klass = model_class
matcher = have_default_scope(scope_call).finding(find_options)
should matcher.description do
assert_accepts matcher.in_context(self), klass.new
end
end
end
# Back up your iTunes library to S3
git clone git://github.com/sstephenson/mackerel.git
ruby -rubygems mackerel/examples/itunes_backup.rb amazon-s3://YOUR_ACCESS_KEY_ID:YOUR_SECRET_ACCESS_KEY@s3.amazonaws.com/YOUR_BUCKET_NAME/itunes.mackerel
# Lo-fi client for the Facebook API. E.g.:
#
# fb = FacebookClient.new(:api_key => 'api-key', :secret => 'secret')
# fb.call 'users.getInfo', :session_key => 'session-key', :uids => 'user-id', :fields => 'birthday'
#
class FacebookClient
def initialize(default_params={})
@default_params = default_params.reverse_merge({
:rest_server => 'http://api.new.facebook.com/restserver.php',
:format => 'JSON',
formatted_time_accessor :occurs_at, :occurs_until
@jpinnix
jpinnix / gist:400152
Created May 13, 2010 18:07
jQuery - Make all external links open in new tab/window
// JQuery - Make all external links open in new tab/window
// Mashup of:
// http://travisroberts.tumblr.com/post/595428703/jquery-external-links-open-new-window
// http://snipplr.com/view.php?codeview&id=29949
$(document).ready(function() {
$("a[href*='http://']:not([href*='"+location.hostname+"'])").click( function() {
window.open( $(this).attr('href') );
return false;
});
@jpinnix
jpinnix / download_twitter_feed.rake
Created July 19, 2010 19:49
Include recent tweets in a Rails app
#lib/tasks/download_twitter_feed.rake
desc "Download Twitter Feed"
task :download_twitter_feed do
require 'open-uri'
etag_cache = open( "#{RAILS_ROOT}/public/system/etag_cache.txt" ).read
begin