My Erlang solution to the dev.to Daily Challenge #19.
The tests.txt file was generateg using the num2en
function of the Lingua::EN::Numbers
Perl module:
use Lingua::EN::Numbers qw{ num2en };
print $_, " ", num2en( $_ ), "\n" for 1 .. 999;
My Erlang solution to the dev.to Daily Challenge #19.
The tests.txt file was generateg using the num2en
function of the Lingua::EN::Numbers
Perl module:
use Lingua::EN::Numbers qw{ num2en };
print $_, " ", num2en( $_ ), "\n" for 1 .. 999;
Extended expression parser for the dev.to daily challenge #10.
Try it:
% erl
1> c(calc).
{ok,calc}
2> calc:test().
All 57 tests passed.
#include "PN532_SWHSU.h" | |
#include "PN532_debug.h" | |
PN532_SWHSU::PN532_SWHSU(SoftwareSerial &serial) | |
{ | |
_serial = &serial; | |
command = 0; | |
} |
gron
is an incredible tool that makes JSON greppable. But it also makes it diffable, which is great if you have JSON files in Git.
To use gron
to diff JSON in Git, save the json-diff
script below and make it executable. Then add a difftool as shown in gitconfig
, and optionally create an alias to invoke it more easily. Then try it:
git init
echo '{"foo":42,"bar":"hello"}' > foo.json
git add foo.json && git commit -m 'Initial commit.'
-module( server ). | |
-export( [ server/1, server/0, client/2, balancer/2, balancer/1, demo/2 ] ). | |
% server/1, reply to the spawning process | |
server( Pid ) -> | |
receive | |
{ check, Text } -> | |
reply( Pid, reply_message( Text ) ), | |
server( Pid ); | |
_ -> ok |
-module( sleep ). | |
-export( [ sort/1, sleep/2, listen/2 ] ). | |
sort( Ns ) -> | |
sort( Ns, 0 ). | |
% spawn a sleep process for each number, then start listening | |
sort( [], Count ) -> | |
listen( Count, [] ); | |
sort( [ N | Ns ], Count ) when is_integer( N ), N > 0 -> |
# http://www.erlang-factory.com/upload/presentations/33/EUnitinPractice.pdf | |
ERLC_FLAGS= | |
# finds all the files in the current directory that end in .erl | |
# and set variable SOURCES to the list | |
SOURCES=$(wildcard *.erl) | |
# same for .hrl files in variable HEADERS | |
HEADERS=$(wildcard *.hrl) | |
# take every file in .erl in variable SOURCES, transform them to a .beam file in folder ebin |
-module(conso). | |
-include_lib("eunit/include/eunit.hrl"). | |
-export( [ join/2, concat/1, member/2, each_head/1, each_head/3, perm/1 ] ). | |
join_test() -> | |
[] = join( [], [] ), | |
[ 1 ] = join( [ 1 ], [] ), | |
[ 2 ] = join( [], [ 2 ] ), | |
[ 1, 2, 3, 4, 5 ] = join( [ 1, 2 ], [ 3, 4, 5 ] ). |
-module( numbers ). | |
-include_lib("eunit/include/eunit.hrl"). | |
-export( [ double/1, evens/1, modes/1, median/1 ] ). | |
% I think the point of double is to make us write map | |
map( _F, [] ) -> | |
[]; | |
map( F, [ X | Xs ] ) -> | |
[ F( X ) | map( F, Xs ) ]. |
-module( occurences ). | |
-export( [ occurences/1 ] ). | |
filter( _F, [] ) -> | |
[]; | |
filter( F, [ X | Xs ] ) -> | |
case F( X ) of | |
true -> [ X | filter( F, Xs ) ]; | |
_ -> filter( F, Xs ) | |
end. |