Skip to content

Instantly share code, notes, and snippets.

View qzaidi's full-sized avatar
💭
smiling

Qasim Zaidi qzaidi

💭
smiling
View GitHub Profile
@qzaidi
qzaidi / mysql.md
Created September 19, 2019 08:50
mysql

Largest DB tables

SELECT CONCAT(table_schema, '.', table_name),
       CONCAT(ROUND(table_rows / 1000000, 2), 'M')                                    rows,
       CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G')                    DATA,
       CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G')                   idx,
       CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size,
       ROUND(index_length / data_length, 2)                                           idxfrac
FROM information_schema.TABLES

Find last updated entry

db.collection.find().limit(1).sort({$natural:-1})

Sort collections by size

var collectionNames = db.getCollectionNames(), stats = []; collectionNames.forEach(function (n) { stats.push(db[n].stats()); });

@qzaidi
qzaidi / README.md
Created June 19, 2019 04:26
godoc with phabricator

Idea

Setup a post recieve hook with phab repos and use it also for godoc.

Systemd config

[Unit]
package main
import (
"os"
"fmt"
"log"
"debug/elf"
)
func main() {
\n\n
content_type: %{content_type}\n
filename_effective: %{filename_effective}\n
ftp_entry_path: %{ftp_entry_path}\n
http_code: %{http_code}\n
http_connect: %{http_connect}\n
local_ip: %{local_ip}\n
local_port: %{local_port}\n
num_connects: %{num_connects}\n
num_redirects: %{num_redirects}\n
@qzaidi
qzaidi / tcpdump.md
Last active September 21, 2020 03:41
capture http headers

HTTP Headers

tcpdump -A -s 10240 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' | egrep --line-buffered "^........(GET |HTTP\/|POST |HEAD )|^[A-Za-z0-9-]+: " | sed -r 's/^........(GET |HTTP\/|POST |HEAD )/\n\1/g'

HTTP Headers and body, on a given interface to a certain dst

tcpdump -i ens4 -A -s 10240 'dst 172.21.43.252 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'

Postgres Queries

sudo tcpdump -i lo -s0 -nl -w- dst port postgres | strings -n8
@qzaidi
qzaidi / imagic.go
Created January 26, 2016 01:47
Imagemagick text manipulation in go
package main
import (
"github.com/gographics/imagick/imagick"
)
func main() {
imagick.Initialize()
defer imagick.Terminate()
@qzaidi
qzaidi / rdbparse.py
Created January 19, 2016 03:42
Find keys without expiry in rdb dump
import sys
from rdbtools import RdbParser, RdbCallback
class MyCallback(RdbCallback) :
def set(self, key, value, expiry,info):
if expiry is None:
print('%s = %s' % (str(key), str(expiry)))
callback = MyCallback()
@qzaidi
qzaidi / jenkins-log
Created May 29, 2015 08:39
jenkins-log
#!/bin/bash
# example cron script to post logs to Jenkins
# exit on error
set -e
log=`mktemp -t tmp.XXXX`
timer=`date +"%s"`
jenkins_job=$1
jenkins_server=http://192.168.33.10:8080/job/$jenkins_job/postBuildResult