Skip to content

Instantly share code, notes, and snippets.

@ehfeng
ehfeng / sequences.go
Created April 20, 2024 02:20
badgerdb sequences
package main
import (
"encoding/binary"
"fmt"
"sync"
"sync/atomic"
"github.com/dgraph-io/badger/v4"
)
@ehfeng
ehfeng / badgerdb.go
Created April 20, 2024 01:22
simple badger usage
package main
import (
"encoding/binary"
"fmt"
"sync"
"github.com/dgraph-io/badger/v4"
)
@ehfeng
ehfeng / v8_internal_fields_and_getters.go
Last active October 30, 2023 04:15
Verified getters work with internal fields in v8
package main
import (
v8 "rogchap.com/v8go"
)
type v8BuiltIns struct {
Object struct {
create *v8.Function
defineProperty *v8.Function
@ehfeng
ehfeng / bbolt_nil_value.go
Created August 30, 2023 00:30
You can store nil values in bbolt. In ForEach, the only way to determine if a key is a nil value or bucket is by attempting to cast it as a bucket.
package main
import (
"fmt"
"go.etcd.io/bbolt"
)
var bucketName = []byte("MyBucket")
@ehfeng
ehfeng / v8_complex_fn_perf.go
Created June 27, 2023 18:22
Performance cost of slightly complicated function call
package main
import (
"encoding/json"
"fmt"
"runtime"
"sync"
"time"
v8 "rogchap.com/v8go"
@ehfeng
ehfeng / v8_json_parse_perf.go
Created June 27, 2023 17:22
Parallelism, JSON parsing, and v8
package main
import (
"encoding/json"
"fmt"
"runtime"
"sync"
"time"
v8 "rogchap.com/v8go"
@ehfeng
ehfeng / v8_startup_parallelism.go
Created June 27, 2023 17:12
Performance cost of starting isolates in parallel
package main
import (
"fmt"
"runtime"
"sync"
"time"
v8 "rogchap.com/v8go"
)
@ehfeng
ehfeng / v8_values.go
Created June 21, 2023 15:18
How pointers works with primitives vs objects in v8go
package main
import (
"fmt"
v8 "rogchap.com/v8go"
)
func main() {
iso := v8.NewIsolate()
func main() {
m := map[string]int{
"one": 1,
}
defer func() {
fmt.Println("deferred first", m)
}()
// a function will evaluate upon defer
// an expression evaluates immediately
defer fmt.Println("deferred second", m)
package main
import "fmt"
func f(x, y, z chan string) {
defer close(x)
a := make(chan bool)
go func() {
for i := 0; i < 3; i++ {
x <- "hi"