Skip to content

Instantly share code, notes, and snippets.

@chriha
chriha / iterm2.zsh
Created August 25, 2021 07:13
Colorize tabs according to environment
# Usage:
# source iterm2.zsh
# iTerm2 tab color commands
# https://iterm2.com/documentation-escape-codes.html
if [[ -n "$ITERM_SESSION_ID" ]]; then
tab-color() {
echo -ne "\033]6;1;bg;red;brightness;$1\a"
echo -ne "\033]6;1;bg;green;brightness;$2\a"
@chriha
chriha / resize_ec2_storage.md
Created September 23, 2020 07:42
Resize EC2 storage

copied from https://stackoverflow.com/a/42800989/10760563

Before resizing the filesystem by "resize2fs" command you should first resize your partition:

let's list block devices attached to our box:

lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 16G 0 disk
@chriha
chriha / createcertfilesfrompfx.sh
Created August 19, 2020 15:17 — forked from refo/createcertfilesfrompfx.sh
Create nginx cert files (pem, key) from pfx
#!/bin/bash
# Source:
# https://gist.github.com/ericharth/8334664
#
# Thanks:
# https://github.com/anderssonjohan
#
# Usage:
# ./createcertfilesfrompfx.sh /path/to/domain.pfx
#
socat - UDP4-DATAGRAM:192.168.30.255:61111,bind=:61111,ip-add-membership=192.168.30.255:eth0
socat - UDP4-DATAGRAM:192.168.30.0:61111,sp=61111,broadcast,range=192.168.30.0/24
ncat -i 5 -m 1 -u -l 0.0.0.0 61111 2> /dev/null
ncat -v -u -l 0.0.0.0 61111
echo '{ "fubar": true, "test": "lorem ipsum" }' | ncat -v --send-only -u 192.168.30.255 61111
nc -uklvv -w 1 0.0.0.0 61111
@chriha
chriha / asymmetric_encryption.php
Last active April 5, 2019 13:56
Asymmetric Encryption - encrypt data via public and decrypt via private key
<?php
/**
* Create private key:
* $ openssl genrsa -out private.key 2048
*
* Create public key:
* $ openssl rsa -in private.key -outform PEM -pubout -out public.pem
*/
@chriha
chriha / next_tag_by_version_constraint.sh
Created April 2, 2018 19:21
Get next version tag of a Git repo considering a version constraint
#!/usr/bin/env bash
# # # # # # # # # # # # # # # # # # # #
# Compare two versions
# https://stackoverflow.com/a/4025065
#
# Arguments:
# VERSION_1
# VERSION_2
# Returns:
@chriha
chriha / spinner.sh
Created April 11, 2017 10:33
bash spinner
#!/usr/bin/env bash
spinner() {
local cl="\r\033[K"
local pid=$1
local spinnging=true
local delay=0.05
local spinstr="⠏⠛⠹⠼⠶⠧"
printf " "
@chriha
chriha / output.sh
Created April 6, 2017 08:18
Formatting the output of a bash script
#!/usr/bin/env bash
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
CLEAR="\r\033[K"
@chriha
chriha / default.conf
Last active October 19, 2017 09:24
nginx config, force SSL
# force https
server {
listen 80;
server_tokens off;
server_name domain.com www.domain.com;
location / {
return 301 https://www.domain.com$request_uri;
}
}
@chriha
chriha / show_osx_notification.sh
Created January 30, 2017 11:20
Show OSX notification via bash script / terminal
#!/usr/bin/env bash
# http://apple.stackexchange.com/questions/57412/how-can-i-trigger-a-notification-center-notification-from-an-applescript-or-shel
if [ "$(uname)" == "Darwin" ]; then
osascript -e 'display notification "This is the description" with title "This is the title" sound name "Sound Name"
fi