Skip to content

Instantly share code, notes, and snippets.

View cideM's full-sized avatar

Florian Beeres cideM

View GitHub Profile
{
description = "Nix. All. The. Things.";
inputs = {
home-manager = {
url = "github:rycee/home-manager";
inputs.nixpkgs.follows = "/unstable";
};
nixpkgs = {
@cideM
cideM / main.go
Created October 18, 2022 08:45
Final main.go
package main
import (
"context"
"errors"
"log"
"strings"
"sync"
"time"
@cideM
cideM / main.go
Created September 8, 2022 13:48
New main.go file before the "Error handling" chapter
package main
import (
"context"
"errors"
"log"
"runtime"
"strings"
"sync"
"time"
@cideM
cideM / eleven.go
Last active September 8, 2022 13:41
The new step function
func step[In any, Out any](
ctx context.Context,
inputChannel <-chan In,
fn func(In) (Out, error),
) (chan Out, chan error) {
outputChannel := make(chan Out)
errorChannel := make(chan error)
limit := int64(2)
// Use all CPU cores to maximize efficiency. We'll set the limit to 2 so you
@cideM
cideM / ten.go
Last active September 8, 2022 13:41
Using semaphores
func main() {
source := []string{"FOO", "BAR", "BAX"}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
inputChannel, err := producer(ctx, source)
if err != nil {
log.Fatal(err)
}
@cideM
cideM / eight.diff
Last active September 8, 2022 13:40
Add error handling
diff --git a/main.go b/main.go
index 3888a36..8794caa 100644
--- a/main.go
+++ b/main.go
@@ -2,6 +2,7 @@ package main
import (
"context"
+ "errors"
"log"
@cideM
cideM / seven.diff
Last active September 8, 2022 12:26
Fix the empty logs
diff --git a/main.go b/main.go
index c45418b..dd7d1ef 100644
--- a/main.go
+++ b/main.go
@@ -31,9 +31,10 @@ func sink(ctx context.Context, values <-chan string) {
log.Print(ctx.Err().Error())
return
case val, ok := <-values:
- log.Println(val)
if ok {
@cideM
cideM / six.diff
Last active September 8, 2022 12:26
Flood the terminal with empty logs
diff --git a/main.go b/main.go
index 08d7580..c45418b 100644
--- a/main.go
+++ b/main.go
@@ -31,6 +31,7 @@ func sink(ctx context.Context, values <-chan string) {
log.Print(ctx.Err().Error())
return
case val, ok := <-values:
+ log.Println(val)
if ok {
@cideM
cideM / five.diff
Last active September 8, 2022 12:26
Add context cancellation
diff --git a/main.go b/main.go
index 606c863..08d7580 100644
--- a/main.go
+++ b/main.go
@@ -1,37 +1,58 @@
package main
import (
+ "context"
"log"
# .config/nixpkgs/overlays/neovim.nix
self: super: {
neovim-unwrapped = (super.neovim-unwrapped.override { lua = self.luajit; }).overrideAttrs(oldAttrs: {
cmakeFlags = oldAttrs.cmakeFlags ++ [ "-DMIN_LOG_LEVEL=0" ];
version = "master";
src = builtins.fetchGit {
url = https://github.com/neovim/neovim.git;
};