Skip to content

Instantly share code, notes, and snippets.

@alexellis
alexellis / metering-bash.md
Last active March 3, 2024 21:12
Metering for GitHub Actions

Running vmmeter outside of GitHub Actions

Download arkade, then crane:

curl https://get.arkade.dev | sudo sh
sudo -E arkade oci install ghcr.io/openfaasltd/vmmeter:latest --path /usr/local/bin/

Start the vmmeter in the background:

@aglassman
aglassman / async_assigns.ex
Last active July 23, 2023 12:36
LiveView - Async Assigns Helper
defmodule AsyncAssigns do
import Phoenix.LiveView, only: [connected?: 1, assign: 2, assign: 3]
@doc """
Provides ability to assign default values to the socket, and kick off a
process that will send a message to the LiveView. The message payload will
be assigned as specified.
## Usage
Add the following lines to a specific LiveView, or to the web module
@evadne
evadne / lecture.md
Last active October 4, 2023 23:24
How to Sell Elixir (2023)

How to Sell Elixir AGAIN (2023)

Presented by Evadne Wu at Code BEAM Lite in Stockholm, Sweden on 12 May 2023

Synopsis

We have celebrated 10 years of Elixir and also nearly 25 years of Erlang since the open source release in December 1998.

Most of the libraries that were needed to make the ecosystem viable have been built, talks given, books written, conferences held and training sessions provided. A new generation of companies have been built on top of the Elixir / Erlang ecosystem. In all measures, we have achieved further reach and maturity than 5 years ago.

status is-interactive
or exit 0
if test -n "$XDG_RUNTIME_DIR"
set -g __starship_async_tmpdir "$XDG_RUNTIME_DIR"/fish-async-prompt
else
set -g __starship_async_tmpdir /tmp/fish-async-prompt
end
mkdir -p "$__starship_async_tmpdir"
set -g __starship_async_signal SIGUSR1
@m-radzikowski
m-radzikowski / script-template.sh
Last active July 13, 2024 13:20
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
@AndrewDryga
AndrewDryga / dynamic_changeset.ex
Last active July 22, 2024 03:46
Dynamic embeds with Ecto
defmodule DynamicChangeset do
@moduledoc """
This module provides helper functions to extend `Ecto.Changeset` to support
dynamic embeds.
"""
alias Ecto.Changeset
@doc """
Casts the given embed with the embedded changeset and field which is used to define it's type.

Phoenix 1.4.x to 1.5.0 upgrade instructions

Phoenix 1.5 requires Elixir >= 1.7. Be sure your existing version is up to date by running elixir -v on the command line.

Install the new phx.new project generator

$ mix archive.uninstall phx_new
$ mix archive.install hex phx_new 1.5.0
@cblavier
cblavier / semaphore.yml
Created October 7, 2019 16:54
SemaphoreCI pipeline
version: v1.0
agent:
machine:
type: e1-standard-2
os_image: ubuntu1804
fail_fast:
stop:
when: "true"
@hl
hl / context.ex
Last active August 28, 2021 04:55
defmodule Context do
@moduledoc false
defmacro __using__(opts) do
repo = Keyword.fetch!(opts, :repo)
quote do
import Context, only: [context: 1, context: 2]
Module.put_attribute(__MODULE__, :__repo__, unquote(repo))