Skip to content

Instantly share code, notes, and snippets.

View rjz's full-sized avatar
👋
Hey there!

RJ Zaworski rjz

👋
Hey there!
View GitHub Profile

React Context API

George Song (Twitter: @zukefresh, Github: @gsong)

  • Need React >= v16.3.0
  • State: Component → Context → Unstated → Redux/MobX/(etc)
  • Two parts: <Provider /> and <Consumer />

How it works

@rjz
rjz / pre-commit
Created January 18, 2018 17:15
TODO git hook
#!/bin/bash
# A pre-commit hook to help you do the right thing (tm)
set -e
changed-files () {
git diff HEAD --name-only "$@"
}
*.swp

RE: envelope_encryption

[Repository][repo].

OSS items

A few notes. First, if we're planning to link the demo from a blog post, I'd be happy to check a couple of boxes on community-friendliness by:

  • adding a LICENSE, README (with install/usage, a bit of background, and
@rjz
rjz / expiresIn.js
Created September 22, 2017 21:38
Expiring promise
const expiresIn = (timeoutMs, promise, msg = 'Promise timed out') =>
new Promise((resolve, reject) => {
const timerId = setTimeout(reject, timeoutMs, msg);
promise.then((result) => {
clearTimeout(timerId);
resolve(result);
});
});
@rjz
rjz / crypto-aes-256-gcm-demo.js
Last active March 11, 2024 20:11
example using node.js crypto API with aes-256-gcm
const buffer = require('buffer');
const crypto = require('crypto');
// Demo implementation of using `aes-256-gcm` with node.js's `crypto` lib.
const aes256gcm = (key) => {
const ALGO = 'aes-256-gcm';
// encrypt returns base64-encoded ciphertext
const encrypt = (str) => {
// The `iv` for a given key must be globally unique to prevent
@rjz
rjz / add_github_keys.sh
Created August 24, 2017 16:24
Add github public keys to authorized_keys
#! /bin/bash
#
# Add a teammate's public key(s) to authorized_keys via the github API
#
# Usage:
#
# GITHUB_LOGIN=rjz ./add_github_keys.sh
#
# PREFIX for authorized_keys entries (default: attach to running
@rjz
rjz / bookmarklet.js
Created June 25, 2017 18:23
LinkedIn message reply bookmarklet
javascript:(function (ta) {
const message = `Thanks for reaching out!
\n\n
I’m unfortunately not open to new opportunities at this time, but I’m certainly wishing you all the best in your search!
\n\n
RJ`;
if (!(ta && ta.length === 1)) {
alert('UI has changed...');
} else {
@rjz
rjz / metrics.sh
Last active May 8, 2017 16:00
Dump dynamo consumption high-water marks from cloudwatch
#!/bin/bash
# Usage:
#
# $ metrics.sh > dynamo_tables.txt
#
# $ cat dynamo_tables.txt \
# | tr : ' ' \
# | sed 's/\./ /' \
# | sed 's/ =//' \