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. The current plan is to migrate package URLs along with a change to /v2 in order to prevent broken go mod upgrades. Thank you for bearing with this transition.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package csvutil_test | |
import ( | |
"bytes" | |
"encoding/csv" | |
"testing" | |
ebcsv "github.com/earthboundkid/csv/v2" | |
"github.com/gocarina/gocsv" | |
"github.com/jszwec/csvutil" |
祇園精舎の鐘の聲、 | 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. |
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function randomHex(n) { | |
let bytes = new Uint8Array(n); | |
crypto.getRandomValues(bytes); | |
return Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join(''); | |
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
<div id="app"> | |
Value is "{{ value }}". <br /> | |
<input v-model="value" @input="handleChange($event)" /> | |
</div> | |
</template> | |
<script> | |
function trimAndSpace(val) { | |
return val |
NewerOlder