Skip to content

Instantly share code, notes, and snippets.

Clemens Schwaighofer gullevek

Block or report user

Report or block gullevek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gullevek
gullevek / filesize_per_year.sh
Created Jul 6, 2018
Find files and group the file size sum per year
View filesize_per_year.sh
find ./ -type f -print0 | xargs -0 stat -f '%Sm %z' -t "%Y" | awk 'function human(x) {s=" B KB MB GB TB EB PB YB ZB"; while (x>=1024 && length(s)>1){x/=1024; s=substr(s,4)} s=substr(s,1,4); xf=(s==" B ")?"%d ":"%.2f"; return sprintf( xf"%s", x, s);}{sum[$1]+= $2;}END{for (date in sum){printf ("%s %s\n", date, human(sum[date]));}}' | sort
@gullevek
gullevek / double_byte_string_format.py
Created Mar 20, 2018
Python class to shorten double byte string and set correct adapted format length for output print
View double_byte_string_format.py
#!/usr/bin/python3
# formatting with double width characters
import unicodedata
# Class for format a double byte string correctly with format length set
class DoubleByteFormat:
# METHOD: init class
@gullevek
gullevek / progress_data_import.sql
Last active May 8, 2018
PostgreSQL function to monitor progress for select -> insert flow
View progress_data_import.sql
CREATE OR REPLACE FUNCTION copy_progress(from_date DATE, to_date DATE, p_precision INT DEFAULT 1) RETURNS "varchar"
AS $$
DECLARE
status VARCHAR; -- return status
my_rec RECORD; -- transfer record
-- progress info
pos INT := 1; -- current position
row_count INT := 0; -- overall row count (max)
percent NUMERIC; -- output percent
old_percent NUMERIC := 0.0; -- previous percent
@gullevek
gullevek / .vimrc
Created Aug 20, 2015
VIM config file
View .vimrc
set nocompatible
set hidden " background buffers
set history=1000
set wildmenu " tab complete like bash
" set ignorecase " ignore case for search
" set smartcase " but if capital letter, make case sensitive again
set scrolloff=3 " keep 3 lines before/after
set bs=2 " backspace command, alt: indent,eol,start
set noexpandtab
set tabstop=4
@gullevek
gullevek / query_to_csv.perl
Last active Dec 25, 2015
Writes all data from a given query to a csv file. Usefull for reading out large batches of data to avoid memory over usage. Uses async and CURSOR. Python version only uses CURSOR as named cursor and async do not work at the same time.
View query_to_csv.perl
#!/usr/bin/perl
# AUTHOR: Clemens Schwaighofer
# DATE: 2015/8/6
# DSCRIPTION:
# Runs a query from a file or command line and outputs the data to a CSV file
# Runs query async/and CURSOR
use strict;
use warnings;
@gullevek
gullevek / screen_init.bash
Last active Aug 29, 2015
[File will no longer be maintained, use the main git entry: https://github.com/gullevek/scripts/blob/master/screen/screen_init.sh] Helps to init a screen session. Very useful if you have various large ones and want to recreate them after a server reboot.
View screen_init.bash
# Final file has moved into a main GIT:
# https://github.com/gullevek/scripts/blob/master/screen/screen_init.sh
# This file below will no longer be updated.
#!/bin/bash
# AUTHOR: Clemens Schwaighofer
# DATE: 2015/8/4
# DESC: inits a screen with shells (sets titles) and runs command in those shells
# reads all data from a config file
@gullevek
gullevek / progress.pm
Last active Aug 29, 2015
perl and python module for progress print out in percent, rows, lines per second, etc
View progress.pm
package Progress;
# AUTHOR: Clemens Schwaighofer
# DATE CREATED: 2009/6/16
# DESCRIPTION: progress percent class
# METHODS
# * init
# my $prg = Progress->new();
# will init a new progress class in the var $prg
@gullevek
gullevek / New New Index Bloat Query
Last active Jul 22, 2019 — forked from mbanck/New New Index Bloat Query
This version uses pg_stats and not pg_statistics so any user can use this query
View New New Index Bloat 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'
),
You can’t perform that action at this time.