Skip to content

Instantly share code, notes, and snippets.

View jcayzac's full-sized avatar

Julien Cayzac jcayzac

View GitHub Profile
@jcayzac
jcayzac / swift-project-build.js
Created December 7, 2020 02:03
Building Swift projects from the command line
mkdir foo && cd $_
swift package init
# 1) Add iOS target to Package.swift
# 2) Add flags for XCode in Package.xcconfig, e.g.
#
# DEVELOPMENT_TEAM = ...;
# CODE_SIGN_STYLE = Automatic;
# INFOPLIST_FILE = ...;
swift package generate-xcodeproj --xcconfig-overrides Package.xcconfig
xcodebuild build -sdk iphoneos -scheme 'foo-Package' -clonedSourcePackagesDirPath SourcePackages \
@jcayzac
jcayzac / BestFitImage.kt
Last active November 17, 2020 12:06
Image size fitting computations
data class RenderSize(val width: Int, val height: Int) {
companion object {
// 0x0 is an alias for "any"
val ANY = RenderSize(0, 0)
}
}
/**
* Scores an image resource based on the set of sizes it supports and on the
* size the caller wants to render it inside of.
@jcayzac
jcayzac / scratch-launch.kt
Created November 6, 2020 08:43
A `launch` for IDEA scratches
import kotlin.coroutines.*
/**
* Minimal, probably-borked implementation of `launch()`, just good enough
* for running in a IDEA scratch.
*
* ### Usage
*
* ```kt
* suspend fun main() {
@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