Skip to content

Instantly share code, notes, and snippets.

#### Get all the numpy array and their size ####
# From https://stackoverflow.com/questions/11784329/python-memory-usage-of-numpy-arrays
import sys
import numpy
from humanize import naturalsize
for size, name in sorted(
(value.nbytes, name)
for name, value in locals().items()
------------ Duplicates management ------------
-- Show the duplicate rows in <table>
select * from <table> ou
where (select count(*) from <table> inr
where inr.id = ou.id) > 1
order by id;
---- OR
#### Get list of objects by size ####
# work over each commit and append all files in tree to $tempFile
tempFile=$(mktemp)
IFS=$'\n'
for commitSHA1 in $(git rev-list --all); do
git ls-tree -r --long "$commitSHA1" >>"$tempFile"
done
# sort files by SHA1, de-dupe list and finally re-sort by filesize
@kiurtis
kiurtis / postgres_management_commands.sql
Last active February 25, 2021 12:11 — 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%'
@kiurtis
kiurtis / gdrive_upload_folder_with_subfolders.py
Last active January 20, 2022 17:05 — forked from jmlrt/gdrive_upload_folder.py
Python script to upload folder to Google Drive
# -*- coding: utf-8 -*-
"""
Snippet based on pydrive allowing to upload full folders to Google Drive, replicating the same subfolders hierarchy.
Settings are set in the yaml files; don't forget to generate google api credentials and to put the client_secrets.json in the folder.
You should get first the id of the parent folder (the gdrive folder where you want to copy your folders), which is the
end of its url.
If the destination folder does not exist, it will be created.