Skip to content

Instantly share code, notes, and snippets.

@mavuio
mavuio / mybutton.html.heex
Last active November 9, 2022 20:27
mybutton #elixir-heex
<.mybutton
phx-click={@phx_click}
phx-target={@phx_target}
phx-value-type="add"
>
<.tw_icon icon={&Heroicons.Solid.plus_circle/1} class="w-5 h-5 mr-1" />
add tags
</.mybutton>
@mavuio
mavuio / appearable_section.heex
Last active November 9, 2022 14:25
appearable section #elixir-heex
<style>
@keyframes expander_appear {
100% { opacity: 1; max-height: 300px}
}
.expander {
animation: expander_appear 900ms 10ms ease-out forwards;
opacity: 1; max-height:0px; overflow: hidden;
}
</style>
@mavuio
mavuio / exit_loop.ex
Created October 5, 2022 05:54
elixir early return/exit from loop/comprehesion/while/each #elixir
# I found Stream.unfold to be quite useful for places where I don’t know how many iterations are #needed to get to the end.
Stream.unfold([], fn words ->
if length(words) < target_length do
words =
(words ++ get_new_words())
|> Enum.uniq()
{new_words, words}
else
def get_next_in_list(list, item) when is_list(list) do
Enum.find_index(list, fn e -> e == item end)
|> case do
nil ->
nil
idx ->
Enum.at(list, idx + 1)
end
end
@mavuio
mavuio / alpinejs_horizontal_slider.heex
Last active September 28, 2022 09:11
alpinejs_horizontal_slider #alpinejs
<section>
<div class="mt-2 mb-4 text-xl font-bold">Import-Attempts</div>
<div
class="flex p-1 space-x-4 overflow-x-scroll cursor-all-scroll"
x-data={"horizontalscroll(#{length(@attempts)})"}
>
<%= for item <- @attempts do %>
<.editlink
upload_id={item.upload_id}
@mavuio
mavuio / simple_heex_table_template.heex
Last active September 28, 2022 08:02
simple table template #elixir-heex
<section class="flex space-x-4">
<article>
<div class="mt-2 mb-4 text-xl font-bold">Rodents</div>
<table>
<thead class="[&>tr>*]:p-2 [&_th]:font-normal [&_th]:text-sm [&_th]:border [&_.num]:text-right ">
<tr>
<th>id</th>
<th>name</th>
<th class="num">price</th>
</tr>
<div class="font-mono text-xs whitespace-pre-wrap">form_state: <%= @form_state |> inspect(pretty: true) %></div>
<div class="font-mono text-xs whitespace-pre-wrap">saved_form_state: <%= @saved_form_state |> inspect(pretty: true) %> </div>
<div class="font-mono text-xs whitespace-pre-wrap">form_changeset: <%= @form_changeset |> inspect(pretty: true) %></div>
<div class="max-w-[300px] my-5">
<%= f = form_for(@form_changeset, "#", [ as: :form_data, phx_submit: :save, phx_change: :validate]) %>
<%= input f, :keyword, label: "Keyword" %>
<%= submit "save", class: "btn btn-outline text-sm mt-4" %>
# sample mount
# @impl true
# def mount(params, _session, socket) do
# context = %{
# params: params,
# lang: "en"
# }
# initial_form_state = get_initial_form_state(socket.assigns)
# {:ok,
@mavuio
mavuio / gist:11144805
Created April 21, 2014 14:46
log_load.sh
#!/bin/bash
LOAD=$(awk '{print $1}' /proc/loadavg)
if [ $(echo "$LOAD > 2" | bc) = 1 ]; then
log_path="/var/log/loadlog"
daystr=`date +%Y_%m/%d`
minutestr=`date +%H_%M`