Skip to content

Instantly share code, notes, and snippets.

View mattmc3's full-sized avatar
🐍
Python!

mattmc3 mattmc3

🐍
Python!
View GitHub Profile
@mattmc3
mattmc3 / tasks.json
Created April 6, 2017 00:41
VSCode tasks for Golang
// See http://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
// ${workspaceRoot} the path of the folder opened in VS Code
// ${file} the current opened file
// ${fileBasename} the current opened file's basename
// ${fileDirname} the current opened file's dirname
// ${fileExtname} the current opened file's extension
// ${cwd} the task runner's current working directory on startup
{
"version": "0.1.0",
@mattmc3
mattmc3 / tasks.json
Created April 6, 2017 00:43
VSCode tasks for Python 3
// # Be sure to set up virtualenv
// python3 -m venv .env
// source .env/bin/activate
// pip install --upgrade pip
// pip freeze > requirements.txt
//
// ${workspaceRoot} the path of the folder opened in VS Code
// ${file} the current opened file
// ${fileBasename} the current opened file's basename
// ${fileDirname} the current opened file's dirname
@mattmc3
mattmc3 / tasks.json
Created April 6, 2017 00:44
VSCode tasks for running a Makefile
// Makefile
// ${workspaceRoot} the path of the folder opened in VS Code
// ${file} the current opened file
// ${fileBasename} the current opened file's basename
// ${fileDirname} the current opened file's dirname
// ${fileExtname} the current opened file's extension
// ${cwd} the task runner's current working directory on startup
{
"version": "0.1.0",
"command": "bash",
@mattmc3
mattmc3 / gen_count_star.sql
Last active March 29, 2018 17:04
SQL Generate count(*) for all tables
select case when ist.ord = 1 then '' else 'union all ' end + 'select ''' + ist.TABLE_SCHEMA + '.' + ist.TABLE_NAME + ''' as table_name, count(*) as cnt from [' + ist.TABLE_SCHEMA + '].[' + ist.TABLE_NAME + ']'
from (
select *, row_number() over (order by x.table_schema, x.table_name) as ord
from INFORMATION_SCHEMA.TABLES x
where x.TABLE_TYPE = 'BASE TABLE'
and x.TABLE_NAME not like 'MSreplication[_]%'
and x.TABLE_NAME not like 'MSsaved%'
and x.TABLE_NAME not like 'MSsubscription[_]%'
and x.TABLE_NAME not like 'MSsnapshot%'
) ist
@mattmc3
mattmc3 / drop_tbl.sql
Created April 6, 2017 00:49
MSSQL drop table if exists
if object_id('{{schema}}.{{table}}') is not null drop table {{schema}}.{{table}}
@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 / better_isnumeric.sql
Last active April 10, 2017 16:04
MSSQL robust isnumeric() for try_cast test prior to 2012
select
@val as str_val
,case
when isnumeric(@val + '.0e0') = 1 then
case
when convert(float, @val) between 0 and 255
then cast(@val as tinyint)
else null
end
else null
@mattmc3
mattmc3 / drop_proc_if_exists.sql
Last active April 6, 2017 20:44
MSSQL drop proc if exists
if objectproperty(object_id('{{schema}}.{{proc_name}}'), 'IsProcedure') is not null drop proc {{schema}}.{{proc_name}}
@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