misc #4

Merged
aynish merged 8 commits from misc into main 2024-08-31 18:12:03 -07:00
3 changed files with 51 additions and 1 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
*.sqlite
mast

View file

@ -7,7 +7,7 @@ import (
"log"
"os"
"mast/db"
mast "mast/db"
"github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea"
@ -89,6 +89,8 @@ func (m *model) addTodo(todo string) {
panic(err)
}
// TODO:
// func sync_changes
rows, err := m.db.Query("SELECT * FROM crsql_changes")
if err != nil {
log.Println("Error querying crsql_changes:", err)

46
server/test.go Normal file
View file

@ -0,0 +1,46 @@
package main
import (
"encoding/base64"
"fmt"
"strconv"
"strings"
)
func decodeBase64ToIntArray(encodedString string) ([]int, error) {
// Decode the base64 string
decodedBytes, err := base64.StdEncoding.DecodeString(encodedString)
if err != nil {
return nil, fmt.Errorf("error decoding base64: %w", err)
}
// Convert bytes to string
decodedString := string(decodedBytes)
// Split the string by commas
stringSlice := strings.Split(decodedString, ",")
// Convert each string to an integer
intSlice := make([]int, len(stringSlice))
for i, s := range stringSlice {
num, err := strconv.Atoi(s)
if err != nil {
return nil, fmt.Errorf("error converting string to int: %w", err)
}
intSlice[i] = num
}
return intSlice, nil
}
func main2() {
encodedString := "MSwxMSwzMiw1MCw5OCw1Nyw1Myw1NywxMDIsNTAsNTQsNTIsNTYsMTAyLDEwMCwxMDAsOTksNTEsNTQsNTcsMTAwLDk3LDEwMCwxMDIsMTAxLDU0LDQ5LDUzLDk5LDQ4LDEwMCw0OSw1NCwxMDIsNTI="
intArray, err := decodeBase64ToIntArray(encodedString)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Decoded integer array:", intArray)
}