Skip to content

Instantly share code, notes, and snippets.

View gullevek's full-sized avatar

Clemens Schwaighofer gullevek

View GitHub Profile
@gullevek
gullevek / remove_quarantine.sh
Created July 21, 2026 01:21
Remove Mac quarantine flag
#!/usr/bin/env bash
if [ -z "${1}" ]; then
echo "Please give an application as full path to file";
exit;
fi;
if [ "${1}" = "/" ]; then
echo "Not a valid path";
exit;
@gullevek
gullevek / read_db_schema_table_column_connections.sql
Last active December 5, 2024 02:58
Read all tables and columns that have some a/i attribute as index, serial, identity
CREATE OR REPLACE VIEW identity_column_status AS
WITH table_data AS (
SELECT
t.table_catalog, t.table_schema, t.table_name,
t.table_schema || '.' || t.table_name AS schema_table_name
FROM
information_schema.tables AS t
WHERE
t.table_type = 'BASE TABLE'
AND t.table_schema NOT IN ('information_schema', 'pg_catalog')
@gullevek
gullevek / convert_serial_to_identity.sql
Last active December 5, 2024 02:55
PostgreSQL convert any serial column to an identity column
-- Upgrade serial to identity type
--
-- Original: https://www.enterprisedb.com/blog/postgresql-10-identity-columns-explained#section-6
--
-- @param reclass tbl The table where the column is located, prefix with 'schema.' if different schema
-- @param name col The column to be changed
-- @param varchar identity_type [default=a] Allowed a, d, assigned, default
-- @param varchar col_type [default=''] Allowed smallint, int, bigint, int2, int4, int8
-- @returns varchar status tring
-- @raises EXCEPTON on column not found, no linked sequence, more than one linked sequence found, invalid col type
@gullevek
gullevek / pgp_gd_transparent_gif_and_png.php
Last active July 30, 2024 09:16
PHP + GD 2.3.3 vs PHP + GD bundles (2.1.0 compatible) gif transparency problem
<?php
// Create transparent gif in certain sizes and print out base64
$gd_version = gd_info()["GD Version"];
// check: bundled -> use a transparency, if not and 2.3.3 or higher, use alternate
$use_imagecolorallocatealpha = true;
if (strstr($gd_version, "bundled") !== false) {
$use_imagecolorallocatealpha = false;
}
@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 / file_size_check.sh
Created February 7, 2020 02:32
Loops over files in a folder and checks if they changed. If they stay the same in 3 loops of 5s wait the script will end
#!/bin/bash
folder=${1};
diff=1;
sleeptime=5;
if [ ! -d "${folder}" ]; then
echo "Folder: ${folder} not found";
exit;
fi;
@gullevek
gullevek / filesize_per_year.sh
Created July 6, 2018 01:11
Find files and group the file size sum per year
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
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='..'):
@gullevek
gullevek / progress_data_import.sql
Last active May 8, 2018 02:48
PostgreSQL function to monitor progress for select -> insert flow
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 August 20, 2015 08:37
VIM config file
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