Skip to content

Instantly share code, notes, and snippets.

View alastairs's full-sized avatar

Alastair Smith alastairs

View GitHub Profile
$encryptionKey = (Get-Content "C:\EncryptionKey.txt")
$encryptionKey = [System.Text.Encoding]::Unicode.GetBytes($encryptionKey)
function Get-MyCredential {
$myPassword = Get-PasswordAsSecureString
return new-object System.Management.Automation.PSCredential "My.Username", $domainAdminPassword
}
function Get-PasswordAsSecureString {
return ConvertTo-SecureString -Key $encryptionKey "Place string representation of encrypted password here"
param([String]$XenServerPoolMaster, [String]$TemplateName, [int]$NumberOfBuildAgents)
Add-PSSnapIn XenServerPSSnapin
. ".\credentials.ps1"
. ".\teamcity.ps1"
Connect-XenServer -Server $XenServerPoolMaster -Creds (Get-XenServerCredential) -NoWarnNewCertificates -NoWarnCertificates
function private:New-BuildAgentVM([string]$XenServerPoolMaster, [string]$templateName, [int]$buildAgentIndex) {
param([string]$XenServerPoolMaster)
Add-PSSnapIn XenServerPSSnapin
. ".\credentials.ps1"
. ".\teamcity.ps1"
Connect-XenServer -Server $XenServerPoolMaster -Creds (Get-XenServerCredential) -NoWarnNewCertificates -NoWarnCertificates
Get-XenServer:VM -Server $XenServerPoolMaster |? { $_.tags -contains 'active' } |? { $_.name_label -ne $env:COMPUTERNAME } |% {
@alastairs
alastairs / Complete a unit of work.cs
Created July 29, 2012 12:14
RavenDB blog post samples
using (var session = documentStore.OpenSession())
{
session.Load<Concert>(1)
}
@alastairs
alastairs / gist:1219663
Created September 15, 2011 16:04
Initialise a collection to an extension of another collection
private static readonly IEnumerable<Foo> BaseCollectionOfFoo = new List<Foo>
{
new Foo(1),
new Foo(2),
new Foo(3)
};
private static readonly IEnumerable<Foo> AllFoo = new List<Foo>(BaseCollectionOfFoo)
{
new Foo(4)
@alastairs
alastairs / get-scriptdirectory.ps1
Created September 13, 2011 21:55
Function to get the directory in which this script resides.
function Get-ScriptDirectory {
$invocation = (Get-Variable MyInvocation -Scope 1).Value
$script = [IO.FileInfo] $invocation.MyCommand.Path
if ([IO.File]::Exists($script)) {
return (Split-Path $script.Fullname)
} else {
return $null
}
}
@alastairs
alastairs / gist:1152445
Created August 17, 2011 19:57
Pretty-print JSON
public string GetPrettyPrintedJson(string json)
{
dynamic parsedJson = JsonConvert.DeserializeObject(json);
return JsonConvert.SerializeObject(parsedJson, Formatting.Indented);
}
@alastairs
alastairs / FirstImpl.cs
Created August 14, 2011 17:35
Leap Year Calculator Second Attempt
public static bool IsLeapYear(int year)
{
return true;
}
@alastairs
alastairs / acceptance_tests.cs
Created August 14, 2011 17:31
Leap Year Calculator First Attempt
[TestFixture]
public class LeapYearCalculatorAcceptanceTests
{
[Test]
public void TestThat_IsLeapYear_ShouldReturnTrue_WhenTheGivenYearIsATypicalLeapYear()
{
const int typicalLeapYear = 1996;
var isLeapYear = LeapYearCalculator.IsLeapYear(typicalLeapYear);
@alastairs
alastairs / gist:1142957
Created August 12, 2011 20:45
Leap Year kata
Write a function that returns true or false depending on whether its input integer is a leap year or not.
A leap year is divisible by 4, but is not otherwise divisible by 100 unless it is also divisible by 400.
2001 is a typical common year
1996 is a typical leap year
1900 is an atypical common year
2000 is an atypical leap year