This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # An extension to the Hash class to inspect what it is made of | |
| class Hash | |
| def whatami | |
| keys.inject({}) do |hash, key| | |
| hash[key] = case self[key].class.to_s | |
| when "Hash" | |
| self[key].whatami | |
| when "Array" | |
| self[key].map do |item| | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Simple extension to string to cut out the middle and leave the beginning and end | |
| class String | |
| def middle_truncate(n, options={}) | |
| return self if self.length <= n | |
| elipses = options.delete(:elipses) || 3 | |
| side = (n/2 - elipses/2) | |
| left_side = (elipses % 2 == 0) ? side : side+1 | |
| left, right = self[0..left_side], self[(self.length-side+elipses)..self.length] | |
| elipses_text = "." * elipses | |
| return "#{left}#{elipses_text}#{right}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require "rubygems" | |
| require "crack" | |
| xml = <<-XML | |
| <parent_node> | |
| <content> | |
| <item attr1="test">this is a string that ruins my life</item> | |
| <item attr1="i am an attribute and i live nicely in the world of hashes" /> | |
| </content> | |
| </parent_node> | |
| XML |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| echo "Setting up chef..." | |
| sudo apt-get -y update | |
| sudo apt-get -y install ruby ruby1.8-dev libopenssl-ruby1.8 rdoc ri irb build-essential wget ssl-cert | |
| cd /tmp | |
| wget http://rubyforge.org/frs/download.php/57643/rubygems-1.3.4.tgz | |
| tar zxf rubygems-1.3.4.tgz |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| User.find(:all, :conditions => "created_at BETWEEN '2004-01-01 12:00:00' AND 2005-01-01 12:00:00") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def pph(hash, depth=0, output="") | |
| if hash.is_a?(Hash) | |
| carriage_return = depth > 0 ? "\n" : "" | |
| output << carriage_return | |
| hash.each do |key, val| | |
| output << "\t" * depth + "#{key}\t=>\t#{pph(val, depth+1)}" | |
| end | |
| elsif hash.is_a?(Array) | |
| return "["+hash.join(", ")+"]" +"\n" | |
| else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # Author => Jason Amster | |
| # Email => [email protected] | |
| # Time.now => Thu Jul 16 17:33:50 -0400 2009 | |
| # Purpose => To get those friggin error codes off of Authorize.net and into somthing i can actually use | |
| require 'rubygems' | |
| require "activesupport" | |
| require 'hpricot' | |
| require 'open-uri' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # bash completion support for core Git. | |
| # | |
| # Copyright (C) 2006,2007 Shawn O. Pearce <[email protected]> | |
| # Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/). | |
| # Distributed under the GNU General Public License, version 2.0. | |
| # | |
| # The contained completion routines provide support for completing: | |
| # | |
| # *) local and remote branch names |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| while 1 | |
| unixtime = Time.new.strftime('%s') | |
| if Integer(unixtime) > 1234567890 | |
| puts "HOORAAAYYYY Unix Time > 1234567890 - #{unixtime}" | |
| else | |
| puts "Booooo Unix Time not yet #{unixtime}" | |
| end | |
| sleep 1 | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # EXTRACTED FROM THIS THREAD: | |
| # http://rails.lighthouseapp.com/projects/8994/tickets/879-finding-the-days-weeks-months-years-between-two-dates | |
| require "rubygems" | |
| require "activesupport" | |
| #activesupport is necessary for Date.parse (I think) | |
| class Date | |
| def self.days_between(start, finish) | |
| (finish - start).to_i | |
| end |