Skip to content

Instantly share code, notes, and snippets.

@andrewthauer
andrewthauer / json-date.js
Last active June 10, 2020 01:32
Automatically parse MS / WCF json date strings to JS date objects (from http://www.asp.net/ajaxlibrary/jquery_webforms_serialize_dates_to_json.ashx)
if (this.JSON && !this.JSON.parseWithDate) {
var reISO = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/;
var reMsAjax = /^\/Date\((d|-|.*)\)[\/|\\]$/;
JSON.parseWithDate = function (json) {
/// <summary>
/// parses a JSON string and turns ISO or MSAJAX date strings
/// into native JS date objects
/// </summary>
/// <param name="json" type="var">json with dates to parse</param>
// Extend the String type to include a format method
String.prototype.format = function (format, args) {
var s = arguments[0];
for (var i = 0; i < arguments.length - 1; i++) {
var reg = new RegExp("\\{" + i + "\\}", "gm");
s = s.replace(reg, arguments[i + 1]);
}
return s;
}
@andrewthauer
andrewthauer / backup-mssql-db.sql
Created March 7, 2014 16:31
Backup an MS SQL database using using a timestamp
DECLARE @dbName nvarchar(max) = '<db_name>'
DECLARE @path nvarchar(max) = '<destination_path>'
DECLARE @date datetime = GETDATE()
DECLARE @timeStamp nvarchar(max) = CONVERT(nvarchar(max), @date, 112) + '-' + REPLACE(CONVERT(nvarchar(max), @date, 108), ':', '')
DECLARE @fileName nvarchar(max) = @path + @dbName + '_' + @timeStamp + '.bak'
BACKUP DATABASE @dbName TO DISK = @fileName
GO
// Create a jquery plugin that prints the given element.
jQuery.fn.print = function () {
// Ensure there is only a single element in the jquery collection
if (this.size() > 1) {
this.eq(0).print();
return;
}
else if (!this.size()) {
return;
}
@andrewthauer
andrewthauer / wsp-deploy.bat
Last active August 19, 2016 01:36
SharePoint WebPart deployment script
@echo off
rem ## --- User variables ---
@set URL=<deploy_site_url>
rem ## --- Other variables ---
@set PATH=C:\Program Files\Common Files\Microsoft Shared\web server extensions\14\BIN;%PATH%
@set FEATURE_NAME=<wsp_feature_name>
@set WSP_NAME=<wsp_name>
@set WSP_FILE=%WSP_NAME%
@andrewthauer
andrewthauer / mssql-search-all-tables.sql
Last active August 19, 2016 01:35
MS SQL Server - Search All Tables
DECLARE @SearchStr nvarchar(100)
SET @SearchStr='Search String'
BEGIN
CREATE TABLE #Results (ColumnName nvarchar(370), ColumnValue nvarchar(3630))
SET NOCOUNT ON
DECLARE
(*
Author: Anil Natha
Description:
This script toggles the visibility of hidden files in OS X. This includes
showing hidden files in Finder windows and on the desktop.
Last Updated: 2015-02-20
*)
tell application "System Events"
try
@andrewthauer
andrewthauer / fp-intro.js
Last active April 17, 2018 03:14
FP Intro with JS
// Imperative
let numbers = [];
for(let i = 0; i < 10; i++) {
numbers.push(i);
}
numbers //?
// Declaritive
;[...Array(10).keys()] //?
@andrewthauer
andrewthauer / dynamic-template-strings.js
Created April 17, 2018 03:33
JS Dynamic Template Strings
// --------------------------------
// Simple dynamic template string
const fillTemplate = function(templateString, templateVars){
return new Function('return `' + templateString + '`;').call(templateVars);
}
const templateString = "Hello ${this.name}!";
const templateVars = { name: 'world' }
fillTemplate(templateString, templateVars) //?
@andrewthauer
andrewthauer / PushTo-S3.ps1
Created April 28, 2018 15:29
Copy Files to S3
# PushTo-S3 script
#
# Description:
# Copies the source files to an S3 bucket
#
# Usage:
# PushTo-S3 -SourcePath [Path] -AwsAccessKey [KEY] -AwsSecretKey [SECRET] -AwsRegion [REGION] -S3BucketName [BUCKET]
#
# Example:
# ./PushTo-S3 -SourcePath "./dist" -AwsAccessKey "KEY" -AwsSecretKey "SECRET" -AwsRegion "REGION" -S3BucketName "BUCKET"