Skip to content

Instantly share code, notes, and snippets.

View Adam--'s full-sized avatar

Adam Anderson Adam--

View GitHub Profile
@Adam--
Adam-- / git.config
Last active July 28, 2022 14:27
Git config
[alias]
# Lists all aliases
alias = config --get-regexp ^alias\\.
# Quote a command to allow it to be used as a git alias
quote-string = "!read -r l; printf \\\"!; printf %s \"$l\" | sed 's/\\([\\\"]\\)/\\\\\\1/g'; printf \" #\\\"\\n\" #"
# Gets information about a repo
url = config remote.origin.url
branch-name = rev-parse --abbrev-ref HEAD
@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-- / 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-- / 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-- / choco packages.bat
Last active June 10, 2022 14:33
Installs software I use
REM Installing chocolatey...
@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
REM Installing packages...
REM General tools
choco install microsoft-teams -fy
choco install 7zip -fy
choco install paint.net -fy
choco install greenshot -fy
choco install licecap -fy
@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-- / TerminalSetup.md
Last active September 16, 2022 13:39
How to setup an awesome terminal for software development on Windows

Windows Terminal

Windows Terminal is a modern feature-rich open source terminal from Microsoft that runs many shells, including PowerShell. The easiest way to install it is from the Microsoft Store.

Go ahead and open Windows Terminal, which should default to PowerShell. Have a look around, it's already pretty awesome. There's support for multiple tabs, color schemes, custom fonts, custom shells, and more. We are going to customize it even further by setting up git support, customizing the prompt, installing custom fonts, setting the color scheme, and optionally adding a couple of extra tools.

posh-git and oh-my-posh

posh-git allows git information to be displayed within PowerShell and provides tab completion of git commands and branches.

oh-my-posh is a prompt theme engine for PowerShell.

#r "nuget:Newtonsoft.Json, 13.0.1"
using Newtonsoft.Json;
public class Product
{
public string Name { get; set; }
public DateTime Expiry { get; set; }
public string[] Sizes { get; set; }
}
{
"version": "1.0",
"components": [
"Component.OpenJDK",
"Component.Android.SDK.MAUI",
"Microsoft.VisualStudio.Component.MonoDebugger",
"Microsoft.VisualStudio.Component.Merq",
"Component.Xamarin.RemotedSimulator",
"Microsoft.VisualStudio.ComponentGroup.WebToolsExtensions.TemplateEngine",
"Microsoft.VisualStudio.Component.NuGet",
@Adam--
Adam-- / Microsoft.PowerShell_profile.ps1
Last active November 29, 2022 16:25
Loads tools I use in the PowerShell prompt
function RunStep([string] $Description, [ScriptBlock]$script)
{
Write-Host -NoNewline "Loading" $Description.PadRight(20)
& $script
Write-Host "✓" # checkmark emoji
}
RunStep "posh-git" {
# Provides prompt with Git status summary information and tab completion for Git commands, parameters, remotes and branch names.
# https://github.com/dahlbyk/posh-git