Skip to content

Instantly share code, notes, and snippets.

View HalCanary's full-sized avatar

Hal Canary HalCanary

View GitHub Profile
// 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 "SkUTF.h"
#include "SkShaper.h"
#include "SkCanvas.h"
template <typename T, SkUnichar (*FN)(const T**, const T*)>
static SkString convert_to_utf8(const void* src, size_t srcBytes) {
// 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 "SkPath.h"
#include "SkTextBlobPriv.h"
#include "SkRSXform.h"
SkPath SkTextBlobToPath(const SkTextBlob* blob) {
SkPath path;
for (SkTextBlobRunIterator it(blob); !it.done(); it.next()) {
uint32_t runSize = it.glyphCount();
const SkFont& font = it.font();
#! /usr/bin/env python
# Copyright 2020 Hal W Canary, III. all rights reserved.
import lxml.html
import subprocess
import sys
import urllib2
class WikipediaTextParser:
@HalCanary
HalCanary / disc_useage_darwin.sh
Created September 24, 2021 14:07
disc_useage_darwin.sh
#!/bin/sh
INFO="$(diskutil ap list disk1)"
printf 'size: %14d\n' "$(printf %s "$INFO" | sed -n 's/ *Size (Capacity Ceiling): *\([0-9]*\).*/\1/p')"
printf 'use: %14d\n' "$(printf %s "$INFO" | sed -n 's/ *Capacity In Use By Volumes: *\([0-9]*\).*/\1/p')"
@HalCanary
HalCanary / makesvg.py
Last active June 7, 2023 12:59
makesvg.py
#! /usr/bin/env python3
'''
Making SVGs by hand is a pain. This is a better way:
It's functional, rather than using the XML "markup language" directly.
No closing tags, just balanced parentheses!
#xml #svg #python #python3 #graphicsprogramming
https://twitter.com/halcanary/status/1458802118136111107
Updated to use `xml.dom.minidom` instead of `lxml`.
package main
import (
"regexp"
"sort"
"strings"
"golang.org/x/net/html"
)
package main
import (
"exec"
"fmt"
"os"
"strings"
)
func ConvertToEbook(src, dst, title, authors, comments string) error {
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
}