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-- / 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-- / 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-- / 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-- / 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-- / PCLStorageCopyExtension.cs
Created September 15, 2016 13:08
Copy a file to a folder using PCLStorage
namespace com.github.gist.adam--
{
using System.Threading;
using PCLStorage;
using FileAccess = PCLStorage.FileAccess;
public static class PCLStorageExtensions
{
public static async void CopyFileTo(this IFile file, IFolder destinationFolder, CancellationToken cancellationToken = default(CancellationToken))
{
@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-- / back key.bat
Created April 8, 2016 14:08
Windows batch files for useful Android ADB commands. Replace [device] with your device as listed from "adb devices" or remove the -s [device] entirely.
adb -s [device] shell input keyevent 4
@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";