Skip to content

Instantly share code, notes, and snippets.

View minmax's full-sized avatar
💭
awaken

Karataev Pavel minmax

💭
awaken
View GitHub Profile
@minmax
minmax / settings.json
Last active September 26, 2023 18:55
VSCode settings
{
"[python]": {
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true,
"source.unusedImports": true
},
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true,
"editor.formatOnType": true
WITH raw_data AS (
SELECT
pg_namespace.nspname,
pg_class.relname,
pg_class.oid AS relid,
pg_class.reltuples,
pg_stat_all_tables.n_dead_tup,
pg_stat_all_tables.n_mod_since_analyze,
(SELECT split_part(x, '=', 2) FROM unnest(pg_class.reloptions) q (x) WHERE x ~ '^autovacuum_analyze_scale_factor=' ) as c_analyze_factor,
(SELECT split_part(x, '=', 2) FROM unnest(pg_class.reloptions) q (x) WHERE x ~ '^autovacuum_analyze_threshold=' ) as c_analyze_threshold,
@minmax
minmax / pg_index_progress.sql
Created January 18, 2022 21:44
pg index progress
-- https://gitlab.com/-/snippets/2138417
select
now(),
query_start as started_at,
now() - query_start as query_duration,
format('[%s] %s', a.pid, a.query) as pid_and_query,
index_relid::regclass as index_name,
relid::regclass as table_name,
(pg_size_pretty(pg_relation_size(relid))) as table_size,
nullif(wait_event_type, '') || ': ' || wait_event as wait_type_and_event,
@minmax
minmax / pg_shared_buffers.sql
Last active May 19, 2017 12:14
View shared buffers content
-- based on https://github.com/lesovsky/uber-scripts/blob/master/postgresql/sql/c2_03_shared_buffers_current_database_detailed.sql
CREATE VIEW pg_shared_buffers AS (
WITH stats AS (
SELECT
c.relname::text as name,
pg_relation_size(c.oid) AS relation_size,
count(b.bufferid) * (
SELECT current_setting('block_size') :: INT
) AS buffered_in_shared_buffers,
@minmax
minmax / pg_size.sql
Created December 15, 2016 18:20
pg_size view
CREATE OR REPLACE VIEW pg_size AS (
SELECT
a.table_name AS name,
a.row_estimate :: INTEGER AS row_estimate,
pg_size_pretty(a.total_bytes) AS total,
pg_size_pretty(a.table_bytes) AS "table",
pg_size_pretty(a.index_bytes) AS index,
pg_size_pretty(a.toast_bytes) AS toast
FROM (SELECT
a_1.oid,
from twisted.internet.task import react
from twisted.internet.defer import Deferred
from twisted.internet.protocol import Factory, connectionDone
from twisted.internet.endpoints import TCP4ServerEndpoint
from twisted.protocols.basic import LineReceiver
class ChatProtocol(LineReceiver):
def lineReceived(self, line):
self.factory.send_message(self, line)
@minmax
minmax / mongo-stat.js
Created November 9, 2014 16:17
Print mongo collections names and objects count
var dbs_names = db.adminCommand('listDatabases');
for (var i = 0; i < dbs_names.databases.length; i += 1) {
var current_db = connect(dbs_names.databases[i].name);
var collection_names = current_db.getCollectionNames();
for (var j = 0; j < collection_names.length; j += 1) {
var collection = current_db[collection_names[j]];
var size = collection.stats().count;
print(dbs_names.databases[i].name + '\t' + collection_names[j] + ':\t' + size);
};
};
@minmax
minmax / master.py
Created March 22, 2012 17:53
bug with xreq\xrep in txzmq
from twisted.internet import reactor
import zmq
from txzmq import ZmqEndpoint, ZmqFactory, ZmqConnection, ZmqEndpointType
REQUEST_COUNT = 10000
EVENTS_COUNT = 20000 - 2
class NewConnection(ZmqConnection):