Skip to content

Instantly share code, notes, and snippets.

View kouk's full-sized avatar

Konstantinos Koukopoulos kouk

View GitHub Profile
import sys
import os
import gspread
from google.oauth2 import service_account
def get_gspread_client() -> gspread.Client:
scope = ["https://www.googleapis.com/auth/drive", "https://www.googleapis.com/auth/spreadsheets"]
# see https://docs.gspread.org/en/latest/oauth2.html
credentials_path = os.environ.get('GOOGLE_SERVICE_ACCOUNT_CREDENTIALS', None)
import airflow
import getpass
import logging
from airflow import models, settings
from airflow.contrib.auth.backends.password_auth import PasswordUser
def set_password(name, password):
session = settings.Session()
u = session.query(PasswordUser).filter_by(username=name).first()
@kouk
kouk / Dockerfile
Created March 17, 2021 14:06
Build mozilla/sops@develop with docker
FROM golang:1.15 AS build
WORKDIR /build
RUN go mod init example.com/sops-build \
&& go get -u go.mozilla.org/sops/v3/cmd/sops@develop
RUN go get -u filippo.io/age/cmd/...
FROM scratch AS bin
COPY --from=build /go/bin/sops /
@kouk
kouk / group-by-ip.sql
Last active November 17, 2020 07:53 — forked from bennadel/group-by-ip.sql
Grouping The MySQL PROCESSLIST By IP Address To View Connection Counts
SELECT
tmp.ipAddress,
-- Calculate how many connections are being held by this IP address.
COUNT( * ) AS ipAddressCount,
-- For each connection, the TIME column represent how many SECONDS it has been in
-- its current state. Running some aggregates will give us a fuzzy picture of what
-- the connections from this IP address is doing.
FLOOR( AVG( tmp.time ) ) AS timeAVG,
SET @COLS = '';
SELECT GROUP_CONCAT( COLUMN_NAME SEPARATOR ',')
INTO @COLS
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_KEY != 'PRI'
AND TABLE_NAME='mytable'
AND TABLE_SCHEMA = 'mydatabase';
SET @SQL = CONCAT('SELECT ', @COLS, ' FROM mytable');
PREPARE stmt FROM @SQL;
EXECUTE stmt;
#!/usr/bin/env bash
# Inspired by: https://github.com/kayrus/kuttle
# Usage:
#
# sshuttle -v -r 'none' -e /path/to/this_script 172.20.0.0/16
#
set -e
VERSION=0.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]
@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
---
kind: DaemonSet
apiVersion: extensions/v1beta1
metadata:
name: whoami-daemonset
labels:
k8s-app: whoami
spec:
template:
metadata:
@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 -- "$@"