Skip to content

Instantly share code, notes, and snippets.

View d11wtq's full-sized avatar

Chris Corbyn d11wtq

  • Melbourne, Australia
View GitHub Profile
@d11wtq
d11wtq / devil_ico_example.rb
Created July 8, 2011 14:44
Quick and dirty example of using Devil to convert ICO to PNG
ico_file = "some-file.ico"
png_file = "output.png"
Devil.load(ico_file) do |img|
img.resize(16, 16).save(png_file)
end
@d11wtq
d11wtq / datamapper_example.rb
Created July 12, 2011 13:06
DataMapper example showing a few different legacy support features
module Commerce
class Refund
include DataMapper::Resource
include Defaults
PENDING = 'pending'
SUCCESSFUL = 'successful'
DECLINED = 'declined'
ERROR = 'error'
@d11wtq
d11wtq / verbose_job.rb
Created August 25, 2011 13:31
Example of wrapping methods using mixins (more complicated than it should be)
module VerboseJob
module ClassMethods
def wrap_perform!
class << self
def perform_with_verbose(*args)
JobLogger.verbose { perform_without_verbose(*args) }
end
alias_method_chain :perform, :verbose \
unless instance_method(:perform) == instance_method(:perform_with_verbose)
@d11wtq
d11wtq / rails_session_bug_spec.rb
Created September 18, 2011 06:40
Showing the current Rails 3.1 bug where generating a new session Set-Cookie header crashes Rack if :domain => :all
require 'spec_helper'
class AbstractStoreSubclass < ActionDispatch::Session::AbstractStore
def get_session(env, sid)
[sid || generate_sid, nil]
end
def set_session(env, sid, data, options)
end
@d11wtq
d11wtq / purcell-init-trace.el
Created September 24, 2011 14:38
Emacs 23 (Ubuntu 10.04) start error.
(string-prefix-p (file-name-as-directory (site-lisp-dir-for name)) f)
(and f (string-prefix-p (file-name-as-directory ...) f))
(let ((f ...)) (and f (string-prefix-p ... f)))
site-lisp-library-loadable-p(package)
(if (site-lisp-library-loadable-p name) nil (download-site-lisp-module name url))
(unless (site-lisp-library-loadable-p name) (download-site-lisp-module name url))
ensure-lib-from-url(package "http://repo.or.cz/w/emacs.git/blob_plain/1a0a666f941c99882093d7bd08ced15033bc3f0c:/lisp$
(if (> emacs-major-version 23) nil (ensure-lib-from-url (quote package) "http://repo.or.cz/w/emacs.git/blob_plain/1a$
(unless (> emacs-major-version 23) (ensure-lib-from-url (quote package) "http://repo.or.cz/w/emacs.git/blob_plain/1a$
;;; dwim-tab.el --- minor mode to force indentation when TAB would otherwise stall
; internal tracking variables
(setq dwim-tab-point-before nil)
(setq dwim-tab-point-after nil)
(defun dwim-tab ()
"Indents normally once, then switches to tab-to-tab-stop if invoked again.
Always performs tab-to-tab-stop if the first TAB press does not cause the
point to move."
;;; dwim-tab.el --- minor mode to force indentation when TAB would otherwise stall
(defun dwim-tab ()
"Indents normally once, then switches to tab-to-tab-stop if invoked again.
Always performs tab-to-tab-stop if the first TAB press does not cause the
point to move."
(interactive)
(when (or (eq last-command this-command)
(= (point) (progn
(indent-for-tab-command)
/home/chris/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:490:in `load_missing_constant': Expected /home/chris/flippa/flippa-rails/app/models/nda.rb to define Nda (LoadError)
from /home/chris/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:181:in `block in const_missing'
from /home/chris/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:179:in `each'
from /home/chris/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.1.0/lib/active_support/dependencies.rb:179:in `const_missing'
from /home/chris/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0.rc2/lib/dm-core/support/ext/object.rb:25:in `block in full_const_get'
from /home/chris/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0.rc2/lib/dm-core/support/ext/object.rb:22:in `each'
from /home/chris/.rbenv/versions/1.9.2-p290/lib/ruby/g
class Message
include DataMapper::Resource
property :id, Serial
property :deleted, Boolean
belongs_to :sender,
'User'
belongs_to :recipient,
class CoercedArray < Array
def initialize(type)
super()
@type = type
end
def push(object)
object = @type.new(object) unless object.kind_of?(@type)
super
end