Skip to content

Instantly share code, notes, and snippets.

LiveView Forms

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)
)
@thmsmlr
thmsmlr / app.js
Created February 14, 2024 16:54
Code Splitting for Phoenix LiveView Hooks
// assets/js/app.js
window._lazy_hooks = window._lazy_hooks || {};
let lazyHook = function(hook) {
return {
mounted() { window._lazy_hooks[hook].mounted(...arguments) },
beforeUpdate() { window._lazy_hooks[hook].beforeUpdate(...arguments) },
updated() { window._lazy_hooks[hook].updated(...arguments) },
destroyed() { window._lazy_hooks[hook].destroyed(...arguments) },
disconnected() { window._lazy_hooks[hook].disconnected(...arguments) },
@mxgrn
mxgrn / lv_modal_close_confirm.md
Last active June 15, 2024 14:18
LiveView modal close confirmation on dirty form
@caspg
caspg / 1_searchbar_live.ex
Last active June 21, 2024 14:23
Example of real-time search bar implementation in Phoenix LiveView and Tailwind. Working example on https://travelermap.net/parks/usa
defmodule TravelerWeb.SearchbarLive do
use TravelerWeb, :live_view
alias Phoenix.LiveView.JS
alias Traveler.Places
def mount(_params, _session, socket) do
socket = assign(socket, places: [])
{:ok, socket, layout: false}
end
@SwitHak
SwitHak / 20211210-TLP-WHITE_LOG4J.md
Last active June 14, 2024 00:16
BlueTeam CheatSheet * Log4Shell* | Last updated: 2021-12-20 2238 UTC

Security Advisories / Bulletins / vendors Responses linked to Log4Shell (CVE-2021-44228)

Errors, typos, something to say ?

  • If you want to add a link, comment or send it to me
  • Feel free to report any mistake directly below in the comment or in DM on Twitter @SwitHak

Other great resources

  • Royce Williams list sorted by vendors responses Royce List
  • Very detailed list NCSC-NL
  • The list maintained by U.S. Cybersecurity and Infrastructure Security Agency: CISA List
@angelikatyborska
angelikatyborska / gettext.ex
Last active March 11, 2024 13:50
A custom `gettext_with_link` macro for easily putting inline links into gettext strings
# Has one external dependency except for Gettext: https://github.com/rrrene/html_sanitize_ex
defmodule MyApp.Gettext do
@doc """
A helper for translations with links.
Pass in the translation string which must include
`%{link_start}`/`%{link_end}`. For multiple URLs, use
`%{link_start_<0,1,2...>}`.
@PJUllrich
PJUllrich / big-o.md
Last active April 28, 2024 14:19
Big-O Time Complexities for Elixir Data Structures

Big-O Time Complexities for Elixir data structures

Map [1]

Operation Time Complexity
Access O(log n)
Search O(log n)
Insertion O(n) for <= 32 elements, O(log n) for > 32 elements [2]
Deletion O(n) for <= 32 elements, O(log n) for > 32 elements
@angelikatyborska
angelikatyborska / gettext_test.exs
Last active January 16, 2022 16:24
A unit test for Gettext translations that checks if the original and the translation use the same HTML tags. Uses Floki to parse HTML.
defmodule MyAppWeb.GettextTest do
use ExUnit.Case
import MyAppWeb.Gettext
# A unit test for Gettext translations that checks if the original and the translation
# use the same HTML tags.
#
# Uses Floki to parse HTML.
describe "translations" do
@idlehands
idlehands / 00_info.md
Last active May 20, 2023 11:28
-info and links
@ks2211
ks2211 / Phoenix esbuild with Tailwind and Fontawesome
Last active January 31, 2024 05:08
Phoenix with esbuild, fortawesome, and tailwindcss
Phoenix esbuild with Tailwind+Fontawesome