Skip to content

Instantly share code, notes, and snippets.

@aelindeman
aelindeman / merge.ts
Created December 26, 2019 21:04
React state hook merge function
// Creates a merge function for React state hooks,
// handy if you want to use state the way you might
// in a class component.
import React from 'react';
const createMerger = <S extends object>(setter: React.Dispatch<React.SetStateAction<S>>): React.Dispatch<Partial<S>> =>
(data: Partial<S>): void => setter(values => ({ ...values, ...data }));
const useMergeState = <S extends object>(initialState: S | (() => S)): [S, React.Dispatch<React.SetStateAction<S>>, React.Dispatch<Partial<S>>] => {
@aelindeman
aelindeman / README.md
Last active February 22, 2024 17:21
ONC-format OpenVPN client configuration (Chrome OS) for OVPN

Instructions

  1. Download https://files.ovpn.com/ubuntu_cli/ovpn-us.zip
  2. Unzip it
  3. Fill in the template
    • UUID #1 and #2: create two UUIDs either from something like https://www.uuidgenerator.net/ or by running cat /proc/sys/kernel/random/uuid in a terminal, then paste them into the fields (leave in the curly braces)
    • Server CA: ovpn-ca.crt from the download - remove the -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- lines, make the rest all one line, then paste it into the X509 field
    • Host: the OVPN server you wish to use - I chose US servers, but if you follow the "Ubuntu CLI" guide and download the zip file, the ovpn.conf file has a remote field where you can find a different host
    • Client key: ovpn-tls.key from the download - run grep -v '#' ovpn-tls.key | perl -p -e 's/\n/\\n/' - and paste the result into the TLSAuthContents field
  • Fill in your OVPN username and password
@aelindeman
aelindeman / http.ts
Created July 3, 2019 22:49
a one-size-fits-most HTTP module in 30 lines
export default {
http: (args: {
method: 'HEAD' | 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS';
url: string;
headers?: {[key: string]: string};
body?: string;
on?: {
[event: string]: {(xhr: {}): void};
};
timeout?: number;
@aelindeman
aelindeman / webhook-find-replace.py
Created January 3, 2019 18:41
find/replace in Github webhook URLs across every repository for a user/organization
'''`pip install github` first'''
import os
from github import Github
g = Github(os.environ.get('GITHUB_TOKEN'))
repos = g.get_organization('aelindeman').get_repos()
find = ''
replace = ''
@aelindeman
aelindeman / darkmode.sh
Last active September 27, 2018 07:05
toggle macOS Mojave's dark mode from the terminal
#!/bin/sh
case "$1" in
on)
osascript -e '
tell application id "com.apple.systemevents"
tell appearance preferences
if dark mode is false then
set dark mode to true
else
@aelindeman
aelindeman / gist:762903349dc853d6acf44dd277c02f6b
Created September 11, 2018 03:37
download Docker CE for Mac without a login
curl -O https://download.docker.com/mac/stable/Docker.dmg
@aelindeman
aelindeman / script.groovy
Created September 1, 2018 00:00
clear a multibranch Jenkins job's history
def projectName = "project/name"
def project = Jenkins.instance.getItem(projectName)
def jobs = project.getItems().each { job ->
job.getBuilds().each { it.delete() }
job.nextBuildNumber = 1
job.save()
}
@aelindeman
aelindeman / anchorizer.css
Created August 21, 2018 15:51
automatically create clickable anchor icon links after headers
h1 a.anchorizer,
h2 a.anchorizer,
h3 a.anchorizer,
h4 a.anchorizer,
h5 a.anchorizer,
h6 a.anchorizer {
display: none;
font-size: 50%;
margin-left: 0.5em;
vertical-align: middle;
@aelindeman
aelindeman / password.groovy
Last active July 18, 2018 17:02
generate a password-like random string in Groovy
def length = 24
def password = new java.util.Random().with { r ->
def pool = ('a'..'z') + ('A'..'Z') + (0..9)
(1..length).collect { pool[r.nextInt(pool.size())] }.join('')
}
@aelindeman
aelindeman / vault-copy-unwrap.sh
Last active July 6, 2018 21:43
vault with copy, move, and token-unwrap-to-path
#!/bin/bash
set -eo pipefail
export VAULT_BIN="$HOME/.local/bin/vault-0.10.3" # or wherever you've installed vault
oopsie() {
echo "usage: $*"
exit 1
}