Skip to content

Instantly share code, notes, and snippets.

View trshafer's full-sized avatar

Thomas Shafer trshafer

View GitHub Profile
@trshafer
trshafer / load_blank_modules.rb
Created November 10, 2012 01:20
Load Blank Modules when const missing
# pretty much copied from active_support
module ModuleConstMissing
def self.append_features(base)
base.class_eval do
# Emulate #exclude via an ivar
return if defined?(@_const_missing) && @_const_missing
@_const_missing = instance_method(:const_missing)
remove_method(:const_missing)
end
super
@trshafer
trshafer / demo.html
Created November 9, 2012 01:43
Center column filling the height of either the left or right sides
<html>
<head>
<title>Middle height</title>
<style type="text/css">
/*Positioning CSS*/
.container{
overflow: hidden;
position: relative;
@trshafer
trshafer / humanized_seconds.rb
Created July 23, 2012 19:05
Humanized Seconds
def humanized_seconds secs
[[60, :second], [60, :minute], [24, :hour], [1000, :day]].map{ |count, name|
name = name.to_s
if secs > 0
secs, n = secs.divmod(count)
pluralized_name = n == 1 ? name : name.pluralize
"#{n.to_i} #{pluralized_name}"
end
}.compact.reverse.join(' ')
end
@trshafer
trshafer / jira_edit_links.js
Created May 8, 2012 22:18
Jira Edit Links
@trshafer
trshafer / How to use
Created May 8, 2012 01:31
Loops songs on beatport.com
In Chrome:
Visit Adam Cobb's Beatport.com remix.
Open the menu "View"
Hover over "Developer"
Click "JavaScript Console"
You'll be presented with a strange window and a blinking cursor. Paste that code in the previous file (replay.js) and press Enter. The song will now continue to loop. Every time you refresh the page follow those steps.
@trshafer
trshafer / gist:1896671
Created February 24, 2012 02:00
SSH to current host Bookmarklet
javascript:void(function()%7Bwindow.location.href=%22ssh://%22+window.location.href.match(/http:%5C/%5C/(%5B%5E:%5C/%5D+).+/)%5B1%5D%7D)();
@trshafer
trshafer / dangerous.rb
Created September 23, 2011 23:10
Module renaming methods dynamically
module Hey
def hi
puts "hi"
end
def sup &block
block.call
end
end
module One
def go
1
end
end
module Two
def go
2
end
@trshafer
trshafer / class_methods.rb
Created August 5, 2011 19:09
Dynamically overwrite methods
class Frog
def self.go
puts 45
end
end
Frog.go
module Whatever
@trshafer
trshafer / cryaboutit.rb
Created August 4, 2011 22:42
stubbing with rrr
require 'rubygems'
require 'rr'
extend RR::Adapters::RRMethods
module Something
def go
puts "going"
end
end