Skip to content

Instantly share code, notes, and snippets.

Alvise Susmel alvises

Block or report user

Report or block alvises

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@alvises
alvises / app.exs
Created Nov 22, 2019
app.exs test script which connects two Elixir nodes running in two containers
View app.exs
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 / app.css
Last active Dec 11, 2019
Phoenix LiveView Gallery with Slideshow
View app.css
/* to add to assets/css/app.css */
.thumb-selected {
border: 4px solid #0069d9;
}
.thumb-unselected {
opacity: 0.5;
}
@alvises
alvises / bench_hash.exs
Created Apr 9, 2019
Elixir File.stream! lines vs chunks
View bench_hash.exs
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 Mar 30, 2019
Chunks to Lines
View README.md
View example.exs
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 Feb 25, 2019
How to run a Docker Container
View start.sh
docker container run -p 8000:80 nginx
@alvises
alvises / lazy_csv_bench.exs
Created Jan 13, 2019
Benchee benchmark of csv processing
View lazy_csv_bench.exs
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 Dec 19, 2018
Realtime market-data updates - full channel - calculating the rate
View client.ex
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 Nov 13, 2018
Poeticoding Ghost blog style
View ghost_main.css
.site-header {
background: white !important;
background-color: white !important;
}
View fppopover.m
-(void)presentPopoverFromView:(UIView *)fromView
onModalViewController:(UIViewController*)modalViewController {
[self presentPopoverFromView:fromView];
 
//converting the origin of the popover from the old parent view to the new modal view
self.origin = [modalViewController.view convertPoint:self.origin fromView:_parentView];
 
//the new parent view is the modal view
[self.view removeFromSuperview];
You can’t perform that action at this time.