Skip to content

Instantly share code, notes, and snippets.

@fengli320
fengli320 / docker-wsl2-setup.sh
Created August 8, 2023 09:33 — forked from Athou/docker-wsl2-setup.sh
install docker in Debian 11/WSL2 without Docker Desktop
# install docker in Debian 11/WSL2
# uses systemd-genie since docker requires systemd but it's not available for WSL
# this is an alternative to Docker Desktop
# prerequisites
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install ca-certificates curl wget gnupg lsb-release apt-transport-https
# systemd-genie requires dotnet runtime, add Microsoft repo
@fengli320
fengli320 / gist:ec8bb7fdd260bd8350583cc4b9a7d0a5
Created June 11, 2023 10:34 — forked from Shazwazza/gist:7147978
How to inspect assemblies before including them in your application with reflection
public class PackageBinaryInspector : MarshalByRefObject
{
/// <summary>
/// Entry point to call from your code
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="dllPath"></param>
/// <param name="errorReport"></param>
/// <returns></returns>
/// <remarks>
using System;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace StateMachineConceptual
{
class Program
{
static async Task Main()
{
@fengli320
fengli320 / Fibers.cs
Created June 3, 2022 06:50 — forked from Horusiath/Fibers.cs
Minimal example of working async method builder
using System;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Threading;
namespace Fibers
{
public struct AsyncFiberMethodBuilder<T>
{
private Fiber<T>? fiber;
@fengli320
fengli320 / introrx.md
Created August 15, 2021 07:19 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
async def main():
coroutine1 = do_some_work(1)
coroutine2 = do_some_work(2)
coroutine3 = do_some_work(4)
tasks = [
asyncio.ensure_future(coroutine1),
asyncio.ensure_future(coroutine2),
asyncio.ensure_future(coroutine3)
]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from ctypes import *
from ctypes.wintypes import *
INVALID_HANDLE_VALUE = -1
CREATE_UNICODE_ENVIRONMENT = 0x00000400
@fengli320
fengli320 / UnitTests.cs
Created April 21, 2021 00:30 — forked from StephenCleary/UnitTests.cs
How StartNew responds to CancellationToken
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[TestClass]
public class StartNewCancellationTokenUnitTests
{
[TestMethod]
public void CancellationTokenPassedToStartNew_CancelsTaskWithTaskCanceledException()
@fengli320
fengli320 / async.cs
Created April 13, 2021 23:56 — forked from dgrunwald/async.cs
Async/Await support for .NET 4.0
// Copyright (c) 2012 Daniel Grunwald
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.