Skip to content

Instantly share code, notes, and snippets.

View alvises's full-sized avatar

Alvise Susmel alvises

View GitHub Profile
@alvises
alvises / app.css
Last active January 3, 2024 18:41
Phoenix LiveView Gallery with Slideshow
/* to add to assets/css/app.css */
.thumb-selected {
border: 4px solid #0069d9;
}
.thumb-unselected {
opacity: 0.5;
}
@alvises
alvises / app.exs
Created November 22, 2019 17:42
app.exs test script which connects two Elixir nodes running in two containers
IO.puts("I'm here! Sleeping for 2 seconds")
Process.sleep 2_000 # waiting for the other node
nodes = MapSet.new([:app@app1, :app@app2])
other_node =
nodes
|> MapSet.delete(Node.self())
|> MapSet.to_list()
|> List.first()
@alvises
alvises / aoc2022.exs
Last active December 7, 2022 21:33
AoC 2022 in Elixir
# AoC 2022 in Elixir
@alvises
alvises / bench_hash.exs
Created April 9, 2019 11:08
Elixir File.stream! lines vs chunks
lines = File.stream!("file_path")
chunks = File.stream!("file_path",[],2_048)
hash_fun = fn enum ->
enum
|> Enum.reduce(:crypto.hash_init(:sha),&(:crypto.hash_update(&2, &1)))
|> :crypto.hash_final()
|> Base.encode16()
end
@alvises
alvises / README.md
Last active March 30, 2019 01:37
Chunks to Lines
@alvises
alvises / example.exs
Created March 18, 2019 13:17
async callback
defmodule Example do
use GenServer
def start_link(_) do
GenServer.start_link __MODULE__, :ok, []
end
def init(:ok) do
{:ok, []}
end
@alvises
alvises / start.sh
Created February 25, 2019 10:56
How to run a Docker Container
docker container run -p 8000:80 nginx
@alvises
alvises / lazy_csv_bench.exs
Created January 13, 2019 20:47
Benchee benchmark of csv processing
lazy_csv_fn = fn ->
File.stream!("large.csv")
|> Stream.map(&String.trim(&1))
|> Stream.map(&String.split(&1, ","))
|> Stream.filter(fn
["Timestamp" | _] -> false
[_, "NaN" | _] -> false
[timestamp | _] ->
true
end) |> Enum.find(fn
@alvises
alvises / client.ex
Created December 19, 2018 19:51
Realtime market-data updates - full channel - calculating the rate
defmodule Coinbase.Client do
use WebSockex
@url "wss://ws-feed.pro.coinbase.com"
def start_link(products \\ []) do
{:ok, pid} = WebSockex.start_link(@url, __MODULE__, %{})
subscribe(pid, products)
{:ok, pid}
end
@alvises
alvises / ghost_main.css
Last active November 13, 2018 22:50
Poeticoding Ghost blog style
.site-header {
background: white !important;
background-color: white !important;
}