Skip to content

Instantly share code, notes, and snippets.

View zwolf's full-sized avatar

Zach Wolfenbarger zwolf

View GitHub Profile
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active November 17, 2024 13:10
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%'
@camallen
camallen / pg_locks.sql
Last active February 8, 2020 04:37 — forked from parrish/pg_locks.sql
Show info on postgres locks
SELECT bl.pid AS blocked_pid,
a.usename AS blocked_user,
ka.query AS current_statement_in_blocking_process,
now() - ka.query_start AS blocking_duration,
kl.pid AS blocking_pid,
ka.usename AS blocking_user,
a.query AS blocked_statement,
now() - a.query_start AS blocked_duration
FROM pg_catalog.pg_locks bl
JOIN pg_catalog.pg_stat_activity a ON a.pid = bl.pid
@camallen
camallen / pg_find_unused_indexes.sql
Created December 2, 2016 13:44
PostgreSQL - find unused indexes
SELECT
relid::regclass AS table,
indexrelid::regclass AS index,
pg_size_pretty(pg_relation_size(indexrelid::regclass)) AS index_size,
idx_tup_read,
idx_tup_fetch,
idx_scan
FROM
pg_stat_user_indexes
JOIN pg_index USING (indexrelid)
@troyharvey
troyharvey / deployment.yml
Last active September 13, 2024 19:00
Using Kubernetes envFrom for environment variables
# Use envFrom to load Secrets and ConfigMaps into environment variables
apiVersion: apps/v1beta2
kind: Deployment
metadata:
name: mans-not-hot
labels:
app: mans-not-hot
spec:
replicas: 1
@camallen
camallen / find_database_relation_sized.sql
Created November 21, 2017 13:27
List top 10 table sizes and report the index usage
select relation, pg_size_pretty(total_size), pg_size_pretty(size), pg_size_pretty(total_size - size) as index_size from
(SELECT relname AS "relation", pg_total_relation_size(C.oid) AS "total_size", pg_relation_size(C.oid) AS "size"
FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
WHERE nspname NOT IN ('pg_catalog', 'information_schema')
ORDER BY pg_relation_size(C.oid) DESC
) as derived
LIMIT 10;
@dleske
dleske / k8s-update-secret.md
Last active January 29, 2024 17:12
k8s: Updating a Secret

Hopefully helped another k8s newbie with the following. The question was, how do you update a single key in a secret in k8s? I don't know anything about secrets but I will probably want to know this in the future, so here we go.

First, to create a dummy secret:

apiVersion: v1
kind: Secret
metadata:
  name: test-secret
data:
@camallen
camallen / project_classifications_csv_dump_export.rb
Last active June 18, 2019 10:25
Manual classification csv exports for a panoptes project
# Manual csv classifications dump
# ensure the config/database.yml is configured to use the read replica database and not the production db.
#
# run via rails runner from the panoptes cmd line via
# rails r project_classifications_csv_dump_export.rb
require 'csv'
PROJECT_ID = 1
@camallen
camallen / test_file_mime_type.py
Created September 21, 2018 08:17
Python magic lib test file mime types
# https://github.com/ahupp/python-magic#usage
import magic, csv
file_paths = (
'480_CornellFeeders_20171024_0921_000.mp4',
'480_CornellFeeders_20171024_0921_000.mp4',
'480_CornellFeeders_20171024_0921_001.mp4',
'480_CornellFeeders_20171024_0921_002.mp4'
)
@camallen
camallen / clear_sidekiq_locks_redis_cli.sh
Created November 2, 2018 13:37
Clear out sidekiq unique & congestion locks from redis
# ssh onto the redis node in question and run these cmds
# congestion:* keys are for https://github.com/parrish/Sidekiq-Congestion
# uniquejobs:* https://github.com/mhenrixon/sidekiq-unique-jobs
# get a count of the locks
redis-cli -n 0 --scan --pattern 'congestion:*' | wc -l
redis-cli -n 0 --scan --pattern 'uniquejobs:*' | wc -l
# clear them for both key namespaces
@adammcmaster
adammcmaster / org_workflow_stats.py
Created May 3, 2019 11:36
Print workflow stats for an organisation
"""
Requires panoptes-client and (on Python 2) futures.
pip install panoptes-client futures
"""
from panoptes_client import Panoptes, Organization
ORG_ID = 16
Panoptes.connect(
username='',