Skip to content

Instantly share code, notes, and snippets.

View dbrady's full-sized avatar

David Brady dbrady

View GitHub Profile

Keybase proof

I hereby claim:

  • I am dbrady on github.
  • I am davidbrady (https://keybase.io/davidbrady) on keybase.
  • I have a public key ASCU2G-o7IcAgrhUI8FSzm7ePC9Bcf8gMD1UuQZIEnYF0Ao

To claim this, I am signing this object:

@dbrady
dbrady / team_name_proposals.md
Created September 26, 2019 16:40
Team Name Proposals

Team Name Proposals

For The Team Formerly Known As Task Force X Formerly Known As Suicide Squad Formerly Knows As EHR Rest Squad

  • Risk Takers
  • Risky Business
  • Laserer Cats (Laserest Cats?)
  • Risklets
  • The Risketeers
  • Task Force X
  • Task Force X, But Ironically
@dbrady
dbrady / private_class_method.rb
Created November 22, 2017 16:22
Best idiom for private class methods nowadays, i.e in Ruby >= 2.1 and/or for values of "nowadays" significantly greater than 2014?
# Names of classes and methods have been changed to protect the innocent. Namely
# my sweet, innocent, cherubic, and hopefully continuing, employment.
class MessageTwiddler
# Okay, so: say I want to make a class method private. What's the best idiom
# for doing this in Ruby circa 2017?
# In Ruby 2.0 I can do Options 1 or 2:
# Option 1 - Original Flavor, Most Explicit
@dbrady
dbrady / private_class_method.rb
Created November 22, 2017 16:18
Which method of declaring a private class method feels most idiomatic now?
# Names of classes and methods have been changed to protect the innocent. Namely
# my sweet, innocent, cherubic, and hopefully continuing, employment.
class MessageTwiddler
# Okay, so: say I want to make a class method private. What's the best idiom
# for doing this in Ruby circa 2017?
# In Ruby 2.0 I can do Options 1 or 2:
# Option 1 - Original Flavor, Most Explicit
@dbrady
dbrady / class_self_self.rb
Created April 4, 2017 16:44
Yo Dawg, Herd U Like DSLs
class Person
def poop
puts "I pooped today!"
end
# One common way to make a class method is to declare it amongst the instance
# methods prefixed with self...
def self.poop!
puts "Everybody pooped today!"
end
EDIT: Was gonna tweetstorm this, then decided to just gist it. Enjoy. ;-)
Tweetstorm about deceptive code incoming.
First Point: People believe comments over the code, even if the code is obvious: x=1; /* put 2 in x */ <-- people believe the 2
Second Point: People maintain code without maintaining (or sometimes even reading) the comments for that code
Third Point: Programmers love to optimize. Makes us feel smart. We think it makes us LOOK smart. But that way lies madness...
So. Dateline: Salt Lake City, 2002. I find this piece of assembly code: "XOR EAX, EAX ; PUT 1 IN EAX"
XOR any number with itself, you get 0. So the comment here was wrong, but if you don't know the XOR trick, it's outright deceptive
If you DO know the trick, it's still distracting and makes you stop and question your sanity for a moment
So I tracked down the commit history for the commit, and here's what happened (exit tweetstorm here if you don't want full history)
#!/usr/bin/env ruby
require 'debug_inspector'
def find_matchers(keys)
matchers = []
matcher_suffixes = ["IS"]
keys.any? do |key|
matcher_suffixes.any? do |suffix|
var = "%s_%s" % [key.upcase, suffix]
matchers << [var, ENV[var]] if ENV.key?(var)
@dbrady
dbrady / hash_to_breadcrumb.rb
Created May 12, 2015 13:49
hash_to_breadcrumb - turn a hash containing items, arrays, or nested hashes into a flattened list of "breadcrumbs" -- e.g. the path through the hash to get to the last value in the list.
# hash_to_breadcrumbs
#
# hash_to_breadcrumb - turn a hash containing items, arrays, or nested hashes
# into a flattened list of "breadcrumbs" -- e.g. the path through the hash to
# get to the last value in the list.
hash = {
a: 1,
b: [2, 3, 4],
c: {
@dbrady
dbrady / gist:6222296
Created August 13, 2013 15:23
Shouldn't this trigger a warning?
09:21:58 dbrady@orthanc:~ ruby-2.0.0-p247
∫ ruby -W4 temp.rb
true
09:22:05 dbrady@orthanc:~ ruby-2.0.0-p247
∫ cat temp.rb
class Ponk
def initialize(x)
@x = x
end
@dbrady
dbrady / linum-activation-snippet.el
Created October 31, 2012 17:40
Autoenable linum-mode in emacs
;; Don't turn on linum-mode by default, it crashes org-mode. Ok to
;; turn it on for various modes, however.
(require 'linum)
(global-set-key "\C-c l" 'linum-mode)
(defun enable-linum-mode ()
(linum-mode t))
; ----------------------------------------------------------------------
; Automatically enable linum mode for various modes