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 / AppServiceProvider.php
Created December 16, 2020 12:40 — forked from simonhamp/AppServiceProvider.php
A pageable Collection implementation for Laravel
<?php
namespace App\Providers;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
class AppServiceProvider extends ServiceProvider
{
public function boot()
@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
#
@chriha
chriha / create_file.sh
Created September 23, 2019 08:30
Create large file to allow higher baseline throughput when using bursting for AWS EFS
# To get better performance out of EFS, you may consider increasing the size of
# your filesystem by adding dummy data onto it. You can create dummy data using
# the command below to create a 256 GB file called "large_file":
sudo dd if=/dev/urandom of=large_file bs=1024k count=256000 status=progress
# A larger EFS fielsystem will result in a higher baseline throughput and you
# will be able to burst for longer periods. In the example above where we have
# an EFS with +256 GB, the baseline throughput will be 12.5 MiB/s and you can
# burst for 360 minutes per day as opposed to a 1GiB EFS which has a baseline
# of 50 KiB/s and can only burst for about 1 minute. However, the tradeoff
@chriha
chriha / create_large_file.sh
Created August 12, 2019 09:15
Create a large file to increase throughput for EFS bursting mode
# create a large file to increase throughput for EFS bursting mode
dd if=/dev/urandom of=large_file bs=1024k count=256000 status=progress
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 " "