Skip to content

Instantly share code, notes, and snippets.

View DeedleFake's full-sized avatar

DeedleFake

View GitHub Profile
@DeedleFake
DeedleFake / fynetest.go
Last active March 20, 2022 16:03
Testing generics with Fyne data binding.
package main
import (
"strings"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/widget"
@DeedleFake
DeedleFake / README.md
Last active December 24, 2021 20:59
Abusing the microtask queue to create a recursive breadth-first search.

This gist contains Dart and JavaScript examples of using the microtask queue to implement a recursive breadth-first search. Normally, a recursive graph/tree search is depth-first, as it uses the call stack to keep track of the frontier. However, the event loop in JavaScript and, by extension, Dart, uses a queue, not a stack. The microtask queue in particular is good for a recursive pattern as it blocks up the entire event loop until every single microtask has been processed.

Interestingly, Dart actually gives much simpler control over which queue things go into. In JavaScript, Promises, and thus async functions, always resolve in the microtask queue, not the regular event queue, which is why the JavaScript implementation does not require anything extra to deal with which queue things get sent to. In Dart, however, Futures normally complete in the normal event queue, not the microtask queue,

@DeedleFake
DeedleFake / flow.go
Created July 20, 2021 19:57
Experimental Kotlin Flow System in Go
package main
import (
"context"
"fmt"
)
type Producer[T any] interface {
Produce(ctx context.Context) (T, bool)
}
@DeedleFake
DeedleFake / client.go
Created June 3, 2021 21:09
QUIC Echo Server Test
package main
import (
"context"
"crypto/tls"
"flag"
"fmt"
"io"
"log"
"os"
@DeedleFake
DeedleFake / err.go2
Last active August 28, 2020 01:44
Generic testing sandbox.
package main
import (
"fmt"
)
type Pair[T1 any, T2 any] struct {
First T1
Second T2
}
@DeedleFake
DeedleFake / check.md
Last active February 20, 2019 04:17
Possible Solution to check Awkwardness with Chained Method Calls

Syntax Problem

One of the issues with the syntax of check, as proposed, is that chaining method calls with error returns will look really, really bad. For example, check (check (check v.m1()).m2()).m3(). The common way around this in many languages, as mentioned in the draft, is the use of ? as a postfix operator instead of prefix keyword, but this has other problems, including resulting in similar illegibility if there are nested function calls, such as in f1(f2(f3()?)?)?. It also would make it unique amongst the various Go control flow modifiying language structures as all of the other ones are keywords.

Proposed Solution

When check is given a compound function expression, such as nested function calls or chained methods, it applies to all calls in the expression, not just the one it was specifically attached to. The previous two examples then become check v.m1().m2().m3() and check f1(f2(f3())), respectively. All other aspects of check remain the same,

Keybase proof

I hereby claim:

  • I am deedlefake on github.
  • I am deedlefake (https://keybase.io/deedlefake) on keybase.
  • I have a public key ASBAslmyHWY1vLJG-aQw5Nnc2ElZK0zwqk2ipj5EJB9kMQo

To claim this, I am signing this object:

diff --git a/PKGBUILD b/PKGBUILD
index 8ef2f13..10f59e4 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -20,9 +20,11 @@ build() {
# Force our own git checkout
export GOPATH="$srcdir"
mkdir -p "$GOPATH/src/github.com/spf13"
ln -s `pwd` "$GOPATH/src/github.com/spf13/hugo"
@DeedleFake
DeedleFake / Percentage Difference
Last active May 10, 2016 02:05
Go1 Benchmark (1.6 vs. devel +9af8346)
BenchmarkFannkuch11-4 -18.05
BenchmarkFmtFprintfEmpty-4 -8.89
BenchmarkFmtFprintfString-4 -20.36
BenchmarkFmtFprintfInt-4 -22.18
BenchmarkFmtFprintfIntInt-4 -28.06
BenchmarkFmtFprintfPrefixedInt-4 -20.63
BenchmarkFmtFprintfFloat-4 -19.17
BenchmarkFmtManyArgs-4 -22.47
BenchmarkGobDecode-4 -12.68
BenchmarkGobEncode-4 -11.14
@DeedleFake
DeedleFake / delta
Created March 28, 2016 19:53
go1 benchmarks devel +cabf73f
BenchmarkBinaryTree17-4 5022008650 -6.02%
BenchmarkFannkuch11-4 4645926951 -23.40%
BenchmarkFmtFprintfEmpty-4 84.9 -7.30%
BenchmarkFmtFprintfString-4 266 -20.30%
BenchmarkFmtFprintfInt-4 264 -20.08%
BenchmarkFmtFprintfIntInt-4 420 -24.05%
BenchmarkFmtFprintfPrefixedInt-4 391 -17.65%
BenchmarkFmtFprintfFloat-4 549 -16.58%
BenchmarkFmtManyArgs-4 1711 -20.86%
BenchmarkGobDecode-4 12907474 -9.27%