Skip to content

Instantly share code, notes, and snippets.

@thmsmlr
thmsmlr / wait_for.ex
Created December 26, 2024 21:20
ExUnit helper function to wait up to a timeout to determine whether a set of assertions completes. Perfect for testing async code
@default_timeout 100
@check_interval 10
# Test Helpers
defp wait_for(fun, timeout \\ @default_timeout) do
start_time = System.monotonic_time(:millisecond)
ref = make_ref()
try do
Mix.install(
[
{:phoenix_playground, "~> 0.1.0"},
{:openai, "~> 0.6.1"},
{:makeup, "~> 1.1.2"},
{:makeup_elixir, "~> 0.14"}
],
config: [
openai: [
api_key: System.get_env("OPENAI_API_KEY"),
@nyku
nyku / resize_convert.sh
Last active August 1, 2024 22:38
Resize & Convert image -> webp
#!/bin/bash
# Usage:
# ./resize_and_convert.sh ~/Desktop/folder-with-images
# Check if the correct number of arguments is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 source_path"
exit 1
fi
@aeons
aeons / config.exs
Last active April 1, 2025 00:33
Erlang 27 :json module in Phoenix
config :phoenix, :json_library, ErlJson
@rsms
rsms / macos-distribution.md
Last active April 21, 2025 04:05
macOS distribution — code signing, notarization, quarantine, distribution vehicles
#!/usr/bin/env bash
# Abort sign off on any error
set -e
# Start the benchmark timer
SECONDS=0
# Repository introspection
OWNER=$(gh repo view --json owner --jq .owner.login)

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)
)
@loreanvictor
loreanvictor / RISS.md
Last active October 29, 2024 07:50
Interaction as Content

Can We Get More Decentralised Than The Fediverse?

I guess that the [fediverse][fediverse] will be as decentralised as email: a bit, but not that much. Most people will be dependent on a few major hubs, some groups might have their own hubs (e.g. company email servers), personal instances will be pretty rare. This is in contrast to personal blogging, where every Bob can easily host their own (and they often do). I mean that's already implied by the name: fediverse is [a federated universe, not a distributed one][fed-v-dis].

Why does this matter? Well I like not being dependent on one entity, but I would like it much more if I was dependent on no entities at all. In other words, I like to publish my own personal blog and get all the goodies of a social network, without being dependent on other micro-blogging / social content platforms.

So in this writing, I'm going to:

  • ❓ Contemplate on why the fediverse gets federated not distributed (spoilers: its push vs pull)
  • 🧠 Ideate on how could we get a distri
@siliconjungle
siliconjungle / simple-diff.js
Created December 10, 2023 19:49
Simple diff
// This is a basic diff mechanism, it is not going to work for characters that take up more than
// one byte. It is also not going to normalise text.
// these are things that *should happen* in the future, but for now they are going to be ignored.
// returns the insert position & the text to insert as well as the delete position & the text to delete
// one of the problems with this kind of diff is that you can't tell in some cases where the insert
// actually occurred.
// for this you will need to take into account the cursor start & end.
export const diff = (a, b) => {
if (a === b) {
@RoyalIcing
RoyalIcing / parse_u8.ex
Last active December 2, 2023 01:34
Lemire’s Parsing 8-bit integers quickly in WebAssembly via Orb. https://lemire.me/blog/2023/11/28/parsing-8-bit-integers-quickly/
defmodule ParseU8 do
@moduledoc """
https://lemire.me/blog/2023/11/28/parsing-8-bit-integers-quickly/
"""
# Orb lets you write WebAssembly with friendly Elixir syntax: https://github.com/RoyalIcing/Orb
use Orb
Memory.pages(1)
wasm_mode(U32)