Skip to content

Instantly share code, notes, and snippets.

View PJUllrich's full-sized avatar

Peter Ullrich PJUllrich

View GitHub Profile
@PJUllrich
PJUllrich / keymap.json
Created April 4, 2024 12:46
zeddev configuration
[
{
"context": "Pane",
"bindings": {
"ctrl-shift-tab": "pane::ActivatePrevItem",
"ctrl-tab": "pane::ActivateNextItem",
"cmd-shift-t": "workspace::NewTerminal"
}
},
{
@PJUllrich
PJUllrich / update_tool_version.sh
Last active February 22, 2024 06:25
A bash script to update the Elixir and erlang versions in your application.
#!/bin/bash
# Updates either the Elixir or erlang version everywhere in the project
set -e
if [ "$#" -ne 2 ]; then
echo "Usage: $0 old_version new_version. Example: $0 1.15.7 1.16.1"
exit 1
fi
@PJUllrich
PJUllrich / http.ex
Last active January 25, 2024 09:09
HTTP Wrapper with optional Caching
defmodule MyApp.Http do
@moduledoc """
Exposes functions to make HTTP requests and optionally cache the response.
If you want to cache the request, simply add `cache: true` to the
request options. You can also define an option time-to-live (TTL) with
`cache_ttl: ttl_in_milliseconds`. The default TTL is 5min.
Only caches 2xx responses.
"""
@PJUllrich
PJUllrich / worker.ex
Created July 22, 2023 12:06
Attack Library Worker
defmodule Attack.Worker do
use GenServer
require Logger
def start_link(init_args) do
GenServer.start_link(__MODULE__, [init_args])
end
def init(_args) do

The Code

Mix.install([{:benchee, "~> 1.0", only: :dev}, {:plug, "~> 1.14"}])

iterations = 10

# Compares the strings with "=="
# Returns 'nil' to minimize time spent on allocating and moving around memory
variable_compare = fn left, right -> 
  for _ <- 1..iterations, do: left == right
@PJUllrich
PJUllrich / example.exs
Created October 22, 2022 11:00
Example Error when using tsvector with regconfig in Ecto
## Migration
def up do
create table(:books) do
add :title, :string
add :summary, :text
add :language, :text
end
for lang <- ['english', 'spanish', 'italian'] do
execute """
@PJUllrich
PJUllrich / tasks.json
Created December 20, 2021 13:20
VSCode Tasks for running Elixir tests quickly
{
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"type": "shell",
"command": "mix compile",
"problemMatcher": ["$mixCompileError", "$mixCompileWarning"],
"group": {
"kind": "build",
@PJUllrich
PJUllrich / big-o.md
Last active March 18, 2024 14:44
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
@PJUllrich
PJUllrich / regularly_check_appointments_in_cologne.exs
Last active June 7, 2021 12:26
Checks for available appointments in the "Bürgeramt" in Cologne and notifies via Pushover
defmodule Terminvergabe do
@moduledoc """
This script checks for available appointments in the "Bürgeramt" (city hall)
every 5min and notifies a user via Pushover if new appointments become were added.
In order to use Pushover, you must configure the following environment variables:
PUSHOVER_USER
PUSHOVER_TOKEN
require 'google/apis/identitytoolkit_v3'
require 'google/apis/core/api_command'
require 'googleauth'
require 'addressable/template'
require 'json'
require 'securerandom'
# Request to delete account.
class CreateSessionCookieRequest
include Google::Apis::Core::Hashable