Skip to content

Instantly share code, notes, and snippets.

🤠
fixin' bugs and givin' hugs

Tom Scott tubbo

🤠
fixin' bugs and givin' hugs
Block or report user

Report or block tubbo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tubbo
tubbo / model.rb
Created Jun 28, 2016
Rails model query
View model.rb
Content::LibraryPage.each { |c| puts c.live.title if c.live.title.in?(months) }
View error.txt
# The error message
undefined method `comments_path' for #<#<Class:0x007f01f0513be8>:0x00000003b43928>
Did you mean? font_path
Extracted source (around line #1):
1
2
3
4
@tubbo
tubbo / log_extender.rb
Last active Mar 22, 2016 — forked from anonymous/log_extender.rb
Example of what I'd like to have happen with logging
View log_extender.rb
class LoggerKhan < Logger
def add(severity, message = nil, progname = nil)
return super unless severity == 'info' && "#{message}" =~ /some_tag/
redis_logger.add(severity, message, progname)
end
private
def redis_logger
@redis_logger ||= Logger.new Rails.root.join('log', "redis_#{Rails.env}.log")
View keys.rb
puts 'holy shit it worked'
View approved_step.rb
class ApprovedStep < ActiveRecord::Base
# you'd probably want to put your structured data here
end
View login.rb
class Login < ActiveRecord::Base
def self.average_seconds_to_login
average :time
end
end
View new.html
<a data-role="collapsible" data-theme="f" data-iconpos="right" data-collapsed-icon="arrow-d" data-expanded-icon="arrow-u" class="inline-collapsible dark-border">
<h3>Categories</h3>
<fieldset data-role="controlgroup">
</fieldset>
</a>
View keybase.md

Keybase proof

I hereby claim:

  • I am tubbo on github.
  • I am tubbo (https://keybase.io/tubbo) on keybase.
  • I have a public key whose fingerprint is F787 E5BA AA9A E3DF 95FC 7791 D414 A7A0 9348 E547

To claim this, I am signing this object:

@tubbo
tubbo / promise.rb
Created May 19, 2015
Playing around with promises in Ruby, inspired by Sandi Metz' talk "Nothing Is Something"
View promise.rb
class Promise
attr_reader :object
def initialize(object)
@object = object
end
def try(method)
@tries << method
self
View gist:d0d799d3651e00081092
class Instance < ActiveRecord::Base
has_many :reports
has_many :exams, primary_key: 'study_instance_uid', foreign_key: 'study_inst_uid', inverse_of: :instance
has_many :patients, through: :exams
before_save :set_reading_physician
def reading_physician
(set_reading_physician and save!) if reading_physician.nil?
read_attribute(:reading_physician) || ''
You can’t perform that action at this time.