Skip to content

Instantly share code, notes, and snippets.

View torson's full-sized avatar

Tomaz Strukelj torson

View GitHub Profile
@torson
torson / aws-assume-role.py
Last active May 3, 2024 16:18
Script for doing AWS Assume Role with MFA and supporting multiple account contexts
#!/usr/bin/env python3
# Requires: pip install pymemcache cryptography boto3 python-dotenv keyring
# This script asks for MFA ARN, ROLE ARN to be assumed , and MFA
# It then creates a file .env where it sets the default and user-inputed configuration,
# assumes the role, caches the access key/secret/token values into the system's vault
# (or memcached, depending what you choose) and outputs the access key/secret/token envvars ,
# in such a format that you can call it with shell's 'eval'.
@torson
torson / iam-user-policy-ttl-detach.sh
Last active February 1, 2021 17:17
Script to detach a policy from a AWS IAM user after a defined period / ttl
#!/bin/bash
set -e
# This script is for removing a policy from a IAM user after a predefined TTL
# It adds a crontab that runs this script every hour
# If run with arguments then that task is added to the .state file
# In addition it attaches the policy to the user if run with '-a'
# If run without arguments it parses the .state file and detaches policies from users if TTL expired
## WORKFLOW
@torson
torson / nepremicnine_scraper.sh
Created August 18, 2020 15:20
nepremicnine_scraper.sh
#!/bin/bash
DOMAIN="https://www.nepremicnine.net"
MAIN_URL="/oglasi-oddaja/ljubljana-mesto/stanovanje/garsonjera,1-sobno,1.5-sobno,2-sobno/cena-od-450-do-700-eur-na-mesec,velikost-od-38-do-60-m2/?s=14&nadst%5B0%5D=vsa&nadst%5B1%5D=vsa"
INDEX_FILE="/tmp/index.txt"
FIRST_PAGE="/tmp/page1.html"
TMP_FILE="/tmp/tmp.html"
SLEEP_BETWEEN_REQUESTS_SECONDS=10
touch ${INDEX_FILE}
@torson
torson / folders_merge_by_timestamp.pl
Last active April 2, 2020 12:37
Copy and position files into another folder by renaming the copied files based on their timestamp
#!/usr/bin/perl
# This script takes the files from the inbound folder and copies them
# into the base folder and in the process positions each inbound file
# between 2 base files - between the older and the newer base file by
# renaming it accordingly (using the older file as the 1st part and the
# inbound file as the 2nd part of the new name)
# Scenario:
# You configured your phone to use SD card for storing pictures.
@torson
torson / docker_images_unique_size_sum.pl
Created March 11, 2020 03:39
Docker multiple images unique layers size total sum
#!/usr/bin/perl
## Purpose:
# To get the real size of your app that is comprised of many services/images.
# This script sums only the sizes of unique image layers.
# This way you can get a better sense of the total size of your app and make optimizations if needed.
## Usage:
# ./docker_images_size.pl IMAGE1:TAG1 IMAGE2:TAG2 ...
## Example:
@torson
torson / vino-server.sh
Last active January 21, 2022 02:47
vino-server start/stop/status script , run it under the logged-in user
#!/bin/bash
### BEGIN INIT INFO
# Provides: vino-server
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Should-Start:
# Should-Stop:
# X-Start-Before:
# X-Stop-After: