Skip to content

Instantly share code, notes, and snippets.

@nyctef
nyctef / 0_results.md
Created October 15, 2021 12:35
String.Equals vs Object.ReferenceEquals (and how string interning can make things fast)
BenchmarkDotNet=v0.12.1, OS=macOS 11.6 (20G165) [Darwin 20.6.0]
Intel Core i5-6267U CPU 2.90GHz (Skylake), 1 CPU, 4 logical and 2 physical cores
.NET Core SDK=5.0.401
  [Host]     : .NET Core 5.0.10 (CoreCLR 5.0.1021.41214, CoreFX 5.0.1021.41214), X64 RyuJIT
  DefaultJob : .NET Core 5.0.10 (CoreCLR 5.0.1021.41214, CoreFX 5.0.1021.41214), X64 RyuJIT

using System;
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet;
using BenchmarkDotNet.Attributes;
namespace dictionary_vs_array
{
public class Benchmarks
{
@nyctef
nyctef / fizzbuzz.ts
Created October 26, 2020 09:22
Fizzbuzz in typescript (types)
// based on https://dev.to/gypsydave5/fizz-buzz-in-typescript-7ip (with some corrections)
type Z = 0;
type S<N> = [N];
type N1 = S<Z>;
type N2 = S<N1>;
type N3 = S<N2>;
type N4 = S<N3>;
type N5 = S<N4>;
using System;
using System.Security.Cryptography;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace MyBenchmarks
{
public class IfVsSwitch
{
private Random random = new Random(42);
@nyctef
nyctef / IsNullable.cs
Created June 19, 2020 13:30
Check if a constructor parameter is nullable
#nullable enable
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
public static partial class Utils
{
/// <summary>Based on https://stackoverflow.com/a/58454489 with simplifications/comments added</summary>
using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace LifxNet
{
/// <summary>
/// Based on https://stackoverflow.com/a/22938345 . Ideally we'd use BufferBlock from the TPL Dataflow
function nextcommit($targetBranch) {
$nextHash = git rev-list --topo-order HEAD..$targetBranch | select -last 1
git checkout $nextHash
}
# run the elixir docker image and share the current directory into the container
docker run -v "$PWD`:/data" -it --rm elixir /bin/bash
@nyctef
nyctef / deletebranches.ps1
Created December 4, 2017 12:51
delete branches with confirmation
function confirm($message) {
$reply = Read-Host -Prompt "$message [y/n]"
return $reply -match "[yY]"
}
git for-each-ref --format='%(refname:short)' refs/heads | `
where { $_ -ne 'master' } | `
where { confirm "Delete branch $_ ?" } | `
foreach { echo "git branch -D $_" }
@nyctef
nyctef / example.md
Last active November 15, 2017 02:22
Don't make decisions across different levels of abstraction

instead of

if (use_alternate_frob_strategy) {
  bloo_counter += 1;
}

do