Skip to content

Instantly share code, notes, and snippets.

@benjaminblack
benjaminblack / index.js
Last active November 16, 2018 16:58
Run JavaScript in the terminal from a gist with npx
#!/usr/bin/env node
console.log('gist');
@benjaminblack
benjaminblack / linear-interpolation-of-font-size-based-on-viewport-dimensions-using-viewport-units.md
Last active July 9, 2018 19:48
Linear interpolation of font size based on viewport dimensions using viewport units

If a font size should scale linearly with the viewport width (or height), e.g. from 12px at 375w to 24px at 1280w, the interpolated font size can be calculated using the slope-intercept line equation (y = mx + b) with x set to 100vw (or vh) and using px units for b.

Make your life easier by using Wolfram Alpha to compute the equation of the line passing through two points (x1, y1) and (x2, y2), where x1 and x2 are the size of the viewport dimension (width or height) and y1 and y2 are the target font sizes at those viewport dimensions.

Continuing the example above, for 12px at 375w to 24px at 1280w, the points are (375,12) and (1280,24).

For the line between those two points, Wolfram Alpha returns the equation:

y = (12/905)x + (1272/181)
@benjaminblack
benjaminblack / converting-fonts-to-woff.md
Last active September 10, 2018 15:00
Converting fonts to WOFF

For some reason, font foundries still do not routinely include web font files, even when the font face is specifically licensed for use on the web, and will only provide the fonts in TrueType (TTF) format.

There is no need to use a sketchy online converter that might illegally save a copy of your expensively-licensed font.

Google maintains free software (MIT) command-line utilities to compress and decompress WOFF2 files.

"Converting" (really, just encoding and compressing) TTF to WOFF is as simple as:

$ woff2_compress myfont.ttf
@benjaminblack
benjaminblack / get-a-list-of-all-your-github-repositories.md
Last active June 5, 2018 00:48
Get a list of all of your GitHub repositories

Replace <username> with your GitHub username and be prepared to enter your GitHub password on the command line.

If you have more than 100 repositories, you'll need to run this command several times, editing the page=? parameter each time.

Replace ssh_url in the jq query with git_url for git:// scheme, and with clone_url for https:// scheme.

LISTFILE=repos.txt
curl -u "<username>" "https://api.github.com/user/repos?page=1&per_page=100" | jq '.[].ssh_url' | while read repo
do
@benjaminblack
benjaminblack / add-all-of-your-youtube-subscriptions-to-inoreader-at-once.md
Last active May 25, 2018 17:11
Add all of your YouTube subscriptions to inoreader at once
@benjaminblack
benjaminblack / trusting-a-self-signed-certificate-in-chrome-on-linux.md
Last active May 23, 2018 04:52
Trusting a self-signed certificate in Chrome on Linux

Add a self-signed certificate:

certutil -d sql:$HOME/.pki/nssdb -A -t "P,," -n <certificate nickname> \
-i <certificate filename>

E.g.,

@benjaminblack
benjaminblack / using-the-server-flag-with-the-certbot-client-for-lets-encrypt-acme-v02.md
Last active May 10, 2018 14:39
Using the --server flag with the certbot client for Let's Encrypt ACME v02

Use the --server flag with certbot to direct the client to a specific ACME server.

The Let's Encrypt status site lists their active servers (along with their status, obviously). Prepend the server fqdn with https:// and append /directory to the end for use with the certbot command.

E.g., for ACME v02 (which supports wildcard certs),

certbot certonly --dns-route53 --server https://acme-v02.api.letsencrypt.org/directory --domain "example.com" --domain "*.example.com"
@benjaminblack
benjaminblack / imagemagick-cheat-sheet.md
Last active March 15, 2018 19:19
ImageMagick cheat sheet

Convert a directory of PNGs to JPEGs:

for file in `ls *.png`
do
    extension="${file##*.}"
    base="${file%.*}"
    convert "$file" -quality 60 "${base}.jpg"
done
@benjaminblack
benjaminblack / show-hidden-files-in-macos-file-dialogs.md
Last active January 23, 2018 22:05
Show hidden files in macOS file dialogs

⌘-⇧-. (Command-Shift-Period)

@benjaminblack
benjaminblack / using-https-in-local-development.md
Last active September 4, 2018 21:40
Using HTTPS in local development

Using HTTPS in local development

Beginning June 2018, Chrome 68 will begin marking HTTP as "Not Secure". Other browsers may swiftly follow Chrome's lead.

The push for Secure Contexts Everywhere and enforcement of HTTPS for all new features is also motivation to secure local development environments, to reduce the delta between development and production environments.

In short, the Web is rapidly moving all traffic to HTTPS, and local development environments should be no different.

The Problem

Easing the use of HTTPS in local environments, where each project gets a domain like ${project_name}.localhost, means automating the process of creating a self-signed certificate for each project, configuring the web server to use it, and locally trusting the certificates. (A new certificate for each project is required in this configuration, because a cer