I hereby claim:
- I am mudge on github.
- I am mudge (https://keybase.io/mudge) on keybase.
- I have a public key ASBDGnU-C3RqiI8Qhc2PUEsdVcNTtf5avLN5urIUcEbzOwo
To claim this, I am signing this object:
| class Maybe | |
| include Enumerable | |
| def initialize(value) | |
| @value = value | |
| end | |
| def each | |
| yield value unless value.nil? | |
| end |
| require 'set' | |
| # Let's provide a default to_proc in terms of threequals | |
| class Object | |
| def to_proc | |
| method(:===).to_proc | |
| end | |
| end | |
| class Set |
| module MongoDB | |
| class URI | |
| attr_reader :uri | |
| def initialize(uri) | |
| @uri = uri | |
| end | |
| def username | |
| matches[:username] |
| class Hash | |
| def to_proc | |
| method(:[]).to_proc | |
| end | |
| end | |
| %w(a b c d).map(&{"a" => 1, "b" => 2, "c" => 3}) | |
| # => [1, 2, 3, nil] | |
| # Or, a more readable example: |
I hereby claim:
To claim this, I am signing this object:
| <?php | |
| $a = array(1, 2, 3); | |
| $pairs = array_map(null, $a, array_slice($a, 1)); | |
| /** | |
| * Prints: | |
| * (1,2)(2, 3)(3, ) | |
| */ | |
| foreach ($pairs as list($x, $y)) { | |
| echo "({$x}, {$y})"; |
| <?php | |
| /* From https://github.com/guzzle/iterator/blob/master/MapIterator.php */ | |
| class MapIterator extends \IteratorIterator | |
| { | |
| /** @var mixed Callback */ | |
| protected $callback; | |
| /** | |
| * @param \Traversable $iterator Traversable iterator |
| <?php | |
| /* Given an anonymous function with a previously unspecified number of arguments like so: */ | |
| $f = function ($x, $y, $z) { | |
| /* Do something interesting with $x, $y and $z. */ | |
| return; | |
| }; | |
| /* How can I convert it into the following nested function (each function yielding one argument), | |
| * finally calling $f when there are enough arguments? | |
| */ |
| /* go(function () { | |
| * console.log('Foo'); | |
| * }); | |
| */ | |
| var go = function (f) { | |
| if (typeof process.nextTick === 'function') { | |
| process.nextTick(f); | |
| } else if (typeof setImmediate === 'function') { | |
| setImmediate(f); | |
| } else { |
| <?php | |
| /* A simple function to determine whether an IP is within a range | |
| * or not. | |
| * | |
| * Examples: | |
| * | |
| * withinCIDR('1.2.3.4', '1.2.3.0/24'); | |
| * => 1 | |
| * | |
| * withinCIDR('1.2.3.4', '1.2.3.4'); |