Skip to content

Instantly share code, notes, and snippets.

View earthboundkid's full-sized avatar

Carlana Johnson earthboundkid

View GitHub Profile

On the canonical repository URL

I changed my GitHub username from @carlmjohnson to @earthboundkid (actually, this was a revert because my username was originally @earthboundkid). Because Go uses URLs for package management, this means that existing packages will continue to use github.com/carlmjohnson/requests (for example) and be automatically redirected to github.com/earthbound/requests. There was a discussion about adding package forwarding to Go, but as of now, this has not been implemented. If package forwarding is added to a future version of Go, the URLs of my repositories may change at that time. I may also choose to change URLs if there is a breaking change to the API of a package. Thank you for bearing with this transition.

祇園精舎の鐘の聲、 Gion shōja no kane no koe
諸行無常の響あり。 shogyō mujō no hibiki ari.
娑羅雙樹の花の色、 Shara sōju no hana no iro
盛者必衰のことわりをあらはす。 jōsha hissui no kotowari o arawasu.
おごれる人も久しからず、 Ogoreru hito mo hisashikarazu,
唯春の夜の夢のごとし。 Tada haru no yo no yume no gotoshi.
たけき者も遂にほろびぬ、 Takeki mono mo tsui ni horobinu.
偏に風の前の塵に同じ。 Hitoe ni kaze no mae no chiri ni onaji.
@earthboundkid
earthboundkid / -Go iterator experiment.md
Last active July 25, 2023 17:28
Go iterator experiment

Go iterator proposal experiment

The second problem in Project Euler is

By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.

Nine years ago, I wrote a blog post that showed how to solve this in Python using iterators and in Go using channels. The Go code started simple, but ended up a bit complicated because it also had stop channels to allow early exit. See euler.py for the Python code, and channel.go for the Go code using channels.

Go issue #61405 proposes to add a new function-based iterator protocol to Go. To test it, I rewrote the Go code using push function iterators. See functional.go. The code is notably simpler and shorter than the channel based code.

export default function createElement(
tag = "div",
{ classList = [], attrs = {}, children = [], ...props } = {}
) {
let el = document.createElement(tag);
for (let c of classList) {
el.classList.add(c);
}
for (let attr in attrs) {
el.setAttribute(attr, attrs[attr]);
@earthboundkid
earthboundkid / crypto-rand.js
Last active June 22, 2021 19:14 — forked from paragonie-scott/gist:c7a73fd0f759e451cf07
Javascript CSPRNG for Integers
function secureRand(min, max) {
let range = max - min;
if (range < 2) {
return min;
}
let bits_needed = Math.ceil(Math.log2(range));
if (bits_needed > 31) {
throw new Error("cannot generate numbers larger than 31 bits.");
}
@earthboundkid
earthboundkid / tot
Last active February 28, 2020 15:12 — forked from zrzka/!IMPORTANT.md
A shell script for Tot
#!/usr/bin/env bash
# Fork of gruber's tot.sh https://gist.github.com/gruber/b18d8b53385fa612713754799ed4d0a2
# which is a fork of chockenberry's tot.sh https://gist.github.com/chockenberry/d33ef5b6e6da4a3e4aa9b07b093d3c23
#
# WARNING some options have different & potentially destructive meaning, for example:
# -r gets the dot contents in original script, but this one REPLACES the dot contents
# and does use -p to get the dot contents
#
@earthboundkid
earthboundkid / random.js
Created January 24, 2020 18:57
Generate random hex digits
function randomHex(n) {
let bytes = new Uint8Array(n);
crypto.getRandomValues(bytes);
return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
<template>
<div id="app">
Value is "{{ value }}". <br />
<input v-model="value" @input="handleChange($event)" />
</div>
</template>
<script>
function trimAndSpace(val) {
return val
@earthboundkid
earthboundkid / xtract.py
Created September 3, 2019 13:02
For SVG files with bloated PNG embeds
def xtract_pngs_from_svgs(name):
fname = name +'.svg'
#
with open(fname) as f:
raw = f.read()
#
prefix = 'xlink:href="data:image/png;base64,'
suffix = '"'
chunks = []
found = []