Skip to content

Instantly share code, notes, and snippets.

View dmgig's full-sized avatar
🏠

Dave M. Giglio dmgig

🏠
View GitHub Profile
@dmgig
dmgig / log_monitor.sh
Created January 14, 2015 14:35
Log monitor. Sums requests by hour. Auto-refresh view each second.
#!/bin/bash
# Log monitor. Sums requests by hour. Auto-refresh view each second.
while :
do
TODAY=$(date +"%b %d")
awk -F: -v t="$TODAY" '$0~t {h[$1]++;m[$1":"$2]++;}END{for(x in h)print x,h[x];'} /var/log/requests.log | sort > /tmp/requests_view.tmp
clear
echo "Requests Pace for"
@dmgig
dmgig / count_matching_rows
Created January 14, 2015 14:47
awk: count matching rows in log file
awk '/Sep 07/ {total += 1} END {print "total requests = " total}' /var/log/requests.log
@dmgig
dmgig / unique_column_values
Last active August 29, 2015 14:13
awk: show unique column values
cat /var/log/requests.log | awk ' { print $4 } ' | sort | uniq
@dmgig
dmgig / color_awk
Last active August 29, 2015 14:13
awk: colorize output
tail -n 5000 -f /var/log/requests.log | awk '
/FAIL$/ {print "\033[30m" $0 "\033[0m"} # black
/(\/delete.php)/ {print "\033[31m" $0 "\033[0m"} # red
/(\/move.php)/ {print "\033[32m" $0 "\033[0m"} # green
/(\/request.php)/ {print "\033[33m" $0 "\033[0m"} # yellow
/(\/change.php)/ {print "\033[34m" $0 "\033[0m"} # blue
/(\/part.php)/ {print "\033[35m" $0 "\033[0m"} # magenta
/(\/process.php)/ {print "\033[36m" $0 "\033[0m"} # cyan
/NO AFFECTED ROWS$/ {print "\033[37m" $0 "\033[0m"}' # white
@dmgig
dmgig / pt-heartbeat
Created January 14, 2015 20:48
Percona pt-heartbeat sample
PTDEBUG=1 pt-heartbeat --host="mysql-b" --user=root --ask-pass --database="percona" --monitor --master-server-id="14" --frames=1m,5m,15m,1h,12h,1d
@dmgig
dmgig / pt-table-checksum-sample
Created January 15, 2015 15:26
Percona pt-table-checksum samples
# whole table check
pt-table-checksum --databases=world --tables=city --user=root --ask-pass --no-check-binlog-format
# with a parameter for smaller samples
pt-table-checksum --databases=world --tables=city --where="name LIKE '%a%'" --user=root --ask-pass --no-check-binlog-format
@dmgig
dmgig / mysql-momentary-general-log.sql
Last active August 29, 2015 14:14
mysql: momentarily enable general log file / table
# mysql: momentarily enable, then view, general log table
SET GLOBAL log_output = 'TABLE';
SET GLOBAL general_log = 'ON';
SELECT SLEEP(5);
SET GLOBAL general_log = 'OFF';
SELECT * FROM mysql.general_log;
######
@dmgig
dmgig / autosave-form.js
Last active August 29, 2015 14:14
Auto-saving Form (jQuery required)
/**
* editBox
* auto-updating form, with reset/resave
* @author D.M. Giglio
*/
(function(window, document, $){
'use strict';
$(document).ready(function(){
@dmgig
dmgig / table_tab_import.sh
Last active February 11, 2016 21:56
MySQL: Import tables & data from sql and tab delimited dumps
#! /bin/bash
# Note: This script disables foreign key checks and ignores all errors!
DUMPDIR='/tmp/mysql_dumps/'
USERNAME='root'
PASSWORD='MyP@55'
DATABASE='databaseName'
@dmgig
dmgig / matrix_math.html
Created February 18, 2016 21:26
Matrix Math QUnit Tests
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>QUnit Matrix Tests</title>
<link rel="stylesheet" href="//code.jquery.com/qunit/qunit-1.19.0.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>