Skip to content

Instantly share code, notes, and snippets.

View matthewrudy's full-sized avatar

Matthew Rudy Jacobs matthewrudy

View GitHub Profile
#include <EEPROM.h>
#include <LiquidCrystal.h>
const int counterAddr = 0;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
@matthewrudy
matthewrudy / md.md
Last active December 28, 2015 05:29 — forked from godfat/md.md

I am aware that they are slightly different, but I am too lazy to make the one in ActiveRecord do the same thing as Sequel. In general it seems Sequel would take the advantage of subqueries, but ActiveRecord might not.

In this case, it seems Sequel's SQL is faster than the one generated by ActiveRecord.

Sequel model:

class User < Sequel::Model(Sequel.connect(DATABASE_CONFIG))
  one_to_many :issues, :class => class_name(:Question),
    :dataset => lambda{
## The quick-and-nasty CVE-2013-0156 Heroku inspector!
## Originally brought to you by @elliottkember with changes by @markpundsack @ Heroku
## Download and run using:
## ruby heroku-CVE-2013-0156.rb
apps = {}
`heroku list`.split("\n").each do |app|
app = app.strip
def get_course
if params[:course] && course_id = params[:course][:id]
Course.find_by_id(course_id)
end
end
@matthewrudy
matthewrudy / benchmark.rb
Created March 21, 2012 09:08 — forked from dentedtriangle/benchmark.rb
Testing the <23 string issue
require 'benchmark'
ITERATIONS = 1000000
Benchmark.bm(10) do |bench|
0.upto(40) do |n|
bench.report("chars: #{n}") do
string = "n"*n
ITERATIONS.times do
string + 'x'
@matthewrudy
matthewrudy / floppy.rb
Created February 12, 2010 03:38 — forked from pjb3/floppy.rb
class Floppy
def metaclass
class << self
return self
end
end
def metaclass_eval(&block)
metaclass.class_eval(&block)
# I'm creating some classes and modules on the fly, but things aren't hooking up quite the way I'd hoped.
# Can anyone explain why when an instance of Mod::Sibling tries to call Child.cry, that it
# doesn't call Mod::Child.cry, but instead looks for Behaviour::Child?
class Base
def self.cry
"#{self.name}.cry called!"
end
end
# 9 out of 10 microbenchmarks agree: implicit return smokes explicit return
require 'benchmark'
def with_explicit
return 1
end
def with_implicit
1
end
irb(main):001:0> name = "réunion-journalière"
=> "r\303\251union-journali\303\250re"
irb(main):002:0> File.open(name, 'w'){|f| f.write 'x' }
=> 1
irb(main):003:0> exit
$ ls -al
> total 36
> drwxr-xr-x 2 rlivsey rlivsey 4096 Jul 3 22:00 .
> drwxrwxr-x 10 rlivsey rlivsey 4096 Jul 3 12:20 ..
>> vdaf = VacancyDownloadableApplicationForm.last
VacancyDownloadableApplicationForm Load (0.122909) SELECT * FROM `vacancy_downloadable_application_forms` ORDER BY vacancy_downloadable_application_forms.id DESC LIMIT 1
VacancyDownloadableApplicationForm Columns (0.063622) SHOW FIELDS FROM `vacancy_downloadable_application_forms`
=> #<VacancyDownloadableApplicationForm id: 54228, vacancy_id: 53520, attachment_id: 3104, name: "Welwyn Hatfield Council - Standard">
>> vdaf.downloadable_application_form
DownloadableApplicationForm Columns (0.027216) SHOW FIELDS FROM `uploaded_files`
DownloadableApplicationForm Load (0.042126) SELECT * FROM `uploaded_files` WHERE (`uploaded_files`.`id` = 3104) AND ( (`uploaded_files`.`type` = 'DownloadableApplicationForm' ) )
=> #<DownloadableApplicationForm id: 3104, file_name: "568.pdf", file_type: "pdf", type: "DownloadableApplicationForm", name: nil, organisation_id: nil, jgp4_id: nil, originated_from: nil>