This file contains 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
(main):001:0> [1, 2, 3] <=> [4, 5, 6] | |
=> -1 | |
(main):002:0> [1, 2, 3] <=> [1, 2, 3] | |
=> 0 | |
(main):003:0> [8, 7, 3] <=> [4, 5, 6] | |
=> 1 | |
(main):004:0> |
This file contains 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
(main):001:0> {:a => 1, :b => 10, :z => 5}.values.max | |
=> 10 | |
(main):002:0> {:a => 1, :b => 10, :z => 5}.max { |a, b| a[1] <=> b[1] } | |
=> [:b, 10] |
This file contains 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 Server | |
def initialize | |
@server = nil | |
end | |
def start | |
@server = TCPServer.new(0) | |
end | |
def stop |
This file contains 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 Twitter | |
def self.get_timeline(screen_name, query = {}) | |
response = HTTParty.get( | |
"http://api.twitter.com/1/statuses/user_timeline.json?screen_name=#{screen_name}", | |
:query => query, | |
:format => :json | |
) | |
response.collect { |t| Hashie::Mash.new(t) } | |
end | |
end |
This file contains 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
@player_state.collect! do |i| | |
{ | |
:p_name => i.shift, | |
:balance => i.shift, | |
:bet => i.shift, | |
:cards => i.collect! { |c| "#{@cr[c / 16]}#{@cs[c % 16]}" } | |
} | |
end |
This file contains 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 'thread' | |
require 'facter' | |
class StaticFact | |
@@facts = {} | |
@@mutex = Mutex.new | |
@@maximum_recursion_level = 4 # Sane default? Hope so ... | |
@@current_recursion_level = 0 | |
class << self |
This file contains 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 'md5' | |
# | |
# unique_crontab_minutes.rb | |
# | |
module Puppet::Parser::Functions | |
newfunction(:unique_crontab_minutes, :type => :rvalue) do |arguments| | |
raise(Puppet::ParseError, "Wrong number of arguments " + |
This file contains 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
# | |
# persistent_crontab_minutes.rb | |
# | |
require 'md5' | |
module Puppet::Parser::Functions | |
newfunction(:persistent_crontab_minutes, :type => :rvalue) do |arguments| | |
raise(Puppet::ParseError, "Wrong number of arguments " + |
This file contains 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 | |
def get(*indices) | |
indices.empty? ? self : indices.collect { |i| self[i] } | |
end | |
end |
This file contains 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
_mco() | |
{ | |
local binary commands current previous | |
binary=$(which mco 2> /dev/null) | |
if [[ -x "${binary}" ]] ; then | |
COMPREPLY=() | |
current=${COMP_WORDS[COMP_CWORD]} |
OlderNewer