Skip to content

Instantly share code, notes, and snippets.

View theorigin's full-sized avatar

Andy Robinson theorigin

View GitHub Profile
@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 / 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 / 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;
var compareResult = new KellermanSoftware.CompareNetObjects.CompareLogic().Compare(actualResult, expectedResult);
Assert.IsTrue(compareResult.AreEqual, compareResult.DifferencesString);
@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 / UrlHelperExtensions.cs
Last active August 29, 2015 13:57
Add a datetime suffix to style/script tags in HTML to force a refresh when they change
public static class UrlHelperExtensions
{
public static string ContentWithHash(this UrlHelper urlHelper, string contentPath)
{
var virtualFile = urlHelper.Content(contentPath);
var actualFile = urlHelper.RequestContext.HttpContext.Server.MapPath(contentPath);
var creationDateTime = (File.Exists(actualFile) ? File.GetLastWriteTimeUtc(actualFile) : new DateTime()).ToString("yyyyddMMHHmmss");
SELECT
t.NAME AS TableName,
s.Name AS SchemaName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM
sys.tables t
INNER JOIN
@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);
}