Skip to content

Instantly share code, notes, and snippets.

🐍
Python!

mattmc3 mattmc3

🐍
Python!
Block or report user

Report or block mattmc3

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mattmc3
mattmc3 / drop_temp_tbl.sql
Created Apr 6, 2017
MSSQL Drop temp table if exists
View drop_temp_tbl.sql
if object_id('tempdb..#{{table}}') is not null drop table #{{table}}
@mattmc3
mattmc3 / drop_db.sql
Created Apr 6, 2017
Postgres drop database
View drop_db.sql
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 Apr 6, 2017
MSSQL Find dreaded 'string or binary data will be truncated' error
View what_string_would_get_truncated.sql
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 Apr 6, 2017
Bash - remove first line of file
View strip_header_line.bash
tail -n +2 $FILE > $FILE.new
View shebang.bash
#!/usr/bin/env bash
@mattmc3
mattmc3 / shebang.py
Created Apr 6, 2017
Python - shebang
View shebang.py
#!/usr/bin/env python
View shebang.awk
#!/usr/bin/env awk -f
@mattmc3
mattmc3 / add_gitkeep_files.bash
Created Apr 6, 2017
Git - add .gitkeep to empty dirs
View add_gitkeep_files.bash
find . -type d ! -path "*.git*" -empty -exec touch '{}'/.gitkeep \;
@mattmc3
mattmc3 / find_and_del.bash
Created Apr 6, 2017
Bash - find and delete files
View find_and_del.bash
# use .DS_Store as notorious example
find . -type f -name '.DS_Store' -delete
@mattmc3
mattmc3 / find_and_del.bash
Last active Apr 6, 2017
Bash - find, print, and delete files
View find_and_del.bash
# use infamous .DS_Store as example. Use `-type d` for dirs
find . -type f -name '.DS_Store' -print -exec rm -rf {} \;
You can’t perform that action at this time.