Skip to content

Instantly share code, notes, and snippets.

@HaloFour
HaloFour / gist:a986f87949145c4c19d3
Created January 22, 2015 16:56
Enumerable/Struct Perf Tests
using System;
using System.Collections.Generic;
using System.Diagnostics;
public struct CompilerGeneratedArgs3 : IEnumerable<int>
{
private struct Enumerator : IEnumerator<int>
{
private readonly CompilerGeneratedArgs3 args;
private int index;
@HaloFour
HaloFour / Covariance.il
Created January 30, 2015 19:50
Covariance in MSIL/CIL
.assembly extern mscorlib {
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 )
.ver 4:0:0:0
}
.assembly Covariance {
.ver 1:0:0:0
}
.module Covariance.exe
.subsystem 0x0003
@HaloFour
HaloFour / SynchronizationContextExtensions.cs
Created February 10, 2016 15:17
SynchronizationContext Awaiter Extension Method
public static class SynchronizationContextExtensions {
public struct SynchronizationContextAwaiter : INotifyCompletion {
private readonly SynchronizationContext context;
public SynchronizationContextAwaiter(SynchronizationContext context) {
this.context = context;
}
public bool IsCompleted {
get { return (context == null); }
@HaloFour
HaloFour / Decomposition.cs
Last active March 7, 2016 15:19
Decomposition Microbenchmark
using System;
using System.Diagnostics;
public struct ValueTuple<T1, T2> {
public T1 Item1;
public T2 Item2;
public ValueTuple(T1 item1, T2 item2) {
this.Item1 = item1;
this.Item2 = item2;
@HaloFour
HaloFour / LoginResource.cs
Last active June 28, 2018 11:41
Data Classes
using System;
using System.Collections.Generic;
/*
* public data class LoginResource
* {
* public string Username { get; }
* public string Password { get; }
* public bool RememberMe { get; } = true;
* }
@HaloFour
HaloFour / LoginResource.cs
Last active June 28, 2018 10:36
Data Classes with Primary Constructor
using System;
using System.Collections.Generic;
/*
* public data class LoginResource(string Username, string Password)
* {
* public bool RememberMe { get; } = true;
* }
*/
public sealed class LoginResource : IEquatable<LoginResource> {
@HaloFour
HaloFour / LoginResource.cs
Created June 29, 2018 20:38
Data Classes, Builder with Assignment Validation
public class LoginResource {
public struct Builder {
private byte _assigned;
private string _username;
private string _password;
public string Username {
get => _username;
set {
@HaloFour
HaloFour / proposal.md
Created July 12, 2018 19:29
C# Language Proposal Template
  1. What kind of problem are you trying to solve?
    • How often do you find yourself running into this problem?
  2. Is this a problem that you can work around today with existing language features?
    • If so, can you write up a snippet? (link to GitHub code fencing documentation)
  3. Can you describe the new language feature and how it addresses this problem?
  4. Can you include some sample syntax for what this new language feature might look like?
  • If possible, use comments or pseudocode to explain the behavior of the feature
@HaloFour
HaloFour / JMoneyTracer.java
Last active January 14, 2019 15:54
Java Money API
package com.comcast.money.japi;
import com.comcast.money.core.Money$;
import com.comcast.money.core.Note;
import com.comcast.money.core.Result;
import com.comcast.money.core.StringNote;
import com.comcast.money.core.Tracer;
public class JMoneyTracer {
private static Tracer tracer() {
@HaloFour
HaloFour / JMoney.java
Created January 15, 2019 01:19
Money Java Async API
public class JMoney {
public static <T, S extends CompletionStage<T>, E extends Exception> S traceAsync(String spanName, CheckedCallable<S, E> callable) throws E {
Tracer tracer = tracer();
tracer.startSpan(spanName);
S stage;
try {
stage = callable.call();
} catch (Exception exception) {