Skip to content

Instantly share code, notes, and snippets.

@kvangrae
kvangrae / Base64Util.java
Last active June 25, 2019 21:34
Computes the expected decoded byte size of the Base64 encoded data. Reference: https://tools.ietf.org/html/rfc4648
import static java.util.Objects.requireNonNull;
public class Base64Util {
private static final double BASE64_SIZE_RATIO = 4.0d / 3;
private Base64Util() {
}
/**
* Computes the expected decoded byte size of the base64 encoded data.
@kvangrae
kvangrae / restore-docker-volume.sh
Created May 23, 2019 22:12
Restore a docker volume from a tar gzip.
#!/bin/bash
usage() {
cat << EOF
usage: $0 volume-name archive-file
e.g. $0 gitlab_config /home/coal/gitlab_config.tar.gz
EOF
exit 1
@kvangrae
kvangrae / backup-docker-file-to-s3.sh
Created May 23, 2019 22:10
Script to copy a file from docker container to AWS S3
#!/bin/bash
backup_file() {
if [ "$#" -ne 3 ]; then
echo "error: 3 parameters required"
echo usage $0 [source-container-name] [source-file] [s3-object-destination]
echo
exit 1
fi
@kvangrae
kvangrae / backup-docker-volume-to-s3.sh
Last active May 23, 2019 22:15
Script to backup Docker volume to AWS S3 bucket
#!/bin/bash
usage() {
cat << EOF
usage: $0 [container-name] [source-directory] [s3-object-destination]
e.g. $0 nginx /etc/nginx/ s3://bucket/nginx-etc.tgz
EOF
exit 1
}
@kvangrae
kvangrae / mirror.sh
Created May 23, 2019 20:43
Git mirror two repositories via intermediary bare repository
# initial clone ane mirror
git clone --bare --mirror /uri/to/[fromrepo.git]
cd [fromrepo.git]
git remote add --mirror=push mirror /uri/to/[to_repo.git]
git push mirror
# update mirror
git remote update --prune origin
git push mirror
@kvangrae
kvangrae / cacheFetch.js
Last active June 20, 2018 15:29
Cache fetch responses using memoize and clone().
import memoize from 'lodash.memoize';
const cache = memoize(req => {
return fetch(req).then(response => {
return response;
});
}, req => req.url);
function cacheFetch(input, init) {
return cache(new Request(input, init)).then(response => response.clone());