Skip to content

Instantly share code, notes, and snippets.

View khunafin's full-sized avatar

Nail Khunafin khunafin

View GitHub Profile
#!/bin/bash
awk '$5=="kB"{if ($4>1024^2){$4=$4/1024^2;$5="GB";} else if ($4>1024){$4=$4/1024;$5="MB";}} 1' /sys/devices/system/node/node*/meminfo | column -t
@khunafin
khunafin / psql_useful_stat_queries.sql
Created July 3, 2019 09:08 — forked from anvk/psql_useful_stat_queries.sql
List of some useful Stat Queries for PSQL
--- PSQL queries which also duplicated from https://github.com/anvk/AwesomePSQLList/blob/master/README.md
--- some of them taken from https://www.slideshare.net/alexeylesovsky/deep-dive-into-postgresql-statistics-54594192
-- I'm not an expert in PSQL. Just a developer who is trying to accumulate useful stat queries which could potentially explain problems in your Postgres DB.
------------
-- Basics --
------------
-- Get indexes of tables
@khunafin
khunafin / statistics.sql
Created July 3, 2019 08:55 — forked from ruckus/statistics.sql
Postgres statistics queries
** Find commmonly accessed tables and their use of indexes:
SELECT relname,seq_tup_read,idx_tup_fetch,cast(idx_tup_fetch AS numeric) / (idx_tup_fetch + seq_tup_read) AS idx_tup_pct FROM pg_stat_user_tables WHERE (idx_tup_fetch + seq_tup_read)>0 ORDER BY idx_tup_pct;
Returns output like:
relname | seq_tup_read | idx_tup_fetch | idx_tup_pct
----------------------+--------------+---------------+------------------------
schema_migrations | 817 | 0 | 0.00000000000000000000
user_device_photos | 349 | 0 | 0.00000000000000000000
ps f -eo size,pid,user,command --sort -size | awk '{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }'
git branch --merged | egrep -v "(^\*|master)" | xargs git branch -d
package main
import (
"net/http"
"database/sql"
"fmt"
"log"
"os"
)
XML_ILLEGALS = u'|'.join(u'[%s-%s]' % (s, e) for s, e in [
(u'\u0000', u'\u0008'), # null and C0 controls
(u'\u000B', u'\u000C'), # vertical tab and form feed
(u'\u000E', u'\u001F'), # shift out / shift in
(u'\u007F', u'\u009F'), # C1 controls
(u'\uD800', u'\uDFFF'), # High and Low surrogate areas
(u'\uFDD0', u'\uFDDF'), # not permitted for interchange
(u'\uFFFE', u'\uFFFF'), # byte order marks
])
RE_SANITIZE_XML = re.compile(XML_ILLEGALS, re.M | re.U)
import operator
import re
def pairs(l):
return zip(l[::2], l[1::2])
def vm(ops, env={}):
class closure:
def __init__(self, pc, env): self.pc, self.env = pc, env
def popn(n):
# Copyright (c) 2014 Andrey Vlasovskikh
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
@khunafin
khunafin / gist:4134114
Last active October 13, 2015 03:47
Git log
git config --global alias.l 'log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short'