Skip to content

Instantly share code, notes, and snippets.

View tsungtwu's full-sized avatar

Tsung Wu tsungtwu

View GitHub Profile
@tsungtwu
tsungtwu / README-setup-tunnel-as-systemd-service.md
Created July 27, 2020 09:43 — forked from drmalex07/README-setup-tunnel-as-systemd-service.md
Setup a secure (SSH) tunnel as a systemd service. #systemd #ssh #ssh-tunnel #ssh-forward

README

Create a template service file at /etc/systemd/system/[email protected]. The template parameter will correspond to the name of target host:

[Unit]
Description=Setup a secure tunnel to %I
After=network.target
@tsungtwu
tsungtwu / postgres_queries_and_commands.sql
Last active December 1, 2020 17:15 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@tsungtwu
tsungtwu / django-grafana-proxy.py
Created September 23, 2020 05:44 — forked from feroda/django-grafana-proxy.py
Django reverse proxy for Grafana SSO
"""
## Install the Django reverse proxy package: `pip install django-revproxy`
## Enable auth.proxy authentication in Grafana like the following
```
[auth.proxy]
enabled = true
header_name = X-WEBAUTH-USER
header_property = username
@tsungtwu
tsungtwu / postgresql-set-id-seq.sql
Created December 27, 2020 02:33 — forked from henriquemenezes/postgresql-set-id-seq.sql
PostgreSQL set Next ID Sequence Value to MAX(id) from Table
-- Get Max ID from table
SELECT MAX(id) FROM table;
-- Get Next ID from table
SELECT nextval('table_id_seq');
-- Set Next ID Value to MAX ID
SELECT setval('table_id_seq', (SELECT MAX(id) FROM table));
@tsungtwu
tsungtwu / monzo-alertmanager-config.yaml
Created February 7, 2021 14:10 — forked from milesbxf/monzo-alertmanager-config.yaml
Monzo's Alertmanager Slack templates
###################################################
##
## Alertmanager YAML configuration for routing.
##
## Will route alerts with a code_owner label to the slack-code-owners receiver
## configured above, but will continue processing them to send to both a
## central Slack channel (slack-monitoring) and PagerDuty receivers
## (pd-warning and pd-critical)
##
@tsungtwu
tsungtwu / prometheus.yml
Created March 2, 2021 18:21 — forked from KekSfabrik/prometheus.yml
prometheus consul SD config
global:
scrape_timeout: 10s
scrape_interval: 15s
external_labels:
cluster: 'MY CLUSTER NAME'
# alternatively can be found via consul -- for details see
# https://prometheus.io/docs/prometheus/latest/migration/#alertmanager-service-discovery
alerting:
alertmanagers:
@tsungtwu
tsungtwu / git-semver.sh
Created March 24, 2021 03:17 — forked from ericbmerritt/git-semver.sh
Shell script for parsing semvers from git-describe
#! /bin/bash
# Assumes that you tag versions with the version number (e.g., "1.1")
# and then the build number is that plus the number of commits since
# the tag (e.g., "1.1.17")
DESCRIBE=`git describe --tags --always`
# increment the build number (ie 115 to 116)
VERSION=`echo $DESCRIBE | awk '{split($0,a,"-"); print a[1]}'`
@tsungtwu
tsungtwu / 2s3.py
Created May 11, 2021 02:31 — forked from andymotta/2s3.py
Watch a directory for changes with Python Watchdog then multipart upload to S3
import sys
import os
import time
from watchdog.observers import Observer
from watchdog.events import FileModifiedEvent, FileCreatedEvent
import boto3
import mimetypes
from botocore.exceptions import ClientError
# Create an S3 client
@tsungtwu
tsungtwu / gitlab-merge-request.sh
Created August 11, 2021 07:49 — forked from bench/gitlab-merge-request.sh
A script to create gitlab MR from a shell
#!/bin/bash
# Check if jq is installed
if ! type "jq" > /dev/null; then
echo please install jq
fi
title="$(git log --oneline | head -1 | cut -f 2- -d ' ')"
source_branch="$(git branch | grep '*' | cut -f 2 -d ' ')"
target_branch=master
import boto3
import re
from urllib.request import urlopen
import logging
# https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/config.html#ConfigService.Client.put_configuration_recorder
# Purpose:
# Activate Custom AWS Record for AWS Config
# Supported resource type: https://docs.aws.amazon.com/config/latest/developerguide/resource-config-reference.html#supported-resources