Skip to content

Instantly share code, notes, and snippets.

View dbrady's full-sized avatar

David Brady dbrady

View GitHub Profile
@dbrady
dbrady / reload-buffer.el
Created September 9, 2011 17:31
reload-buffer
; ----------------------------------------------------------------------
; 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()
(interactive)
(let ((buffername (buffer-name)))
@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
@dbrady
dbrady / utah_fire_omg.rb
Created June 28, 2012 21:43
Ruby script to generate an animated map of Utah that is very, VERY on fire
#!/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
dbrady / rand.sh
Created April 6, 2012 05:48
Rand using bc
#!/bin/sh
# 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
dbrady / dangeromatic.rb
Created March 16, 2012 16:17
Graph Splitter Complexity-o-Mat (Inspired by Jack Danger)
# Inspired by Jack "Best Name Ever" Danger Carty's talk at MWRC 2012
def cplx(n)
(n**2-n)/2
end
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"
puts "THE DANGER-O-MATIC EFFECT!!!"
@dbrady
dbrady / descendants.rb
Created March 15, 2012 21:14
Return the list of descendants of a class
class Class
def extend?(klass)
superclass && (superclass == klass || superclass.extend?(klass))
end
def descendants
Module.constants.select do |constant_name|
constant = eval(constant_name.to_s)
if constant && constant.is_a?(Class) && constant.extend?(self)
constant
@dbrady
dbrady / day_labels.rb
Created March 12, 2012 23:52
pattern for maps that take n-dimensional inputs and yield m-dimensional inputs
# 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
dbrady / gist:2023535
Created March 12, 2012 17:34
Iterating by columns with a nudge factor
We couldn’t find that file to show.
@dbrady
dbrady / vector3.rb
Created March 7, 2012 04:06
Ruby 3D Vector w/UTF
#!/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
end