Skip to content

Instantly share code, notes, and snippets.

View sedyh's full-sized avatar
🏠
Working from home

Artem Sedykh sedyh

🏠
Working from home
View GitHub Profile
@sedyh
sedyh / main.go
Created October 15, 2024 13:01
Strange spacing
package main
import (
"fmt"
"image/color"
"github.com/ebitenui/ebitenui"
"github.com/ebitenui/ebitenui/image"
"github.com/ebitenui/ebitenui/widget"
"github.com/hajimehoshi/ebiten/v2"
@sedyh
sedyh / main.go
Created October 15, 2024 11:44
Basic grid example
package main
import (
"image/color"
"github.com/ebitenui/ebitenui"
"github.com/ebitenui/ebitenui/image"
"github.com/ebitenui/ebitenui/widget"
"github.com/hajimehoshi/ebiten/v2"
"golang.org/x/image/colornames"
@sedyh
sedyh / main.go
Created April 12, 2024 15:38
graceful shutdown example
package main
import "graceful"
func main() {
graceful.Ensure()
mysql, err := NewMySQL()
if err != nil {
graceful.Stop(fmt.Errorf("mysql: %w", err))
@sedyh
sedyh / request.go
Last active March 14, 2024 15:40
Generic http request
package request
type Option = func(req *http.Request)
func Do(
client *http.Client,
ctx context.Context,
method, url, resource string,
in, out any, options ...Option,
) (e error) {
@sedyh
sedyh / fib_test.go
Created August 21, 2023 11:43
recursion
package main
import (
"testing"
)
var fib = 12
func BenchmarkPlainFib(b *testing.B) {
for i := 0; i < b.N; i++ {
@sedyh
sedyh / ANSI.md
Created January 4, 2023 15:47 — forked from fnky/ANSI.md
ANSI Escape Codes

ANSI Escape Sequences

Standard escape codes are prefixed with Escape:

  • Ctrl-Key: ^[
  • Octal: \033
  • Unicode: \u001b
  • Hexadecimal: \x1B
  • Decimal: 27
@sedyh
sedyh / main.go
Created September 9, 2022 11:12
Mock any type in Go
func initAnyType[T any]() *T {
var x T
t := reflect.TypeOf(x)
v := reflect.New(t)
if t.Kind() == reflect.Struct {
walkInitStruct(t, v.Elem())
}
@sedyh
sedyh / main.go
Last active February 9, 2023 16:25
Getting around type incovariance in Go, a cool slice trick
package main
import (
"fmt"
"strconv"
)
type Point struct {
Name int
Marked // You don't need to initialize it
@sedyh
sedyh / main.go
Last active May 17, 2022 21:00
Bone Animation Skeleton
package main
import (
"bytes"
"embed"
"fmt"
"image"
"log"
"math"
"image/color"
@sedyh
sedyh / relative-crop.go
Created November 14, 2021 16:20
Golang relative image cropping
import "image"
type SubImager interface {
SubImage(r image.Rectangle) image.Image
}
// RelativeSubImage return cropped image relative to the previous crop
// If you try to make a sub image from another sub image, you may run into
// unusual behavior due to the fact that absolute coordinates are used for each crop,
// instead you can use this function so as not to constantly remember this nuance.