Skip to content

Instantly share code, notes, and snippets.

CREATE FUNCTION [dbo].[GetAge] (
@DOB AS DATE
,@EndDate AS DATE = NULL
)
RETURNS TINYINT
AS
BEGIN
DECLARE @Result AS TINYINT
IF (@EndDate IS NULL)
@kiwipiet
kiwipiet / GetIntegerSequence
Created August 19, 2014 04:22
Get a sequence of integer numbers, from 1 to @count
CREATE FUNCTION [dbo].[GetIntegerSequence]
(
@count INT
)
RETURNS TABLE
WITH SCHEMABINDING
AS RETURN
(
WITH C0 (c) AS (SELECT 1 UNION ALL SELECT 1)
,C1 (c) AS (SELECT 1 FROM C0 AS A CROSS JOIN C0 AS B)
CREATE FUNCTION [dbo].[GetWellingtonHolidays]
(
@startdate DATE,
@enddate DATE
)
RETURNS TABLE
WITH SCHEMABINDING
AS RETURN
(
WITH alldates ([date]) AS (
@kiwipiet
kiwipiet / 0_reuse_code.js
Created October 16, 2015 01:21
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
/// <summary>
/// Easily get access to embedded resources
/// </summary>
internal static class EmbeddedResource
{
/// <summary>
/// Return a resource stream
/// </summary>
/// <param name="assembly">The assembly the resource is embedded in</param>
/// <param name="name">FQDN or the resource</param>
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
namespace KiwiPiet
{
[Serializable]
[DebuggerDisplay("{DisplayName} - {Value}")]
@kiwipiet
kiwipiet / Enumeration PCL
Created July 18, 2016 20:22
Enumeration class that is PCL compatible
[DataContract]
[DebuggerDisplay("{DisplayName} - {Value}")]
public abstract class Enumeration<TEnumeration> : Enumeration<TEnumeration, int> where TEnumeration : Enumeration<TEnumeration>
{
protected Enumeration(int value, string displayName) : base(value, displayName) { }
public static TEnumeration FromInt32(int value)
{
return FromValue(value);
}
@kiwipiet
kiwipiet / DefaultFilterProvider
Created July 19, 2016 20:25
Applies FilterAttribute T to all MVC controller actions in case action or it's controller do not have FilterAttribute derived from BaseT
/// <summary>
/// Applies FilterAttribute T to all MVC controller actions
/// in case action or it's controller do not have FilterAttribute derived from BaseT
/// </summary>
/// <example>
/// <![CDATA[
/// FilterProviders.Providers.Add(new DefaultFilterProvider<NoAuthorizeAttribute, AuthorizeUserAttribute>());
/// ]]>
/// </example>
/// <typeparam name="T">FilterAttribute to be applied</typeparam>
@kiwipiet
kiwipiet / GoogleServices.cs
Created July 26, 2016 21:15
GoogleServices.IsGoogleServicesAvailable
using System;
using Android.Content;
using Android.Gms.Common;
public static class GoogleServices
{
private static Context _context;
public static void Init(Context context)
{
_context = context;
-- #########################################################
-- Author: www.sqlbook.com
-- Copyright: (c) www.sqlbook.com. You are free to use and redistribute
-- this script as long as this comments section with the
-- author and copyright details are not altered.
-- Purpose: For a specified user defined table (or all user defined
-- tables) in the database this script generates 4 Stored
-- Procedure definitions with different Procedure name
-- suffixes:
-- 1) List all records in the table (suffix of _lst)