Skip to content

Instantly share code, notes, and snippets.

View ehfeng's full-sized avatar

Eric Feng ehfeng

View GitHub Profile
@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"
package main
import (
"fmt"
"strconv"
"time"
v8 "rogchap.com/v8go"
)
@ehfeng
ehfeng / bigint.go
Created October 15, 2022 21:40
BigInt
package bigint
import (
"encoding/json"
"errors"
"strconv"
"gopkg.in/guregu/null.v4"
)
@ehfeng
ehfeng / nginx.conf
Created July 10, 2022 21:11
Mapping requests to localhost servers based on Accept header
events {
worker_connections 1024;
}
http {
map $http_accept $accept {
default app;
~text/html web;
}
package main
import (
"fmt"
"log"
"math/rand"
"time"
v8 "rogchap.com/v8go"
)
package main
import (
"fmt"
"time"
"github.com/ry/v8worker2"
)
var script string = `
echo "{\"filename\": \"main.py\", \"code\": \"from raven import Client\n\nclient = Client('https://c3a66f7b59044173b7f0e7cf8367a6a5:a9b80f66c31d476db3ae2cd4fd8279ab@sentry.io/1257305')\n\ntry:\n 1 / 0\nexcept ZeroDivisionError:\n client.captureException()\n\nprint('testing print')\n\"}" | http POST https://us-central1-hackweek-fastrack.cloudfunctions.net/python-eval
{"code": "var Raven = require('raven');\nRaven.config('https://c3a66f7b59044173b7f0e7cf8367a6a5@sentry.io/1257305').install();\ntry {\n doAnotherThing(a[0]);\n} catch (e) {\n Raven.captureException(e);\n}"}