Skip to content

Instantly share code, notes, and snippets.

@adamjasinski
adamjasinski / base32_decode.py
Created February 12, 2022 17:34
Decodes a Base32 command-line parameter to UUID, using .NET Guid-compatible byte order
#!/usr/bin/python3
import uuid
import base64
import sys
def base32decode(s):
# NB - input should be a hex string of 26 characters
padded_bytes = f"{s}======".encode('ascii')
decoded_bytes = base64.b32decode(padded_bytes, casefold=True)
# NB - bytes_le uses .NET Guid-compatible byte order
@adamjasinski
adamjasinski / base32_encode.py
Created February 12, 2022 17:32
Encodes a UUID command-line parameter to Base32, using .NET Guid byte order
#!/usr/bin/python3
import uuid
import base64
import sys
def base32encode(guid):
# NB - bytes_le order matches .NET Guid.ToByteArray() order
# cf. https://docs.microsoft.com/en-us/dotnet/api/system.guid.tobytearray?view=net-6.0#system-guid-tobytearray
bytes = guid.bytes_le
encoded_bytes = base64.b32encode(bytes)
@adamjasinski
adamjasinski / StructureMapPolicyTest.cs
Last active July 30, 2019 10:02
StructureMap policies
using System;
using Xunit;
using StructureMap;
using StructureMap.Pipeline;
using System.Linq;
namespace StructureMapDemo
{
public class UnitTest1
{
@adamjasinski
adamjasinski / gist:b5f46c3935a39101128b9ef5cf32e6dc
Last active June 16, 2019 23:05
.NET on Linux/Wine - notes
apt update
export WINEARCH="win32"
apt install wine
apt-get install cabextract
dpkg --add-architecture i386 && apt-get update && apt-get install wine32
curl http://download.microsoft.com/download/D/D/3/DD35CC25-6E9C-484B-A746-C5BE0C923290/NDP47-KB3186497-x86-x64-AllOS-ENU.exe --output NDP47.exe
apt-get install wget unzip cabextract
curl https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks --output winetricks
@adamjasinski
adamjasinski / Dockerfile
Last active June 16, 2019 23:00
NetFx on Linux+Wine Hydra Dockerfile
#FROM i386/ubuntu:latest
FROM i386/debian:latest
#Note: it is less messy to use 32-bit Wine, so we stick with i386 Linux distro
RUN apt-get update && \
apt-get install -y curl unzip cabextract
#Install Wine
RUN apt-get install -y wine-development
WORKDIR /root
/// <summary>
/// Registers a specimen builder for open generic type Lazy<>.
// When asked for a concrete instance of Lazy<T>, the specimen builder constructs it using a func that returns the concrete inner specimen T using the current fixture.
// So it works like:
// fixture.Register<Lazy<T>>( fixture, () => new Lazy<T>( () => fixture.CreateAnonymous<T>() ) );
// where T is a runtime type
/// </summary>
class LazyCustomization : ICustomization
{
public void Customize( IFixture fixture )
$computerName = "someazurevm.cloudapp.net"
$userName = "CONTOSO\myuser"
$password = "secret"
$cred = New-Object System.Management.Automation.PSCredential $userName, $(ConvertTo-SecureString $password -AsPlainText -Force)
Invoke-Command -ComputerName $computerName -Credential $cred -Port 62397 -UseSSL -FilePath .\deploy\MyUpgradeScript.ps1
$ErrorActionPreference = "Stop"
function exec( [ScriptBlock] $cmd){
( & $cmd ) 2>&1 # TeamCity doesn't show the output without the 2>&1
if($LASTEXITCODE -ne 0){
throw "Exec returned $LASTEXITCODE"
}
}
public static class ExceptionsFacts
{
[Theory, AutoData]
static void AllExceptionsShouldBeSerializable( SerializableAssertion assertion )
{
assertion.Verify( typeof( MyException ).Assembly.GetTypes()
.Where( x => typeof( Exception ).IsAssignableFrom( x ) ) );
}
}
@adamjasinski
adamjasinski / CompositeDataAttribute.cs
Last active December 12, 2015 06:48
AutoFixture.xUnit - CompositeDataAttribute rewrite - lazy enumeration - shorter code
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using Xunit.Extensions;
namespace Prototypes.AutoFixture.Xunit.Extensions
{
public class CompositeDataAttribute : DataAttribute