Skip to content

Instantly share code, notes, and snippets.

View mikebaldry's full-sized avatar

Michael Baldry mikebaldry

View GitHub Profile
@mikebaldry
mikebaldry / gist:1411646
Created November 30, 2011 22:58
qemu-ifup
deploy@buildroot:~/buildroot$ sudo /etc/qemu-ifup tap0
Wed Nov 30 22:57:27 2011 Note: Cannot ioctl TUNSETIFF tap0: Device or resource busy (errno=16)
Wed Nov 30 22:57:27 2011 Note: Attempting fallback to kernel 2.2 TUN/TAP interface
Wed Nov 30 22:57:27 2011 Cannot open TUN/TAP dev /dev/tap0: No such file or directory (errno=2)
Wed Nov 30 22:57:27 2011 Exiting
@mikebaldry
mikebaldry / gist:1410563
Created November 30, 2011 20:02
ne2k-pci error
ne2k-pci.c:v1.03 9/22/2003 D. Becker/P. Gortmaker
PCI: enabling device 0000:00:0c.0 (0100 -> 0101)
Unable to handle kernel paging request at virtual address 44000000
pgd = c0004000
[44000000] *pgd=00000000
Internal error: Oops: 35 [#1]
Modules linked in:
CPU: 0 Not tainted (3.1.0 #2)
PC is at ne2k_pci_init_one+0xc8/0x3d4
LR is at __request_region+0x88/0x128
@mikebaldry
mikebaldry / gist:1366593
Created November 15, 2011 09:49
find subclasses
def self.all
results = []
ObjectSpace.each_object(Class) do |c|
(results << c) if c.ancestors.include?(PullSource) && c != PullSource
end
results
end
@mikebaldry
mikebaldry / gist:1358563
Created November 11, 2011 17:05
DRY my haml
-if t.incomplete?
%a{:href => lead_task_path(t.lead, t)}
=t.title
.sub= t.lead.business_name
-else
=t.title
.sub= t.lead.business_name
@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
@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)’
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 / 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:
@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
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?