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 / tasks.json
Created Apr 6, 2017
VSCode tasks for Golang
View tasks.json
// 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 Apr 6, 2017
VSCode tasks for Python 3
View tasks.json
// # 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 Apr 6, 2017
VSCode tasks for running a Makefile
View tasks.json
// 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 Mar 29, 2018
SQL Generate count(*) for all tables
View gen_count_star.sql
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 Apr 6, 2017
MSSQL drop table if exists
View drop_tbl.sql
if object_id('{{schema}}.{{table}}') is not null drop table {{schema}}.{{table}}
@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 / better_isnumeric.sql
Last active Apr 10, 2017
MSSQL robust isnumeric() for try_cast test prior to 2012
View better_isnumeric.sql
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 Apr 6, 2017
MSSQL drop proc if exists
View drop_proc_if_exists.sql
if objectproperty(object_id('{{schema}}.{{proc_name}}'), 'IsProcedure') is not null drop proc {{schema}}.{{proc_name}}
@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
You can’t perform that action at this time.