Skip to content

Instantly share code, notes, and snippets.

View adolfont's full-sized avatar

Adolfo Neto adolfont

View GitHub Profile
defmodule Center do
require Integer
def center(string_list) do
size_max = string_list |> Enum.max_by(&String.length/1) |> String.length()
Enum.map(string_list, fn x -> show(x, size_max) end)
end
defp show(string, size_max) do
@adolfont
adolfont / ElixirConf2014.md
Created November 13, 2019 19:00 — forked from rob-brown/ElixirConf2014.md
Notes from ElixirConf 2014

ElixirConf 2014

Dave Thomas—Opening Keynote

Twitter | Slides

Think different(ly)

Get out of your rut and learn new ways to think.

Horários de Apresentações 2019!!!

Local: Sala 8 do DAINF (ramal 4747)

Equipes

Notas (link público)

Reserve seu horário comentando abaixo com seu nome, dia e horário! O(A) primeiro(a) a reservar fica com o horário!

@adolfont
adolfont / weighted.exs
Last active March 16, 2020 17:52
Philip Brown @philipbrown's Simple Weighted Random
weighted = fn choices ->
max = Enum.reduce(choices, 0, &(&2 + elem(&1, 1)))
Enum.reduce_while(choices, Enum.random(1..max), fn
{item, weight}, acc when acc <= weight -> {:halt, item}
{_item, weight}, acc -> {:cont, acc - weight}
end)
end
weighted.([{"likely", 9}, {"not likely", 1}])
@adolfont
adolfont / asabranca.rb
Created March 30, 2020 21:17
Asa Branca em Sonic Pi
play :C
sleep 0.5
play :D
sleep 0.5
play :E
sleep 1
play :G
sleep 1
play :G
sleep 1
-module(first).
-export([double/1, treble/1, mult/2, area/3, square/1]).
mult(X,Y) ->
X*Y.
double(X) ->
mult(2,X).
treble(X) ->
mult(3,X).
area(A,B,C) ->
-module(logic).
% In the previous video step on pattern matching we saw two ways of defining
% “exclusive or”. Give at least three others. You might find it useful to
% know that:
% =/= and == are the operations for inequality and equality in Erlang;
% not is the Erlang negation function; and,
% and and or are the Erlang conjunction and disjunction (infix) operators.
-export([exclusive_or_1/2,exclusive_or_2/2,exclusive_or_3/2,exclusive_or_4/2,
exclusive_or_5/2, max_three/3, how_many_equal/3, test_exclusive_or_1/0]).
@adolfont
adolfont / geometry.erl
Last active May 19, 2020 10:59
Solution to Week 2 activity for Functional Programming in Erlang
% a mdoule to calculate areas, perimeters and bits
% https://www.futurelearn.com/courses/functional-programming-erlang/3/steps/488101/assignment/submissions/new
-module(geometry).
-export([area/1, test_area/0]).
-export([perimeter/1, test_perimeter/0]).
-export([enclose/1, test_enclose/0]).
-export([bits/1, test_bits/0]).
-export([bits_direct_recursive/1, test_bits_direct_recursive/0]).
-export([bits_tail_recursive/1, test_bits_tail_recursive/0]).
defmodule BMI do
def compute(height_in_m, weight_in_kg) do
weight_in_kg/(height_in_m*height_in_m)
end
def test_bmi() do
22.395413419331717 = BMI.compute(1.83, 75)
37.10937499999999 = BMI.compute(1.60, 95)
80 = BMI.compute(1.10, 100)
-module(exercise).
-export([product/1, test_product/0]).
-export([direct_product/1, test_direct_product/0]).
-export([max_list/1, test_max_list/0]).
-export([direct_max_list/1, test_direct_max_list/0]).
product(X) ->
product_aux(X, 1).