Skip to content

Instantly share code, notes, and snippets.


David Brady dbrady

View GitHub Profile
View reload-buffer.el
; ----------------------------------------------------------------------
; reload-buffer
; Seriously, why doesn't this already exist? Reloads the current
; buffer. find-alternate-file will sort of already do this; if you do
; not supply an argument to it it will reload the current
; buffer... but it will switch you to another buffer when it does
; it. All this function does is find-alt and then switch you back.
(defun reload-buffer()
(let ((buffername (buffer-name)))
dbrady / gist:6222296
Created Aug 13, 2013
Shouldn't this trigger a warning?
View gist:6222296
09:21:58 dbrady@orthanc:~ ruby-2.0.0-p247
∫ ruby -W4 temp.rb
09:22:05 dbrady@orthanc:~ ruby-2.0.0-p247
∫ cat temp.rb
class Ponk
def initialize(x)
@x = x
dbrady / linum-activation-snippet.el
Created Oct 31, 2012
Autoenable linum-mode in emacs
View linum-activation-snippet.el
;; 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
dbrady / utah_fire_omg.rb
Created Jun 28, 2012
Ruby script to generate an animated map of Utah that is very, VERY on fire
View utah_fire_omg.rb
#!/usr/bin/env ruby
# Generate an astonishingly accurate, animated map of Utah with
# thousands of wildfire pins scattered around it by throwing dozens of
# random lat/lng pairs at the google static maps API.
# NOTE: This script requires ImageMagick. Good luck with that.
# returns a latitude and longitude that lies within the state of Utah
dbrady /
Created Apr 6, 2012
Rand using bc
# Linear Congruential Generator using bc
# Note the shenanigans necessary to seed the generator with the epoch
# time: $(date -j -f "%a %b %d %T %Z %Y" "`date`" "+%s") does nothing
# more than return the current date in epoch seconds, which we use to
# seed the generator. This generator is due to Knuth, and cited in
# Numerical Recipes in C, chapter 7. It's fast on old 32-bit machines
# but not a very good RNG:
dbrady / dangeromatic.rb
Created Mar 16, 2012
Graph Splitter Complexity-o-Mat (Inspired by Jack Danger)
View dangeromatic.rb
# Inspired by Jack "Best Name Ever" Danger Carty's talk at MWRC 2012
def cplx(n)
def dangeromat(n)
puts "Interconnection Complexity: #{cplx(n)}"
b=n/2; a=n-b
puts "If you split your project evenly an app and a service api, you get"
dbrady / descendants.rb
Created Mar 15, 2012
Return the list of descendants of a class
View descendants.rb
class Class
def extend?(klass)
superclass && (superclass == klass || superclass.extend?(klass))
def descendants do |constant_name|
constant = eval(constant_name.to_s)
if constant && constant.is_a?(Class) && constant.extend?(self)
dbrady / day_labels.rb
Created Mar 12, 2012
pattern for maps that take n-dimensional inputs and yield m-dimensional inputs
View day_labels.rb
# Draw day labels, e.g. "Mon 1/30", "Tue 1/31", "Wed 2/1" etc.
day_labels = (0...DAYS_PER_WEEK).map {|d| (start_date + d).strftime("%a %-m/%-d")}
# HEY GISTERS LOOK HERE: Okay, I have a loop that iterates 0 to
# 6, and I need this for the day_label in question, but I *also*
# need to know the x-coordinate at which to draw the label. What
# I would like in this SPECIFIC case, is a loop construct that
# somehow yields the day_label and x-coordinate, perhaps as a
# pair, which I guess I could do with a map. But in general I'm
# looking for a loop construct that accepts n-dimensional inputs
dbrady / gist:2023535
Created Mar 12, 2012
Iterating by columns with a nudge factor
We couldn’t find that file to show.
dbrady / vector3.rb
Created Mar 7, 2012
Ruby 3D Vector w/UTF
View vector3.rb
#!/usr/bin/env ruby
# encoding: utf-8
class Vector
attr_accessor :x, :y, :z
def initialize(x,y,z)
@x,@y,@z = x,y,z