Skip to content

Instantly share code, notes, and snippets.

View mattmc3's full-sized avatar
🐍
Python!

mattmc3 mattmc3

🐍
Python!
View GitHub Profile
@mattmc3
mattmc3 / drop_temp_tbl.sql
Created April 6, 2017 00:50
MSSQL Drop temp table if exists
if object_id('tempdb..#{{table}}') is not null drop table #{{table}}
@mattmc3
mattmc3 / drop_db.sql
Created April 6, 2017 00:55
Postgres drop database
select pg_terminate_backend(pid) from pg_stat_activity where datname='$DB_NAME';
DROP DATABASE "$DB_NAME";
@mattmc3
mattmc3 / what_string_would_get_truncated.sql
Created April 6, 2017 01:07
MSSQL Find dreaded 'string or binary data will be truncated' error
select 'union all select ''' + isc.COLUMN_NAME + ''' as cn, max(len(' + isc.COLUMN_NAME + ')) as length, ' + convert(varchar(5), isc.CHARACTER_MAXIMUM_LENGTH) + ' as maxlen from {{table}} having max(len(' + isc.COLUMN_NAME + ')) > ' + convert(varchar(5), isc.CHARACTER_MAXIMUM_LENGTH) + ''
from INFORMATION_SCHEMA.COLUMNS isc
where isc.TABLE_NAME = '{{table}}'
and isc.CHARACTER_MAXIMUM_LENGTH is not null
@mattmc3
mattmc3 / strip_header_line.bash
Created April 6, 2017 01:10
Bash - remove first line of file
tail -n +2 $FILE > $FILE.new
@mattmc3
mattmc3 / shebang.bash
Created April 6, 2017 01:11
Bash - shebang
#!/usr/bin/env bash
@mattmc3
mattmc3 / shebang.py
Created April 6, 2017 01:11
Python - shebang
#!/usr/bin/env python
@mattmc3
mattmc3 / shebang.awk
Created April 6, 2017 01:12
Awk - shebang
#!/usr/bin/env awk -f
@mattmc3
mattmc3 / add_gitkeep_files.bash
Created April 6, 2017 01:14
Git - add .gitkeep to empty dirs
find . -type d ! -path "*.git*" -empty -exec touch '{}'/.gitkeep \;
@mattmc3
mattmc3 / find_and_del.bash
Created April 6, 2017 01:16
Bash - find and delete files
# use .DS_Store as notorious example
find . -type f -name '.DS_Store' -delete
@mattmc3
mattmc3 / find_and_del.bash
Last active April 6, 2017 01:21
Bash - find, print, and delete files
# use infamous .DS_Store as example. Use `-type d` for dirs
find . -type f -name '.DS_Store' -print -exec rm -rf {} \;