Skip to content

Instantly share code, notes, and snippets.

🐍
Python!

mattmc3 mattmc3

View GitHub Profile
@mattmc3
mattmc3 / sel_schema_from_all_dbs.sql
Created Apr 15, 2019
MSSQL - information_schema all dbs
View sel_schema_from_all_dbs.sql
drop table if exists #cols
select top 0 isc.*, cast(null as varchar(10)) as table_type, cast(null as bit) as is_primary
into #cols
from INFORMATION_SCHEMA.COLUMNS isc
declare @sql varchar(max)
set @sql = '
use ?
insert into #cols
select isc.*, ist.table_type, sys.fn_hadr_is_primary_replica(''?'')
View benchmark.zsh
#!/usr/bin/env zsh
for i in $(seq 1 10); do
/usr/bin/time zsh -i -c exit
done
@mattmc3
mattmc3 / mssql.ahk
Created Mar 29, 2019
AHK - AutoHotKey save MSSQL script execution history
View mssql.ahk
;CTRL+SHIFT+R run a query, but will also copy the script and save it off
;^+r is QWERTY, ^+s is Colemak for ^+r
^+r::
Send, ^c
EnvGet, HomeDir, USERPROFILE
FormatTime, DateString,,yyyyMMdd
FormatTime, TimeString,,hhmmss
FileCreateDir %HomeDir%\Documents\sqlhist\%DateString%
FileAppend, %Clipboard%, %HomeDir%\Documents\sqlhist\%DateString%\%TimeString%.sql
Send, {f5}
@mattmc3
mattmc3 / colemak.ahk
Created Mar 29, 2019
AHK - Colemak remapping
View colemak.ahk
; Colemak layout for AutoHotkey (MS Windows)
#SingleInstance force
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetTitleMatchMode 3 ; Exact matching to avoid confusing T/B with Tab/Backspace.
#Persistent
;top row
@mattmc3
mattmc3 / save_clipboard.ahk
Created Mar 29, 2019
AHK - save clipboard to file
View save_clipboard.ahk
; Save clipboard to file
OnClipboardChange:
EnvGet, HomeDir, USERPROFILE
FileDelete, %HomeDir%\Documents\clipboard.txt
FileAppend, %Clipboard%, %HomeDir%\Documents\clipboard.txt
Return
@mattmc3
mattmc3 / regex_scrub.sql
Created Mar 26, 2019
MSSQL - replace non-printable non-ascii characters
View regex_scrub.sql
select dbo.RegexReplace(t.my_column, '[^\x20-\x7E]', '~') as scrubbed
from my_table t
@mattmc3
mattmc3 / safelyrm.bash
Created Mar 25, 2019
Bash - safely rm from a script
View safelyrm.bash
under_home() {
# $HOME has to be set. Should always be, but make sure.
[[ -z "$HOME" ]] && return 1
# Handle tricky trailing slash inputs. ie: $HOME/// becomes $HOME
local somepath="$( echo "$1" | tr -s '/' )"
somepath=${somepath%/}
# Tailing slashes already removed, so now ensure the path lives under $HOME
[[ "$somepath" == "$HOME/"* ]] && return 0 || return 1
@mattmc3
mattmc3 / split_repo_example.sh
Last active Apr 15, 2019
Bash: split string on delimiter and echo substring before/after
View split_repo_example.sh
# http://tldp.org/LDP/abs/html/string-manipulation.html
function split_repo() {
local gitpath="${1:-github.com/mattmc3/myrepo}"
echo "\$gitpath = $gitpath"
echo "repo part \${gitpath##*/} = ${gitpath##*/}"
echo "user/repo \${gitpath#*/} = ${gitpath#*/}"
echo "url \${gitpath%%/*} = ${gitpath%%/*}"
echo "giturl/user \${gitpath%/*} = ${gitpath%/*}"
echo "user \${\${gitpath%/*}#*/} = ${${gitpath%/*}#*/}"
}
@mattmc3
mattmc3 / .gitignore
Last active Feb 11, 2019
git - Sublime Text .gitignore
View .gitignore
# https://github.com/github/gitignore/blob/master/Global/SublimeText.gitignore
# Put this .gitignore in the Sublime Text 3 User directory
# Mac Location: "~/Library/Application Support/Sublime Text 3/Packages/User"
# ignore subdirs except whitelisted ones
*/
!Snippets/
!Snippets/*
# Cache files for Sublime Text
@mattmc3
mattmc3 / pub_info.sql
Created Jan 23, 2019
MSSQL - replication publication information
View pub_info.sql
drop table if exists #pub_nfo
create table #pub_nfo (
server_name nvarchar(255)
,distribution_db nvarchar(255)
,pub_name nvarchar(255)
,db_name nvarchar(255)
,article_name nvarchar(255)
,schema_name nvarchar(255)
,table_name nvarchar(255)
)
You can’t perform that action at this time.