Skip to content

Instantly share code, notes, and snippets.

View gowon's full-sized avatar

Gowon Patterson gowon

View GitHub Profile
@gowon
gowon / excel-is08601.md
Created November 4, 2016 20:26
Parse ISO 8601 format date in excel with formula
@gowon
gowon / foreach-with-index.cs
Last active July 29, 2016 20:36
Getting an index on an enumeration.
// http://stackoverflow.com/a/77542
System.Collections.IEnumerable collection = Enumerable.Range(100, 10);
foreach (var o in collection.OfType<object>().Select((x, i) => new {x, i}))
{
Console.WriteLine("{0} {1}", o.i, o.x);
}
@gowon
gowon / fnCapitalize.sql
Created May 24, 2016 20:11
TSQL Capitalize String
CREATE FUNCTION [dbo].[Capitalize](@input VARCHAR(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN
RETURN UPPER(LEFT(@input, 1)) + LOWER(SUBSTRING(@input, 2, LEN(@input)))
END
@gowon
gowon / fnRegexReplace.sql
Created May 24, 2016 19:52
TSQL Regex Replace Scalar Function
CREATE FUNCTION [dbo].[RegexReplace](@input VARCHAR(MAX), @pattern VARCHAR(MAX), @replacement VARCHAR(MAX))
RETURNS VARCHAR(MAX)
AS
BEGIN
WHILE PATINDEX(@pattern, @input) > 0
SET @input = STUFF(@input, PATINDEX(@pattern, @input), 1, @replacement)
RETURN @input
END
//https://github.com/jakkaj/Xamling-Core/blob/918a7400583774106d5a9fba82a5f14656d52b06/XamlingCore/XamlingCore.Portable/Data/Mapper/SimpleMapper.cs
//From: http://stackoverflow.com/questions/930433/apply-properties-values-from-one-object-to-another-of-the-same-type-automaticall
//user: http://stackoverflow.com/users/428886/azerothian
//with Modifications for PCL by Jordan Knight.
using System;
using System.Linq;
using System.Reflection;
namespace XamlingCore.Portable.Data.Mapper
-- http://stackoverflow.com/a/8439798
DECLARE @Sql NVARCHAR(500) DECLARE @Cursor CURSOR
SET @Cursor = CURSOR FAST_FORWARD FOR
SELECT DISTINCT sql = 'ALTER TABLE [' + tc2.TABLE_NAME + '] DROP [' + rc1.CONSTRAINT_NAME + ']'
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc1
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc2 ON tc2.CONSTRAINT_NAME =rc1.CONSTRAINT_NAME
OPEN @Cursor FETCH NEXT FROM @Cursor INTO @Sql
@gowon
gowon / download.js
Created February 19, 2016 20:30
jQuery-powered AJAX downloader
// http://www.adequatelygood.com/JavaScript-Module-Pattern-In-Depth.html
// http://stackoverflow.com/a/20354786
var UTIL = (function (parent, $, undefined) {
var my = parent._private = parent._private || {};
my.iframeform = function (url, callback) {
var object = this;
object.time = new Date().getTime();
object.callback = callback || function (){};
@gowon
gowon / dotnet-development-stack.md
Last active February 10, 2016 17:10
Visual Studio Development Stack

.NET Development Stack

  • Visual Studio
  • ReSharper
  • Web Essentials
  • Indent Guides
  • OzCode?
  • GhostDoc?
@gowon
gowon / detectDataURL.js
Last active June 14, 2021 17:03 — forked from bgrins/detectDataURL.js
Detect if a string is a data URL. Doesn't try to parse it or determine validity, just a quick check if a string appears to be a data URL. See http://jsfiddle.net/bgrins/aZWTB/ for a demo.
// Detecting data URLs
// data URI - MDN https://developer.mozilla.org/en-US/docs/data_URIs
// The "data" URL scheme: http://tools.ietf.org/html/rfc2397
// Valid URL Characters: http://tools.ietf.org/html/rfc2396#section2
function isDataURL(s) {
return isDataURL.regex.test(s);
}
isDataURI.regex = /^\s*data:([a-z]+\/[a-z0-9\-]+(;[a-z\-]+\=[a-z\-]+)?)?(;base64)?,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i;
@gowon
gowon / index.html
Last active November 14, 2016 21:31
HTML5 Boilerplate
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Title</title>
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.js"></script>
<![endif]-->
</head>