Skip to content

Instantly share code, notes, and snippets.

View petemcfarlane's full-sized avatar

Pete McFarlane petemcfarlane

View GitHub Profile
-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").
-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,
-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
%
@petemcfarlane
petemcfarlane / groupBy.php
Last active April 17, 2017 04:49
php implementation of groupBy, which takes an array and a callback
<?php
$groupBy = function (array $items, callable $cb) {
return array_reduce($items, function ($acc, $item) use ($cb) {
$key = $cb($item);
$acc[$key][] = $item;
return $acc;
}, []);
};
@petemcfarlane
petemcfarlane / convert-short-tag-to-full-tag
Last active August 29, 2015 14:15
Recursively converts short opening tags to standard ones for php files for a given directory
#!/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);