Skip to content

Instantly share code, notes, and snippets.

View yakuter's full-sized avatar
💭
Working #golang @binalyze

Erhan Yakut yakuter

💭
Working #golang @binalyze
View GitHub Profile
@yakuter
yakuter / copy.go
Created February 14, 2024 11:05
Copy and Movement 1
src := []int{1, 2, 3, 4, 5}
dst := make([]int, 5)
// copy from slice to slice
copied := copy(dst, src)
// copied: 5
// dst: [1 2 3 4 5]
// copy from string to slice
var b = make([]byte, 5)
@yakuter
yakuter / Logger.swift
Created March 13, 2023 10:08
A useful logger struct in swift
// Usage
let logger = Logger("YakuterPackage.ViewController")
logger.info("Result: %{public}@", result)
logger.error("This is an error log")
// Logger.swift file content
@yakuter
yakuter / error-handling.swift
Last active March 13, 2023 10:03
Swift error handling
// Method 1
struct User {
}
enum SecurityError: Error {
case emptyEmail
case emptyPassword
}
@yakuter
yakuter / empty-struct-2.go
Last active November 3, 2022 19:40
Empty Struct 2
// Versiyon 2
package main
import "fmt"
type Foo struct{}
func main() {
a := &Foo{}
b := &Foo{}
@yakuter
yakuter / empty-struct-1.go
Last active November 3, 2022 19:40
Empty Struct
// Versiyon 1
package main
import "fmt"
type Foo struct{}
func main() {
a := &Foo{}
b := &Foo{}
@yakuter
yakuter / multipart-pipe.go
Last active September 27, 2022 08:42
Multipart and Pipe file stream
// This example shows how to send files via pipe using multipart package
package main
import (
"errors"
"fmt"
"io"
"mime/multipart"
"os"
@yakuter
yakuter / distro.sh
Created May 2, 2022 04:30
distro sh function
# distro prints the detected operating system including linux distros.
# Also parses ID_LIKE for common distro bases.
#
# Example outputs:
# - macos -> macos
# - freebsd -> freebsd
# - ubuntu, raspbian, debian ... -> debian
# - amzn, centos, rhel, fedora, ... -> fedora
# - opensuse-{leap,tumbleweed} -> opensuse
# - alpine -> alpine
# Private Keys and Certificates in this file generated with the commands below
openssl genrsa 2048 > ca-key.pem
openssl req -new -x509 -nodes -days 365000 \
-key ca-key.pem \
-out ca-cert.pem \
-addext "subjectAltName = IP:127.0.0.1"
openssl req -newkey rsa:2048 -nodes -days 365000 \
@yakuter
yakuter / ast_walk.go
Created February 24, 2022 06:56
AST walk example
func main() {
fs := token.NewFileSet()
f, err := parser.ParseFile(fs, "", "package main\nvar x int = 9\nfunc main(){b:=2}", parser.AllErrors)
if err != nil {
log.Fatal(err)
}
var v visitor
ast.Walk(v, f)
//fmt.Printf("%#v",f)
}
@yakuter
yakuter / golang-ca-certs-windows.go
Last active February 14, 2022 08:55
Golang Windows System CA Certificates
// +build windows
package main
import (
"crypto/x509"
"fmt"
"syscall"
"unsafe"
)