Skip to content

Instantly share code, notes, and snippets.

@mayel
mayel / open_modal_live.ex
Last active July 21, 2022 21:40
reusable modal in Surface/LiveView
defmodule Bonfire.UI.Common.OpenModalLive do
@moduledoc """
A button that opens a **modal**
"""
use Bonfire.UI.Common.Web, :stateful_component
alias Bonfire.UI.Common.ReusableModalLive
@doc "The title of the modal. Only used if no title slot is passed."
prop title_text, :string
@mayel
mayel / gist:a6ca4c2d0def19600e86803232b7709c
Created October 22, 2022 08:35
mix-docs-gh-pages-action.yaml
name: Generate mix docs & deploy to github pages
on:
push:
branches:
- main
jobs:
docs:
name: Generate & deploy
runs-on: ubuntu-latest
defmodule Types do
def typeof(nil), do: nil
def typeof(false), do: false
def typeof(true), do: true
def typeof(atom) when is_atom(atom) do
if function_exported?(atom, :__info__, 1) || Code.ensure_loaded?(atom) do
if function_exported?(atom, :__struct__, 0), do: :struct, else: Module
else
Atom
end
defmodule Module.Extend do
@doc """
Extend a module (i.e. define `defdelegate` and `defoverridable` for all functions from the source module in the current module.
Usage:
import Module.Extend
extend_module Common.Text
"""
defmacro extend_module(module) do
require Logger
@mayel
mayel / up
Created July 20, 2017 14:50
up - script to keep your Mac up-to-date (OS, Homebrew, and App Store updates) via the command line
#!/bin/sh
# up - v2 - script to keep your Mac up-to-date (OS, Homebrew, and App Store updates) via the command line
# run thus to to install: cd /usr/local/bin && curl -s -O https://gist.githubusercontent.com/mayel/c07bc0acb91824501d5bdbdc9eb7b33a/raw/08821f64c067327ea68a1a817eb43657db10f10e/up && chmod 755 /usr/local/bin/up
# and then run it anytime by simply entering the command: up
# By https://github.com/mayel based on a script by https://github.com/imwally
# homebrew
{
"@context": [
"https://www.w3.org/ns/activitystreams",
{
"@language": "und",
"Hashtag": "as:Hashtag",
"ValueFlows": "https://w3id.org/valueflows#",
"alsoKnownAs": {"@id": "as:alsoKnownAs", "@type": "@id"},
"om2": "http://www.ontology-of-units-of-measure.org/resource/om-2/"
@mayel
mayel / deps.ex
Last active September 30, 2023 10:00
bonfire deps by app size
[
bonfire: %{total: "3.56GiB", deps: "1.95GiB", app: "2.8MiB},
bonfire_ui_common: %{total: "2.04GiB", deps: "346.71MiB", app: "1.70GiB"},
iconify_ex: %{total: "333.30MiB", deps: "2.99MiB", app: "330.31MiB"},
bonfire_editor_milkdown: %{total: "1.80GiB", deps: "1.70GiB", app: "96.43MiB"},
ex_doc: %{total: "53.90MiB", deps: "423.44KiB", app: "53.49MiB"},
text_corpus_udhr: %{total: "45.08MiB", deps: "70.67KiB", app: "45.01MiB"},
bonfire_ui_me: %{total: "1.74GiB", deps: "1.70GiB", app: "32.16MiB"},
bonfire_editor_quill: %{total: "1.73GiB", deps: "1.70GiB", app: "27.69MiB"},
paper_trail: %{total: "22.43MiB", deps: "8.61MiB", app: "13.83MiB"},
defmodule UserInput do
@doc "Takes a data structure and converts any keys in maps to (previously defined) atoms, recursively. By default any unknown string keys will be discarded. It can optionally also convert string values to known atoms as well."
def input_to_atoms(
data,
opts \\ []
)
def input_to_atoms(data, opts) do
opts =
iex(12)> M.infinity
1 : one (0 zeros)
10 : ten (1 zeros)
100 : one hundred (2 zeros)
1000 : one thousand (3 zeros)
10000 : ten thousand (4 zeros)
100000 : one hundred thousand (5 zeros)
1000000 : one million (6 zeros)
10000000 : ten million (7 zeros)