Skip to content

Instantly share code, notes, and snippets.

View kouk's full-sized avatar

Konstantinos Koukopoulos kouk

View GitHub Profile
@kouk
kouk / How to add a submodule with shallow checkout and shallow clone
Last active April 17, 2024 20:16
.How to add a submodule with shallow checkout and shallow clone
If you have a huge repository (in size and in history) and want to add a subfolder
to your project as a submodule you can follow this example to save time and space
using git's shallow clone and shallow checkout feature. It is a bit more complicated
in this example because I assume that you want your submodule to track a non-default
branch, called `mybranch`, instead of the `master` branch. Things could probably get
a lot simpler when using the default branch. After following the commands in these
examples you can use `git submodule update` and `git submodule update --remote` as normal.
@kouk
kouk / wtf8.py
Last active February 17, 2022 00:14
Python codec for Wobbly Transformation Format - 8-bit (WTF-8)
# -*- coding: utf-8 -*-
# To the extent possible under law, the author of this work, Konstantinos
# Koukopoulos, has waived all copyright and related or neighboring rights to
# "Python codec for Wobbly Transformation Format - 8-bit (WTF-8)". It is
# dedicated to the public domain, as described in:
# http://creativecommons.org/publicdomain/zero/1.0/
# This work is published from Greece and is available here:
# https://gist.github.com/kouk/d4e1faababf14b09b27f
from __future__ import unicode_literals, print_function
import six
@kouk
kouk / igrouper-test.py
Created November 11, 2016 15:13
Consume an iterable in chunks, skipping what's not needed. Similar to the "grouper" recipe in https://docs.python.org/2/library/itertools.html#recipes
from itertools import islice
from igrouper import igrouper
test = []
for batch in list(igrouper(range(24), 5)):
test.append(list(batch))
assert test == [[], [], [], [], []]
@kouk
kouk / wale-delete-backups.sh
Last active June 12, 2019 17:29
wale-delete-backups.sh
#!/bin/sh -e
# cf. https://github.com/wal-e/wal-e/issues/206
cutoff=`date -u -d '1 month ago' +%s`
latest=`date -u +%s`
wal-e --terse backup-list | tail -n +2 | {
# find the oldest backup after the cutoff date
while IFS= read -r line; do
last_modified_date=`echo $line|awk '{print $2}'`
last_modified=`date -u -d "$last_modified_date" +%s`
if [ $last_modified -gt $cutoff -a $last_modified -lt $latest ]; then
2018/09/25 14:14:32 [INFO] Terraform version: 0.11.7 41e50bd32a8825a84535e353c3674af8ce799161
2018/09/25 14:14:32 [INFO] Go runtime version: go1.10.1
2018/09/25 14:14:32 [INFO] CLI args: []string{"/bin/terraform", "apply"}
2018/09/25 14:14:32 [DEBUG] Attempting to open CLI config file: /home/ansible/.terraformrc
2018/09/25 14:14:32 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2018/09/25 14:14:32 [INFO] CLI command args: []string{"apply"}
2018/09/25 14:14:32 [INFO] command: empty terraform config, returning nil
2018/09/25 14:14:32 [DEBUG] command: no data state file found for backend config
2018/09/25 14:14:32 [DEBUG] New state was assigned lineage "2adf3ae4-aa99-0739-0027-8b17ae7c3762"
2018/09/25 14:14:32 [INFO] command: backend initialized: <nil>
@kouk
kouk / Dockerfile
Created April 11, 2019 08:47
Run google meet in chrome via docker with user namespace
FROM jess/chrome
USER root
# Add chrome user
RUN groupadd -r -g 1001 kouk && useradd -r -g kouk -u 1001 -G audio,video kouk \
&& mkdir -p /home/kouk/Downloads && chown -R kouk:kouk /home/kouk
USER kouk
@kouk
kouk / tfexec.sh
Created April 22, 2019 15:11
tfexec.sh
#!/bin/sh
NAME=$(basename $0)
PROFILE=${NAME#tf}
export TERRAGRUNT_DOWNLOAD=.terragrunt-cache-$PROFILE
exec env -u TF_DATA_DIR aws-vault exec $PROFILE -- "$@"
---
kind: DaemonSet
apiVersion: extensions/v1beta1
metadata:
name: whoami-daemonset
labels:
k8s-app: whoami
spec:
template:
metadata:
@kouk
kouk / sshuttle-over-k8s.sh
Last active December 22, 2022 15:04
Route traffic via a k8s cluster, using sshuttle
#!/bin/sh
HOST_PORT=30022
DRYRUN=
if [ "$1" = "-n" ] ; then
DRYRUN=true
shift
fi
TARGET=$1
import io
import boto3
import datetime
from zipfile import ZipFile
from dateutil.tz import tzutc
from botocore.config import Config
outfile = sys.argv[1]