SNIPS.PLAINTEXT.DEV


2024-12-12 - Creating Random Strings in Elixir

A simple way to create a random string in Elixir:
Enum.take_random(~c"abcdefghijklmnopqrstuvwxyz", 4) |> to_string
Tags: elixir, random, strings

2024-12-12 - Simple Web Endpoint in Elixir

To spawn a very simple web endpoint in Elixir a simple script can be used:
#!/usr/bin/env elixir Mix.install([:plug, :plug_cowboy]) defmodule Router do use Plug.Router plug Plug.Logger plug :match plug :dispatch get "/" do send_resp(conn, 200, "Hello World\n") end end require Logger webserver = {Plug.Cowboy, plug: Router, scheme: :http, options: [port: 4000]} {:ok, _} = Supervisor.start_link([webserver], strategy: :one_for_one) Logger.info("Server now running on localhost:4000") Process.sleep(:infinity)
curl localhost:4000 Hello World
Tags: elixir, webserver, phoenix, http, curl

2024-12-02 - Taking Screenshots More Comfortably In i3wm

Tiling window managers like i3 do not provide the same comfort for taking screenshots as e.g. KDE does. An example how to take screenshots, copy them to the clipboard (for easy sharing) and saving them to `~/.screenshots` for later use:
bindsym --release Mod1+Shift+4 exec /home/user/bin/screenshot
#!/bin/sh SDATE=$(date +%Y-%m-%d-%H%M%S) SPATH=/home/user/.screenshots scrot -s - | tee ${SPATH}/${SDATE}.png | xclip -selection clipboard -target image/png feh ${SPATH}/${SDATE}.png
The `scrot` command takes the screenshot, saves it into the `~/.screenshot` directory with the date as name, copies the image to your clipboard for pasting and opens it in a new window. Tags: i3, screenshot

2024-11-30 - Start Erlang's Observer In iex With Or Without mix

It is sometimes useful to be able to start Erlang's observer tool from iex. After starting iex with `iex -S mix` in a terminal from within an Elixir project folder:
Mix.ensure_application!(:observer)
After starting iex with simply `iex` in an a terminal:
Application.ensure_all_started(:observer)
The observer can now be started with `:observer.start()`. Tags: Elixir, Erlang, iex, mix, observer

2024-11-29 - Display Brightness With xrandr

To change your display brightness with xrandr use this command:
xrandr --output DisplayPort-1 --brightness 0.7
Replace `DisplayPort-1` with your used output. Use `xrandr` itself to find the correct output. Use a brightness value between 0 and 1 e.g. 0.7. Tags: OpenBSD, xrandr, display, brightness

2024-11-29 - Building TailwindCSS On OpenBSD

Currently there is no simple way to build tailwind via the hex package on OpenBSD. As a workaround replace the tailwind_os_$arch executable in the _build directory of your Phoenix application with this script:
#!/bin/sh npx tailwindcss "$@"
Make the file executable with `chmod +x`. Running your phoenix application should now work with the correct styling. Tags: Elixir, OpenBSD, TailwindCSS, Phoenix