Skip to content

Instantly share code, notes, and snippets.

@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 / 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
@ffeast
ffeast / mysql_tables_by_column.sh
Created July 18, 2016 12:29
Tables in the current mysql db containing the specified column
SELECT
DISTINCT table_name
FROM
information_schema.columns
WHERE
column_name IN ('your_column')
AND table_schema=(select database());
@ffeast
ffeast / ec2_instype.sh
Created July 4, 2016 10:08
EC2 instance type from inside EC2 instance
#!/bin/sh
# just copy & paste this line into your CLI
# more info http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
curl http://169.254.169.254/latest/meta-data/instance-type && echo