Skip to content

Instantly share code, notes, and snippets.

View ststeiger's full-sized avatar
😎
Back from holidays

Stefan Steiger ststeiger

😎
Back from holidays
  • Switzerland
View GitHub Profile
@ststeiger
ststeiger / dpkg-divert.txt
Last active May 9, 2025 09:37
Diverting google-chrome script with DPKG
sudo apt-get remove --purge google-chrome-stable
cd ~/Downloads
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
sudo apt-get update
sudo dpkg-divert --divert /usr/bin/original-google-chrome-stable --rename /usr/bin/google-chrome-stable
dpkg-divert --list
@ststeiger
ststeiger / Find_Dependent_Tables_of_View.sql
Last active May 7, 2025 16:11
Find the tables a VIEW depends on
SELECT
sch.name AS referenced_schema
,o.name AS referended_object
,o.type_desc AS referenced_object_type
-- ,pk_cols.COLUMN_NAME AS primary_key_column
FROM sys.sql_expression_dependencies AS d
JOIN sys.objects AS o ON d.referenced_id = o.object_id
JOIN sys.schemas AS sch ON sch.schema_id = o.schema_id
@ststeiger
ststeiger / Last_Executed_Queries.sql
Created April 25, 2025 14:21
Get the last executed sql queries on MS-SQL
SELECT TOP 100
qt.text AS sql_query
,qs.last_execution_time
,qs.execution_count
,sd.name AS db
FROM sys.dm_exec_query_stats AS qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) AS qt
@ststeiger
ststeiger / format_filesize.js
Last active April 22, 2025 12:47
How to properly format file-size in JS
enum ByteFormatMode {
Binary, // 1024-based (KiB, MiB, GiB - IEC standard)
Decimal, // 1000-based (KB, MB, GB - SI standard)
Pseudo // 1024-based but uses KB/MB/GB (Windows-style)
}
function formatBytes(bytes: number, mode: ByteFormatMode = ByteFormatMode.Binary): string {
const suffixesBinary = ["bytes", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB", "RiB", "QiB"];
const suffixesDecimal = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", "RB", "QB"];
const suffixesPseudo = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", "RB", "QB"];
@ststeiger
ststeiger / NormalForms.txt
Created April 11, 2025 15:41
SQL Normal Forms
https://www.perplexity.ai/search/can-you-find-me-information-re-Kv6Kcel1R..clYeGhwa6xg
OK, so to put this down to the Level of an intelligent 12year old:
First normal form is violated if
A) cells have multiple values inside the same cell (e.g. separated by separator)
or
B) there are repeating columns for the same thing, e.g. Tel1, Tel2, Tel3,
@ststeiger
ststeiger / NetCoreIIS_Tutorial.md
Last active March 1, 2025 19:00
Tutorial - install asp.net core application in IIS
@ststeiger
ststeiger / JsonType.sql
Last active December 13, 2024 15:38
Determine the type of a JSON-object in MSSQL
;WITH CTE AS
(
SELECT NULL AS CLV_Value
UNION ALL SELECT '123' AS CLV_Value
UNION ALL SELECT '[1,2,3]' AS CLV_Value
UNION ALL SELECT '{"0": 1234}'
UNION ALL SELECT '{
"json": "[]",
"svg": null,
@ststeiger
ststeiger / pgsql.cmd
Last active October 14, 2024 17:48
Batch-start PostGreSQL on Windows
@echo off
title PostgreSQL Portable
cls
:: set default code page
chcp 1252 > nul
:: initialise a new database on first use
if not exist "%PGDATA%" (
echo.
@ststeiger
ststeiger / Find_MultiValue_FKs.sql
Created September 24, 2024 11:56
Find multi-column foreign-keys in MSSQL
SELECT
sch.name AS table_schema
,tp.name AS table_name
,schFK.name AS fk_schema
,fk.name AS fk_name
,STUFF
(
(
SELECT ', ' + c.name
@ststeiger
ststeiger / CollationInfo.sql
Created September 20, 2024 15:12
Show info about collation
SELECT
-- name
DISTINCT collation_name
FROM sys.databases
WHERE (1=1)
-- AND name = 'tempdb';
SELECT name, collation_name
FROM sys.databases
WHERE (1=1)