Skip to content

Instantly share code, notes, and snippets.


Adam Anderson Adam--

View GitHub Profile
Adam-- /
Last active May 25, 2021
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
View Example.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Adam-- / Example.xaml
Created Oct 3, 2019
Create view model and set binding context in view's XAML
View Example.xaml
<!-- From -->
<?xml version="1.0" encoding="utf-8" ?>
Adam-- / git.config
Last active Mar 8, 2021
Git config
View git.config
# 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-- / TestingCloudTableWithAzureStorageEmulator.cs
Last active Feb 14, 2021
Testing CloudTable dependent code using the Azure Storage Emulator and NUnit
View TestingCloudTableWithAzureStorageEmulator.cs
public class TestingCloudTableWithAzureStorageEmulator
private CloudTableClient developmentCloudTableClient;
private CloudTable emulatedCloudTable;
public void OneTimeSetUp()
var azureStorageEmulatorProcess = Process.Start("C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\Storage Emulator\\AzureStorageEmulator.exe", "start");
Adam-- / app.config
Created Apr 26, 2017
Newtonsoft.Json binding redirect
View app.config
<?xml version="1.0" encoding="utf-8"?>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="" newVersion="" />
Adam-- / adb_screenshot.bat
Last active Oct 25, 2020
Take an Android screenshot using ADB on Windows
View adb_screenshot.bat
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-- / PCLStorageCopyExtension.cs
Created Sep 15, 2016
Copy a file to a folder using PCLStorage
View PCLStorageCopyExtension.cs
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-- / GifImageView.cs
Last active Jun 8, 2018
Android GifImageView custom renderer for Xamarin Forms
View GifImageView.cs
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-- / back key.bat
Created Apr 8, 2016
Windows batch files for useful Android ADB commands. Replace [device] with your device as listed from "adb devices" or remove the -s [device] entirely.
View back key.bat
adb -s [device] shell input keyevent 4