Skip to content

Instantly share code, notes, and snippets.

View codeadict's full-sized avatar
🕸️
λ: f(f(state)) = f(state)

Dairon M. codeadict

🕸️
λ: f(f(state)) = f(state)
View GitHub Profile
@PJUllrich
PJUllrich / update_tool_version.sh
Last active February 22, 2024 06:25
A bash script to update the Elixir and erlang versions in your application.
#!/bin/bash
# Updates either the Elixir or erlang version everywhere in the project
set -e
if [ "$#" -ne 2 ]; then
echo "Usage: $0 old_version new_version. Example: $0 1.15.7 1.16.1"
exit 1
fi
@PJUllrich
PJUllrich / http.ex
Last active January 25, 2024 09:09
HTTP Wrapper with optional Caching
defmodule MyApp.Http do
@moduledoc """
Exposes functions to make HTTP requests and optionally cache the response.
If you want to cache the request, simply add `cache: true` to the
request options. You can also define an option time-to-live (TTL) with
`cache_ttl: ttl_in_milliseconds`. The default TTL is 5min.
Only caches 2xx responses.
"""
@paulo-ferraz-oliveira
paulo-ferraz-oliveira / logging_decorator.md
Created May 5, 2023 13:17
Wrap a function in a "timed-performance" log decorator, using Elixir library decorator and Logger

Here's an example of how to do it.

def with_performance_log(options, body, context) do
  quote bind_quoted: [
          context: Macro.escape(context),
          options: Macro.escape(options),
          body: body
        ] do
 module = "#{context.module}"
@paulo-ferraz-oliveira
paulo-ferraz-oliveira / gha-tool-versions.md
Last active January 8, 2024 18:42
Read .tool-versions to GitHub env. and use it in between jobs
@mcrumm
mcrumm / intl.ex
Created July 11, 2022 21:41
Intl data via LiveView connect params
defmodule MyAppWeb.Intl do
@moduledoc """
Loads internationalization info from socket.
"""
import Phoenix.LiveView
def on_mount(:default, _params, _session, socket) do
cparams = get_connect_params(socket)
{:cont,
@cadebward
cadebward / rename_phoenix_project.sh
Last active February 9, 2023 19:24 — forked from krystofbe/rename_phoenix_project.sh
rename a phoenix 1.3 project
#!/bin/bash
set -e
CURRENT_NAME="WatchParty"
CURRENT_OTP="watch-party"
NEW_NAME="Chat"
NEW_OTP="chat"
@mcrumm
mcrumm / phx_sqlite_fly_launch.md
Last active May 3, 2024 09:38
Phoenix + SQLite Deployment tips

Deploying to Fly.io with SQLite

Deploying a Phoenix app to Fly.io is a breeze...is what everyone kept telling me. In fairness, I imagine the process would have been breezier had I just used postgres, but all the sqlite and litestream talk has been far too intriguing to ignore. "Wait", you say. "It is just a flat file. How much harder can it be?"

It is easy to make something harder than it should be. It is hard to take something complex and make it truly simple. flyctl launch does an amazing job at providing a simple interface to the utterly complex task of generating deployment resources, especially now that we are living in a containerd (erm, firecracker) world.

This gist is for anyone who, like me, thinks they know better than to read all of the documentation and therefore necessari

Neural network from scratch in ... Elixir

Pure Elixir initial version test

inputs = [1, 2, 3, 2.5]
weights = [0.2, 0.8, -0.5, 1.0]
bias = 2.0
@gcauchon
gcauchon / !Protocol for external APIs
Last active September 8, 2023 15:47
Using protocol for external APIs
iex(1)> Foo.Correspondence.validate_number("234-555-6789")
{:ok, "Verizon Wireless", "mobile"}
@ctsrc
ctsrc / README.md
Last active June 17, 2024 18:39 — forked from niw/README.en.md
Guide: Run FreeBSD 13.1-RELEASE for ARM64 in QEMU on Apple Silicon Mac (MacBook Pro M1, etc) with HVF acceleration (Hypervisor.framework)