Skip to content

Instantly share code, notes, and snippets.

View anderssonjohan's full-sized avatar
👨‍🚒

Johan Andersson anderssonjohan

👨‍🚒
View GitHub Profile
@anderssonjohan
anderssonjohan / Chunk list of items.cs
Created April 17, 2013 23:08
A pretty basic chunk method I use to chunk, or split, lists of items
public static IEnumerable<T[]> Chunk<T>( this T[] source, int size )
{
var acc = new List<T>( size );
for ( var i = 0; i < source.Length; i++ )
{
acc.Add( source[i] );
if ( acc.Count < size && i < source.Length - 1 )
continue;
yield return acc.ToArray();
acc.Clear();
@anderssonjohan
anderssonjohan / ErrorReporterTests.cs
Created March 23, 2013 23:18
Saturday night coding... faking HTTP and SMTP all night long.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Mail;
using NUnit.Framework;
using RemoteX.Libraries.ClientDataAccess.Entities.DTO;
using RemoteX.Libraries.Integration;
using RemoteX.Libraries.Integration.Testing;
using Should;
@anderssonjohan
anderssonjohan / Setup-IIS.ps1
Created February 27, 2013 14:05
A pretty simple script we use at RemoteX to provision IIS on our servers
param( $logsDirectory, $compressionDirectory )
$ScriptDir = $MyInvocation.MyCommand.Path | split-path
# https://github.com/remotex/Scripts/tree/master/Windows
Set-Alias enableFeature $ScriptDir\Enable-WindowsFeature.ps1
$wantedFeatures = @()
# install IIS Role
$wantedFeatures += "IIS-WebServerRole"
$wantedFeatures += "IIS-WebServer"
@anderssonjohan
anderssonjohan / testargs.ps1
Last active December 12, 2015 07:48
Upgraded to PowerShell 3.0 and found a piece in one of our scripts that wasn't compatible. Here is a sample with the corrected code which works in both 2.0 and 3.0. Conclusion: Do not use $MyInvocation.BoundParameters. However, $PSBoundParameters will work on both v2 and v3.
param(
[string] $foo,
[int] $bar
)
$arguments = ""
# Change to $PSBoundParameters..
$MyInvocation.BoundParameters.Keys | %{
Write-Host "key $_"
# $MyInvocation.BoundParameters.Item( string key ) fails in PowerShell 3.0:
# $paramValue = $MyInvocation.BoundParameters.Item( $_ )
@anderssonjohan
anderssonjohan / Install-ARRFromWeb.ps1
Created January 19, 2013 21:01
A basic PowerShell script used to push IIS 7 Application Request Routing (tl;dr; reverse proxy features for UrlRewrite) to several servers. Assumptions: - cURL is in the path on the source machine - servers are specified as objects on the pipeline with properties telling the unc path and local path to a writable network share on the server - Win…
param(
[parameter(mandatory=$true, valuefrompipeline=$true)]
$TargetHost,
[switch] $force
)
begin {
$packages = @( `
@{ Name = "rewrite.msi"; Url = "http://download.microsoft.com/download/6/7/D/67D80164-7DD0-48AF-86E3-DE7A182D6815/rewrite_2.0_rtw_x64.msi" }, `
@{ Name = "webpi.msi"; Url = "http://download.microsoft.com/download/B/0/0/B00FEF21-79DE-48B0-8731-F9CFE70CE613/WebPlatformInstaller_3_10_amd64_en-US.msi" }, `
@{ Name = "webfarm.msi"; Url = "http://download.microsoft.com/download/3/4/1/3415F3F9-5698-44FE-A072-D4AF09728390/webfarm_amd64_en-US.msi" }, `
@anderssonjohan
anderssonjohan / WordWrapTests.cs
Created November 3, 2010 10:38
Word wrap function in c#
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace WordWrapSnippet
{
[TestClass]
public class WordWrapTests
{
public static List<string> WordWrap( string text, int maxLineLength )