Skip to content

Instantly share code, notes, and snippets.

Avatar

Adam Anderson Adam--

View GitHub Profile
@Adam--
Adam-- / LinqAnyPerformance.md
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?
View LinqAnyPerformance.md

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>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
@Adam--
Adam-- / Example.xaml
Created Oct 3, 2019
Create view model and set binding context in view's XAML
View Example.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-- / git.config
Last active Mar 8, 2021
Git config
View 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 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;
[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 Apr 26, 2017
Newtonsoft.Json binding redirect
View app.config
<?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 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--
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--
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--
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