Skip to content

Instantly share code, notes, and snippets.

View HalCanary's full-sized avatar

Hal Canary HalCanary

View GitHub Profile
@HalCanary
HalCanary / slog_Lshortfile_example.go
Last active April 1, 2024 15:44
log/slog Lshortfile replacement example.
package main
import (
"os"
)
import (
"io"
"log/slog"
"path/filepath"
@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 / html_generator_example.go
Last active November 14, 2023 13:20
html_generator_example.go
// Go Playground: https://go.dev/play/p/ao7M54vTDRQ
package main
import (
"os"
"strings"
"golang.org/x/net/html"
)
@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 {
/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
/*
## build.ninja ##
PNGD = /home/halcanary/src/skia/third_party/libpng
cflags = -I$PNGD
// Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "skia.h"
#include "SkShaper.h"
#include <iostream>
#include <string>
int main() {
constexpr int kWidth = 1080;
constexpr int kXMargin = 40;
constexpr int kYMargin = 40;
#include "SkFontTypes.h"
#include <cstddef>
class SkFont;
class SkTextBlob;
template<typename T> class sk_sp;
sk_sp<SkTextBlob> SkShapeText(const void* text,
size_t byteLength,
const SkFont& font,
SkTextEncoding encoding = kUTF8_SkTextEncoding);
/*
Idea: put all of the primitive-shaping functions in a single place in our API.
This will make clear that the NONE of these functions do what you expect them
to do.
*/
// Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#ifndef SkSimpleShaper_DEFINED
#define SkSimpleShaper_DEFINED