Skip to content

Instantly share code, notes, and snippets.

View HalCanary's full-sized avatar

Hal Canary HalCanary

View GitHub Profile
@HalCanary
HalCanary / Makefile
Created November 28, 2023 12:05
Go Makefile Example
all: test build
COMMANDS = $(notdir $(wildcard cmd/*))
BINARIES = $(addprefix build/,$(COMMANDS))
${BINARIES}: $(shell find . -name '*.go') go.mod go.sum
@mkdir -p build
go get ./...
go build -o build ./...
@HalCanary
HalCanary / slog_Lshortfile_example.go
Last active August 29, 2023 14:14
log/slog Lshortfile replacement example.
package main
import (
"os"
)
import (
"io"
"log/slog"
"path/filepath"
@HalCanary
HalCanary / example.go
Created August 23, 2023 14:11
Golang Protobuff Message Copy Function
package main
import (
"fmt"
"google.golang.org/protobuf/proto"
// type proto.Message interface { ....
// func proto.Merge(dst, src Message)
"[...]/foo"
// syntax = "proto3";
// message Foo {
@HalCanary
HalCanary / get_boolean_value_from_json.sh
Last active June 23, 2023 15:30
[MacOS] get_boolean_value_from_json.sh
get_boolean_value_from_json() {
# Return true if the JSON file exists, the variable is set, and it
# evaluates as true in javascript.
test -f "$1" && osascript -l 'JavaScript' 2>&1 <<- EOF
ObjC.import('stdlib');
$.exit(JSON.parse(\`$(cat "$1")\`).${2} ? 0 : 1);
EOF
}
package main
import (
"fmt"
"os"
"os/exec"
"strings"
)
func MuttSendFile(dstEmail, filePath string) error {
package main
import (
"exec"
"fmt"
"os"
"strings"
)
func ConvertToEbook(src, dst, title, authors, comments string) error {
package main
import (
"regexp"
"sort"
"strings"
"golang.org/x/net/html"
)
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"strings"
)
@HalCanary
HalCanary / logExample.go
Created May 22, 2023 15:04
logExample.go
package main
import (
"errors"
"log"
"os"
)
func expectNil(err error) {
if err != nil {
@HalCanary
HalCanary / element.js
Created May 2, 2023 21:35
element.js
function E(tagName, clas, ...children) {
var e = document.createElement(tagName);
if (clas) {
e.className = clas;
}
for (const c of children) {
e.appendChild(c);
}
return e
}