Skip to content

Instantly share code, notes, and snippets.

View ftes's full-sized avatar

Fredrik Teschke ftes

View GitHub Profile
@ftes
ftes / load-test.js
Created July 11, 2025 17:56
Load test phoenix liveview form submission with k6
import http from "k6/http";
import ws from "k6/ws";
export const options = {
// Key configurations for spike in this section
stages: [
{ duration: "2m", target: 100 }, // fast ramp-up to a high point
// No plateau
{ duration: "1m", target: 0 }, // quick ramp-down to 0 users
],
@ftes
ftes / reveal-slides.html
Created July 11, 2025 16:57
reveal.js + mermaid.js: Fix diagram size, text clipping, lazy loading
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<title>Let it Crash with Elixir</title>
@ftes
ftes / csv.ex
Last active June 30, 2025 14:35
Elixir NimbleCSV prevent CSV injection via credo rule
defmodule MyApp.CSV do
@moduledoc false
NimbleCSV.define(MyyApp.CSV.RFC4180,
# defaults from NimbleCSV.Spreadsheet
separator: ",",
escape: "\"",
line_separator: "\r\n",
escape_formula: %{["@", "+", "-", "=", "\t", "\r"] => "'"}
)
@ftes
ftes / heex-global-attr-override.exs
Created May 2, 2025 07:40
Single file phoenix example: .heex global attribute overrides
Application.put_env(:sample, Example.Endpoint,
http: [ip: {127, 0, 0, 1}, port: 5001],
server: true,
live_view: [signing_salt: "aaaaaaaa"],
secret_key_base: String.duplicate("a", 64)
)
Mix.install(
[
{:plug_cowboy, "~> 2.5"},
@ftes
ftes / exercises.md
Created March 14, 2023 06:39
Software Developer Bootcamp
@ftes
ftes / dijkstra.livemd
Created December 12, 2022 19:42
Elixir Dijkstra's Shortest Path Algorithm

dijkstra

Mix.install(
  [
    {:kino, "~> 0.7.0"},
    {:vega_lite, "~> 0.1.6"},
    {:kino_vega_lite, "~> 0.1.7"}
@ftes
ftes / FormWebComponent.jsx
Created September 5, 2022 15:29
Phoenix LiveView Form + HeadlessUI
export default class ComboboxFormWebcomponent extends HTMLElement {
connectedCallback() {
// ...
const inputId = this.getAttribute("input-id")
this.inputEl = document.getElementById(inputId)
this.inputEl.addEventListener("change", this.onValueChange)
this.render()
}
disconnectedCallback() {
@ftes
ftes / PushEventHook.js
Created September 5, 2022 07:00
Phoenix LiveView + HeadlessUI
const PushEventHook = {
mounted() {
const target = this.el.attributes["phx-target"]?.value
this.el.__pushEvent = (event, value, onReply = () => {}) =>
target
? this.pushEventTo(target, event, value, onReply)
: this.pushEvent(event, value, onReply)
}
}
@ftes
ftes / projection.ex
Created November 5, 2021 09:32
Reset all commanded read model projections via macro and module attribute
defmodule Mixins.Projection do
defmacro __using__(params) do
table = Keyword.get(params, :table) || raise "Missing param :table"
Module.register_attribute(__CALLER__.module, :table, persist: true)
Module.put_attribute(__CALLER__.module, :table, table)
quote do
use Ecto.Schema
end
end
@ftes
ftes / grid_with_drag_and_drop.ex
Created October 3, 2021 19:51
Drag 'n drop on the PETAL(S) stack
if @dragged.target == :live_view do
"hook.pushEvent('#{@dragged.name}', {from, to});"
else
"hook.pushEventTo('#{@dragged.target}', '#{@dragged.name}', {from, to});"
end