Skip to content

Instantly share code, notes, and snippets.

@wingedpig
wingedpig / inlinestyles.js
Created August 31, 2023 04:52
A function to calculate the computed styles of elements and write them as inline styles
const attributesToInline = ['flex', 'flex-basis', 'flex-direction', 'flex-grow', 'display', 'max-width', 'max-height', 'overflow-y', 'overflow-x'];
function inlineStyles(element) {
// Get computed styles of the element
const computedStyle = window.getComputedStyle(element);
let styleString = '';
for (const attr of attributesToInline) {
const value = computedStyle.getPropertyValue(attr);
if (value) {
if ((attr == "overflow-x" || attr == "overflow-y") && value == "visible") {
@wingedpig
wingedpig / chatgptparseexport.go
Created April 23, 2023 15:30
A Go program to parse ChatGPT export files
package main
import (
"encoding/json"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"sort"
package main
type Config struct {
Includes []string
UserDbConfig userdb.Config
Port int
}
package userdb
type Config struct {
URL string
MaxIdleConnections int
MaxOpenConnections int
ConnMaxLifetime int
Replica bool
}
{
"Includes": [
"userdb_conf.json"
],
"Port": 3000
}
{
"UserDbConfig": {
"URL": "user=groupsio password=dev host=127.0.0.1 dbname=userdb",
"MaxIdleConnections": 1,
"MaxOpenConnections": 10,
"ConnMaxLifetime": 0,
"Replica": false
}
}
// ReadConfig reads in a JSON-formatted configuration file, looking for any
// include directives, and recursively reading those files as well. Include directives
// are specified as a list keyed on the "Includes" key.
func ReadConfig(filename string, configuration interface{}) error {
// grab any path to the config file to add to the include names
var prefix string
slashindex := strings.LastIndex(filename, "/")
if slashindex != -1 {
prefix = filename[:slashindex+1]
@wingedpig
wingedpig / testpage.go
Created October 14, 2020 20:47
A thought experiment about a new Go-based UI framework.
package testpage
/*
This is a thought experiment about a new Go-based UI framework. A project to accomplish the same thing as React or Vue.js.
I strongly dislike Javascript and all the existing reactive UI frameworks. For whatever reason, and try as I might, I cannot get my head around
them. Hence this thought experiment about what kind of UI framework I would like to use.
== Goals ==
- I want to be able to build a responsive website easily.
@wingedpig
wingedpig / testconsumer.go
Created October 5, 2017 16:47
Test Kafka Consumer
package main
import (
"log"
"os"
"os/signal"
"github.com/Shopify/sarama"
)
@wingedpig
wingedpig / testproducer.go
Last active October 5, 2017 16:46
Test Kafka producer
package main
import (
"fmt"
"log"
"os"
"strings"
"sync"
"github.com/Shopify/sarama"