Skip to content

Instantly share code, notes, and snippets.

View HalCanary's full-sized avatar

Hal Canary HalCanary

View GitHub Profile
@HalCanary
HalCanary / Makefile
Last active July 6, 2024 13:48
Location/Makefile
Location: Location.m Location.info.plist
cc $< \
-framework CoreLocation \
-framework AppKit \
-sectcreate __TEXT __info_plist Location.info.plist \
-o $@
[ "$$CODESIGN_IDENTITY" ] && \
codesign \
-s "${CODESIGN_IDENTITY}" \
--verbose --force \
@HalCanary
HalCanary / Location.info.plist
Last active July 6, 2024 16:37
Location/Location.info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist
PUBLIC '-//Apple//DTD PLIST 1.0//EN'
'http://www.apple.com/DTDs/PropertyList-1.0.dtd'>
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>Location</string>
<key>CFBundleIdentifier</key>
<string>com.example.location</string>
@HalCanary
HalCanary / Location.m
Last active July 6, 2024 13:41
Location/Location.m
// Exmaple of using CoreLocation on macOS.
//
// Link with:
// -framework AppKit
// -framework CoreLocation
#include <stdio.h>
#include <stdlib.h>
#include <AppKit/AppKit.h>
#include <CoreLocation/CoreLocation.h>
@interface Delegate : NSObject <CLLocationManagerDelegate>
@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 May 8, 2024 15:48
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"
)