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 (rockpaperscissors). | |
-compile(export_all). | |
-include_lib("eunit/include/eunit.hrl"). | |
beat(rock) -> paper; | |
beat(paper) -> scissors; | |
beat(scissors) -> rock; | |
beat(_) -> error("expected rock, paper or scissors"). |
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 (textprocessing). | |
-export ([input/0,format/2,format/3,squeezeWordsIntoLine/2,words/1,justify/2,wordsWithSpaces/3]). | |
input () -> | |
"The heat bloomed in December | |
as the carnival season | |
kicked into gear. | |
Nearly helpless with sun and glare, I avoided Rio's brilliant | |
sidewalks | |
and glittering beaches, |
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 (till). | |
-compile(export_all). | |
% A supermarket billing system will take a sequence of barcodes such as | |
% | |
% [1234,4719,3814,1112,1113,1234] | |
% | |
% into a printed bill of the form | |
% | |
% Erlang Stores | |
% |
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
<?php | |
$groupBy = function (array $items, callable $cb) { | |
return array_reduce($items, function ($acc, $item) use ($cb) { | |
$key = $cb($item); | |
$acc[$key][] = $item; | |
return $acc; | |
}, []); | |
}; |
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
#!/usr/bin/env php | |
<?php | |
/* | |
* This script recursively converts short opening tags to standard ones for php files, | |
* given a directory as an argument | |
*/ | |
$path = $argv[1]; | |
if (!is_dir($path)) { | |
die("Error, $path is not a valid directory" . PHP_EOL); |