Skip to content

Instantly share code, notes, and snippets.

Avatar

David Brady dbrady

View GitHub Profile
View keybase.md

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:

View team_name_proposals.md

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 / vim_eshell.el
Created May 25, 2011
Run vim natively inside emacs
View vim_eshell.el
(defun run-vim ()
(interactive)
(eshell)
(switch-to-buffer "*eshell*")
(insert "vi")
(eshell-send-input))
@dbrady
dbrady / hash_to_breadcrumb.rb
Created May 12, 2015
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.
View hash_to_breadcrumb.rb
# 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 / private_class_method.rb
Created Nov 22, 2017
Best idiom for private class methods nowadays, i.e in Ruby >= 2.1 and/or for values of "nowadays" significantly greater than 2014?
View private_class_method.rb
# 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 Nov 22, 2017
Which method of declaring a private class method feels most idiomatic now?
View private_class_method.rb
# 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 / change_case.el
Created Feb 28, 2011
emacs lisp defuns to change the case (camelCase <-> snake_case) of the word under cursor, or an entire region if selected. NOTE: the snake-case defuns do not work, they just camelCase. Ooops.
View change_case.el
;; Grateful thanks are given to Brian Marick (@marick) for helping me
;; write these. I got the original idea while reading through
;; http://xahlee.org/emacs/elisp_idioms.html, but couldn't work out
;; the elisp regexes. Brian Marick (@marick) stepped in and helped. He
;; took my tortured and broken camelcase-region and turned it into
;; something that actually worked. I then created
;; camelcase-word-or-region. I then wrote the snakecase versions but I
;; see now that all I did was copy the camelcase defuns over and,
;; meaning to go back and finish them Real Soon Now, forgot all about
;; them. I've had a quick look (2011-02-27) but elisp regexes are
@dbrady
dbrady / class_self_self.rb
Created Apr 4, 2017
Yo Dawg, Herd U Like DSLs
View class_self_self.rb
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
View deceptive-code-tweetstorm.txt
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)
View interesting.rb
#!/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)
You can’t perform that action at this time.