Skip to content

Instantly share code, notes, and snippets.

View cideM's full-sized avatar
🎄
Advent of Code 2025

Florian Beeres cideM

🎄
Advent of Code 2025
View GitHub Profile
@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"
@cideM
cideM / four.diff
Created September 20, 2021 08:22
Add a delay
diff --git a/main.go b/main.go
index 638af00..af15140 100644
--- a/main.go
+++ b/main.go
@@ -2,6 +2,7 @@ package main
import (
"log"
+ "time"
)
@cideM
cideM / three.diff
Created September 20, 2021 08:22
Fix the second deadlock
diff --git a/main.go b/main.go
index 5c20c9f..638af00 100644
--- a/main.go
+++ b/main.go
@@ -8,7 +8,7 @@ func producer(strings []string) (<-chan string, error) {
outChannel := make(chan string)
go func() {
-
+ defer close(outChannel)
@cideM
cideM / one.go
Created September 20, 2021 08:21
Producer Consumer
package main
import (
"log"
)
func producer(strings []string) (<-chan string, error) {
outChannel := make(chan string)
for _, s := range strings {
@cideM
cideM / two.diff
Created September 20, 2021 08:21
Fix the first deadlock
diff --git a/main.go b/main.go
index 92bcd33..5c20c9f 100644
--- a/main.go
+++ b/main.go
@@ -7,9 +7,12 @@ import (
func producer(strings []string) (<-chan string, error) {
outChannel := make(chan string)
- for _, s := range strings {
- outChannel <- s
@cideM
cideM / gadt.hs
Last active August 24, 2021 08:56
Haskell GADT with Existential
#! /usr/bin/env nix-shell
#! nix-shell -p ghcid -p "haskellPackages.ghcWithPackages (pkgs: with pkgs; [])" -i "ghcid -c 'ghci -Wall' -T main"
-- Run this with
-- $ chmod +x ./file.hs
-- $ ./file.hs
--
-- See this thread https://discourse.haskell.org/t/how-to-restrict-function-to-certain-constructors/2785/7
-- for a discussion of the problem
getSessionFromDb :: SQLite.Connection -> ByteString -> IO (Maybe Session)
getSessionFromDb conn id =
SQLite.query conn "SELECT expires,userid FROM sessions WHERE id = ?" [id]
>>= \dbResult -> case dbResult of
[s :: Session] -> return $ Just s
[] -> return Nothing
other -> throwString $ "unexpected DB result: " <> show other
getRolesFromDb :: SQLite.Connection -> Int -> IO (Maybe [Role])
getRolesFromDb conn userId =
echo '[{"name":"v1.22.10","zipball_url":"https://api.github.com/repos/yarnpkg/yarn/zipball/v1.22.10","tarball_url":"https://api.github.com/repos/yarnpkg/yarn/tarball/v1.22.10","commit":{"sha":"785cda8020aa5f513d6f60b8349bca8dab9dd79b","url":"https://api.github.com/repos/yarnpkg/yarn/commits/785cda8020aa5f513d6f60b8349bca8dab9dd79b"},"node_id":"MDM6UmVmNDk5NzA2NDI6cmVmcy90YWdzL3YxLjIyLjEw"}]' | tr ',' '\n' | awk -F'":"' '{ version; gsub(/"/, "", $2); if ($1 ~ /name/ ) { version = $2; } if ($1 ~ /tarball/) { gsub(/v/, "", version); print version, $2; } }'
echo '[{"name":"v1.22.10","zipball_url":"https://api.github.com/repos/yarnpkg/yarn/zipball/v1.22.10","tarball_url":"https://api.github.com/repos/yarnpkg/yarn/tarball/v1.22.10","commit":{"sha":"785cda8020aa5f513d6f60b8349bca8dab9dd79b","url":"https://api.github.com/repos/yarnpkg/yarn/commits/785cda8020aa5f513d6f60b8349bca8dab9dd79b"},"node_id":"MDM6UmVmNDk5NzA2NDI6cmVmcy90YWdzL3YxLjIyLjEw"}]' | tr ',' '\n' | awk -F'":"' '{ version;
gsub(/"/, "", $2)
if ($1 ~ /name/ ) { version = $2 }
if ($1 ~ /tarball/) { gsub(/v/, "", version); print version, $2 } }'