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
def game(attackers = 3, defenders = 2) # returns [attacker, defender] loses | |
attack = (1..attackers).map { rand(6) }.sort.reverse[0..1].reverse | |
defense = (1..defenders).map { rand(6) }.sort | |
max_wins = [attackers, defenders].min | |
attack_wins = (1..max_wins).map { attack.pop > defense.pop }.select{ |x| x}.count | |
[max_wins - attack_wins, attack_wins] | |
end | |
def full_game(armies = 30) | |
attack = defense = armies | |
while [attack-1, defense].min > 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
# ruby -rpp -e 'pp Encoding.list.map(&:name)' | |
["ASCII-8BIT", | |
"UTF-8", | |
"US-ASCII", | |
"Big5", | |
"Big5-HKSCS", | |
"Big5-UAO", | |
"CP949", | |
"Emacs-Mule", | |
"EUC-JP", |
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
bash -c ' | |
<% if knife_config[:bootstrap_proxy] -%> | |
( | |
cat <<'EOP' | |
<%= "proxy = #{knife_config[:bootstrap_proxy]}" %> | |
EOP | |
) > ~/.curlrc | |
<% end -%> | |
if [ ! -f /usr/bin/chef-client ]; then |
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
> nanoc deploy --target default | |
Captain! We’ve been hit! | |
=== MESSAGE: | |
LoadError: cannot load such file -- fog | |
=== COMPILATION STACK: |
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
inline(:C) do |builder| | |
builder.c " | |
VALUE c_unpack_l(char *bytes) { | |
uint32_t tmp; | |
memcpy(&tmp, bytes, sizeof(uint32_t)); | |
return INT2NUM(tmp); | |
}" | |
builder.c " | |
VALUE c_unpack_s(char *bytes) { | |
uint16_t tmp; |
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 ActiveSupport::BufferedLogger | |
# Print a logger.debug line with colored Name | |
# If the msg is not a string, it will inspect it | |
# Pass it a block to record the time_taken to yield it | |
# Symbols in the msg like :method will be interpolated with block_result.send(:method) | |
# eg: fancy_debug("Find Users", "Found :count users") { User.where() } | |
def fancy_debug(name, msg = '', &block) | |
if block_given? | |
start_time = Time.now | |
result = yield |
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
# VAlidate Part Of Resource | |
module Vapor | |
extend ActiveSupport::Concern | |
included do | |
class_attribute :target_name, :attribute_names | |
include ActiveModel::Validations | |
include ActiveModel::Conversion | |
include ActiveModel::Naming | |
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
# Dirty monkey patch to globally disable certificate validation | |
# YOU SHOULD NEVER USE THIS | |
# Except when testing/debugging with self signed certificates | |
require 'net/http' | |
module OpenSSL | |
module SSL | |
VERIFY_PEER = VERIFY_NONE | |
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
require 'benchmark' | |
def is_it_true? | |
true | |
end | |
CONSTANT = 1 | |
BenchTimes = 1_000_000 | |
Benchmark.bm(20) do |bm| |
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
if defined?(Footnotes) && Rails.env.development? | |
Footnotes.run! | |
Footnotes::Filter.notes -= [:cookies, :session] | |
Footnotes::Notes::AssignsNote.ignored_assigns += [:@_view_renderer, :@_response_body, :@_routes, :@_view_context_class] | |
end |