Skip to content

Instantly share code, notes, and snippets.

View arturtamborski's full-sized avatar
💃

Artur Tamborski arturtamborski

💃
View GitHub Profile
@arturtamborski
arturtamborski / abomination.pl
Created August 7, 2023 10:26
parse hcl with perl xD
use strict;
use warnings;
use JSON 'encode_json';
my $code = `find .. -name '*.tf' -exec cat {} +`;
my @blocks = map { $_ =~ m/ (?^:((?:\{(?:(?>[^\{\}]+)|(?-1))*\}))) /xg } $code;
my @repos = grep { m| \s* source \s*=\s* ".+/modules/repository" |xg } @blocks;
my @names = map { $_ =~ m/ \s* name \s*=\s* "((?:[^"]+|"")*)" /xg } @repos;
my @unique = sort { $a cmp $b } do { my %seen; grep { !$seen{$_}++ } @names };
print encode_json { data => encode_json { repos => \@unique } };
#!/usr/bin/env python3
import os
import sys
import yaml
from collections import defaultdict
environments = [
d.removesuffix(".tfvars")
@arturtamborski
arturtamborski / git-xargs.sh
Last active May 17, 2023 13:02
git-xargs.sh
#!/usr/bin/env bash
SELF_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd -P)
SELF_FILE="$SELF_DIR/$(basename "${BASH_SOURCE[0]}")"
replace() {
local inpat=$1
local outpat=$2
echo "$inpat ==> $outpat ..."
@arturtamborski
arturtamborski / bash.sh
Created March 22, 2023 10:28
nice string loading in bash
read -r -d '' TF_CLI_ARGS_plan << \
----------------------------------------------
-compact-warnings
-var-file=${PWD}/environments/${ENVIRONMENT}.tfvars
----------------------------------------------
@arturtamborski
arturtamborski / __init__.py
Created January 18, 2023 16:04
python fokin logging
from logging import getLevelName, basicConfig, INFO
format = "%(asctime)s⏐%(levelname)5.5s⏐%(name)s.%(funcName)s():%(lineno)d⏐ %(message)s"
basicConfig(format=format, level=getLevelName(INFO))
@arturtamborski
arturtamborski / quicklinks.js
Created November 30, 2022 07:56
Add quicklinks to github (userscripts)
@arturtamborski
arturtamborski / jsondict.py
Created September 19, 2022 09:03
json dict in python :)
class jsondict(dict):
__getattribute__ = dict.__getitem__
def __init__(self, d):
for k, v in d.items():
if isinstance(v, dict):
d[k] = jsondict(v)
super().__init__(d)
@arturtamborski
arturtamborski / size.py
Created September 8, 2022 08:03
python3 file size from bytes
Bytes
print(f"{os.path.getsize(filepath):,} B")
Kilobits
print(f"{os.path.getsize(filepath)/float(1<<7):,.0f} kb")
Kilobytes
print(f"{os.path.getsize(filepath)/float(1<<10):,.0f} KB")
Megabits
@arturtamborski
arturtamborski / git-rm.sh
Created August 30, 2022 07:17
remove file from git history
#!/usr/bin/env bash
# source: https://stackoverflow.com/a/43640996
FILE=$1
# replace FILE with the file or folder you wish to remove from the given git repository.
git filter-branch -f --index-filter "git rm -rf --cached --ignore-unmatch $FILE" -- --all
rm -rf .git/refs/original/
@arturtamborski
arturtamborski / commands.sh
Created August 16, 2022 07:54
move terraform resources between components
cd dirA
terraform state pull > ../dirA.tfstate
cd ../dirB
terraform state pull > ../dirB.tfstate
terraform state mv -state=../dirA.tfstate -state-out=../dirB.tfstate module.foo module.foo
terraform state push ../dirB.tfstate