Skip to content

Instantly share code, notes, and snippets.

View gullevek's full-sized avatar

Clemens Schwaighofer gullevek

View GitHub Profile
@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 / 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 / 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')