Skip to content

Instantly share code, notes, and snippets.

View gullevek's full-sized avatar

Clemens Schwaighofer gullevek

View GitHub Profile
@gullevek
gullevek / human_readable_bytes_to_number.js
Last active May 20, 2021 02:09
javascript to convert human readable bytes (eg 10MB) to a number (10,485,760)
/**
* Convert a string with B/K/M/etc into a byte number
* @param {String|Number} bytes Any string with B/K/M/etc
* @return {String|Number} A byte number, or original string as is
*/
function stringByteFormat(bytes)
{
// if anything not string return
if (!(typeof bytes === 'string' || bytes instanceof String)) {
return bytes;
@gullevek
gullevek / New New Index Bloat Query
Last active July 25, 2022 17:35 — forked from mbanck/New New Index Bloat Query
This version uses pg_stats and not pg_statistics so any user can use this query
WITH btree_index_atts AS (
SELECT nspname, relname, reltuples, relpages, indrelid, relam,
regexp_split_to_table(indkey::text, ' ')::smallint AS attnum,
indexrelid as index_oid
FROM pg_index
JOIN pg_class ON pg_class.oid=pg_index.indexrelid
JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace
JOIN pg_am ON pg_class.relam = pg_am.oid
WHERE pg_am.amname = 'btree'
),
@gullevek
gullevek / double_byte_string_format.py
Last active December 3, 2022 06:37
Python class to shorten double byte string and set correct adapted format length for output print
#!/usr/bin/env python3
"""
formatting with double width characters
"""
import unicodedata
def shorten_string_cjk(intput_string, width, placeholder='..'):