Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am richardtifelt on github.
  • I am richardj (https://keybase.io/richardj) on keybase.
  • I have a public key ASCTDLdqpgddnMkLhWo4_glnCZdqVHB0Pg89Y4ymyT9P1wo

To claim this, I am signing this object:

Cloudinary::Migrator.new(
db_file: "tmp/cloudinary_resource_images.db",
threads: 1,
retrieve: ->(id) {
resource = Resource.find(id)
if (resource.size || resource.image.size) > 19.megabytes
file = open(resource.image.url)
`convert #{file.path} -quality 85 jpg:-`
else
resource.url
@richardtifelt
richardtifelt / .bash_profile
Created October 20, 2011 12:11
Great testbot alias for better output, and a separated logfile
alias testbot='bundle exec rake testbot:rspec 2>&1 | tee /tmp/testbot-output.txt | grep "^\(Finished.*\.$\|rspec\|\d\+ examples\)"'
@richardtifelt
richardtifelt / my_command.rb
Created June 27, 2011 21:40
Example Flower command class
class MyCommand < Flower::Command
respond_to %w(testing test)
def self.respond(command, message, sender, flower)
# Do something with "flower"
flower.say("Only testing")
end
def self.description
"Text that describes your command. It's used in the built-in Help command."
@richardtifelt
richardtifelt / helpers.rb
Created June 15, 2011 12:48
Computing asset host in my Rails 3 models using compute_asset_host
module Mynewsdesk
module Helpers
def self.compute_asset_host(path)
host_config = Mynewsdesk::Application.config.asset_host
if host_config.respond_to?(:call) && host_config.arity == 1
host_config.call(path)
else
raise "Please set up config.asset_host with a proc that takes one argument"
end
end
@richardtifelt
richardtifelt / tracking.js
Created February 10, 2011 14:11
Global Google Analytics Event Tracking script
document.observe("dom:loaded",function(){
initEventTrackingLinks();
});
var initEventTrackingLinks = function(){
$$(".event-tracking").each(function(elm){
elm.observe("click", function(evt){
var category = elm.readAttribute("data-event-category");
var action = elm.readAttribute("data-event-action");
var label = elm.readAttribute("data-event-label");
class Class
def memoize(*methods)
methods.each do |method_name|
safe_method_name = method_name.to_s.gsub(/(\!|\?)/, '_')
class_eval("
alias :'#{safe_method_name}_without_memo' :'#{method_name}'
def #{method_name}
if defined?(@#{safe_method_name})
@#{safe_method_name}
require 'httparty'
module DetectLanguage
class GoogleTranslate
include HTTParty
base_uri 'http://ajax.googleapis.com/ajax/services/language'
format(:json)
def self.detect_language str
@richardtifelt
richardtifelt / bitly.rb
Created May 15, 2009 12:31
Simple bit.ly API class in Ruby
require 'httparty'
class Api::Bitly
include HTTParty
base_uri 'api.bit.ly'
basic_auth 'username', 'password'
format :json
def self.shorten(url)
response = get('/shorten', :query => required_params.merge(:longUrl => url))