Skip to content

Instantly share code, notes, and snippets.

@mohanpedala
mohanpedala / bash_strict_mode.md
Last active Sep 25, 2021
set -e, -u, -o, -x pipefail explanation
View bash_strict_mode.md

set -e, -u, -x, -o pipefail

The set lines

  • These lines deliberately cause your script to fail. Wait, what? Believe me, this is a good thing.
  • With these settings, certain common errors will cause the script to immediately fail, explicitly and loudly. Otherwise, you can get hidden bugs that are discovered only when they blow up in production.
  • set -euxo pipefail is short for:
set -e
set -u
View cleanup-docker.sh
#!/bin/bash
# remove exited containers:
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi
# remove unused volumes:
find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <(
@dkrnl
dkrnl / gist:95f9d1809368c3c3a07b
Last active Mar 2, 2020
Mysql Optimize Table InnoDB
View gist:95f9d1809368c3c3a07b
#!/usr/bin/env php
<?php
$server = "localhost";
$username = "***";
$password = "****";
$connection = mysql_connect($server, $username, $password);
if (!$connection) {
die("Connection error: " . mysql_error());
@jlong
jlong / uri.js
Created Apr 20, 2012
URI Parsing with Javascript
View uri.js
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"