Skip to content

Instantly share code, notes, and snippets.

@polvalente
polvalente / gist:bd0eb1aa8b2a1fa01734019a60b27ca5
Last active December 5, 2025 09:25
Example Python-Nx runtime bridge

Untitled notebook

Mix.install [
  {:exla, github: "elixir-nx/nx", sparse: "exla"},
  {:nx, github: "elixir-nx/nx", sparse: "nx", override: true},
  {:pythonx, "~> 0.4.7"}
]
@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.
"""
@mxgrn
mxgrn / lv_modal_close_confirm.md
Last active June 15, 2024 14:18
LiveView modal close confirmation on dirty form
@toranb
toranb / bert_medium_training.ex
Last active November 14, 2023 15:56
The bumblebee fine tuning example with one of the smaller Pytorch pre-trained BERT variants
defmodule Training.Example do
def train() do
Nx.default_backend(EXLA.Backend)
{:ok, spec} =
Bumblebee.load_spec({:hf, "prajjwal1/bert-medium"},
module: Bumblebee.Text.Bert,
architecture: :for_sequence_classification
)
@arjan
arjan / live_acl.ex
Created March 7, 2023 11:13
LiveView ACL check example code
defmodule ExampleApp.Web.LiveAcl do
@moduledoc """
ACL checks for LiveView
```
use ExampleApp.Web.LiveAcl
```
Provides an `on_mount` hook to do ACL checks on mount, for instance
to ensure the current user has access to a given invoice ID.
@andreaseriksson
andreaseriksson / convert_to_verified_routes.ex
Last active March 25, 2025 14:01
This is a mix task for converting old Phoenix routes to new verified routes
defmodule Mix.Tasks.ConvertToVerifiedRoutes do
@shortdoc "Fix routes"
use Mix.Task
@regex ~r/(Routes\.)(.*)_(path|url)\(.*?\)/
@web_module MyAppWeb
def run(_) do
Path.wildcard("lib/**/*.*ex")
@jmatsushita
jmatsushita / README
Last active October 29, 2025 09:57
Setup nix, nix-darwin and home-manager from scratch on an M1 Macbook Pro
###
### [2023-06-19] UPDATE: Just tried to use my instructions again on a fresh install and it failed in a number of places.
###. Not sure if I'll update this gist (though I realise it seems to still have some traffic), but here's a list of
###. things to watch out for:
### - Check out the `nix-darwin` instructions, as they have changed.
### - There's a home manager gotcha https://github.com/nix-community/home-manager/issues/4026
###
# I found some good resources but they seem to do a bit too much (maybe from a time when there were more bugs).
# So here's a minimal Gist which worked for me as an install on a new M1 Pro.
@ityonemo
ityonemo / test.md
Last active December 8, 2025 03:51
Zig in 30 minutes

A half-hour to learn Zig

This is inspired by https://fasterthanli.me/blog/2020/a-half-hour-to-learn-rust/

Basics

the command zig run my_code.zig will compile and immediately run your Zig program. Each of these cells contains a zig program that you can try to run (some of them contain compile-time errors that you can comment out to play with)

@fuelen
fuelen / ecto_cond.ex
Created November 12, 2020 15:17
Ecto cond
defmodule Ecto.Extension.Query.API do
defmacro cond_(do: block) do
bindings =
Enum.reduce(block, [], fn
{:->, _, [[clause], branch]}, acc ->
[branch, clause | acc]
end)
|> Enum.reverse()
bindings_number = length(bindings)