Skip to content

Instantly share code, notes, and snippets.

View haneytron's full-sized avatar

David Haney haneytron

View GitHub Profile
@haneytron
haneytron / RemoveInstanceId.cs
Last active July 11, 2023 14:04
Remove instanceId from query string value and return a new query string. If instanceId is not present, return the original query string.
// NOTE: assumption that query doesn't start with '?'
static string? RemoveInstanceIdFromQueryString(string query)
{
if (string.IsNullOrWhiteSpace(query))
{
return query;
}
// Opting to not use a StringBuilder as a single string concat feels OK re: allocations
@haneytron
haneytron / BloomFilter.cs
Last active November 14, 2023 06:13
A simple Bloom Filter implementation in C#
using System;
namespace BloomFilter
{
class Program
{
static void Main(string[] args)
{
AddItem("test");
AddItem("test2");
@haneytron
haneytron / MarsRovers.cs
Last active May 17, 2021 12:20
A compact C# solution to the Mars Rovers ThoughtWorks problem described in my repo: https://github.com/ironyx/marsrovers
static void Main(string[] args)
{
var input = @"5 5
1 2 N
LMLMLMLMM
3 3 E
MMRMMRMRRM".Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
var bounds = input[0].Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(i => int.Parse(i)).ToArray();
var dirs = "NESW"; var magnitudes = new[] { Tuple.Create(0, 1), Tuple.Create(1, 0), Tuple.Create(0, -1), Tuple.Create(-1, 0) };
for (int i = 1; i < input.Length; i += 2) {