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
| class Array | |
| # invoke a method on each element of the array and return an array of return values | |
| def invoke(method_name, *args, &block) | |
| collect { |item| item.send(method_name, *args, &block) } | |
| end | |
| 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
| # Benchmark of different solutions to mislav's "Find the longest common starting substring in a set of strings" contest | |
| # http://stackoverflow.com/questions/1916218/find-the-longest-common-starting-substring-in-a-set-of-strings | |
| # Solutions: | |
| # mislav | |
| class String | |
| def &(other) | |
| difference = other.to_str.each_char.with_index.find { |ch, idx| | |
| self[idx].nil? or ch != self[idx].chr |
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 'appscript' | |
| require 'open-uri' | |
| require 'json' | |
| require 'youtube_g' | |
| include Appscript | |
| itunes = app('iTunes') | |
| safari = app('Safari') | |
| # Get info on track | |
| current_track = "#{itunes.current_track.name.get}" |
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
| Appscript | |
| http://appscript.sourceforge.net/ | |
| http://appscript.sourceforge.net/rb-appscript/index.html | |
| Matt Neuburg "Scripting Mac Applications With Ruby: An AppleScript Alternative" | |
| http://www.apeth.com/rbappscript/00intro.html | |
| Things-client | |
| http://github.com/marcinbunsch/things-client |
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 | |
| # | |
| # Simple hostfile manager | |
| # | |
| # Only tested on OSX | |
| # | |
| # Usage: | |
| # | |
| # To list defined entries in the hostfile, call: | |
| # |
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
| str = '4/11/01' | |
| # => "4/11/01" | |
| str.sub!(/(\d+)\/(\d+)\/(\d+)/, '\\2/\\1/\\3') | |
| # => "11/4/01" | |
| str.sub!(/(\d+)\/(\d+)\/(\d+)/, '\\2/\\1/\\3') | |
| # => "4/11/01" | |
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/ruby | |
| # gem install things-client --source http://gemcutter.org | |
| # gem install broadcast | |
| require 'rubygems' | |
| require 'things' | |
| require 'broadcast' | |
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
| class TrueClass | |
| def dat | |
| self | |
| end | |
| end | |
| true.dat # => true |
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
| class String | |
| def loch_ness_monster_case | |
| self.split('::').collect do |section| | |
| section.gsub(/([^\/])([A-Z])/, '\1_\2').downcase.split(/_/).collect { |part| | |
| chars = part.split('') | |
| half = chars.length/2 | |
| chars[half].upcase! | |
| chars[half - 1].upcase! | |
| chars.join('') |
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 "singleton" | |
| class GracefulQuit | |
| include Singleton | |
| attr_accessor :breaker | |
| def initialize | |
| self.breaker = false | |
| end |
OlderNewer