Skip to content

Instantly share code, notes, and snippets.

View jweyrich's full-sized avatar
:octocat:
Making some lives easier and happier!

Jardel Weyrich jweyrich

:octocat:
Making some lives easier and happier!
View GitHub Profile
@jweyrich
jweyrich / aws-dotenv-update.py
Last active October 16, 2024 14:58
Update a dotenv file with AWS credentials directly from aws-vault
#!/usr/bin/env python3
#
# AUTHOR: Jardel Weyrich <jweyrich at gmail dot com>
#
import argparse
import os
import subprocess
DEFAULT_DOTENV_FILE = '.env.dev'
DEFAULT_PROFILE = 'default'
@jweyrich
jweyrich / pgsql_performance.sql
Created July 8, 2020 14:04
PostgreSQL performance troubleshooting
psql -h <host> -U <user> -W -d postgres
SELECT * from pg_stat_activity;
SELECT * from pg_stat_database;
# Queries running during >5 minutes
SELECT
pid,
datname,
query,
@jweyrich
jweyrich / buildspec.yml
Last active June 28, 2024 05:56
Sample of buildspec.yml for AWS CodeBuild that builds a Docker image from code and push it to ECR to be deployed via CodePipeline
# Change the following to your desired values:
# __ACCOUNT_NUMBER__
# __ECR_REGION__
# __ECR_REPOSITORY_NAME__
# __ECS_CONTAINER_NAME__
version: 0.2
phases:
install:
runtime-versions:
@jweyrich
jweyrich / haproxy.cfg
Last active June 23, 2024 04:07
HAproxy forwarding to https backend
#
# This is just a snippet of HAProxy config.
# Please replace ENTRY_DOMAIN_HERE and TARGET_DOMAIN_HERE accordingly.
#
frontend front_http
log global
bind :80
use_backend back_target if { hdr(host) -i ENTRY_DOMAIN_HERE }
default_backend back_healthcheck
@jweyrich
jweyrich / aws_alb_log_parser.py
Last active June 11, 2024 14:39
AWS ALB Log Parser written in Python
#!/usr/bin/env python3
# coding=utf8
#
# AUTHOR: Jardel Weyrich <jweyrich at gmail dot com>
#
from __future__ import print_function
import re, sys
def parse_alb_log_file(file_path):
fields = [
@jweyrich
jweyrich / azure_sql_find_circular_ref_paths.sql
Created November 14, 2017 14:31
Azure SQL - Find circular reference paths
--
-- Script originally from https://azure.microsoft.com/en-gb/blog/finding-circular-foreign-key-references/
--
SET NOCOUNT ON
-- WWB: Create a Temp Table Of All Relationship To Improve Overall Performance
CREATE TABLE #TableRelationships (
FK_Schema nvarchar(max),
FK_Table nvarchar(max),
@jweyrich
jweyrich / mssql_query_stats.sql
Last active May 16, 2023 09:41
SQL Server query stats & average execution time
SELECT *
FROM sys.dm_exec_requests
CROSS APPLY sys.dm_exec_sql_text(sql_handle);
SELECT TOP 30
creation_time
, last_execution_time
, total_physical_reads
, total_logical_reads
@jweyrich
jweyrich / jest.config.js
Last active February 4, 2023 00:57
Example of Jest config with support for Path Mapping
const { pathsToModuleNameMapper } = require('ts-jest/utils');
// In the following statement, replace `./tsconfig` with the path to your `tsconfig` file
// which contains the path mapping (ie the `compilerOptions.paths` option):
const { compilerOptions } = require('./tsconfig');
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/tst/**/*.test.ts'],
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' }),
@jweyrich
jweyrich / dotenv-exec
Last active December 26, 2022 16:30
Load environment variables from a dotenv file before running an executable
#!/bin/sh
#
# Load environment variables from a dotenv file before running an executable
# Usage: dotenv-exec <.env> <executable> [executable-parameters]
#
usage() {
echo "Usage: $(basename "$0") <.env> <executable> [executable-parameters]" 1>&2
exit 1
@jweyrich
jweyrich / interval_string_to_seconds.py
Last active August 12, 2022 13:56
Python function to convert an interval string to seconds
#
# Author: Jardel Weyrich <jweyrich at gmail dot com>
#
import re
def interval_string_to_seconds(input: str) -> int:
SUFFIX_MAP = {
'y': 'y',
'year': 'y',