Skip to content

Instantly share code, notes, and snippets.

View kmatt's full-sized avatar
😐

Matt Keranen kmatt

😐
  • SE US
View GitHub Profile
@kmatt
kmatt / gistbackup.sh
Created January 10, 2025 05:30
Download all Gists using Github CLI
# Download all Gists
for i in $(gh gist list -L 1000 | cut -f1); do echo "ID: $i"; gh gist view $i > $i; done
# Rename each file with a slug of the first line / description
for f in *; do mv -v $f $(gawk 'NR==1{gsub(/[^[:alnum:]]/, "-"); gsub(/-+/, "-"); print $0 "_" FILENAME}' $f); done
#
# This shell prompt config file was created by promptline.vim
#
function __promptline_host {
local only_if_ssh="0"
if [ $only_if_ssh -eq 0 -o -n "${SSH_CLIENT}" ]; then
if [[ -n ${ZSH_VERSION-} ]]; then print %m; elif [[ -n ${FISH_VERSION-} ]]; then hostname -s; else printf "%s" \\h; fi
fi
}
@kmatt
kmatt / wef.ps1
Created December 20, 2024 21:42
Select and browse Windows event logs with FZF
(Get-EventLog *).Log | fzf | % { Get-EventLog -LogName $_.Trim() -after (Get-Date).AddDays(-7) } | fzf
@kmatt
kmatt / SMOScripter.ps1
Last active November 20, 2024 02:13
Script SQL Server database to individual files for schema history
param ([string]$s, [string[]] $d, [switch]$commit, [switch]$verbose, [string]$path=(Get-Location))
# Install-Module -Name SqlServer -Scope CurrentUser
# Systemd service unit:
# ExecStart=/usr/bin/pwsh /localdata/SMOSchema/scripter.ps1 -s ALL -commit
#
# Add to $SERVICENAME.service.d/override.conf
# [Service]
# Environment=SQLCMDUSER=
@kmatt
kmatt / pl_to_sql.py
Last active November 19, 2024 02:05 — forked from bthaman/df_to_sql_fast.py
Polars dataframe to SQL Server using pyodbc, without Pandas or SQLAlchemy dependencies
def pl_to_sql(df, table, replace=False):
"""
to_sql() without Pandas
Appends or overwrites a SQL Server table using data from a DataFrame
Parameters:
df (DataFrame): df used to create/append table
table (str): Name of existing SQL Server table
replace (bool): Truncate before insert
Returns:
@kmatt
kmatt / ddb_rowhash.txt
Created November 11, 2024 15:21
DuckDB rowhash
SELECT tbl::TEXT, HASH(tbl::TEXT), MD5(tbl::TEXT) FROM tbl;
D create table tbl as (select 1 as a, 2 as b, 3 as c);
D select tbl::text, hash(tbl::text), md5(tbl::text) from tbl;
┌──────────────────────────┬────────────────────────────┬──────────────────────────────────┐
│ CAST(tbl AS VARCHAR) │ hash(CAST(tbl AS VARCHAR)) │ md5(CAST(tbl AS VARCHAR)) │
│ varchar │ uint64 │ varchar │
├──────────────────────────┼────────────────────────────┼──────────────────────────────────┤
│ {'a': 1, 'b': 2, 'c': 3} │ 6764392534128998287 │ e31681d6e7ab078c9679fcd4f50136eb │
└──────────────────────────┴────────────────────────────┴──────────────────────────────────┘
@kmatt
kmatt / NPP_CLI.reg
Created August 19, 2024 16:18
Notepad++ CLI
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\npp.exe]
@="C:\\Program Files (x86)\\Notepad++\\notepad++.exe"
@kmatt
kmatt / tigrc
Created July 3, 2024 02:18
Delta diffs in Tig
# View diffs using delta
# Via https://github.com/jonas/tig/issues/26#issuecomment-1923835137
bind diff D >sh -c "git show %(commit) | delta --paging always"
bind diff S >sh -c "git show %(commit) | delta --paging always --side-by-side"
bind stage D >sh -c "git diff HEAD -- %(file) | delta --paging always"
bind stage S >sh -c "git diff HEAD -- %(file) | delta --paging always --side-by-side"
bind status D >sh -c "git diff HEAD -- %(file) | delta --paging always"
bind status S >sh -c "git diff HEAD -- %(file) | delta --paging always --side-by-side"
@kmatt
kmatt / tmux.conf
Created April 30, 2024 14:46
Multiple timezones in tmux status bar
set-option -g status-right '#{client_tty} (#(TZ=US/Mountain date +%%H:%%M)MT #(TZ=UTC date +%%H:%%M)Z) %Y-%m-%d %H:%M'
@kmatt
kmatt / TDM.cmake
Created March 1, 2024 01:42
TDM-GCC and cmake on Windows notes
# To configure for MinGW instead of nmake
#
# C:\TDM-GCC-64\mingwvars.bat
# cmake . -G "MinGw Makefiles"
#
# Makefile: cmake ... -DCMAKE_TOOLCHAIN_FILE=TDM.cmake
set(CMAKE_SYSTEM_NAME Windows)
set(CMAKE_C_COMPILER C:/TDM-GCC-64/bin/gcc.exe)