Skip to content

Instantly share code, notes, and snippets.

View manuthu's full-sized avatar

Mike manuthu

View GitHub Profile
@manuthu
manuthu / postgres_queries_and_commands.sql
Created May 17, 2022 05:51 — forked from rgreenjr/postgres_queries_and_commands.sql
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
# Install the nifty client
# pip install git+https://github.com/east36/python-nifty-client.git
import logging
from niftyclient import NiftyClient
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger('STK')
@manuthu
manuthu / psql_encoding.markdown
Created February 21, 2022 11:09 — forked from joshteng/psql_encoding.markdown
This solves Postgresql's encoding issue (happened to me when running postgres on my vagrant box) The error happens when trying to create db "rake db:create": Error message: "encoding UTF8 does not match locale en_US; the chosen LC_CTYPE setting requires encoding LATIN1"
sudo su postgres
psql
update pg_database set datistemplate=false where datname='template1';
drop database Template1;
create database template1 with owner=postgres encoding='UTF-8' lc_collate='en_US.utf8' lc_ctype='en_US.utf8' template template0;
update pg_database set datistemplate=true where datname='template1';
@manuthu
manuthu / sane-caching.nginx.conf
Created May 25, 2021 12:01 — forked from philipstanislaus/sane-caching.nginx.conf
Sample Nginx config with sane caching settings for modern web development
# Sample Nginx config with sane caching settings for modern web development
#
# Motivation:
# Modern web development often happens with developer tools open, e. g. the Chrome Dev Tools.
# These tools automatically deactivate all sorts of caching for you, so you always have a fresh
# and juicy version of your assets available.
# At some point, however, you want to show your work to testers, your boss or your client.
# After you implemented and deployed their feedback, they reload the testing page – and report
# the exact same issues as before! What happened? Of course, they did not have developer tools
# open, and of course, they did not empty their caches before navigating to your site.

Get the user_id from the console/portal

List all the files belonging to the user . For this case, we use - 6a76bf01-dc90-4996-a846-8472cb086565

rados ls -p .rgw.buckets | grep 6a76bf01-dc90-4996-a846-8472cb086565

Save the files to a log file

-- db=# \d order_payment
-- Table "public.order_payment"
-- Column | Type | Collation | Nullable | Default
-- -----------------+-----------------------------+-----------+----------+---------
-- id | uuid | | not null |
-- order_id | uuid | | |
-- amount_paid | numeric | | |
-- ...
select
@manuthu
manuthu / cloudstack-routers-running-in-a-storagepool.sh
Last active April 15, 2020 15:38
A script to get all the running routers in a given storage pool in XEN.
# Get all running routers. Routers in cloudstack are prefixed with `r-DIGIT`
RUNNING_VMS=$(xe vm-list | grep -A2 -B2 'r-[0-9]' | grep uuid | awk -F':' '{print $2}')
SRID=8c269040-fc42-c12d-b091-8958784ec65e
for vm_id in $RUNNING_VMS
do
xe vbd-list vm-uuid=$vm_id | grep vdi-uuid | awk -F':' '{print $2}' | xargs -I {} xe vdi-list uuid={} | grep $SRID && echo $vm_id
done
@manuthu
manuthu / install-postgres-10-ubuntu.md
Created June 6, 2019 12:42 — forked from alistairewj/install-postgres-10-ubuntu.md
Install PostgreSQL 10 on Ubuntu

Install PostgreSQL 10 on Ubuntu

This is a quick guide to install PostgreSQL 10 - tested on Ubuntu 16.04 but likely can be used for Ubuntu 14.04 and 17.04 as well, with one minor modification detailed below.

(Optional) Uninstall other versions of postgres

To make life simple, remove all other versions of Postgres. Obviously not required, but again, makes life simple.

dpkg -l | grep postgres
@manuthu
manuthu / ipblock.py
Created December 4, 2018 16:03
IP Block with signal handling
#!/opt/venv/ipblock/env/bin/python
__author__ = 'Mike Manuthu <muragumichael@gmail.com>'
"""
A simple script to disable the number of connections to the server.
Uses IPTables to block the IPS with more than the threshold connections.
Uses Fail2Ban as the default IP Blocker.
usage: IP Blocker :: [-h] [-i IP] [-I IPRANGE] [-c CONNECTIONS] [-B]
[-f FREQUENCY]