Skip to content

Instantly share code, notes, and snippets.

View alastairs's full-sized avatar

Alastair Smith alastairs

View GitHub Profile
@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)
}
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 } |% {
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) {
$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"
@alastairs
alastairs / debug.log
Last active December 17, 2015 08:09
SaveAllTheTime debug.log
2013-05-13 21:44:23.1672 - WARN: *** Detected Unit Test Runner, setting MainThreadScheduler to Immediate ***
2013-05-13 21:44:23.1825 - WARN: If we are not actually in a test runner, please file a bug
2013-05-13 21:44:23.2136 - ERROR: Couldn't load settings, creating them from scratch
EXCEPTION: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\alastair\AppData\Roaming\SaveAllTheTime\settings.json'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.StreamReader
@alastairs
alastairs / top-left-accumulation.js
Last active May 13, 2016 20:11
Artificial Intelligence implementations for 2048
function Ai() {
this.UP = 0;
this.RIGHT = 1;
this.DOWN = 2;
this.LEFT = 3;
this.ORIGIN =
this.init = function() {
this.move = this.UP;
@alastairs
alastairs / _init.ps1
Last active November 17, 2016 16:02
Code snippets for "How we do builds"
function global:build() {
 param(
  # The Tasks to execute. An empty list runs the 
  # default task, as defined in build.ps1
  [string[]] $Tasks = @(),
  [string] $Configuration = "Release",
  [string] $BuildNumber = '0'
  )
RestoreBuildLevelPackages
@alastairs
alastairs / Declarative.cs
Created February 5, 2017 19:45
Express Yourself! Motivating Example
public int WhatDoIDo(int[] numbers)
{
return numbers.Count(i => i % 2 == 0)
}
@alastairs
alastairs / New-K8sClsuter.ps1
Created May 6, 2017 11:50
Deploy a new Kubernetes cluster to Azure Container Service using the Azure Command Line 2.0
param(
[Parameter(Mandatory=$true)]
[string]$SshKeyFile,
[Parameter(Mandatory=$true)]
[string]$Location = "westeurope",
[string]$ResourceGroup = "k8s-$Location",
[string]$ClusterName = "k8s-$Location",
[string]$DnsPrefix = "ch360",
[int]$MasterCount = 1,
[int]$AgentCount = 3,
@alastairs
alastairs / GitHubSignIn.ts
Created May 6, 2017 14:26
Failing GitHub authorisation
import { ScreenCap } from "../../helpers/ScreenCap"
import { Casper } from "casperjs"
export class GitHubSignIn {
private readonly OAUTH_AUTHORISATION_FORM = '.oauth-review-permissions form[method=post]';
constructor(private casper: Casper, private screencap: ScreenCap) { }
login(username: string, password: string): void {
this.casper