Skip to content

Instantly share code, notes, and snippets.

@joshuaflanagan
joshuaflanagan / big_decimal_marshal.rb
Created November 15, 2015 01:56
BigDecimal does not Marshal round trip in ruby 2.1/2.2 (did in 1.9.3)
# Ruby 2.1.2
2.1.2 :173 > x = BigDecimal.new(1.0, 1)
=> #<BigDecimal:7ffcee09bb98,'0.1E1',9(27)>
2.1.2 :174 > y = Marshal.load Marshal.dump x
=> #<BigDecimal:7ffcec5d9ee0,'0.1E1',9(18)>
2.1.2 :175 > x == y
=> true
2.1.2 :176 > Marshal.dump(x) == Marshal.dump(y)
=> false
@joshuaflanagan
joshuaflanagan / watch_git.rb
Created June 27, 2012 01:10
See what's going on in your .git folder when you perform git commands
# I used this to monitor changes to the .git folder during
# my Austin on Rails lightning talk on Understanding Git.
#
# I ignore any changes to the .git/logs folder, because they are
# noisy and don't add a lot to understanding.
# If you want "the whole truth", remove the :ignore parameter below.
#
# ruby listen.rb <path to .git folder>
#
# gem install listen # its the foundation of Guard
@joshuaflanagan
joshuaflanagan / delegate_eql.rb
Created May 5, 2012 22:13
DelegateClass instance doesn't eql? itself
require 'test/unit'
require 'delegate'
# These tests demonstrate some unexpected (to me)
# behavior of a class created by DelegateClass.
# An instance of a DelegateClass created class does not eql? itself.
#
# The WidgetTests all pass.
# The comparison and eql WidgetWrapperTests fail.
# ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]
@joshuaflanagan
joshuaflanagan / xml_parser.rb
Created January 9, 2012 02:22 — forked from kmile/xml_parser.rb
A small nokogiri xml reader DSL.
# A small DSL for helping parsing documents using Nokogiri::XML::Reader. The
# XML Reader is a good way to move a cursor through a (large) XML document fast,
# but is not as cumbersome as writing a full SAX document handler. Read about
# it here: http://nokogiri.org/Nokogiri/XML/Reader.html
#
# Just pass the reader in this parser and specificy the nodes that you are interested
# in in a block. You can just parse every node or only look inside certain nodes.
#
# A small example:
#
@joshuaflanagan
joshuaflanagan / bt.sh
Created December 10, 2011 16:24
Toggle Bluetooth
# copy blueutil from http://www.frederikseiffert.de/blueutil/ to ~/bin
# I created this as a Shell Extension in Alfred and assigned a global hotkey to it (Command+Ctrl-B)
if ~/bin/blueutil status|grep -q on; then ~/bin/blueutil off; else ~/bin/blueutil on;fi
@joshuaflanagan
joshuaflanagan / gist:1412771
Created December 1, 2011 02:02
Git aliases
# add to your ~/.gitconfig
[alias]
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
@joshuaflanagan
joshuaflanagan / gist:1302978
Last active September 27, 2015 17:07
Example of jquery.when
$.when( getTweets('austintexasgov'),
getTweets('greenling_com'),
getTweets('themomandpops')
).done(function(atxArgs, greenlingArgs, momandpopsArgs){
var allTweets = [].concat(atxArgs[0]).concat(greenlingArgs[0]).concat(momandpopsArgs[0]);
var sortedTweets = sortTweets(allTweets);
showTweets(sortedTweets);
});
var getTweets = function(user){
@joshuaflanagan
joshuaflanagan / gist:1026358
Created June 15, 2011 02:25
Resharper demo
Assumes Resharper IntelliJ/IDEA Resharper keybindings
Create a new ASP.NET MVC Web application (Internet)
Open HomeController.cs and start typing outside of HomeController, but within the namespace:
cl[Tab]WorkController[Enter]
p[Tab]Ac[Tab]Show(){[Enter]
return _workflowService.GetResult();[Enter]
*position cursor on _workflowService
@joshuaflanagan
joshuaflanagan / SystemClock.cs
Created June 14, 2011 16:30
Stubbable replacement for DateTime.Now
public static class SystemClock
{
static SystemClock()
{
Live();
}
public static DateTime Now
{
@joshuaflanagan
joshuaflanagan / gist:981417
Created May 19, 2011 18:37
SQL Server commands to backup/restore database
BACKUP DATABASE MyDbName TO DISK = 'C:\MSSQL\Backup\mydbname_backup.bak'
RESTORE DATABASE MyDbName FROM DISK = 'C:\MSSQL\Backup\mydbname_backup.bak' WITH RECOVERY, REPLACE