Skip to content

Instantly share code, notes, and snippets.

View DavidBrower's full-sized avatar

David Brower DavidBrower

  • Civica MDM
  • Glasgow, Scotland
View GitHub Profile
@DavidBrower
DavidBrower / Euler6.cs
Last active March 29, 2016 20:20
Sum of Squares vs Square of Sum
open System
let sumOfSquares =
[|1 .. 100|]
|> Array.map (fun x -> x * x)
|> Array.sum
let squareOfSum =
[|1 .. 100|]
|> Array.sum
@DavidBrower
DavidBrower / Euler7.fs
Created March 29, 2016 20:54
10,001st Prime
open System
let isPrime (n : int64) =
let upperBound = n |> float |> sqrt |> int64
seq {2L .. upperBound}
|> Seq.forall (fun x -> n % x <> 0L)
Seq.unfold (fun x -> Some(x, x + 1L)) 1L
|> Seq.filter isPrime
|> Seq.nth 10001
@DavidBrower
DavidBrower / Euler.hs
Created April 19, 2016 11:58
First Euler in Haskell
sum [x | x <- [1..999], mod x 3 == 0 || mod x 5 == 0]
@DavidBrower
DavidBrower / New.cs
Last active May 9, 2016 11:00
Generic Class Instantiator
/// <summary>
/// Instantiates TClass using a compiled lambda expression and caches it. This assumes a parameterless constructor.
/// </summary>
/// <typeparam name="TClass">The type of the class to be instantiated.</typeparam>
internal static class New<TClass> where TClass : class
{
public static readonly Func<TClass> Instance = Expression.Lambda<Func<TClass>>(Expression.New(typeof(TClass))).Compile();
/// <summary>
/// Allows a class to be instantiated using a parameterised constructor
@DavidBrower
DavidBrower / TypeSwitch.cs
Created May 16, 2016 10:01
TypeSwitch that returns a string
using System;
public static class TypeSwitch
{
public class CaseInfo
{
public bool IsDefault { get; set; }
public Type Target { get; set; }
public Func<object, string> Action { get; set; }
}
@DavidBrower
DavidBrower / SQLServerSpace.sql
Created October 19, 2016 09:08
Display Used and Available Space on SQL Server Database
select
name
, filename
, convert(decimal(12,2),round(a.size/128.000,2)) as FileSizeMB
, convert(decimal(12,2),round(fileproperty(a.name,'SpaceUsed')/128.000,2)) as SpaceUsedMB
, convert(decimal(12,2),round((a.size-fileproperty(a.name,'SpaceUsed'))/128.000,2)) as FreeSpaceMB
from dbo.sysfiles a
@DavidBrower
DavidBrower / RowCount.sql
Last active October 24, 2016 15:13
Gets the row count from a SQL Server with around two logical reads
DECLARE @TableName sysname
SET @TableName = 'table_name'
SELECT OBJECT_NAME(object_id) as [Table Name], format(SUM(row_count), '###,###') AS [Row Count]
FROM sys.dm_db_partition_stats
WHERE object_id = OBJECT_ID(@TableName)
AND index_id < 2
GROUP BY OBJECT_NAME(object_id);
@DavidBrower
DavidBrower / ValueObject.cs
Created September 1, 2015 16:24
ValueObject Base Class
public abstract class ValueObject<T> : IEquatable<T> where T : ValueObject<T>
{
private List<PropertyInfo> Properties { get; }
protected ValueObject()
{
Properties = new List<PropertyInfo>();
}
public override Boolean Equals(object obj)
@DavidBrower
DavidBrower / WindowsDeveloper.ps1
Created January 27, 2018 20:34
Set Up Windows Development Machine
# Set PowerShell execution policy
Set-ExecutionPolicy Unrestricted
Set-ExecutionPolicy Bypass -Scope Process -Force
# Install Chocolatey
ex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
# Install Boxstarter
. { iwr -useb http://boxstarter.org/bootstrapper.ps1 } | iex; get-boxstarter -Force
@DavidBrower
DavidBrower / windows.boxstarter
Last active January 27, 2018 20:48
Boxstarter for Windows Development
# Configure Windows
Set-WindowsExplorerOptions -EnableShowHiddenFilesFoldersDrives -EnableShowProtectedOSFiles -EnableShowFileExtensions -EnableShowFullPathInTitleBar
Update-ExecutionPolicy Unrestricted
# cinst -y Microsoft-Hyper-V-All -source windowsFeatures
#Visual Studio 2017 Community Edition
cinst -y visualstudio2017community