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
package ranges_test | |
// tests for https://gist.github.com/petrkotek/317dbcf6a73387682bc8d899b09c36df | |
import ( | |
"bitbucket.org/kayakrent/booking-api/lib/ranges" | |
"math" | |
"reflect" | |
"testing" | |
) |
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
package ranges | |
import ( | |
"math" | |
"sort" | |
) | |
type Range struct { | |
From int64 | |
To int64 |
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 | |
function walkTree($tree, $depth = 0) { | |
foreach ($tree as $key => $value) { | |
yield ['depth' => $depth, 'name' => $key]; | |
if (is_array($value)) { | |
yield from walkTree($value, $depth + 1); | |
} | |
} | |
} | |
$tree = [ |
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 | |
function walkTree($tree, $depth = 0) { | |
foreach ($tree as $key => $value) { | |
yield ['depth' => $depth, 'name' => $key]; | |
if (is_array($value)) { | |
foreach (walkTree($value, $depth + 1) as $yeilded) { | |
yield $yeilded; | |
} | |
} | |
} |
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
/** | |
* Sets a default value for a given input. | |
* | |
* @param mixed input | |
* @param string defaultValue | |
* @return string | |
*/ | |
module.filter('default', function() { | |
return function(input, defaultValue) { | |
return input ? input : defaultValue; |
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 | |
/** | |
* Replacement of str_split() function with multi-byte encoding support. | |
* | |
* @param string $string The input string. | |
* @param int $string_length [optional] Maximum length of the chunk. | |
* @param string $charset Character encoding. | |
* | |
* @return array |