Skip to content

Instantly share code, notes, and snippets.

View joelwitherspoon's full-sized avatar
👁️
Learning Python

Joel Witherspoon joelwitherspoon

👁️
Learning Python
  • Mimir Data Products
  • California
View GitHub Profile
@joelwitherspoon
joelwitherspoon / Generate_Random_Dates.sql
Created November 22, 2024 22:26
SQL - Generate random dates
DECLARE @fn nvarchar(100), @ln nvarchar(100), @join_date datetime2(0), @datediff bigint, @datetime datetime2(0);
DECLARE @join_date_upper_limit datetime2(0), @join_date_lower_limit datetime2(0);
SET @join_date_lower_limit = '2002-11-01 00:00:00';
SET @join_date_upper_limit = GETDATE();
SELECT @datediff = DATEDIFF(DAY,@join_date_lower_limit,@join_date_upper_limit)
@joelwitherspoon
joelwitherspoon / comment_block_1.txt
Created August 8, 2024 19:08
Common header block
/***************************************************************************************************
Procedure: dbo.usp_DoSomeStuff
Create Date: 2018-01-25
Author: Joe Expert
Description: Verbose description of what the query does goes here. Be specific and don't be
afraid to say too much. More is better, than less, every single time. Think about
"what, when, where, how and why" when authoring a description.
Call by: [schema.usp_ProcThatCallsThis]
[Application Name]
[Job]
DECLARE @login sysname = N'name of user';
DECLARE @sql nvarchar(max),
@sid varbinary(85),
@coll nvarchar(64) = N'COLLATE SQL_Latin1_General_CP1_CI_AS';
SELECT @sid = [sid] FROM sys.server_principals AS dp WHERE name = @login;
;WITH d AS
(
@joelwitherspoon
joelwitherspoon / DirToFile.ps1
Last active October 8, 2021 15:54
Powershell get directory list of files into text file
$list = Get-ChildItem -Path .\B* -Recurse | `
Where-Object { $_.PSIsContainer -eq $false}
write-host "`nTotal : "$list.Count "files `n"
ForEach($n in $list){
$n.Name | Out-File -Append 'Y:\BCDEFiles\BList.txt'
}
@joelwitherspoon
joelwitherspoon / MSSQL_EmptyTables.sql
Created September 20, 2021 15:04
MSSQL Server Find empty tables based on index
select schema_name(tab.schema_id) + '.' + tab.name as [table]
from sys.tables tab
inner join sys.partitions part
on tab.object_id = part.object_id
where part.index_id IN (1, 0) -- 0 - table without PK, 1 table with PK
group by schema_name(tab.schema_id) + '.' + tab.name
having sum(part.rows) = 0
order by [table]
@joelwitherspoon
joelwitherspoon / RowSize.sql
Created September 9, 2021 16:55
Creates a list of row sizes in a database
create table ##tmpRowSize (TableName varchar(100),RowSizeDefinition int)
exec sp_msforeachtable 'INSERT INTO ##tmpRowSize Select ''?'' As TableName, SUM(C.Length) as Length from dbo.SysColumns C where C.id = object_id(''?'') '
select * from ##tmpRowSize order by RowSizeDefinition desc
drop table ##tmpRowSize
@joelwitherspoon
joelwitherspoon / DataDictQuery.sql
Created September 2, 2021 20:50
Database dictionary query
SELECT IST.TABLE_NAME AS [Table_Name]
, UPPER(IST.TABLE_SCHEMA) AS [Table_Schema]
, ISC.COLUMN_NAME AS [Column_Name]
, ISC.IS_NULLABLE AS [ISNULL?]
,
CASE
WHEN ISC.DATA_TYPE LIKE 'datetime2' OR ISC.DATA_TYPE LIKE 'datetime' THEN UPPER(ISC.DATA_TYPE)+'('+ UPPER(CONVERT(VARCHAR,ISC.DATETIME_PRECISION)) +')'
WHEN ISC.DATA_TYPE LIKE 'varchar' THEN UPPER(ISC.DATA_TYPE)+'('+ CONVERT(VARCHAR,ISC.CHARACTER_MAXIMUM_LENGTH )+')'
WHEN ISC.DATA_TYPE NOT LIKE 'varchar' THEN UPPER(ISC.DATA_TYPE)+' ('+ CONVERT(NVARCHAR,ISC.NUMERIC_PRECISION) +','+ CONVERT(NVARCHAR,ISC.NUMERIC_SCALE) +')'
@joelwitherspoon
joelwitherspoon / conv.OracleTime2SQLTime.txt
Last active August 28, 2021 00:26
SQL- Convert Oracle TIMESTAMP to SQL Server DATETIME2(7)
SELECT CONVERT(DATETIME2(7), CAST(CAST(SUBSTRING(@OracleTimestamp,1,9) AS DATE) AS VARCHAR) +' '+ CAST(REPLACE(SUBSTRING(@OracleTimestamp,11,8),'.',':')+''+SUBSTRING(@OracleTimestamp,19,6)+' '+SUBSTRING(@OracleTimestamp,27,2) AS VARCHAR),0)
@joelwitherspoon
joelwitherspoon / css_resources.md
Created July 15, 2014 03:03 — forked from jookyboi/css_resources.md
CSS libraries and guides to bring some order to the chaos.

Libraries

  • 960 Grid System - An effort to streamline web development workflow by providing commonly used dimensions, based on a width of 960 pixels. There are two variants: 12 and 16 columns, which can be used separately or in tandem.
  • Compass - Open source CSS Authoring Framework.
  • Bootstrap - Sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development.
  • Font Awesome - The iconic font designed for Bootstrap.
  • Zurb Foundation - Framework for writing responsive web sites.
  • SASS - CSS extension language which allows variables, mixins and rules nesting.
  • Skeleton - Boilerplate for responsive, mobile-friendly development.

Guides

@joelwitherspoon
joelwitherspoon / rails_resources.md
Created July 15, 2014 03:03 — forked from jookyboi/rails_resources.md
Rails-related Gems and guides to accelerate your web project.

Gems

  • Bundler - Bundler maintains a consistent environment for ruby applications. It tracks an application's code and the rubygems it needs to run, so that an application will always have the exact gems (and versions) that it needs to run.
  • rabl - General ruby templating with json, bson, xml, plist and msgpack support
  • Thin - Very fast and lightweight Ruby web server
  • Unicorn - Unicorn is an HTTP server for Rack applications designed to only serve fast clients on low-latency, high-bandwidth connections and take advantage of features in Unix/Unix-like kernels.
  • SimpleCov - SimpleCov is a code coverage analysis tool for Ruby 1.9.
  • Zeus - Zeus preloads your Rails app so that your normal development tasks such as console, server, generate, and specs/tests take less than one second.
  • [factory_girl](h