Skip to content

Instantly share code, notes, and snippets.

View gorkaio's full-sized avatar
👾

Gorka López de Torre gorkaio

👾
View GitHub Profile
@gorkaio
gorkaio / uuid.php
Last active September 9, 2016 22:56
PHP UUID
<?php
// See https://benramsey.com/projects/ramsey-uuid/
// Install ramsey/uuid through composer and use the following snippet:
require 'vendor/autoload.php';
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
@gorkaio
gorkaio / first.erl
Last active May 6, 2020 06:35
First steps in Erlang
-module(first).
-export([double/1,treble/1,square/1,mult/2,area/3]).
mult(X,Y) ->
X*Y.
double(X) ->
mult(2,X).
treble(X) ->
-module(third).
-export([xOr_1/2, xOr_2/2, xOr_3/2, maxThree/3, howManyEqual/3]).
% XOR implementation #1
xOr_1(A,A) ->
false;
xOr_1(A,B) ->
A or B.
% XOR implementation #2
-module(recursion).
-export([fib/1,fibTail/1,pieces/2]).
-export([fibTest/0,fibTailTest/0,piecesTest/0]).
% Fibonaaci
fib(0) -> 0;
fib(1) -> 1;
fib(N) when N>1 ->
fib(N-2) + fib(N-1).
-module(tail_recursion).
-export([fib/1,perfect/1]).
-export([fibTest/0,perfectTest/0]).
% Tail recursive fibonacci
fib(N) -> fib(N, 0, 1).
fib(0, A, _) -> A;
fib(N, A, B) -> fib(N-1, A+B, A).
fibTest() ->
-module(assignment).
-export([bits/1,distance/2,perimeter/1,area/1]).
-export([bitsTest/0,perimeterTest/0,areaTest/0]).
% Bits %%%
%% Exposed bit counter function
bits(N) -> bits(N, 0).
-module(list_functions).
-export([product/1,maximum/1,product_notail/1,maximum_notail/1]).
-export([product_test/0,maximum_test/0,product_notail_test/0,maximum_notail_test/0]).
%% Product %%%
product([]) -> 1;
product([A|B]) -> product([A|B], 1).
product([], P) -> P;
-module(take).
-export([take/2]).
-export([take_test/0]).
-spec take(integer(), [T]) -> [T].
take(_, []) -> [];
take(0, _) -> [];
take(N, L) -> take(N, L, []).
take(_, [], Ac) -> lists:reverse(Ac);
-module(list_functions2).
-export([double/1,evens/1]).
-export([double_test/0,evens_test/0]).
%% double %%%
double([]) -> [];
double([_|_] = L) -> double(L, []).
double([], Ac) -> lists:reverse(Ac);
-module(nub).
-export([nub/1]).
-export([nub_test/0]).
nub([]) -> [];
nub([_|_] = L) -> nub(L, []).
nub([], Ac) -> lists:reverse(Ac);
nub([H|T], Ac) ->
case lists:member(H, Ac) of