Skip to content

Instantly share code, notes, and snippets.

View christopherslee's full-sized avatar

Christopher Lee christopherslee

View GitHub Profile
# instead of using the "binary" type suggested by the README, use a "longblob" type (at least, in mysql)
create_table :db_files do |t|
t.column :data, :longblob
end
# to send the file in your controller
# if photo is the object using attachment_fu
def download
send_data( photo.current_data, :type => photo.content_type, :filename => photo.filename, :disposition => 'attachment' )
end
<% remote_form_for 'document', Document.new, :url => documents_url, :html => {:multipart => true},
:loading => "$('indicator').show();",
:loaded => "$('indicator').hide();",
:update => {:failure => "new_document_errors"},
:success => "parent.location = request.responseText;" do |f| %>
@christopherslee
christopherslee / application.js.coffee
Created April 25, 2012 02:06
Rails turns JSON array into numbered hash in controller params
app = window.app = {
doSomething: ->
jQuery.ajax
type : "POST"
path : "/"
datatype : "JSON"
data : { arraystuff : [ { foo : "bar" }, { bar : "baz" }, { baz : "bop" } ] }
return
<script type="text/javascript">
$(document).ready(function() {
$("#sparkline").sparkline([5,6,7,5,6,8,6,], {
type: 'bar',
barWidth: 6,
zeroAxis: false,
barColor: '#999999'});
});
</script>
@christopherslee
christopherslee / stacktrace
Last active December 15, 2015 22:29
Seeing this error frequently (not always?) when running rspec on a Rails 4/Ruby 2.0.0 application
/Users/username/.rvm/gems/ruby-2.0.0-p0@rails4/bin/ruby_noexec_wrapper: [BUG] Bus Error
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.3.0]
-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:
* ~/Library/Logs/CrashReporter
* /Library/Logs/CrashReporter
* ~/Library/Logs/DiagnosticReports
* /Library/Logs/DiagnosticReports
the more detail of.
@christopherslee
christopherslee / customer.rb
Last active December 17, 2015 00:29
Introduction to Metaprogramming: Lesson 1
class Customer
attr_reader :id, :datasource
def initialize(id, datasource)
@id = id
@datasource = datasource
end
def first
value = datasource.get_first_value(id)
@christopherslee
christopherslee / customer.rb
Last active December 17, 2015 00:29
Introduction to Metaprogramming: Lesson 2
class Customer
attr_reader :id, :datasource
def initialize(id, datasource)
@id = id
@datasource = datasource
end
def first
field :first
@christopherslee
christopherslee / customer.rb
Last active December 17, 2015 00:29
Introduction to Metaprogramming: Lesson 3
class Customer
attr_reader :id, :datasource
def initialize(id, datasource)
@id = id
@datasource = datasource
end
def self.has_field(fieldname)
define_method fieldname do
@christopherslee
christopherslee / customer.rb
Created May 5, 2013 18:50
Introduction to Metaprogramming: Lesson 4
class Customer
attr_reader :id, :datasource
def initialize(id, datasource)
@id = id
@datasource = datasource
@datasource.methods.grep(/^get_(.*)_value/) { Customer.has_field $1 }
end
def self.has_field(fieldname)
@christopherslee
christopherslee / customer.rb
Last active December 17, 2015 00:29
Introduction to Metaprogramming: Lesson 4
class Customer
attr_reader :id, :datasource
def initialize(id, datasource)
@id = id
@datasource = datasource
end
def method_missing(methodname, *args, &block)
super unless @datasource.respond_to? "get_#{methodname}_value"