Skip to content

Instantly share code, notes, and snippets.

View stnc's full-sized avatar
🎯
Focusing

TUNÇ Selman stnc

🎯
Focusing
View GitHub Profile
@stnc
stnc / rsasign.go
Created July 16, 2023 04:27 — forked from hansstimer/rsasign.go
Go: rsa signpkcs1v15 signing
package main
import (
"bytes"
"crypto"
"crypto/rand"
"crypto/rsa"
"crypto/sha512"
"fmt"
)
@stnc
stnc / datatable.go
Last active July 12, 2023 16:49
terminal datatabel application
package main
import (
"database/sql"
"fmt"
"github.com/gdamore/tcell/v2"
_ "github.com/go-sql-driver/mysql"
"github.com/rivo/tview"
"log"
"strconv"
@stnc
stnc / builder.go
Last active April 14, 2025 06:50
golang duck type example
package main
import (
"encoding/json"
"fmt"
"log"
)
type Builder struct {
ResponseRoot
@stnc
stnc / EmbedStruct3.go
Last active July 11, 2023 07:53
embed strcut and pointer example 3
package main
import (
"encoding/json"
"fmt"
"log"
)
type MyResponseRoot struct {
Version string `json:"version,omitempty"`
@stnc
stnc / AdvancPointer.go
Last active July 11, 2023 19:12
golang pointer example 2
package main
import (
"encoding/json"
"fmt"
"log"
)
@stnc
stnc / basic1.go
Last active September 6, 2023 04:49
golang deep pointer example
package main
import (
"fmt"
)
func increment(ptr *int) {
*ptr = *ptr + 1
}
@stnc
stnc / calculator.go
Last active July 6, 2023 03:46
golang first init interface and struct https://go.dev/play/p/5Grp31thhPr
//https://go.dev/play/p/5Grp31thhPr
package main
import "fmt"
type Start struct {
Number1 float64
Number2 float64
Text string
RequestHandler RequestHandler
@stnc
stnc / three_dot.go
Last active April 16, 2025 19:33
How to use Ellipsis (…) in Golang? - using a variadic function
package main
import (
"fmt"
)
// using a variadic function
func find(num int, nums ...int) {
fmt.Printf("type of nums is %T\n", nums)
found := false
@stnc
stnc / embed_map_fo_structure.go
Created July 2, 2023 09:15
Embed map in JSON output for struct
type Response struct {
Text string `json:"text,omitempty"`
SessionAttributes map[string]any `json:"sessionAttributes,omitempty"`
}
func main() {
var renderA Response
renderA.Text = "dsds"
renderA.SessionAttributes = make(map[string]interface{}) //https://dev.to/rytsh/embed-map-in-json-output-5dnj
renderA.SessionAttributes["read"] = true
@stnc
stnc / pointer_structure_with_embed.go
Last active April 14, 2025 07:18
A field declared with a type but no explicit field name is an anonymous field, also called an
//https://www.appsloveworld.com/go/12/embedding-when-to-use-pointer
//https://go.dev/play/p/IeUvieCOjs4
//https://go.dev/play/p/IeUvieCOjs4 You can use one or the other: for struct type, the spec mentions:
//A field declared with a type but no explicit field name is an anonymous field, also called an
//embedded field or an embedding of the type in the struct.
//An embedded type must be specified as a type name T or as a pointer to a
//non-interface type name *T, and T itself may not be a pointer type
package main