Skip to content

Instantly share code, notes, and snippets.

@guneysus
guneysus / Task Extension.cs
Last active Nov 17, 2021 — forked from CleanCoder/Task Extension
Task Extensions
View Task Extension.cs
static async Task<T> Otherwise<T> (this Task<T> task, Func<Task<T>> orTask) {
task.ContinueWith (async innerTask => {
if (innerTask.Status == TaskStatus.Faulted)
return await orTask ();
return await Task.FromResult<T> (innerTask.Result);
}).Unwrap ();
}
static async Task<T> Retry<T> (Func<Task<T>> task, int retries, TimeSpan delay, CancellationToken cts = default (CancellationToken)) {
@guneysus
guneysus / FP.cs
Last active Apr 8, 2020 — forked from CleanCoder/FP
Funtional Programming
View FP.cs
struct Result<T> {
public T Ok { get; }
public Exception Error { get; }
public bool IsFailed { get => Error != null; }
public bool IsOk => !IsFailed;
public Result (T ok) {
Ok = ok;
Error = default (Exception);
}
@guneysus
guneysus / FastMethodInvoker.cs
Last active Apr 8, 2020 — forked from CleanCoder/Reflaction
FastMethodInvoker
View FastMethodInvoker.cs
public static FastInvokeHandler GetMethodInvoker(MethodInfo methodInfo)
{
DynamicMethod dynamicMethod = new DynamicMethod(string.Empty,
typeof(object), new Type[] { typeof(object),
typeof(object[]) },
methodInfo.DeclaringType.Module);
ILGenerator il = dynamicMethod.GetILGenerator();
ParameterInfo[] ps = methodInfo.GetParameters();
Type[] paramTypes = new Type[ps.Length];
for (int i = 0; i < paramTypes.Length; i++)
@guneysus
guneysus / markdown-details-collapsible.md
Created Mar 27, 2020 — forked from pierrejoubert73/markdown-details-collapsible.md
How to add a collapsible section in markdown.
View markdown-details-collapsible.md

A collapsible section containing markdown

Click to expand!

Heading

  1. A numbered
  2. list
    • With some
    • Sub bullets
@guneysus
guneysus / Makefile
Created Mar 26, 2020 — forked from puzrin/Makefile
Makefile example for fontello.com API
View Makefile
# Edit here - set path to you directory with config.json & fonts
FONT_DIR ?= ./assets/vendor/fontello/src
### Don't edit below ###
FONTELLO_HOST ?= http://fontello.com
fontopen:
@if test ! `which curl` ; then \
@guneysus
guneysus / How-to-Permalink-to-a-Gist's-Raw-File.md
Last active Mar 15, 2020 — forked from atenni/README.md
How to permalink to a gist's raw file
View How-to-Permalink-to-a-Gist's-Raw-File.md