Skip to content

Instantly share code, notes, and snippets.

View Adam--'s full-sized avatar

Adam Anderson Adam--

View GitHub Profile
@Adam--
Adam-- / unit_test_git_hook.md
Last active June 15, 2021 20:08
Using git hooks to run unit tests prior to push

Something that I have been using lately is a git pre-push hook to build and run our unit test suite before pushing. I like that I can ensure that I do not push any commits that break the build or unit tests and that I get fast feedback. Of course no of us would ever do that, right?

Git hooks allow for you to run scripts pre or post important workflow events (commit, push, rebase, etc). Hooks are stored in .git\hooks and contain a bunch of samples. For my case, I want to run my unit test project, check if all tests passed, and prevent the push if any failed.

To do this I need to create pre-push script. In this script I use dotnet test to build and run all test projects in the dotnet folder and verify that all tests pass. If anything fails, I exit with a error return code of 1. This prevents the push from continuing. The folder dotnet test points to needs to be updated to point to either the location of your solution, or the unit test project

@Adam--
Adam-- / LinqAnyPerformance.md
Last active May 25, 2021 16:58
I often see `.Count() > 0` or `.Count > 0` to check if there are any elements in some collection. Linq provides an `Any()` method to check if there are any elements. `Any()` sure reads better but does it come with any downsides?

Linq Any() performance compared to Count() > 0

I often see .Count() > 0 or .Count > 0 to check if there are any elements in some collection. Linq provides an Any() method to check if there are any elements. Any() sure reads better but does it come with any downsides? Inspired by a twitter post on using Any() and benchmarking it, I decided to run some of my own tests using BenchmarkDotNet.

The benchmarks that were run compare the use of these two methods, comparing enumerables and lists with two sizes, 1000 and 1000.

BenchmarkDotNet=v0.13.0, OS=Windows 10.0.19042.985 (20H2/October2020Update)
Intel Core i7-8650U CPU 1.90GHz (Kaby Lake R), 1 CPU, 8 logical and 4 physical cores
@Adam--
Adam-- / app.config
Created April 26, 2017 11:56
Newtonsoft.Json binding redirect
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
</assemblyBinding>
@Adam--
Adam-- / TestingCloudTableWithAzureStorageEmulator.cs
Last active February 14, 2021 13:58
Testing CloudTable dependent code using the Azure Storage Emulator and NUnit
public class TestingCloudTableWithAzureStorageEmulator
{
private CloudTableClient developmentCloudTableClient;
private CloudTable emulatedCloudTable;
[OneTimeSetUp]
public void OneTimeSetUp()
{
var azureStorageEmulatorProcess = Process.Start("C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\Storage Emulator\\AzureStorageEmulator.exe", "start");
azureStorageEmulatorProcess?.WaitForExit(2000);
@Adam--
Adam-- / adb_screenshot.bat
Last active October 25, 2020 02:13
Take an Android screenshot using ADB on Windows
adb devices
adb shell screencap -p /sdcard/screen.png
adb pull -p -a /sdcard/screen.png
adb shell rm /sdcard/screen.png
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set mydate=%%c-%%a-%%b)
For /f "tokens=1-3 delims=/:" %%a in ("%TIME%") do (set mytime=%%a-%%b-%%c)
set mytime=%mytime: =%
@Adam--
Adam-- / Example.csproj
Last active October 3, 2019 17:18
Load image resource from netstandard library in Xamarin Forms (from https://github.com/xamarin/xamarin-forms-samples/tree/master/UserInterface/ThemingDemo)
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
@Adam--
Adam-- / Example.xaml
Created October 3, 2019 17:09
Create view model and set binding context in view's XAML
<!-- From https://github.com/jamesmontemagno/app-pretty-weather/blob/master/PrettyWeather/PrettyWeather/MainPage.xaml -->
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="PrettyWeather.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:pancake="clr-namespace:Xamarin.Forms.PancakeView;assembly=Xamarin.Forms.PancakeView"
xmlns:converters="clr-namespace:PrettyWeather.Converters"
xmlns:viewmodel="clr-namespace:PrettyWeather.ViewModel"
xmlns:model="clr-namespace:PrettyWeather.Model"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
@Adam--
Adam-- / GifImageView.cs
Last active June 8, 2018 14:53
Android GifImageView custom renderer for Xamarin Forms
namespace LakeShore.Sources.Core.Instrument
{
using Xamarin.Forms;
public class GifImageView : View
{
public static readonly BindableProperty SourceProperty = BindableProperty.Create(
propertyName: nameof(Source),
returnType: typeof(string),
declaringType: typeof(GifImageView),
@Adam--
Adam-- / OverrideFormattedStringExtension.cs
Created February 19, 2016 15:27 — forked from alexlau811/OverrideFormattedStringExtension.cs
Override default FormattedString behaviour to allow custom font to be used in Label of Xamarin.Forms.Android
public static class OverrideFormattedStringExtension
{
//
// Static Methods
//
public static SpannableString ToAttributed(this FormattedString formattedString, Font defaultFont, Color defaultForegroundColor, TextView view)
{
if (formattedString == null)
{
return null;
@Adam--
Adam-- / PropertyNameSupport.cs
Last active September 25, 2015 13:09
Extracts a property name string from an Expression.
using System;
using System.Globalization;
using System.Linq.Expressions;
using System.Reflection;
public static class PropertyNameSupport
{
private const string ExceptionMessageFormat = "Property expression {0}. Ensure calling with () => Property.";
private const string ParameterName = "propertyExpression";