Skip to content

Instantly share code, notes, and snippets.

View mintsoft's full-sized avatar
💭
Probably alive.

Rob Emery mintsoft

💭
Probably alive.
  • UK
View GitHub Profile
@mintsoft
mintsoft / change_db_owner.sh
Last active December 16, 2015 21:49 — forked from gingerlime/change_db_owner.sh
Changes the owner on all the tables in a database with support for tables with whitespace and schemata
#!/bin/bash
usage()
{
cat << EOF
usage: $0 options
This script set ownership for all table, sequence and views for a given database
Credit: Based on http://stackoverflow.com/a/2686185/305019 by Alex Soto
@mintsoft
mintsoft / convert_pfx_to_pem.sh
Last active October 24, 2016 07:21
Wrapper around openssl for converting pkcs12 certificates exported out of IIS into unencrypted x509 for Apache
#!/bin/bash
[[ -z "$1" ]] && echo "Please specify a .pfx file!" && exit 1;
#combined format:
openssl pkcs12 -in "$1" -out "${1%.pfx}.key_cert.pem" -nodes
#extract certificate/public key
openssl x509 -in "${1%.pfx}.key_cert.pem" -out "${1%.pfx}.cert"
@mintsoft
mintsoft / verify_pem_cert_key_pair.sh
Created May 11, 2013 20:07
Wrapper around openssl to verify the certificate and key files match
#!/bin/bash
[[ -z "$1" || -z "$2" ]] && echo "Please specify a certificate and keyfile (in that order)" && exit 1;
diff -sq <(openssl x509 -noout -modulus -in "$1" | openssl md5) <(openssl rsa -noout -modulus -in "$2" | openssl md5) > /dev/null;
[[ $? == 0 ]] && echo "Keys Match" || echo "Keys do NOT Match";
@mintsoft
mintsoft / 99_fix_suggests
Created May 12, 2013 20:10
Fix ridiculous "lets install everything possible" settings in Ubuntu
APT
{
Install-Recommends "false";
Install-Suggests "false";
}
@mintsoft
mintsoft / swapfiles
Created May 13, 2013 13:28
Swap two files on disk
#!/bin/bash
if [[ ! -e "$1" ]] || [[ ! -e "$2" ]]; then
echo -e "Please specify files that exist:";
echo -e "\tFor example: $0 fileOne fileTwo\n";
exit 1;
fi
echo "Swapping Files: $1 $2";
mv "$1" ".tmp.$1";
@mintsoft
mintsoft / repeat_psql.pl
Created May 19, 2013 22:01
Pipe a command into psql within a loop with a heredoc
#!/usr/bin/perl
$svr="localhost";
$dbname="rob";
for $x (1..10) {
open(CMD, " | psql -h $svr $dbname");
print CMD <<END;
BEGIN TRANSACTION;
INSERT INTO insert_log ("when") VALUES(NOW());
@mintsoft
mintsoft / cryptospeed
Last active December 18, 2015 05:09
openSSL Speedtests - stolen from the openwrt wiki
openssl speed md5 sha1 sha256 sha512 des des-ede3 aes-128-cbc aes-192-cbc aes-256-cbc rsa2048 dsa2048
@mintsoft
mintsoft / TSQL_Query.ps1
Created June 14, 2013 10:03
Execute TSQL against a SQL Server from Powershell without SQL Server Management Studio modules installed
$connectionString = "Data Source=cidbsql.cwserverfarm.local;Initial Catalog=workdb;Integrated Security=True;Application Name=PowerSheQL";
$SQL = "SELECT TOP 5 * FROM dbo.RE_Trace;";
$dbc = New-Object System.Data.SqlClient.SqlConnection($connectionString);
$dbc.Open();
$sqlcmd = $dbc.CreateCommand();
$sqlcmd.CommandTimeout = 1;
$sqlcmd.CommandText = $SQL;
$sqlcmd.Prepare();
@mintsoft
mintsoft / analyze_8.4.sh
Created June 17, 2013 14:07
Iterate over tables in public schema and run analyze
#!/bin/bash
db="postgres"
psql -qAt -c "SELECT tablename FROM pg_tables WHERE schemaname='public';" $db | while read line; do
psql -qAt -c "ANALYZE $line;" $db;
done
@mintsoft
mintsoft / captureHTTPTraffic.sh
Created June 24, 2013 15:13
Capture HTTP Traffic on a linux box from the kernel
#!/bin/bash
sudo tcpdump -i eth1 -c 100000 -w $(date '+%F_%H-%M-%S').pcap 'tcp port 80'