Skip to content

Instantly share code, notes, and snippets.

@nkiraly
nkiraly / db.go
Created February 12, 2024 20:19 — forked from molind/db.go
Disable migration in gorm.io
package db
import (
"fmt"
"userspace_back/db/model"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/schema"
@nkiraly
nkiraly / tf_vars_sort.awk
Created January 9, 2024 22:15 — forked from yermulnik/tf_vars_sort.awk
Sort Terraform (HCL) file by Resource Block Names using GNU `awk`
#!/usr/bin/env -S awk -f
# https://gist.github.com/yermulnik/7e0cf991962680d406692e1db1b551e6
# Tested with GNU Awk 5.0.1, API: 2.0 (GNU MPFR 4.0.2, GNU MP 6.2.0)
# Usage: /path/to/tf_vars_sort.awk < variables.tf | tee sorted_variables.tf
# Note: "chmod +x /path/to/tf_vars_sort.awk" before use
# No licensing; [email protected], 2021-2023
{
# skip blank lines at the beginning of file
if (!resource_type && length($0) == 0) next
@nkiraly
nkiraly / readme.md
Created October 5, 2022 19:12 — forked from thomasdarimont/readme.md
Example for decoding a JWT Payload with your Shell (bash, zsh...)

Setup

Add this to your .profile, .bashrc, .zshrc...

decode_base64_url() {
  local len=$((${#1} % 4))
  local result="$1"
  if [ $len -eq 2 ]; then result="$1"'=='
  elif [ $len -eq 3 ]; then result="$1"'=' 
  fi
 echo "$result" | tr '_-' '/+' | openssl enc -d -base64
@nkiraly
nkiraly / json-to-ndjson.md
Created April 13, 2022 01:26 — forked from bzerangue/json-to-ndjson.md
JSON to NDJSON

NDJSON is a convenient format for storing or streaming structured data that may be processed one record at a time.

  • Each line is a valid JSON value
  • Line separator is ‘\n’

1. Convert JSON to NDJSON?

cat test.json | jq -c '.[]' > testNDJSON.json
@nkiraly
nkiraly / gist:6269f3e8aa8e4752029c7819db655b58
Created December 15, 2021 04:54 — forked from cdown/gist:1163649
Bash urlencode and urldecode
urlencode() {
# urlencode <string>
old_lc_collate=$LC_COLLATE
LC_COLLATE=C
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:$i:1}"
case $c in
@nkiraly
nkiraly / README.md
Created September 26, 2021 12:40 — forked from jjenkins70/README.md
HashiCorp Vault TLS Certificate Auth Samples

Simple Vault TLS Certificate validation & testing

Set of scripts to deploy locally, vault and configure TLS server and user certificates for testing TLS AUTH.

credit to @reard3n (https://github.com/reard3n) and @v6 (https://github.com/v6) for the gist this grew from

Notes

This was tested using Vagrant and Ubuntu

Getting Setup

  • On the OS of your choice copy VaultCASetup.sh script locally and update any variables that would be specific to your environment and/or
@nkiraly
nkiraly / hashicorp-vault-auth-cert-and-token-role-creation.md
Created September 26, 2021 12:34 — forked from davidmintz/hashicorp-vault-auth-cert-and-token-role-creation.md
notes on setting up and using Vault TLS authentication, policies, and tokens with named roles

Our goal is to save sensitive data in a MySQL database in a responsible way, and be able to read/write it programmatically in a PHP web application. Asymmetric encryption would be best, but is not practical here. Symmetric encryption with a strong algorithm and hard-to-guess cipher is acceptable, but not if we store the cipher in plain text on the same server where the database credentials also live in plain text!

This work-in-progress is subject to change if/when I come up with a better scheme, but for now, the plan is to:

  • store the cipher as a vault secret;
  • configure TLS authentication so that our PHP application can log in, and then
  • create a token that allows its bearer to read the secret (our cipher);
  • use a PHP component and our cipher to encrypt/decrypt our sensitive data.
@nkiraly
nkiraly / rke2-commands.md
Created August 27, 2021 21:24 — forked from superseb/rke2-commands.md
RKE2 / rancherd commands

RKE2 commands

Install

curl -sL https://get.rke2.io | sh
systemctl daemon-reload
systemctl start rke2-server
@nkiraly
nkiraly / install_pipenv.md
Created July 16, 2021 03:24 — forked from planetceres/install_pipenv.md
pipenv installation notes Ubuntu 18.04

Installation Notes for pipenv on Ubuntu 18.04

1. Add ~/.local/bin to PATH

pypa/pipenv#2122 (comment)

echo 'export PATH="${HOME}/.local/bin:$PATH"' >> ~/.bashrc