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
<?php | |
require_once dirname(__FILE__) . '/../lib/simpletest/autorun.php'; | |
// Retries $f (A function) with arguments ($args as array) | |
// 3 ($retries) times after 10 secs $delay | |
// Usage: | |
// retry( 'function_name', array('arg1', 'arg2'), 15, 5 ); | |
// #=> Retries function_name 5 times with arg1 and $arg2 as arguments at interval of 15 secs | |
function retry($f, $args = null, $delay = 10, $retries = 3) | |
{ |
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
ALPHABET_SIZE = 26 | |
def caesar_cipher(string) | |
shiftyArray = [] | |
charLine = string.chars.map(&:ord) | |
shift = 1 | |
ALPHABET_SIZE.times do |shift| | |
shiftyArray << charLine.map do |c| | |
((c + shift) < 123 ? (c + shift) : (c + shift) - 26).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
@flattened_array = [] #To store the flattened array | |
def flatten(array) | |
array.each do |value| | |
# If value is itself an array, call the function recursively | |
# Store each value found that is not array in the flattened array | |
value.instance_of? Array ? flatten value : @flattened_array << value | |
end | |
@flattened_array | |
end |
NewerOlder