Skip to content

Instantly share code, notes, and snippets.

View monkeypatch_content_type.rb
# Override Paperclip's content-type guessing support to add more MIME types.
# We actually have to monkey-patch File to do this, because Paperclip
# monkey-patches File to add #content_type (from module Paperclip::Upfile).
class File
def content_type_with_extras
type = (self.path.match(/\.(\w+)$/)[1] rescue "octet-stream").downcase
case type
when "pdf" then "application/pdf"
# add more content types here
else content_type_without_extras
samstokes / regex-snippet.rb
Created Nov 20, 2009
Code snippet from that taught me something new about Ruby syntax and regex usage.
View regex-snippet.rb
caller[0][/`([^']*)'/, 1]
samstokes / equi.rb
Created Jan 8, 2010
Solution to Codility demo problem, finding equilibrium index of an array
View equi.rb
def sums_before(src)
dest = [0]
src.each_with_index do |item, index|
dest[index + 1] = dest[index] + item
def equi ( arr )
sums_left = sums_before(arr)
You can’t perform that action at this time.