Skip to content

Instantly share code, notes, and snippets.

View sandcastle's full-sized avatar
🍦

Glenn Morton sandcastle

🍦
View GitHub Profile
@sandcastle
sandcastle / time_histogram.sql
Last active December 8, 2020 22:42
Time histogram helper function
View time_histogram.sql
CREATE OR REPLACE FUNCTION time_histogram(
start_time timestamp,
end_time timestamp
)
RETURNS TABLE(bucket timestamp) AS $$
DECLARE diff_hours int;
BEGIN
diff_hours = abs(extract(epoch from end_time - start_time) / 3600)
raise notice 'diff hours: ', diff_hours;
@sandcastle
sandcastle / posgres_size.sql
Created November 8, 2020 21:34
Postgres table sizes
View posgres_size.sql
WITH RECURSIVE pg_inherit(inhrelid, inhparent) AS
(select inhrelid, inhparent
FROM pg_inherits
UNION
SELECT child.inhrelid, parent.inhparent
FROM pg_inherit child, pg_inherits parent
WHERE child.inhparent = parent.inhrelid),
pg_inherit_short AS (SELECT * FROM pg_inherit WHERE inhparent NOT IN (SELECT inhrelid FROM pg_inherit))
SELECT table_schema
, TABLE_NAME
@sandcastle
sandcastle / IsLoopbackOrPrivate.cs
Created April 21, 2020 07:49
Check if loop back is private network or a loopback address...
View IsLoopbackOrPrivate.cs
static bool IsLoopbackOrPrivate([NotNull] IPAddress clientIp)
{
// RFC for private networks:
// http://www.faqs.org/rfcs/rfc1918.html
byte[] bytes = clientIp.GetAddressBytes();
switch(bytes[0])
{
case 10:
return true;
@sandcastle
sandcastle / animals.txt
Last active December 18, 2019 03:08
Animal and colour names for randomly generating anonymous names for users.
View animals.txt
Alligator
Anteater
Armadillo
Axolotl
Badger
Bat
Beaver
Buffalo
Camel
Capybara
@sandcastle
sandcastle / name_blacklist.txt
Last active December 18, 2019 02:19
A blacklist of names and words that can be used for user registrations
View name_blacklist.txt
airhead
allah
altar
anal
anus
aryan
ass
ass lick
asshole
asshole cleaner
@sandcastle
sandcastle / pi-mount.sh
Last active March 4, 2023 21:05
Mount HFS+ USB Drive on a Raspberry Pi
View pi-mount.sh
sudo apt-get update
sudo apt-get upgrade -y
# install hfs tools (for macos extended journaled)
sudo apt-get install hfsplus hfsutils hfsprogs
sudo reboot
# get device id
df -h
# example:
@sandcastle
sandcastle / Dockerfile
Created October 21, 2019 12:18
Install .Net 3.0 diagnostic tools in a docker container
View Dockerfile
# https://github.com/dotnet/diagnostics/issues/573#issuecomment-543886037
# dotnet tools are currently available as part of SDK so we need to create them in an sdk image
# and copy them to our final runtime image
FROM mcr.microsoft.com/dotnet/core/sdk:3.0 AS tools-install
RUN dotnet tool install --tool-path /dotnetcore-tools dotnet-sos
RUN dotnet tool install --tool-path /dotnetcore-tools dotnet-trace
RUN dotnet tool install --tool-path /dotnetcore-tools dotnet-dump
RUN dotnet tool install --tool-path /dotnetcore-tools dotnet-counters
@sandcastle
sandcastle / postgres_version.sql
Created September 16, 2019 06:40
Determine the version of postgres a statement is run on.
View postgres_version.sql
select version();
-- PostgreSQL 9.6.12 on x86_64-pc-linux-musl, compiled by gcc (Alpine 8.2.0) 8.2.0, 64-bit
SHOW server_version;
-- 9.6.12
SELECT current_setting('server_version_num');
-- 90612
select current_setting('server_version');
@sandcastle
sandcastle / text_replace.sh
Created August 3, 2018 14:07
Replace text function for shell
View text_replace.sh
function text_replace() {
case "${OSTYPE}" in
darwin*) PLATFORM="OSX" ;;
linux*) PLATFORM="LINUX" ;;
bsd*) PLATFORM="BSD" ;;
*) PLATFORM="UNKNOWN" ;;
esac
if [[ "${PLATFORM}" == "OSX" || "${PLATFORM}" == "BSD" ]]; then
find $1 -type f -name $2 -exec sed -i "" "s/$3/$4/g" {} +
@sandcastle
sandcastle / kubetool.sh
Created July 28, 2018 10:28
A lightweight (no deps) kubectl wrapper for working with contexts and namespaces, heavily inspired by kubectx
View kubetool.sh
#!/bin/sh
[[ -n $DEBUG ]] && set -x
set -eou pipefail
usage() {
cat <<"EOF"
USAGE:
kubetool : show this message
kubetool ctx get : gets the current context