Skip to content

Instantly share code, notes, and snippets.

@sathed
sathed / zsh
Created February 20, 2020 22:00
Git branch in (zsh) terminal on Mac.
function parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
COLOR_DEF=$'\e[0m'
COLOR_USR=$'\e[38;5;243m'
COLOR_DIR=$'\e[38;5;197m'
COLOR_GIT=$'\e[38;5;39m'
setopt PROMPT_SUBST
export PROMPT='${COLOR_USR}%n ${COLOR_DIR}%~ ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF} $ '
@sathed
sathed / skeleton.sh
Last active February 20, 2020 15:25
Skeleton shell script
#!/usr/bin/bash
# Clone
# Build
# Deploy
# Notes:
# # Save the shell script with a '.sh' extension
@sathed
sathed / .nanorc
Created November 21, 2019 16:11
My nanorc file.
set linenumbers
set tabsize 4
set autoindent
set tabstospaces
@sathed
sathed / aws_cli_filters
Created November 8, 2019 20:19
AWS CLI filters using tags
# Usage: --filters "Name=string,Values=string,string..."
# Example using `tag` key-value pairs:
aws ec2 describe-instances --filters "Name=tag:<tag_name>,Values=<value1>,<value2>..."
# Example using `tag-key` name:
# Note: This only looks at the key name(s), not the value of the key(s).
aws ec2 describe-instances --filters "Name=tag-key,Values=<tag-key1>,<tag-key2>..."
@sathed
sathed / curl_status_code.sh
Last active October 29, 2019 20:19
Use curl to retrieve only the status code.
#!/bin/bash
# For CA certs.
curl -so /dev/null -w "%{http_code}" https://google.com/
# For self-signed certs:
curl --insecure -so /dev/null -w "%{http_code}" https://somesite.com/
@sathed
sathed / git_revert.txt
Created October 24, 2019 16:49
Revert commits on published branches
# Range of commits
# git revert --no-edit <first_bad_commit_hash>..<last_bad_commit_hash>
git revert --no-edit 1abeb478e11..e272b5a3680
# Single commit
# git revert --no-edit <bad_commit_hash>
git refert --no-edit e272b5a3680
@sathed
sathed / promql_dst_offset
Last active October 4, 2019 15:36
Timezone Offset for Prometheus (Mountain Time/US)
# The following will create an DST offset in the US. Obviously, if you're in an area that doesn't
# observe DST (Arizona, etc.), this doesn't apply. To tweak it for your specific TZ, change the last value to
# your UTC offset during the summer months. A chart is below. I threw this together pretty quick,
# so it may need a bit of tweaking. It's a modified version of the PromQL found on Medium, here:
# https://link.medium.com/vcfRGNuYv0
# 4 - Eastern
# 5 - Central
# 6 - Mountain
# 7 - Pacific
# Use root/example as user/password credentials
version: '3.1'
services:
mongo:
image: mongo
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
@sathed
sathed / process_status.ps1
Last active September 6, 2018 19:19
Get the state of a Windows process.
#Using Notepad as an example.
$target = "notepad"
#Get the process
$process = Get-Process -Name $target -ErrorAction SilentlyContinue
#Get the execution state of the thread.
$threads=$process.Threads
$threads | select Id,ThreadState,WaitReason
@sathed
sathed / postgres_fdw.sql
Created October 25, 2017 21:48
postgres_fdw example
/***** "Remote" server first *****/
-- Note: Unless the object you are trying to gain access to is in the same DATABASE, it's a remote datebase. Even if it's
-- on the same node!
-- 1. create the role and assign it a password. Note: CREATE USER is an alias for CREATE ROLE. Either one is fine
CREATE ROLE new_user WITH PASSWORD 'somepassword';
-- 2. Grant the required permissions. This grants select, insert, update, and delete on all tables in the public schema.
-- I also gave execute to all functions in the public schema as well.
GRANT SELECT, INSERT, UPDATE, DELETE ON ALL TABLES IN SCHEMA public TO new_user;
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO new_user;