Skip to content

Instantly share code, notes, and snippets.

View jcayzac's full-sized avatar

Julien Cayzac jcayzac

View GitHub Profile
@jcayzac
jcayzac / capture_timelapse.sh
Last active June 16, 2023 21:31
Timelapse screen capture for macOS
# Start a 1fps screen capture to `~/Movies/timelapse - <end-datetime>.webm`.
# Requires ffmpeg+libvpx installed: `brew install ffmpeg`.
# Press `q` to stop.
capture_timelapse() {
local output="$HOME/Movies/timelapse - $(date '+%y-%m-%d %H%M%S').webm"
local device=$(set +e +o pipefail; ffmpeg -f avfoundation -list_devices true -i '' 2>&1 | sed -En 's#^.*\[([a0-9]+)\] Capture screen 0#\1#p'; true)
if [ -n "$device" ]
then
printf 'Capturing timelapse to "%s"…\nPress Q to stop.\n' "$output"
ffmpeg \
# $1: items power of 10 (e.g. 3=kilo, 6=mega)
# $2: entropy bits (80=2^80 values)
# Requires `brew install bc` (GNU bc)
birthday_probability() {
function bc() {
declare fmt="$1"
shift
printf 'scale=256\n'"$fmt"'\n' ${1+"$@"} | BC_LINE_LENGTH=0 /usr/local/opt/bc/bin/bc -l
}
declare exact="$(bc '1-e(-((10^%s)^2)/((2^%s)*2))' "$1" "$2")"
@jcayzac
jcayzac / trim-fonts.sh
Created July 5, 2020 06:17
Remove non-latin alphabets from WOFF2 fonts
# $1: /path/to/woff.2
trim-font() {
local OUTPUT_DIR="${1%/*}/trimmed"
mkdir -p "$OUTPUT_DIR"
pyftsubset "$1" \
--unicodes=U+0000-036F \
--ignore-missing-glyphs \
--layout-features='*' \
--output-file="${OUTPUT_DIR}/${1##*/}" --flavor=woff2
}
const { spawn } = require('child_process')
const { Transform } = require('stream')
const { createHash } = require('crypto')
const split2 = require('split2')
const report = require('vfile-reporter')
const { nextTick } = require('process')
const DELIMITER = '___PLANTUML_DIAGRAM_DELIMITER___'
const SPLITTER = split2(DELIMITER)
const OPTIONS = [
@jcayzac
jcayzac / graal-docker-plantuml.md
Created May 1, 2020 06:49
Building PlantUML as a native executable
FROM oracle/graalvm-ce:20.0.0-java8
RUN gu install native-image
WORKDIR /opt/graalvm
ADD https://sourceforge.net/projects/plantuml/files/1.2020.8/plantuml.1.2020.8.jar/download /opt/graalvm/plantuml.jar
RUN native-image \
  --verbose \
  -J-Xmx16G -J-Xms16G -Djava.awt.headless=true \
  --no-server \
  --no-fallback \
@jcayzac
jcayzac / Server API Testing.md
Last active February 27, 2019 07:40
Server API Testing
@jcayzac
jcayzac / Convert from iPhone MOV to MP4 preserving metadata.sh
Last active December 29, 2018 08:28
Photo and video command-line editing
# Example
ffm -i video.mov -map_metadata 0 -map 0 -c:v copy -c:a copy -c:s copy -c:d copy -c:t copy -f mp4 video.mp4
# Convert one file
# $1: video.mov
convert-mov-to-mp4() {
(
set -e -u -o pipefail
! [[ "$1" =~ ^(.+)\.[mM][oO][vV]$ ]] || {
local D="${BASH_REMATCH[1]}.mp4" T="${BASH_REMATCH[1]}.tmp.mp4"
@jcayzac
jcayzac / WORKSPACE
Created October 29, 2018 06:10 — forked from jart/WORKSPACE
Google Auto and Dagger Bazel Config
load("@bazel_tools//tools/build_defs/repo:java.bzl", "java_import_external")
java_import_external(
name = "com_google_auto_common",
jar_sha256 = "eee75e0d1b1b8f31584dcbe25e7c30752545001b46673d007d468d75cf6b2c52",
jar_urls = [
"http://domain-registry-maven.storage.googleapis.com/repo1.maven.org/maven2/com/google/auto/auto-common/0.7/auto-common-0.7.jar",
"http://repo1.maven.org/maven2/com/google/auto/auto-common/0.7/auto-common-0.7.jar",
],
licenses = ["notice"], # Apache 2.0

WebP (lossless)

$ cwebp -lossless -z 9 -mt -m 6 -sharp_yuv "$INPUT" -o "$OUTPUT"

WebP (lossy)

$ cwebp -preset photo -q 80 -mt -m 6 -sharp_yuv -metadata none "$INPUT" -o "$OUTPUT"