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
| correct_order = [ 'g', 'c', 'b', 'e', 'f', 'd', 'b' ] | |
| actual_order = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g' ] | |
| actual_order.sort_by! {|x| correct_order.include?(x) ? correct_order.index(x) : actual_order.length} |
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: false | |
| :verbose: true | |
| gem: --no-ri --no-rdoc | |
| :update_sources: true | |
| :sources: | |
| - http://rubygems.org | |
| :backtrace: false | |
| :bulk_threshold: 1000 | |
| rdoc: --inline-source --line-numbers --format=html --template=hanna |
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
| module Serialize | |
| def to_h | |
| h = {} | |
| # My classes have an "attributes method that's created via JSON::Schema | |
| attrs = self.class.attributes | |
| attrs.each {|attr| h.store(attr, self.send(attr))} | |
| h.delete_if {|k,v| v.nil?} | |
| return h.symbolize_keys | |
| 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
| set current_track to the current track | |
| set track_album to the album of the current track | |
| set track_artist to the artist of the current track | |
| set track_comments to the comment of the current track | |
| set track_name to the name of the current track |
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 'logger' | |
| module MyLogger | |
| module ClassMethods | |
| def log(msg=nil) | |
| # Approximate syslog format | |
| logger = Logger.new("my.log") | |
| logger.formatter = proc { |severity, datetime, progname, msg| | |
| progname ||= "my-log" | |
| datetime_format = "%b %d %H:%M:%S" |
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 Foo | |
| attr_accessor :blah | |
| def initialize(options={}) | |
| options.each {|k,v| self.__send__("#{k}=", v) if self.respond_to?(k.to_sym)} | |
| end | |
| end | |
| foo = Foo.new(:blah => "test", :blargh => "stuff") |
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
| config = {} | |
| config[:security_groups] = ["default"] | |
| config[:puppet_params] = {} | |
| opt_parser = OptionParser.new do |opts| | |
| opts.on("-c", "=CLASS", "") {|val| classes.push(val)} | |
| opts.on("-p", /[a-zA-Z0-9_-]+=.*/,"=PARAMETER=VALUE", | |
| "Set puppet variable PARAMETER to VALUE") do |val| |
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
| params = {} | |
| security_group = {} | |
| opt_parser = OptionParser.new do |opts| | |
| opts.on("-c", "=CLASS", "") {|val| classes.push(val)} | |
| opts.on("-p", /[a-zA-Z0-9_-]+=.*/,"=PARAMETER=VALUE", | |
| "Set puppet variable PARAMETER to VALUE") do |val| | |
| a = val.split('=',2) | |
| params[a[0]] = a[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
| class NotExecutable < RuntimeError; end | |
| begin | |
| f = File.open("test") | |
| raise NotExecutable unless File.executable?(f) | |
| rescue Errno::ENOENT => e | |
| puts e.inspect | |
| %x{touch test} | |
| retry | |
| rescue NotExecutable => e | |
| %x{chmod +x test} |
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
| if days_to_wait == 1 | |
| puts "." | |
| else | |
| puts "s." | |
| end |