Skip to content

Instantly share code, notes, and snippets.

View Valian's full-sized avatar
🔮
Diving deep into Elixir

Jakub Skałecki Valian

🔮
Diving deep into Elixir
View GitHub Profile
@Valian
Valian / app.js
Created May 7, 2024 21:08
Set data-active attributes on LiveView navigation in Phoenix
window.addEventListener("phx:page-loading-start", (_info) => {
Array.from(document.getElementsByTagName("a")).forEach(
(a) => (a.dataset.active = "false")
);
});
window.addEventListener("phx:page-loading-stop", (_info) => {
Array.from(document.getElementsByTagName("a")).forEach(
(a) => {a.dataset.active = (a.href === document.location.href).toString()}
);
@Valian
Valian / usePushEvent.ts
Created August 20, 2024 15:47
usePushEvent - similar to useFetch, but for live_vue library
export function usePushEvent<T extends object, Params extends object = object>(
eventName: string,
defaultValue?: T
) {
const live = useLiveVue();
const isLoading = ref(false);
const isFinished = ref(false);
const response = ref<T | undefined>(defaultValue);
const error = ref<string | null>(null);
const execute = (data: Params) => {
@Valian
Valian / ai_message_sigil.ex
Created February 28, 2025 10:26
Sigils for AI prompts supporting Liquid syntax in Elixir. Requires Solid package.
defmodule Prompts.AIMessageSigils do
@moduledoc """
Provides sigils for creating AI message structures with liquid template validation.
This module includes:
- `~SYSTEM` for system messages
- `~ASSISTANT` for assistant messages
- `~USER` for user messages
Each sigil validates the Liquid template syntax at compile time and returns a