Skip to content

Instantly share code, notes, and snippets.

@hazelweakly
hazelweakly / cry-more.html
Last active January 8, 2023 07:46
Enron Mullet Is A Giant CryBaby
<!DOCTYPE html>
<meta charset="utf-8" />
<title>Redirecting to the Fediverse</title>
<head>
<script>
// let's say this is hosted at example.com. Given a url of one of the forms:
// - example.com/@user@instance.com/post_id
// - example.com/@user@instance.com
// - example.com/@instance.com
// redirect accordingly
@noseratio
noseratio / TaskSchedulerAwaiter.cs
Created September 16, 2020 11:29
Continue on the specified task scheduler, which becomes the current one
// by @noseratio
#nullable enable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace Noseratio.Experimental
@AArnott
AArnott / Cancellation.cs
Last active December 12, 2023 16:33
Graceful console app cancellation on Ctrl+C
class Program
{
static async Task Main(string[] args)
{
// Add this to your C# console app's Main method to give yourself
// a CancellationToken that is canceled when the user hits Ctrl+C.
var cts = new CancellationTokenSource();
Console.CancelKeyPress += (s, e) =>
{
Console.WriteLine("Canceling...");
@mgravell
mgravell / more awaiting.md
Last active April 20, 2017 07:08
More comparisons of async/await implementations

Objective:

For Task<T> and ValueTask<T> (T=int as a common non-trivial but inlineable case), compare async performance in the synchronous scenario (i.e. where data happens to be buffered - common in deserialization etc code) for 3 implementations:

  • using await throughout
  • using synchronous code until incompleteness detected (via IsCompleted); switch via local async Awaited if needed
  • using synchronous code until incompleteness detected (via IsCompletedSuccessfully); switch via local async Awaited if needed

Note:

@baralong
baralong / aa_init.ps1
Last active July 20, 2023 08:03
Sysinit
Set-ExecutionPolicy Unrestricted -force
# fix Mouse scrolling
Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Enum\HID\*\*\Device` Parameters FlipFlopWheel -EA 0 | ForEach-Object { Set-ItemProperty $_.PSPath FlipFlopWheel 1 }
# Choco install
iex ((new-object net.webclient).DownloadString('https://community.chocolatey.org/install.ps1'))
choco feature enable -n=allowGlobalConfirmation
choco install FiraCode
choco install GoogleChrome
choco install vscode
@anaisbetts
anaisbetts / AsyncReaderWriterLock.cs
Created March 12, 2014 20:45
Async reader/writer lock via abusing ConcurrentExclusiveSchedulerPair
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@kevin-smets
kevin-smets / iterm2-solarized.md
Last active April 22, 2024 01:47
iTerm2 + Oh My Zsh + Solarized color scheme + Source Code Pro Powerline + Font Awesome + [Powerlevel10k] - (macOS)

Default

Default

Powerlevel10k

Powerlevel10k

@SimonCropp
SimonCropp / gist:8485964
Last active April 30, 2016 08:55
Roslyn weaver

Roslyn Weaver

deployed

As a nuget package the same as Fody

Injection into the pipeline

Optionally replace/add cs files to the build pipeline in a similar wat to GFV

@mikeminutillo
mikeminutillo / AwesomeWeb.cs
Created December 11, 2013 07:23
Create a new Console App, Install all of the Packages (or enable package restore and hand-edit the packages.config file), Create a Web Folder and move your Scripts folder into it, Create Home.html in the root of /Web, mark all of the child files of /Web as Copy Always. Hit F5 and go to your browser for NancyFx, SignalR and static file hosting on…
using Microsoft.AspNet.SignalR;
using Microsoft.Owin.Hosting;
using Nancy;
using Nancy.Owin;
using Owin;
using System;
using System.IO;
using System.Reflection;
public class Program
// Only let input Observable fire every 'n' seconds at most
// but unlike Throttle, items fire immediately when they aren't
// rate-limited.
public IObservable<T> RateLimit<T>(this IObservable<T> This, TimeSpan interval, IScheduler scheduler)
{
var slot = default(IObservable<Unit>);
var input = This.Publish().RefCount();
return input.Window(input, _ => {
if (slot != null) return slot;