Skip to content

Instantly share code, notes, and snippets.

@kdarty
kdarty / Delete-Duplicate-Records.sql
Created July 2, 2014 14:58
Delete Duplicate Records in SQL Server Keeping only One
--Description: Delete Duplicate Records in SQL Server Keeping only One
--Author: Ben Thul
--Source: http://stackoverflow.com/questions/6025367/t-sql-deleting-all-duplicate-rows-but-keeping-one
--NOTE: A common use-case is that "foo, bar" are the group identifier and "baz" is some sort of time stamp. In order to keep the latest, you'd do ORDER BY baz desc)
WITH cte AS (
SELECT[foo], [bar],
row_number() OVER(PARTITION BY foo, bar ORDER BY baz) AS [rn]
FROM TABLE
)
@kdarty
kdarty / vanilla.css
Created February 10, 2015 18:33
Vanilla CSS From http://www.cssreset.com/scripts/vanilla-css-un-reset/ to be used after a CSS Reset to define "default" styles for all.
/**
* Vanilla CSS 1.0.2
* http://cssreset.com
*/
body {
font: 9pt/1.5em sans-serif;
}
pre, code, tt {
font: 1em/1.5em 'Andale Mono', 'Lucida Console', monospace;
}
@kdarty
kdarty / Customer.js
Created March 10, 2015 17:52
Basic Namespace Example in JavaScript. (FYI: This dates back to a Google+ Discussion from 2011)
"use strict";
var ACME = {};
ACME.Web = {};
ACME.Web.UI = {};
ACME.Web.UI.Customer = function () {
var FirstName, LastName, FullName;
FullName = function () {
return this.FirstName + " " + this.LastName;
@kdarty
kdarty / web.config
Created April 8, 2015 16:53
Prevent web.config Inheritance from Root Web Applications (for Virtual Path Applications)
<?xml version="1.0"?>
<configuration>
<!-- Disable Inheritance -->
<location path="." inheritInChildApplications="false">
<system.web>
<compilation debug="false" />
@kdarty
kdarty / OOP-GetterAndSetter-Demo.js
Last active September 1, 2015 19:44
Object Oriented JavaScript with Getters and Setters for Properties. This is but just one example that seems rather friendly and straight forward. #OOP
var Person = new function () {
var _firstName = null;
var _lastName = null;
// Public Properties
this.FirstName = {
get: function () {
return _firstName;
},
set: function (value) {
@kdarty
kdarty / IsNullOrEmpty.ExtensionMethod.cs
Last active September 4, 2015 17:48
Safely make sure that a List is not NULL or Empty in C#. The following Extension Method and corresponding sample code works well whether the List object has been initialized or not. The "!=null" ensures that the object is initialized and the ".Any()" makes sure that there are items in the List.
/// <summary>
/// Extension Metion to verify that a Generic List is not NULL or Empty
/// </summary>
/// <typeparam name="T">List Type</typeparam>
/// <param name="source"><see cref="List"/> Source</param>
/// <returns><see cref="bool"/> (true/false)</returns>
public static bool IsNullOrEmpty<T>(this List<T> source)
{
if (source != null && source.Any())
{
@kdarty
kdarty / Check-Max-Table-Column-Size.sql
Created October 8, 2015 18:02
If you are ever in a position where you need to migrate data from one SQL Server Database (or Table) to Another which differ in Column sizes (length of fields), use this script to determine the Max Length of each column to compare for your Migration Scripts. Once you know the Max Length of the Data you are getting, you can properly handle placin…
--Source Discussion: https://community.spiceworks.com/topic/131997-sql-copy-field-in-to-smaller-field
--Author: Jason Crider - https://twitter.com/jasoncrider
--Get MaxLength on all columns in a table
DECLARE @SQL VARCHAR(MAX)
DECLARE @TableName sysname
SET @TableName = 'INSERT_TABLENAME_HERE'
@kdarty
kdarty / Report-All-Unique-Constraints.sql
Last active November 3, 2015 14:14
The following SQL Script will retrieve a list of all "Unique" Constraints for a given Database. This is intended for use within SQL Server. Other Constraint Types that can be queried: Foreign Key and Primary Key
-- StackOverflow Discussion:
-- http://stackoverflow.com/questions/2675168/get-the-unique-constraint-columns-list-in-tsql
SELECT TC.CONSTRAINT_NAME,
CC.COLUMN_NAME,
TC.TABLE_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC
INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE CC
ON TC.CONSTRAINT_NAME = CC.CONSTRAINT_NAME
WHERE TC.CONSTRAINT_TYPE = 'Unique'
ORDER BY TC.Constraint_Name;
@kdarty
kdarty / Set-Max-Memory-SQL-Server.sql
Created November 10, 2015 12:58
If you find that processes running in SQL Server tend to make it peg out your system's available RAM it is likely because the default settings for SQL Server say "use all available RAM". While that is nice it is like having 5 children in the house and 4 pieces of candy and telling one of the children they can have all they want. Somebody in this…
/****************************************************************************************************************************/
/* Source Article: */
/* http://www.sqlservercentral.com/blogs/glennberry/2009/10/29/suggested-max-memory-settings-for-sql-server-2005_2F00_2008/ */
/****************************************************************************************************************************/
-- Turn on advanced options
EXEC sp_configure'Show Advanced Options',1;
GO
RECONFIGURE;
GO
@kdarty
kdarty / JSONDateHelper.js
Created November 12, 2015 18:43
A topic that comes up often is how to Convert a Date or DateTime to "JSON Date". While there really isn't such a thing as a "JSON Date" Format, what it really is is a UNIX Time Format. While there is a standardized "sortable" DateTime Format, this "JSON Date" Format works quite well when dealing with JavaScript.
// Convert DateTime to "JSON Date" Format
// Adapted From: http://overpie.com/javascript/articles/convert-datetime-to-JSON-datetime-format
function convertToJSONDate(strDate) {
var dt = new Date(strDate);
var newDate = new Date(Date.UTC(dt.getFullYear(), dt.getMonth(), dt.getDate(), dt.getHours(), dt.getMinutes(), dt.getSeconds(), dt.getMilliseconds()));
return newDate.getTime().toString();
}