Skip to content

Instantly share code, notes, and snippets.

View s-andringa's full-sized avatar

Sjoerd Andringa s-andringa

View GitHub Profile
@s-andringa
s-andringa / Locales.yml
Created September 19, 2012 10:09
Amsrb talk 18 sept - exceptions_app in Rails 3.2
# config/locales/en.yml
en:
exception:
show:
not_found:
title: "Not Found"
description: "The page you were looking for does not exists."
internal_server_error:
title: "Internal Server Error"
@s-andringa
s-andringa / import_notes_and_emails.rb
Created December 1, 2017 09:24
Highrise - ActiveCampaign migration
# TODO
@s-andringa
s-andringa / meta_code.rb
Created March 4, 2012 20:56
Meta Code converts itself into a highlighted HTML or PDF document.
require "coderay"
require "pdfkit"
require File.join(File.dirname(__FILE__), "styles/tomorrow_night")
module Meta
class Code
attr_reader :creator
def initialize(options = {})
@creator = options[:creator]
@s-andringa
s-andringa / Countries
Created February 25, 2011 09:58
Countries of the world. Copy-pastable for testing long word lists.
Afghanistan
Albania
Algeria
Andorra
Angola
Antigua & Deps
Argentina
Armenia
Australia
Austria
@s-andringa
s-andringa / constant_gardener.rb
Created December 28, 2010 15:38
Deal with bitmask-form options & Safely monkey patch Ruby gems
class ConstantGardener
def self.create(*booleans)
Class.new do
def initialize(bitmask)
@bitmask = bitmask
end
booleans.each_with_index do |b, i|
const_set b.to_s.upcase, 2**i
class Object
def metaclass
class << self; return self; end
end
end
class Foo
# 1. def within class definition
def self.set_a
class Object
def metaclass
class << self; self; end
end
end
# - Normal cases -
class Foo
@@bar = 0
class User < ActiveRecord::Base
def email
# Make REST call, parse response, extract email address and return it.
# Probably not the most concise and expressive code.
end
end
# Is more or less equal to:
class RemoteUser < ActiveResource::Base
# HTTP Basic Auth
class User < ActiveRecord::Base
has_remote :site => "http://example.com", :user => "foo", :password => "bar" do |remote|
#...
end
end
# API key
class User < ActiveRecord::Base
has_remote :site => "http://example.com?api_key=12x34x5" do |remote|
Processing UsersController#create (for 195.232.229.139 at 2009-06-18 14:50:29) [POST]
Parameters: {"user"=>{"password_confirmation"=>"[FILTERED]", "password"=>"[FILTERED]", "login"=>"XXX"}, "profile"=>{"first_name"=>"XXX", "last_name"=>"XXX"}, "action"=>"create", "authenticity_token"=>"XXX", "controller"=>"users"}
Sent mail to XXX
=========
Unable to send e-mail! 501 Syntax: HELO hostname
/usr/local/lib/ruby/1.8/net/smtp.rb:679:in `check_response'