Skip to content

Instantly share code, notes, and snippets.

View theorigin's full-sized avatar

Andy Robinson theorigin

View GitHub Profile
@theorigin
theorigin / SQLServer-APIPost.sql
Last active January 9, 2024 12:10
SQL Server code to POST to an API
DECLARE @Object AS INT;
DECLARE @ResponseText AS VARCHAR(8000);
DECLARE @Body AS VARCHAR(8000) =
'{
"what": 1,
"ever": "you",
"need": "to send as the body"
}'
EXEC sp_OACreate 'MSXML2.XMLHTTP', @Object OUT;
@theorigin
theorigin / JSON-Date-Validate.js
Created August 19, 2014 15:40
Validation of date in JSON using JSON schema
{
"$schema": "http://json-schema.org/draft-03/schema#",
"type": "object",
"properties": {
"orderDate": {
"type": "string",
"format": "date"
}
}
@theorigin
theorigin / RollTheDice.cs
Created May 29, 2021 10:15
Roll the dice
void Main()
{
var numberOfDice = 2;
var numberOfRolls = 2;
Console.WriteLine("Roll the Dice");
Console.WriteLine("=============");
Console.WriteLine("How many dice do you want to roll?");
@theorigin
theorigin / merge_lookups.sql
Created July 23, 2012 07:42
SQL Server MERGE statement
MERGE INTO Lookups AS Target
USING (VALUES
(0, N'Lookup Number 0'),
(1, N'Lookup Number 1'),
(2, N'Lookup Number 2'),
(3, N'Lookup Number 3'),
(4, N'Lookup Number 4'),
(5, N'Lookup Number 5'),
(6, N'Lookup Number 6')
)
@theorigin
theorigin / Update-CloudFrontDistribution-OriginPath.ps1
Created April 17, 2018 08:13
PS script to update cloudfront distribution
<#
.SYNOPSIS
Updates the Cloudfront distribution origin path with the supplied version number
.DESCRIPTION
Given a version number this script will retrieve the current distribution, extract the ETAG value, update the current-distribution.json file with the version number (for the OriginPath),
save the JSON and then update the distribution using the new file. A CloudFront invalidation is then created to expire all edge caches.
.PARAMETER version
A value indicating the version number to be used e.g. 1.12.1
<!DOCTYPE html>
<html>
<head>
<script src="https://npmcdn.com/react@0.14.2/dist/react.min.js"></script>
<script src="https://npmcdn.com/react-dom@0.14.2/dist/react-dom.min.js"></script>
<script src="https://npmcdn.com/google-map-react@0.14.6/dist/GoogleMapReact.js"></script>
<meta charset="utf-8">
@theorigin
theorigin / SPTemplate.sql
Created January 10, 2014 17:11
TSQL stored procedure template
CREATE PROCEDURE [dbo].[xxx]
AS
BEGIN
SET NOCOUNT ON;
DECLARE @transactionName VARCHAR(32) = REPLACE((CAST(NEWID() AS VARCHAR(36))),'-','')
BEGIN TRY
DECLARE @TranCounter INT;
@theorigin
theorigin / IFile.cs
Created October 29, 2013 13:41
An interface definition for the System.IO.File class. Allows mocking of code that uses any of these methods
namespace namespace VS.Library.Interfaces
{
public interface IFile
{
void Move(string sourceFileName, string destFileName);
bool Exists(string fileName);
void Delete(string fileName);
}
@theorigin
theorigin / IDirectory.cs
Created October 29, 2013 13:41
An interface definition for the System.IO.Directory class. Allows mocking of code that uses any of these methods
namespace VS.Library.Interfaces
{
using System.Collections.Generic;
using System.IO;
using System.Security.AccessControl;
public interface IDirectory
{
bool Exists(string path);
@theorigin
theorigin / DatasetToJson.cs
Created October 3, 2013 16:36
Converts a dataset (containing many datatables) into a List<Dictionary<string, object>> which can be converted into JSON and returned from an API. Stored procedure returns the required data in a known format which is then read in C# and push out in JSON. Should be fairly generic i.e. what ever you return from the database will be converted and s…
private IEnumerable<Dictionary<string, object>> DataSetToOrder(DataSet orderDetails)
{
var s = orderDetails.Tables[0].Rows[0][0].ToString();
var tableDefinitions = s.Replace(", ", ",").Split(',');
var tables = tableDefinitions.Select(tableDefinition => tableDefinition.Split('/')).Select(temp => new Tuple<int, int, string>(int.Parse(temp[0]), int.Parse(temp[1]), temp[2])).ToList();
var parent = tables.First(t => t.Item1.Equals(1));