Skip to content

Instantly share code, notes, and snippets.

View tomaustin700's full-sized avatar
🏠
Working from home

Tom Austin tomaustin700

🏠
Working from home
View GitHub Profile
@tomaustin700
tomaustin700 / install-powershell.sh
Created January 9, 2018 09:49
Install Powershell on Ubuntu 16.10
#!/bin/bash
# from https://blogs.msdn.microsoft.com/powershell/2017/02/01/installing-latest-powershell-core-6-0-release-on-linux-just-got-easier/
# Import the public repository GPG keys
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
# Register the Microsoft Ubuntu repository
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list | sudo tee /etc/apt/sources.list.d/microsoft.list
# Update apt-get
/// <summary>
/// Used for getting DateTime.Now(), time is changeable for unit testing
/// </summary>
public static class SystemTime
{
/// <summary> Normally this is a pass-through to DateTime.Now, but it can be overridden with SetDateTime( .. ) for testing or debugging.
/// </summary>
public static Func<DateTime> Now = () => DateTime.Now;
/// <summary> Set time to return when SystemTime.Now() is called.
#!/usr/bin/env bash
# ----------------------------------------------------------------------------------
# Script for checking the temperature reported by the ambient temperature sensor,
# and if deemed to high send the raw IPMI command to enable dynamic fan control.
#
# Requires ipmitool – apt-get install ipmitool
# Tested on Ubuntu 17.04
# ----------------------------------------------------------------------------------
@tomaustin700
tomaustin700 / ListExtensions.cs
Created April 18, 2018 07:12
Extension method for generating a Cartesian product
public static class ListExtentions
{
public static IEnumerable Cartesian(this IEnumerable<IEnumerable> items)
{
var slots = items
// initialize enumerators
.Select(x => x.GetEnumerator())
// get only those that could start in case there is an empty collection
.Where(x => x.MoveNext())
.ToArray();
@tomaustin700
tomaustin700 / VarbinaryToByte[]C#
Created April 20, 2018 10:23
Converts SQL varbinary image into C# Byte[]
string stringFromSQL = "0x6100730064006600";
List<byte> byteList = new List<byte>();
string hexPart = stringFromSQL.Substring(2);
for (int i = 0; i < hexPart.Length / 2; i++)
{
string hexNumber = hexPart.Substring(i * 2, 2);
byteList.Add((byte)Convert.ToInt32(hexNumber, 16));
}
//Returns time taken for execution of synchronous code
var syncTime = Metricity.Timings.Time(() =>
{
SyncMethod();
});
//Returns time taken for execution of asynchronous code
var asyncTime = Metricity.Timings.Time(async () =>
{
await ASyncMethod();
static MetricsCollector _collector;
_collector = new MetricsCollector(new BosunOptions(ex => Handle(ex))
{
MetricsNamePrefix = "TestApp.",
BosunUrl = new System.Uri("http://192.168.1.5:8070"),
PropertyToTagName = NameTransformers.CamelToLowerSnakeCase,
ThrowOnPostFail = true,
DefaultTags = new Dictionary<string, string>{ {"host", NameTransformers.Sanitize(Environment.MachineName.ToLower())},
{ "client", "home" }, }
_timer = _collector.CreateMetric<EventGauge>("GetWeather", "time taken", "measures time taken to get weather from api");
await Time(async () =>
{
await GetWeather();
}, _timer);
public static async Task Time(Func<Task> action, EventGauge gauge)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
await action.Invoke();
stopwatch.Stop();
gauge.Record(stopwatch.Elapsed.TotalMilliseconds, DateTime.Now);
}