Skip to content

Instantly share code, notes, and snippets.

@ffeast
ffeast / mysql_tcpdump.sh
Last active March 8, 2022 09:04
Mysql traffic tcpdump one-liner
# a handy one-liner to print out sql queries if you wouldn't like to enable
# queries logging in mysql server itself
tcpdump -i lo -s 0 -l -w - dst port 3306 | strings | perl -e '
while(<>) { chomp; next if /^[^ ]+[ ]*$/;
if(/^(SELECT|UPDATE|DELETE|INSERT|SET|COMMIT|ROLLBACK|CREATE|DROP|ALTER)/i) {
if (defined $q) { print "$q\n\n"; }
$q=$_;
} else {
$_ =~ s/^[ \t]+//; $q.=" $_";
}
@ffeast
ffeast / gist:43dd512532d0ea1b8434faea89c6eb16
Created June 16, 2019 16:43
redis-benchmark 1M zset operations
redis-benchmark -n 1000000 -r 1000000 -q -P 32 zadd zset __rand_int__ __rand_int__
@ffeast
ffeast / pgsql_kill_connections.sql
Created December 27, 2017 08:00
Postgresql kill connections
# https://stackoverflow.com/questions/5108876/kill-a-postgresql-session-connection
SELECT
pg_terminate_backend(pid)
FROM
pg_stat_activity
WHERE
-- don't kill my own connection!
pid <> pg_backend_pid()
-- don't kill the connections to other databases
AND datname = 'database_name'
@ffeast
ffeast / certgen.sh
Created November 2, 2017 19:59
ssl certificates generation one-liner
# https://stackoverflow.com/questions/10175812/how-to-create-a-self-signed-certificate-with-openssl
openssl req -x509 -nodes -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
@ffeast
ffeast / tracelog.py
Created October 30, 2017 16:19
Trace logging configuration
import logging
import sys
# Traces what's updating the logging configuration
# https://stackoverflow.com/questions/28694540/python-default-logger-disabled
def get_disabled(self):
return self._disabled
def set_disabled(self, disabled):
nginx version: nginx/1.4.6 (Ubuntu)
# 1. passwords
both password are ‘123’ passed through openssl passwd
# cat /etc/nginx/default.htpasswd
# default:ZE3exsFczUZUY
# cat /etc/nginx/test.htpasswd
# test:ZE3exsFczUZUY
@ffeast
ffeast / gist:3ac219d8488fe15c41cd6002f1722d14
Created August 17, 2017 12:38
suds.sudsobject usage example
from suds.sudsobject import Object as SudsObject
obj = SudsObject()
obj.Title = "My title"
obj.JustAList = [1, 2, 3]
obj.Child = SudsObject()
obj.Child.Title = "Child title"
obj.Child.AnotherList = ["4", "5", "6"]
child_obj = SudsObject()
@ffeast
ffeast / gist:9781d730fc4dda63361d0060ad2b12cd
Created July 12, 2017 16:29
json pretty-print 1-liner
echo '{"json":"obj"}' | python -m json.tool
@ffeast
ffeast / mysql_kill_queries.sql
Created February 11, 2016 10:25
Mysql kill queries
/* run \. /tmp/mysql_victims.txt after executing this query */
SELECT
concat('KILL ', id, ';')
FROM
information_schema.processlist
WHERE
user='victim' AND time > 60
INTO OUTFILE '/tmp/mysql_victims.txt';
@ffeast
ffeast / ip.py
Last active August 6, 2016 07:14
ansible_1x_ns_lookup plugin
# borrowed from http://stackoverflow.com/questions/32324120/arbitrary-host-name-resolution-in-ansible
# might be used as {{ lookup('ip', 'www.google.com') }}
import socket
import ansible.errors as errors
class LookupModule(object):
def __init__(self, basedir=None, **kwargs):
self.basedir = basedir