Skip to content

Instantly share code, notes, and snippets.

View niksteff's full-sized avatar
⌨️
Just hacking away ...

Nik niksteff

⌨️
Just hacking away ...
View GitHub Profile
@niksteff
niksteff / context.go
Created December 18, 2024 13:43
Just a play projec to check context behaviour
package gocontext
import (
"context"
"log/slog"
"sync"
"testing"
"time"
)
@niksteff
niksteff / http2_test.go
Last active December 14, 2023 12:33
Testing golang http2 client and server
package http2_test
import (
"crypto/tls"
"crypto/x509"
"net/http"
"net/http/httptest"
"testing"
"time"
@niksteff
niksteff / resty_test.go
Last active December 8, 2023 10:29
rest v2.10.0 lab
package resty_test
import (
"context"
"crypto/tls"
"encoding/json"
"fmt"
"io"
"net/http"
"net/http/httptest"
@niksteff
niksteff / wordByteReader.go
Created November 30, 2023 14:05
This is some go example code of two readers reading words/bytes from input data before passing a limited size buffer on to a server.
func GetExampleData() []byte {
return []byte(`"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."`)
}
var ErrWordTooLong = errors.New("word too long")
var ErrBufferEmpty = errors.New("buffer empty")
var ErrEndOfWord = errors.New("end of word")
func TestWordBuffer(t *testing.T) {
b := bytes.NewBuffer(GetExampleData())
@niksteff
niksteff / example.go
Created November 15, 2023 12:25
Example http handler with api client dep
type APIClient struct {
baseUrl url.URL
}
type Something struct {
Id string // the response data
}
// NewAPIClient is a constructor and instantiating our api
@niksteff
niksteff / main.go
Created September 29, 2023 11:32
Go semaphore worker pattern
// this is a simple example of a semaphore in go.
//
// it replaces the typical waitgroup pattern. The benefit of a semaphore is that
// no workers will be left abandoned and no unneeded workers are started in
// contrast to a typical waitgroup based worker pool pattern. We also can only
// start a limited amount of workers at once. In a waitgroup we coul start more
// workers than we have tasks, which is not always optimal.
package main
@niksteff
niksteff / buffer_test.go
Last active April 4, 2023 14:37
Just a basic golang flusher implementation using bytes buffer
package buffer_test
import (
"bytes"
"log"
"sync"
"testing"
"time"
)
# Description: Sets up a windows developer machine with all needed application to start Microsoft developing right away
#
# Edited for private and company use by:
# Editor 1: Dominik Steffen <[email protected]>
# Last Updated: 2017-09-30
#
# Original Author: Jess Frazelle <[email protected]>, special thanks to Jess!
#
# Install boxstarter:
# . { iwr -useb http://boxstarter.org/bootstrapper.ps1 } | iex; get-boxstarter -Force
import sys
import math
# Test primality for 2 to sqrt(n) and check for rest
def testPrimality(n):
if(n == 1):
return;
m = 2
while m < math.sqrt(n):
if(n == 1):
# Description: Sets up a windows developer machine with all needed application to start Microsoft developing right away
#
# Edited for private and company use by:
# Editor 1: Dominik Steffen <[email protected]>
# Last Updated: 2017-09-30
#
# Original Author: Jess Frazelle <[email protected]>, special thanks to Jess!
#
# Install boxstarter:
# . { iwr -useb http://boxstarter.org/bootstrapper.ps1 } | iex; get-boxstarter -Force