Skip to content

Instantly share code, notes, and snippets.

View mazdak78's full-sized avatar

Mazdak Mansouri mazdak78

View GitHub Profile
@mazdak78
mazdak78 / Find the index of first occurrence in a string.go
Created August 20, 2024 12:20
leetcode - Find the index of first occurrence in a string - golang
func strStr(haystack string, needle string) int {
if len(haystack) < len(needle) {
return -1
}
needleBytes := needle[0:]
for i := 0; i < len(haystack); i++ {
if haystack[i:i+len(needle)] == needleBytes {
return i
}
@mazdak78
mazdak78 / graphql_nullable_int64_field.go
Last active November 21, 2019 22:21
graphql-golang nullable int field
//the idea is taken from https://gist.github.com/bosgood/d9687f5d64c0f4038bc19c478d51fa64
// but that code throw exception and does not compile
// I just refined that and fix the problem and convert it to Int version
// same can be done for other nullable types
// LeadItem struct
type LeadItem struct {
CustomerId sql.NullInt64
}