Skip to content

Instantly share code, notes, and snippets.

View oscherler's full-sized avatar

Olivier Scherler oscherler

View GitHub Profile

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;
@oscherler
oscherler / README.md
Created August 15, 2019 09:49
Expression parser in Erlang

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.
@oscherler
oscherler / PN532_SWHSU.cpp
Last active July 10, 2018 20:23
Add support for SoftwareSerial to the elechouse Arduino NFC library for PN532 (https://github.com/elechouse/PN532). It’s just their PN532_HSU, modified to use SoftwareSerial.
#include "PN532_SWHSU.h"
#include "PN532_debug.h"
PN532_SWHSU::PN532_SWHSU(SoftwareSerial &serial)
{
_serial = &serial;
command = 0;
}
@oscherler
oscherler / README.md
Last active April 6, 2023 10:03
Diff JSON in Git using gron

jsondiff: diff JSON in Git using gron

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.'
@oscherler
oscherler / server.erl
Created May 3, 2017 20:14
Palindrome checking server in Erlang.
-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
@oscherler
oscherler / sleep.erl
Created April 28, 2017 20:03
Erlang toy program to sort a list of positive numbers using the sleep sort algorithm.
-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
@oscherler
oscherler / conso.erl
Created March 18, 2017 21:34
Erlang Week 2 Consolidation
-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.