Skip to content

Instantly share code, notes, and snippets.

View win-t's full-sized avatar

Kurnia D Win win-t

View GitHub Profile
@win-t
win-t / resource.go
Last active April 12, 2022 02:26
golang owned goroutine
package resource
import (
"context"
"fmt"
"io"
"runtime"
"sync/atomic"
"time"
)
@win-t
win-t / keybase.md
Created July 23, 2021 07:43
keybase.md

Keybase proof

I hereby claim:

  • I am win-t on github.
  • I am wint (https://keybase.io/wint) on keybase.
  • I have a public key whose fingerprint is EE94 ED16 177C D701 4BA8 01D7 69AC 2B30 4E2A 3BA8

To claim this, I am signing this object:

<?php
namespace main;
define("BACKEND_SOCKET", '<where the unix socket>');
define("BASE_URL", '<where this file located>');
function exit_500($msg) {
$msg = rtrim($msg, "\n") . "\nDebug trace:\n";
foreach(debug_backtrace() as $trace) {
@win-t
win-t / defer.h
Created May 3, 2020 10:27
C++ defer
#pragma once
template<typename F>
class DeferFinalizer final {
F func;
bool moved;
public:
DeferFinalizer(F&& f)
: func(std::forward<F>(f))
@win-t
win-t / main.rs
Last active April 8, 2020 00:25
Demo of bad example mixing blocking and non blocking call on rust async/await
/*
# dpependencies in Cargo.toml
[dependencies]
diesel = { version = "1.4.4", features = ["postgres"] }
hyper = "0.13.4"
r2d2 = "0.8.8"
r2d2-diesel = "1.0.0"
tokio = { version = "0.2.16", features = ["full"] }
*/
@win-t
win-t / Makefile
Created June 29, 2019 00:23
help: link against rust std
main: main.o vec.o
# how to link against rust std ?
# or can we compile rust std into staticlib ?
gcc -o main main.o vec.o
main.o: main.c
gcc -o main.o -c main.c
vec.o: vec.rs
rustc --emit obj --crate-type staticlib -o vec.o vec.rs
@win-t
win-t / client.go
Last active June 29, 2018 01:13
golang: unix socket: get peer credential
package main
import (
"fmt"
"net"
"os"
)
func main() {
addr, _ := net.ResolveUnixAddr("unix", "@testabstractsocket")
@win-t
win-t / phonebooks.go
Last active March 17, 2019 01:38
Example usage of go-router and go-middleware
package main
import (
"encoding/json"
"net/http"
"sort"
"strconv"
"sync"
"github.com/payfazz/go-middleware"