Skip to content

Instantly share code, notes, and snippets.

View anderssonjohan's full-sized avatar
👨‍🚒

Johan Andersson anderssonjohan

👨‍🚒
View GitHub Profile
@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 )
@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 / 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 / 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 / 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 / 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 / StartsWithSubstringOrIndexOfTest.cs
Last active December 18, 2015 21:48
Which method is the fastest one of string StartsWith, Substring and IndexOf? (Spoiler: Substring)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace startswithorsubstring

Integratör sökes till RemoteX!

Vår duktiga, men inhyrda konsult/integratör, har lämnat oss pga flytt och nu jagar vi en ny person som tycker det är kul att koda kod, integrera system och inte är rädd för att möta likasinnade ute hos våra kunder och partners. Som anställd hos oss har man fördelar av den lilla organisationen i kombination med spännande kunder. Hos oss är det "högt i tak" och den person som vi anställer kommer att rapportera direkt till vår team lead för kundprojekt.

I kod används främst c# men vi har även med ruby, python, node.js, powershell där det lämpat sig bättre. Vi använder både PC och mac och vanligaste verktygen på utvecklingssidan är Visual Studio, Sublime och Webstorm.

Hos oss är den viktigaste egenskapen att leverera med enkelhet och effektivitet. Vi sätter ett högt värde på vår organisation och därmed vår förmåga att sprida kunskap inom den.

@anderssonjohan
anderssonjohan / generate-createscript.ps1
Created September 29, 2014 08:16
Sample script we use at RemoteX to generate a SQL file with the database schema. We call this script each time we make a change script (migration), which will be used when setting up new DB instances rather than executing all the change scripts.
param(
[parameter(mandatory=$false)]
$sqlInstance = "(local)",
[parameter(mandatory=$false)]
$database,
[switch] $silent
)
$csFilePath = join-path -resolve $PSScriptRoot "Services/RESTService/Service/connectionstrings.config"
$CreateTablesSql = join-path -resolve $PSScriptRoot "Setup/SetupSkeleton/DB/Schema/CreateScripts/CreateTables.sql"
@anderssonjohan
anderssonjohan / profile.ps1
Created March 31, 2015 16:27
Profile.ps1 that fixes the problem with missing PSDrives when running Powershell with elevated privileges
# Reconnect PSDrives for network connections when running with elevated privileges
# Fixes http://stackoverflow.com/questions/4742992/cannot-access-network-drive-in-powershell-running-as-administrator
$elevated = (([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))
if( $elevated ) {
net use | ?{ $_ -match ":\s+\\\\" -and !$_.StartsWith("Unavailable") } | %{
$tokens = $_.split(":")
$psdrivename = $tokens[0][$tokens[0].length-1]
$path = $tokens[1].trim().split(" ")[0].trim()
if( !(get-psdrive | ?{ $_.Name -eq $psdrivename } )) {