Skip to content

Instantly share code, notes, and snippets.

@BenjaminHolland
BenjaminHolland / gist:8464010
Last active January 3, 2016 12:39
Async Problem Code
public class AsyncObjectWait<T1, TriggerType>
{
private Queue<TaskCompletionSource<TriggerType>> _waits;
T1 _value;
public AsyncObjectWait(T1 triggerValue)
{
_value = triggerValue;
_waits = new Queue<TaskCompletionSource<TriggerType>>();
}
void setup()
{
size(400,400);
background(255);
}
void drawBlob(int x,int y)
{
noStroke();
float val=0f;
for(int i=0;i<10;i++)
public Boolean TryOpen(){
.
.
.
_hDrive = FileIO.Methods.CreateFile(
Info.PhysicalPath,
FileIO.FileAccess.GenericRead | FileIO.FileAccess.GenericWrite,
FileIO.FileShare.Read | FileIO.FileShare.Write,
IntPtr.Zero,
@BenjaminHolland
BenjaminHolland / .gitattributes
Created April 26, 2017 01:26
Git Attributes File
* text=lf
*.js text
*.sh text
*.py text
*.md text
*.css text
*.html text
*.txt text
@BenjaminHolland
BenjaminHolland / RxStreamAdapter.cs
Created July 15, 2017 17:30
Reactive Observable Asynchronous Stream Adapter
using RJCP.IO.Ports;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Text;
using System.Threading;
public static Task WaitOneAsync(this WaitHandle waitHandle)
{
if (waitHandle == null)
throw new ArgumentNullException("waitHandle");
var tcs = new TaskCompletionSource<bool>();
var t = tcs.Task;
RegisteredWaitHandle rwh = null;
t=t.ContinueWith((antecedent) => rwh.Unregister(null));
rwh = ThreadPool.RegisterWaitForSingleObject(waitHandle,
@BenjaminHolland
BenjaminHolland / gist:c4e209b6b5fc5db925cbd8e79b7d5e7e
Created December 1, 2017 18:53
Strange Overload Resolution Issue.
#include <functional>
#include <iostream>
#include <string>
#include <mutex>
#include <thread>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
using namespace std;
public static class NumericConverter
{
public enum PadMode
{
Zeros,
Ones,
Sign
}
private const int positiveExt = 0x00;
private const int negativeExt = 0xFF;
let input: [boolean] = [
true, true, true,
false, false,
true, true,
false,
true,
false,
true,
false, false]
@BenjaminHolland
BenjaminHolland / OverlappedIOToTask.cs
Created January 5, 2019 02:38
Example of converting an overlapped IO call into a task. Extremely Incomplete. .NET Core 2.1
using System;
using System.Buffers;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using PInvoke;
namespace PInvoke