Skip to content

Instantly share code, notes, and snippets.

Avatar

debedb debedb

View GitHub Profile
View context.go
package main
import (
"context"
"fmt"
"sync"
"time"
)
func withCancel() {
@debedb
debedb / faafco.go
Last active Nov 25, 2022
Go: functions as first-class objects, variadic functions and generics
View faafco.go
package main
import "fmt"
func plus[T int | float32](i1 T, i2 T) T {
return i1 + i2
}
func minus[T int | float32](i1 T, i2 T) T {
return i1 - i2
@debedb
debedb / channels.go
Last active Nov 25, 2022
Go: Goroutines and channels
View channels.go
package main
import (
"fmt"
"strconv"
"sync"
"sync/atomic"
)
// No deadlock on all sleeping, etc.
@debedb
debedb / slices.go
Last active Nov 25, 2022
Go: Arrays vs slices
View slices.go
package main
import (
"fmt"
)
func slices2() {
slice1 := []string{"Ferrari", "Honda", "Ford"}
slice2 := slice1[:]
fmt.Println("Slice1: ", slice1)
@debedb
debedb / ptrrecv.go
Created Nov 25, 2022
Go: Pointer receivers
View ptrrecv.go
package main
import "fmt"
type _struct struct {
field string
}
func (s *_struct) doStuff(msg string) {
s.field = msg
View jsonconfigurer.md
@debedb
debedb / Generic usage of Google Ads API using reflection
Created Jun 26, 2021
Generic usage of Google Ads API using reflection
View Generic usage of Google Ads API using reflection
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.google.ads.googleads.v6.services.GoogleAdsVersion;
import com.google.api.gax.core.BackgroundResource;
import com.google.protobuf.AbstractMessage;
@debedb
debedb / MockUtils.java
Created Apr 9, 2021
Utilities for mocking DB calls
View MockUtils.java
import java.sql.Array;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
View OAuth1AuthorizationHeaderBuilder.java
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.Instant;
import java.util.Arrays;
import java.util.Base64;
import java.util.HashSet;
@debedb
debedb / pom-compare.py
Created Feb 10, 2021
Quick diff between pom dependencies
View pom-compare.py
#!/Library/Frameworks/Python.framework/Versions/3.6/bin/python3
from packaging import version
import sys
# files produced from pom.xml by
# mvn dependency:list -f pom.xml | grep "] " | sed 's/.*]\ \ \ \ //g' | sort | uniq
# arg1 - current file
# arg2 - "should-be" file
cur = open(sys.argv[1])