Skip to content

Instantly share code, notes, and snippets.

View PJUllrich's full-sized avatar

Peter Ullrich PJUllrich

View GitHub Profile
We can make this file beautiful and searchable if this error is corrected: It looks like row 6 should actually have 13 columns, instead of 9 in line 5.
medal_type,medal_code,medal_date,name,gender,discipline,event,event_type,url_event,code,country_code,country,country_long
Gold Medal,1,2024-07-27,Remco EVENEPOEL,M,Cycling Road,Men's Individual Time Trial,ATH,/en/paris-2024/results/cycling-road/men-s-individual-time-trial/fnl-000100--,1903136,BEL,Belgium,Belgium
Silver Medal,2,2024-07-27,Filippo GANNA,M,Cycling Road,Men's Individual Time Trial,ATH,/en/paris-2024/results/cycling-road/men-s-individual-time-trial/fnl-000100--,1923520,ITA,Italy,Italy
Bronze Medal,3,2024-07-27,Wout van AERT,M,Cycling Road,Men's Individual Time Trial,ATH,/en/paris-2024/results/cycling-road/men-s-individual-time-trial/fnl-000100--,1903147,BEL,Belgium,Belgium
Gold Medal,1,2024-07-27,Grace BROWN,W,Cycling Road,Women's Individual Time Trial,ATH,/en/paris-2024/results/cycling-road/women-s-individual-time-trial/fnl-000100--,1940173,AUS,Australia,Australia
Silver Medal,2,2024-07-27,Anna HENDERSON,W,Cycling Road,Women's Individual Time Trial,ATH,/en/paris-2024/results/cycling-road/women-s-
@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 September 11, 2024 02:10
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 October 14, 2024 21:37
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