Skip to content

Instantly share code, notes, and snippets.

View EricCrosson's full-sized avatar
💭
This is not my status.

Eric Crosson EricCrosson

💭
This is not my status.
View GitHub Profile
@EricCrosson
EricCrosson / README.md
Created February 19, 2023 01:02 — forked from swinton/README.md
Automatically sign your commits from GitHub Actions, using the REST API

Verified commits made easy with GitHub Actions

image

So you want to commit changes generated by a GitHub Actions workflow back to your repo, and have that commit signed automatically?

Here's one way this is possible, using the REST API, the auto-generated GITHUB_TOKEN, and the GitHub CLI, gh, which is pre-installed on GitHub's hosted Actions runners.

You don't have to configure the git client, just add a step like the one below... Be sure to edit FILE_TO_COMMIT and DESTINATION_BRANCH to suit your needs.

Other 10 hrs 15 mins █████████████████████ 100.0%
@EricCrosson
EricCrosson / autozoom.lua
Created May 21, 2022 13:12 — forked from mason-larobina/autozoom.lua
Auto save/apply zoom levels on a per-domain basis
--------------------------------------------------------
-- Auto save/apply zoom levels on a per-domain basis --
-- (C) 2011 Roman Leonov <rliaonau@gmail.com>         --
-- (C) 2011 Mason Larobina <mason.larobina@gmail.com> --
--------------------------------------------------------
-- Get lua environment
local math = require "math"
local tonumber = tonumber
local string = string
@EricCrosson
EricCrosson / gocover.sh
Created February 5, 2022 15:28
Shell Aliases for Testing in Go
# Calculate test-coverage over a set of tests identified by a regex
# Usage: gocover <package> [<regex>]
#
# @example
# gocover ./service/foo 'TestFoo/Behavior/.*'
gocover() {
local package="${1:?Package must be specified}"
local regex="${2:+-run $2}"
local t="$(mktemp -t cover-XXXXXXXXXX)"
go test "${package}" -v -coverprofile="${t}" ${regex}
#!/usr/bin/env bash
# helix-editor hash: {{ include ".git-submodule-shas/helix" | sha256sum }}
readonly prefix="${HOME}/.local/share/chezmoi"
readonly helix_dir="${prefix}/helix"
readonly helix_config_dir="${HOME}/.config.helix"
readonly helix_runtime_directory="${helix_config_dir}/runtime"
# update helix and submodules
#!/usr/bin/env bash
readonly chezmoi_dir="${HOME}/.local/share/chezmoi"
readonly git_submodule_sha_dir="${chezmoi_dir}/.git-submodule-shas"
cd "${chezmoi_dir}" || exit
mkdir -p "${git_submodule_sha_dir}"
IFS=$'\n'

There are three easy to make mistakes in go. I present them here in the way they are often found in the wild, not in the way that is easiest to understand.

All three of these mistakes have been made in Kubernetes code, getting past code review at least once each that I know of.

  1. Loop variables are scoped outside the loop.

What do these lines do? Make predictions and then scroll down.

func print(pi *int) { fmt.Println(*pi) }
@EricCrosson
EricCrosson / latency.txt
Created January 3, 2022 01:46 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@EricCrosson
EricCrosson / BLOG.md
Created December 28, 2021 23:41 — forked from elierotenberg/BLOG.md
Idiomatic Data Fetching using React Hooks

Idiomatic Data Fetching using React Hooks

This post has been written in collaboration with @klervicn

Virtually all web apps and websites need to pull data from a server, usually through a JSON-returning API. When it comes to integrating data fetching in React component, the "impedence mismatch" between the React components, which are declarative and synchronous, and the HTTP requests, which are imperative and asynchronous, is often problematic.

Many apps use third-party libraries such as Redux or Apollo Client to abstract it away. This requires extra dependencies, and couple your app with a specific library to perform data fetching. In most cases, what we want is a direct way to integrate plain HTTP requests (e.g. using native fetch) for usage in React components.

Here we will discuss how we can use React Hooks to do this in an elegant, scalable manner.

@EricCrosson
EricCrosson / collate-unhoistable-lerna-dependencies.sh
Created October 29, 2021 15:26
Collate unhoistable lerna dependencies
npx lerna bootstrap --force-local --strict --hoist 2> >(jq --raw-input --slurp '
# create an array of relevant lines
split("\n")
| map(
select(. != "")
| select(contains("WARN EHOIST_PKG_VERSION"))
)
# create { hoisted: string, unhoisted: string }[]
| map(