Skip to content

Instantly share code, notes, and snippets.

View mikebaldry's full-sized avatar

Michael Baldry mikebaldry

View GitHub Profile
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
UbuReporting::Application.initialize!
Dir[File.expand_path('../../lib/reports/*.rb', __FILE__)].each { |f| load f }
Dir[File.expand_path('../../app/reports/*.rb', __FILE__)].each { |f| load f }
class Game
constructor: ->
@drawInterval = 150
@characterX = 2
@characterY = 2
@imageRepository = null
@imagesLoadedCallback = (loadedImages) ->
alert "Hey!"
@imageRepository = loadedImages
setInterval(@draw, @drawInterval)
@mikebaldry
mikebaldry / gist:942127
Created April 26, 2011 11:35
coffee script error
NoMethodError: undefined method `best_available' for ExecJS::Runtimes:Module
/Users/clockwize/.rvm/gems/ruby-1.8.7-p334/gems/execjs-0.1.0/lib/execjs.rb:30:in `runtime'
/Users/clockwize/.rvm/gems/ruby-1.8.7-p334/gems/execjs-0.1.0/lib/execjs.rb:22:in `compile'
/Users/clockwize/.rvm/gems/ruby-1.8.7-p334/gems/coffee-script-2.2.0/lib/coffee_script.rb:31:in `context'
/Users/clockwize/.rvm/gems/ruby-1.8.7-p334/gems/coffee-script-2.2.0/lib/coffee_script.rb:57:in `compile'
Rendered reports/filters/date_range.html.haml (32.0ms)
Rendered reports/filters/multi_select.html.haml (48.0ms)
Rendered reports/filters/multi_select.html.haml (10.2ms)
Rendered reports/_table.html.haml (34642.6ms)
Rendered reports/view.html.haml within layouts/application (35273.0ms)
::_table.html.haml::
%table
%thead
%tr
def self.by_id(id)
cached_supplier = @suppliers.find { |s| s.db_id == id }
return cached_supplier if cached_supplier
supplier = from_row(DB[:supplier].filter(:supplier_id => id).first)
@suppliers << supplier
supplier
end
def self.all
return @suppliers unless @suppliers.empty?
@mikebaldry
mikebaldry / gist:994924
Created May 27, 2011 09:24
TagCloud map/reduce Mongo Mapper
class TagCloud
MAP = <<-JS
function () {
this.tags.forEach(function (tag) {
emit(tag, 1);
});
}
JS
REDUCE = <<-JS
@mikebaldry
mikebaldry / gist:1082104
Created July 14, 2011 08:36
Rails 3.1 page titles
app/views/energy/index.html.haml:
-page_title = "Test title"
%h1 energy page
app/views/layouts/application.html.haml:
%title= page_title
app/helpers/application_helper.rb:
view:
= f.inputs :name => "Contract details", :class => "accordion" do
= f.input :mpan
= f.input :kva
= f.input :voltage, :as => :radio, :collection => {"Low" => "LV", "High" => "HV"}
= f.input :estimated_annual_consumption
model:
@mikebaldry
mikebaldry / Output
Created October 18, 2011 10:55
Ruby ext
g++ -I. -I/Users/clockwize/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/i686-darwin10.8.0 -I/Users/clockwize/.rvm/rubies/ruby-1.8.7-p352/lib/ruby/1.8/i686-darwin10.8.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -fno-common -arch x86_64 -g -Os -pipe -no-cpp-precomp -fno-common -pipe -fno-common -c MyClass.cpp
MyClass.cpp: In function ‘void Init_MyClass()’:
MyClass.cpp:11: error: invalid conversion from ‘VALUE (*)(VALUE, VALUE)’ to ‘VALUE (*)(...)’
MyClass.cpp:11: error: initializing argument 3 of ‘void rb_define_method(VALUE, const char*, VALUE (*)(...), int)’
@mikebaldry
mikebaldry / gist:1327695
Created October 31, 2011 15:09
MySQl/Sequel issue
(rdb:3) p x = ContractStatusChange.new(:changed_status => "", :date_changed => DateTime.now, :contract_id => "77b3271e-1563-4cd4-a9a1-67c3f0020a62", :request_message => "")
#<ContractStatusChange @values={:changed_status=>"", :date_changed=>2011-10-31 15:06:47 UTC, :contract_id=>"77b3271e-1563-4cd4-a9a1-67c3f0020a62", :request_message=>""}>
(rdb:3) p x.date_changed
2011-10-31 15:06:47 UTC
(rdb:3) p x.save
(0.000136s) BEGIN
(0.002530s) INSERT INTO `contract_status_change` (`changed_status`, `date_changed`, `contract_id`, `request_message`, `contract_status_change_id`) VALUES ('None', --->>'15:06:47'<<---, '77b3271e-1563-4cd4-a9a1-67c3f0020a62', '', 'a81ee36a-8b85-0f1d-136f-403fd1b23313')
(0.000478s) SELECT * FROM `contract_status_change` WHERE (`contract_status_change_id` = 'a81ee36a-8b85-0f1d-136f-403fd1b23313') LIMIT 1