Skip to content

Instantly share code, notes, and snippets.

View rsperl's full-sized avatar

Richard rsperl

  • North Carolina, United States
View GitHub Profile
@rsperl
rsperl / dns-flush-cache.sh
Last active July 25, 2022 16:01
flush the DNS cache on mac #shell #macos #snippet
#!/bin/sh
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
@rsperl
rsperl / todo.sh
Last active July 25, 2022 13:30
find todo/hack/fixme/bug comments #snippet
#!/bin/sh
# TODO - this is here for testing
if [ -z "$VSCODE_PID" ] ; then
ag -i '#\s*todo|#\s*hack|#\s*fixme' 2>/dev/null
else
ag --vimgrep -i '#\s*todo|#\s*hack|#\s*fixme' 2>/dev/null
fi
@rsperl
rsperl / update_iterm2_profiles.py
Last active July 25, 2022 13:11
update iterm2 dynamic profiles from ssh config #snippet
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import json
class SshConfigParser(object):
entries = []
@rsperl
rsperl / ConditionalVariableTemplates.md
Last active July 25, 2022 13:27
conditional variable includes #ansible #snippet

Variable Templates

Variables in defaults/ cannot be conditionally included. Instead place variable files in vars/filename.yml for conditional including. For example, given

% tree roles/testvars
.
├── defaults/
├── tasks/
│   └── main.yml

└── vars/

@rsperl
rsperl / database_size.sql
Last active July 25, 2022 14:04
find the size of mysql databases #snippet
SELECT
table_schema `Database`,
SUM( data_length + index_length ) / 1024 / 1024 AS SizeMB,
SUM( data_free )/ 1024 / 1024 AS FreeSpaceMB
FROM information_schema.TABLES
GROUP BY table_schema
@rsperl
rsperl / no_primary_key.sql
Last active July 25, 2022 14:13
find mysql tables without a primary key #nosnippet
SELECT DISTINCT(CONCAT(table_schema, '.', table_name)) t FROM information_schema.`COLUMNS`
WHERE
-- excluding these databases
table_schema NOT IN ('db1', 'mysql', 'db2', 'db3') AND
-- excluding views
CONCAT(table_schema, '.', table_name) NOT IN (SELECT DISTINCT(CONCAT(table_schema, '.', table_name)) t FROM information_schema.`VIEWS`) AND
@rsperl
rsperl / find_myisam.sql
Last active July 25, 2022 14:19
find myisam tables in mysql #snippet
SELECT
CONCAT(TABLE_SCHEMA, '.', TABLE_NAME) t FROM information_schema.`TABLES`
WHERE
ENGINE='MyISAM'
AND table_schema NOT IN ('information_schema', 'mysql')
ORDER BY t
@rsperl
rsperl / table_doc.sql
Last active July 25, 2022 15:59
use comments to show table and column documentation #mysql #snippet
-- table documentation
SELECT t.TABLE_SCHEMA, t.TABLE_NAME, t.TABLE_COMMENT
FROM TABLES t
WHERE t.TABLE_SCHEMA not in ('information_schema', 'mysql')
ORDER BY t.TABLE_SCHEMA, t.TABLE_NAME;
-- column documentation
SELECT c.TABLE_SCHEMA, c.TABLE_NAME, c.COLUMN_NAME, c.COLUMN_DEFAULT, c.COLUMN_TYPE, c.COLUMN_COMMENT
@rsperl
rsperl / sqlite_log.pl
Last active July 25, 2022 15:59
use log4perl to log to a sqlite database #perl #logging #snippet
#!/usr/bin/env perl
use strict;
use Log::Log4perl qw(get_logger);
use Data::Dumper;
use Data::Printer;
my $log_config = q{
# log4perl.category = TRACE, DB
log4perl.logger = TRACE, DB
@rsperl
rsperl / structured_log.pl
Last active July 25, 2022 15:59
use log4perl to generate structured logs #perl #logging #snippet
#!/usr/bin/env perl
use strict;
use Log::Log4perl qw(get_logger);
my $log_config =<<EOF;
log4perl.rootLogger = TRACE, Test
log4perl.appender.Test = Log::Log4perl::Appender::File
log4perl.appender.Test.filename = logfile.json