Compare commits

..

6 Commits

Author SHA1 Message Date
Jeff Carr 00d9cbf64f setup rwhois (?) 2025-09-16 09:32:21 -05:00
Jeff Carr 3e8e5fba8f a telegram example 2025-08-16 18:59:08 -05:00
Jeff Carr f5a8c9b672 dumb files that don't build 2025-05-23 03:28:13 -05:00
Jeff Carr 605ebd6c8b ai code builds kinda 2025-04-12 11:27:04 -05:00
Jeff Carr 1b0344899f hmm 2025-04-12 08:51:39 -05:00
Jeff Carr 9ba9093875 add a vnc record example 2025-03-17 05:08:28 -05:00
11 changed files with 396 additions and 0 deletions

2
.gitignore vendored
View File

@ -3,6 +3,7 @@ go.mod
go.sum
/files/*
/work/*
*.mov
forgeConfig/forgeConfig
scanGoSrc/scanGoSrc
@ -19,3 +20,4 @@ cf-r2/cf-r2
cf-r2/download
cf-r2/upload
wit-utils
vncrecord/vncrecord

12
genai/Makefile Normal file
View File

@ -0,0 +1,12 @@
testgo: goimports
# GO111MODULE=off go run aistudio.go
go run -v aistudio.go
real:
GO111MODULE=off go run aistudio.go
vet:
GO111MODULE=off go vet
goimports:
goimports -w *.go

54
genai/aistudio.go Normal file
View File

@ -0,0 +1,54 @@
package main
import (
"context"
"fmt"
"log"
"os"
// "github.com/google/generative-ai-go/genai"
"cloud.google.com/go/ai/vertexai/genai"
"google.golang.org/api/option"
)
func main() {
ctx := context.Background()
apiKey := os.Getenv("GEMINI_API_KEY")
if apiKey == "" {
log.Fatal("GEMINI_API_KEY environment variable not set")
}
client, err := genai.NewClient(ctx, option.WithAPIKey(apiKey))
if err != nil {
log.Fatalf("Failed to create genai client: %v", err)
}
defer client.Close()
model := client.GenerativeModel("gemini-2.5-pro-preview-03-25")
// Set system instruction
model.SystemInstruction = &genai.Content{
Parts: []genai.Part{
genai.Text("This is for working with the GO language files at http://go.wit.com/"),
},
}
// Stream content generation
iter := model.GenerateContentStream(ctx, genai.Text("what is the current version of forge on the webpage?"))
for {
resp, err := iter.Next()
if err != nil {
break
}
for _, part := range resp.Candidates {
if part.Content != nil {
for _, p := range part.Content.Parts {
if text, ok := p.(genai.Text); ok {
fmt.Print(string(text))
}
}
}
}
}
}

24
git-bug-proto/Makefile Normal file
View File

@ -0,0 +1,24 @@
VERSION = $(shell git describe --tags)
GUIVERSION = $(shell git describe --tags)
BUILDTIME = $(shell date +%s)
all: vet build
build: goimports
GO111MODULE=off go build \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
vet:
GO111MODULE=off go vet
goimports:
goimports -w *.go
# // to globally reset paths:
# // gofmt -w -r '"go.wit.com/gui/gadgets" -> "go.wit.com/lib/gadgets"' *.go
install: goimports
GO111MODULE=off go install \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
force: build
./go-clone-test --force

12
git-bug-proto/main.go Normal file
View File

@ -0,0 +1,12 @@
//go:generate go run doc/generate.go
//go:generate go run misc/completion/generate.go
package main
import (
"github.com/git-bug/git-bug/commands"
)
func main() {
commands.Execute()
}

53
rwhois/main.go Normal file
View File

@ -0,0 +1,53 @@
package main
import (
"bufio"
"fmt"
"log"
"net"
"strings"
)
const RWhoisPort = "4321"
func handleConnection(conn net.Conn) {
defer conn.Close()
reader := bufio.NewReader(conn)
query, err := reader.ReadString('\n')
if err != nil {
log.Printf("Error reading query: %v", err)
return
}
query = strings.TrimSpace(query)
log.Printf("Received query: %s", query)
// In a real RWhois server, you would parse the query,
// look up data, and potentially issue referrals.
// For this example, we'll send a simple response.
response := fmt.Sprintf("RWhois response for: %s\n", query)
_, err = conn.Write([]byte(response))
if err != nil {
log.Printf("Error writing response: %v", err)
return
}
}
func main() {
listener, err := net.Listen("tcp", ":"+RWhoisPort)
if err != nil {
log.Fatalf("Error listening: %v", err)
}
defer listener.Close()
log.Printf("RWhois server listening on port %s", RWhoisPort)
for {
conn, err := listener.Accept()
if err != nil {
log.Printf("Error accepting connection: %v", err)
continue
}
go handleConnection(conn)
}
}

1
telegram/.env Normal file
View File

@ -0,0 +1 @@
TOKEN=5292519055:AAGJPrxYs70PoIWEvLcS3oV3XZ2ldko-M4k

5
telegram/Makefile Normal file
View File

@ -0,0 +1,5 @@
run:
go run -v -x send_after.go
test:
curl https://api.telegram.org/bot5292519055:AAGJPrxYs70PoIWEvLcS3oV3XZ2ldko-M4k/getMe

37
telegram/send_after.go Normal file
View File

@ -0,0 +1,37 @@
package main
import (
"time"
"fmt"
. "github.com/enetx/g"
"github.com/enetx/tg/bot"
"github.com/enetx/tg/ctx"
)
func main() {
fmt.Println("started...")
// Read the bot token from the .env file
token := NewFile(".env").Read().Ok().Trim().Split("=").Collect().Last().Some()
b := bot.New(token).Build().Unwrap()
// Register a command handler for /start
b.Command("start", func(ctx *ctx.Context) error {
// Send an immediate message so Telegram considers the update as "handled"
ctx.SendMessage("Preparing self-destruct...").Send()
// Schedule a second message to be sent after 3 seconds,
// and automatically delete it 5 seconds after it is sent
ctx.SendMessage("This message will self-destruct in 5 seconds.").
After(3 * time.Second). // Delay sending by 3 seconds
DeleteAfter(5 * time.Second). // Delete 5 seconds after it is sent
Send()
// Delete the original /start message (from the user)
// This should be done after responding to avoid Telegram resending the update
return ctx.DeleteMessage().Send().Err()
})
// Start polling for updates and drop any pending ones from before startup
b.Polling().DropPendingUpdates().Start()
}

10
vncrecord/Makefile Normal file
View File

@ -0,0 +1,10 @@
all: build test
build:
GO111MODULE=off go build
test:
./vncrecord localhost:6910
clean:
rm -f *.mov vncrecord

186
vncrecord/main.go Normal file
View File

@ -0,0 +1,186 @@
package main
import (
"context"
"log"
"net"
"os"
"os/signal"
"runtime"
"runtime/pprof"
"syscall"
"time"
vnc "github.com/amitbet/vnc2video"
"github.com/amitbet/vnc2video/encoders"
"github.com/amitbet/vnc2video/logger"
)
func main() {
runtime.GOMAXPROCS(4)
framerate := 12
runWithProfiler := false
// Establish TCP connection to VNC server.
nc, err := net.DialTimeout("tcp", os.Args[1], 5*time.Second)
if err != nil {
logger.Fatalf("Error connecting to VNC host. %v", err)
}
logger.Tracef("starting up the client, connecting to: %s", os.Args[1])
// Negotiate connection with the server.
cchServer := make(chan vnc.ServerMessage)
cchClient := make(chan vnc.ClientMessage)
errorCh := make(chan error)
ccfg := &vnc.ClientConfig{
SecurityHandlers: []vnc.SecurityHandler{
//&vnc.ClientAuthATEN{Username: []byte(os.Args[2]), Password: []byte(os.Args[3])}
// &vnc.ClientAuthVNC{Password: []byte("12345")},
&vnc.ClientAuthNone{},
},
DrawCursor: true,
PixelFormat: vnc.PixelFormat32bit,
ClientMessageCh: cchClient,
ServerMessageCh: cchServer,
Messages: vnc.DefaultServerMessages,
Encodings: []vnc.Encoding{
&vnc.RawEncoding{},
&vnc.TightEncoding{},
&vnc.HextileEncoding{},
&vnc.ZRLEEncoding{},
&vnc.CopyRectEncoding{},
&vnc.CursorPseudoEncoding{},
&vnc.CursorPosPseudoEncoding{},
&vnc.ZLibEncoding{},
&vnc.RREEncoding{},
},
ErrorCh: errorCh,
}
cc, err := vnc.Connect(context.Background(), nc, ccfg)
screenImage := cc.Canvas
if err != nil {
logger.Fatalf("Error negotiating connection to VNC host. %v", err)
}
// out, err := os.Create("./output" + strconv.Itoa(counter) + ".jpg")
// if err != nil {
// fmt.Println(err)p
// os.Exit(1)
// }
//vcodec := &encoders.MJPegImageEncoder{Quality: 60 , Framerate: framerate}
//vcodec := &encoders.X264ImageEncoder{FFMpegBinPath: "./ffmpeg", Framerate: framerate}
//vcodec := &encoders.HuffYuvImageEncoder{FFMpegBinPath: "./ffmpeg", Framerate: framerate}
vcodec := &encoders.QTRLEImageEncoder{FFMpegBinPath: "/usr/bin/ffmpeg", Framerate: framerate}
//vcodec := &encoders.VP8ImageEncoder{FFMpegBinPath:"./ffmpeg", Framerate: framerate}
//vcodec := &encoders.DV9ImageEncoder{FFMpegBinPath:"./ffmpeg", Framerate: framerate}
//counter := 0
//vcodec.Init("./output" + strconv.Itoa(counter))
go vcodec.Run("./output.mp4")
//windows
///go vcodec.Run("/Users/amitbet/Dropbox/go/src/vnc2webm/example/file-reader/ffmpeg", "./output.mp4")
//go vcodec.Run("C:\\Users\\betzalel\\Dropbox\\go\\src\\vnc2video\\example\\client\\ffmpeg.exe", "output.mp4")
//vcodec.Run("./output")
//screenImage := vnc.NewVncCanvas(int(cc.Width()), int(cc.Height()))
for _, enc := range ccfg.Encodings {
myRenderer, ok := enc.(vnc.Renderer)
if ok {
myRenderer.SetTargetImage(screenImage)
}
}
// var out *os.File
logger.Tracef("connected to: %s", os.Args[1])
defer cc.Close()
cc.SetEncodings([]vnc.EncodingType{
vnc.EncCursorPseudo,
vnc.EncPointerPosPseudo,
vnc.EncCopyRect,
vnc.EncTight,
vnc.EncZRLE,
//vnc.EncHextile,
//vnc.EncZlib,
//vnc.EncRRE,
})
//rect := image.Rect(0, 0, int(cc.Width()), int(cc.Height()))
//screenImage := image.NewRGBA64(rect)
// Process messages coming in on the ServerMessage channel.
go func() {
for {
timeStart := time.Now()
vcodec.Encode(screenImage.Image)
timeTarget := timeStart.Add((1000 / time.Duration(framerate)) * time.Millisecond)
timeLeft := timeTarget.Sub(time.Now())
if timeLeft > 0 {
time.Sleep(timeLeft)
}
}
}()
sigc := make(chan os.Signal, 1)
signal.Notify(sigc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
frameBufferReq := 0
timeStart := time.Now()
if runWithProfiler {
profFile := "prof.file"
f, err := os.Create(profFile)
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
for {
select {
case err := <-errorCh:
panic(err)
case msg := <-cchClient:
logger.Tracef("Received client message type:%v msg:%v\n", msg.Type(), msg)
case msg := <-cchServer:
//logger.Tracef("Received server message type:%v msg:%v\n", msg.Type(), msg)
// out, err := os.Create("./output" + strconv.Itoa(counter) + ".jpg")
// if err != nil {
// fmt.Println(err)
// os.Exit(1)
// }
if msg.Type() == vnc.FramebufferUpdateMsgType {
secsPassed := time.Now().Sub(timeStart).Seconds()
frameBufferReq++
reqPerSec := float64(frameBufferReq) / secsPassed
//counter++
//jpeg.Encode(out, screenImage, nil)
///vcodec.Encode(screenImage)
logger.Infof("reqs=%d, seconds=%f, Req Per second= %f", frameBufferReq, secsPassed, reqPerSec)
reqMsg := vnc.FramebufferUpdateRequest{Inc: 1, X: 0, Y: 0, Width: cc.Width(), Height: cc.Height()}
//cc.ResetAllEncodings()
reqMsg.Write(cc)
}
case signal := <-sigc:
if signal != nil {
vcodec.Close()
pprof.StopCPUProfile()
time.Sleep(2 * time.Second)
os.Exit(1)
}
}
}
//cc.Wait()
}