Skip to content

Instantly share code, notes, and snippets.

defmodule Zipper do
defstruct node: nil, focus: []
@type t :: %__MODULE__{node: BinTree.t(), focus: list({:left | :right, BinTree.t()})}
@doc """
Get a zipper focused on the root node.
"""
@spec from_tree(BinTree.t()) :: Zipper.t()
def from_tree(bin_tree), do: %__MODULE__{node: bin_tree}
@aschiavon91
aschiavon91 / snippets.json
Last active May 23, 2022 19:13
Elixir snippets for vscode
{
"iex": {
"prefix": "iex",
"body": "require IEx;IEx.pry",
"description": "put iex for debug"
},
"inspect": {
"prefix": "insp",
"body": "|> IO.inspect()",
"description": "put iex for debug"
@aschiavon91
aschiavon91 / my_decoder.ex
Last active November 16, 2020 03:39
decode cloudflare protected email in Elixir
defmodule MyDecoder do
use Bitwise
def decode_email(encoded) do
r =
encoded
|> String.slice(0..1)
|> Integer.parse(16)
|> elem(0)
:lists.seq(2, String.length(encoded) - 2, 2)
document.addEventListener('DOMContentLoaded', () => document.querySelectorAll('.alert').forEach((alert) =>
alert.addEventListener('click', (_) => alert.style.display = "none")));
@aschiavon91
aschiavon91 / script backup
Created May 7, 2020 02:49
mysql + web path bkp script with asset encoded using gpg
#!/bin/bash
readonly BKP_TIME_STAMP=$(date +"%Y-%m-%d")
readonly BKP_PATH_NAME=bkp-$BKP_TIME_STAMP
readonly RECIPIENT_MAIL="rm85297@fiap.com.br"
function check_mysql_config_file() {
if [[ ! -f ./.my.cnf ]]
then
echo "Arquivo configuração do mysql não existe"
@aschiavon91
aschiavon91 / caddy.service
Last active March 29, 2020 21:41
Caddy service
[Unit]
Description=Caddy HTTP/2 web server
Documentation=https://caddyserver.com/docs
After=network-online.target
Wants=network-online.target
[Service]
Restart=on-failure
StartLimitInterval=86400
StartLimitBurst=5
@aschiavon91
aschiavon91 / inlets.service
Last active March 29, 2020 21:25
inlets server service
[Unit]
Description=Inlets Server Service
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=1
StartLimitInterval=0
EnvironmentFile=/etc/default/inlets
@aschiavon91
aschiavon91 / inlets.service
Last active March 30, 2020 02:59
inlets client service
[Unit]
Description=Inlets Client Service
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=1
StartLimitInterval=0
EnvironmentFile=/etc/default/inlets
<img data-defer-src="">
(function () {
var Elp = Element.prototype;
var observer = new IntersectionObserver(function (entries, observer) {
entries.forEach(function (entry) {
if (!entry.target || entry.target.tagName.toUpperCase() !== 'IMG') {
return;
@aschiavon91
aschiavon91 / Ecto unload association
Last active June 16, 2025 12:30
[Elixir][Ecto][Phoenix] A simple way to unload preloaded association of an ecto record struct.
defmodule MyApp.Repo do
use Ecto.Repo,
otp_app: :my_app,
adapter: Ecto.Adapters.Postgres
def unload(_, _, cardinality \\ :one)
def unload(struct, fields, cardinality) when is_list(fields) do
Enum.reduce(fields, struct, fn field, struct_acc ->
unload(struct_acc, field, cardinality)