Skip to content

Instantly share code, notes, and snippets.

View tkue's full-sized avatar

Tom Kuecken tkue

  • Portland, Oregon
View GitHub Profile
@tkue
tkue / mssql_segment_table_into_batches.sql
Created July 10, 2025 14:41
TSQL - segment table data into batches
drop table if exists #t
create table #t (
RowId int primary key identity(1,1)
,Col1 int
,BatchId smallint
)
insert into #t (Col1)
values
(1)
@tkue
tkue / convert_virtualbox_to_qcow2.sh
Last active March 2, 2025 18:50
Convert VirtualBox disk to qcow2 for KVM
qemu-img convert -f vdi -O qcow2 WorkWindowsServer2022.vdi WorkWindowsServer2022.qcow2
@tkue
tkue / encoding_helpers.py
Last active February 18, 2025 08:31
py encoding helpers
@staticmethod
def encodingDetect(s):
import chardet
try:
return chardet.detect(s)
except UnicodeDecodeError:
return chardet.detect(s.encode('utf-8'))
@staticmethod
def encodingConvertUnicode(s):
@tkue
tkue / get_public_ip.py
Created February 18, 2025 07:32
py get public ip
@staticmethod
def get_public_ip():
import requests
from Validator import Validator
IP_URL = 'http://checkip.amazonaws.com/'
try:
@tkue
tkue / get_unique_filename.py
Created February 18, 2025 07:32
py get unique filename
@staticmethod
def get_unique_filename(filepath: str):
if StringUtil.isNullOrEmpty(filepath):
return
import os
filepath = os.path.getabspath(filepath)
if os.path.exists(filepath):
@tkue
tkue / get_files_recursively.py
Created February 18, 2025 07:31
py get files recursively
@staticmethod
def get_files_recursively(directory: str, file_extensions: ()):
if not directory or not file_extensions:
return
matched_files = [] # files that have matching extension
directory = os.path.abspath(directory)
fileslist = os.listdir(directory)
@tkue
tkue / enumerate_files_from_paths.py
Created February 18, 2025 07:31
py enumerate path and get a list of all files
@staticmethod
def enumerate_files_from_paths(paths):
"""
Description:
Returns list of all files from a list of paths
:param paths: tuple
List of all paths to enumerate
:return:
"""
try:
@tkue
tkue / calc_crc32.py
Last active February 18, 2025 07:30
py calc crc32
@staticmethod
def calc_crc32(file_path: str):
if not file_path:
return
import binascii
with open(file_path, 'rb') as f:
buf = f.read()
buf = (binascii.crc32(buf) & 0xFFFFFFFF)
@tkue
tkue / py_ backup_file.py
Last active February 18, 2025 07:29
py backup file with unique name and timestamp
@staticmethod
def backup_file(filename: str, backupname: str = None):
"""
Pass in filename/path to create a backup
Ensures the name for the backup is unique, whehter it is specifically given or not
:param filename: str
Name of file or path to the file
If os.path.isfile(filename) returns False, it raises an IOException
:param backupname:
Optional
@tkue
tkue / py_md5sum.py
Created February 18, 2025 07:20
py_mod5sum.py
import hashlib
def md5sum(filename):
if not filename or not os.path.isfile(filename):
return
hash_md5 = hashlib.md5()
with open(filename, "rb") as f:
for chunk in iter(lambda: f.read(8192), b""):
hash_md5.update(chunk)