Skip to content

Instantly share code, notes, and snippets.

View moroz's full-sized avatar

Karol Moroz moroz

  • Senior Full Stack Developer at virtualQ GmbH
  • Bay Area, Kaohsiung, TW
  • 03:36 (UTC +08:00)
View GitHub Profile
@moroz
moroz / iwlwifi.sh
Last active April 28, 2026 11:20
Fix wifi after system sleep on MSI prestige
#!/bin/sh
# /usr/lib/systemd/system-sleep/iwlwifi.sh
# https://forums.linuxmint.com/viewtopic.php?t=413512
case $1/$2 in
pre/*)
modprobe -r iwlmld iwlmvm iwlwifi 2>/dev/null || true
;;
@moroz
moroz / cookie_helper.ex
Created February 3, 2021 14:20
Set session with Absinthe mutation
@moroz
moroz / DESCRIPTION.md
Last active December 18, 2023 13:58
Introduction to databases in Go

Homework for 12/17

Write a program that connects to a Postgres database and stores contact information in a table.

Sample input:

$ go run .
First name: John
Last name: Smith
#!/usr/bin/env -S bash -e
if [[ "$1" = "" ]]; then
echo "Usage: ./calculate_time.sh FILE.csv"
exit 1
fi
FILE="$(realpath $1)"
if [[ ! -f "$FILE" ]]; then
@moroz
moroz / format_page.ex
Created November 26, 2020 04:21
Format a pagination struct into neat GraphQL response (scrivener_ecto, absinthe)
defmodule MyAppWeb.Api.Middleware.FormatPage do
@behaviour Absinthe.Middleware
def call(%{value: %Scrivener.Page{} = page} = res, _) do
%{
entries: data,
page_number: page_number,
page_size: page_size,
total_pages: total_pages,
total_entries: total_entries
@moroz
moroz / import.sh
Created July 4, 2023 08:08
Import a CSV file into postgres with dynamic paths
#!/bin/bash -e
SAMPLES_PATH="$(pwd)/samples.csv"
uname="$(uname)"
# When on Windows, you need to pass the path as c:/path/to/file
# rather than /c/path/to/file (as expected by PostgreSQL).
if [[ "$uname" != "Linux" && "$uname" != "Darwin" ]]; then
# remove the leading slash and replace the second slash with :/
@moroz
moroz / escape.ex
Created March 7, 2023 00:14
Escape non-alphanumerics in HTML strings
escape = fn str ->
str
|> Base.encode16()
|> String.replace_prefix("", "&#x")
|> String.replace_suffix("", ";")
end
String.replace(string, ~r/\W/, escape)
@moroz
moroz / clean_up.sh
Created February 9, 2023 15:51
Clean up AWS ECS task definition template using jq
#!/bin/bash
if [ "$1" = "" ]; then
echo "No input file!"
exit 1
fi
cat $1 | \
jq -S 'del(.compatibilities, .registeredAt, .registeredBy, .requiresAttributes, .revision, .status, .taskDefinitionArn)' | \
sponge $1
@moroz
moroz / empty_ecr_repo.sh
Created December 16, 2022 23:18
Empty an ECR repository
#!/bin/sh
# Implies that AWS_PROFILE and AWS_REGION are set
aws ecr list-images --repository-name $1 \
| jq -r '.imageIds[].imageTag' \
| xargs printf -- 'imageTag=%s\n' \
| xargs aws ecr batch-delete-image --repository-name $1 --image-ids
@moroz
moroz / paginatable.ex
Created November 17, 2022 22:55
Pagination behavior for scrivener_ecto
defmodule UnterEats.Paginatable do
@callback base_query() :: Ecto.Queryable.t()
@callback filter_by_params({atom(), term()}, Ecto.Queryable.t()) :: Ecto.Queryable.t()
@optional_callbacks filter_by_params: 2
alias UnterEats.Repo
def filter_and_paginate_resource(module, params) when is_atom(module) do
query = module.base_query()