Skip to content

Instantly share code, notes, and snippets.

View kana's full-sized avatar

Kana Natsuno kana

View GitHub Profile
@kana
kana / ramdisk.sh
Created April 26, 2024 04:43
Create a RAM disk on macOS.
#!/bin/bash
set -euxo pipefail
MB=100
NUMSECTORS=$((MB * 1024 * 1024 / 512)) # A sector is 512 bytes.
# "hdiutil attach" outputs extra spaces/tabs. They must be removed.
MYDEV="$(hdiutil attach -nomount "ram://$NUMSECTORS" | sed 's/[ \t]*$//')"
#!/bin/bash
set -euxo pipefail
# These parameters are taken from:
# https://developers.google.com/assistant/tools/audio-loudness
TARGET_LUFS=-16
TP=-1.5
LRA=11
#!/usr/bin/env ruby
require 'date'
require 'json'
# cstimer data format:
#
# {
# "session1": [Solve, ...],
# "session2": [Solve, ...],
@kana
kana / vim9.vim
Created October 6, 2021 23:08
"A is B" in Vim9 script
vim9script
# "A is 0" in legacy Vim script is an idiom to compare values which might be
# different types. This is especially useful to check the existence of a key
# in a dictionary and to use its value if that key exists. For example:
#
# let Hook = get(g:config, 'hook', 0)
# if Hook is 0
# return
# endif
@kana
kana / ip7p.sh
Last active January 14, 2022 02:42
i='input.psd[1]'
magick -background None -gravity Center -virtual-pixel Edge \
"$i" -colorspace RGB \
\( -clone 0 -resize "1242x2208^" -blur 0x16 -extent 1242x2208 \) \
\( -size 1242x2208 xc:#000C \) \
\( -clone 0 -resize "1242x$((2208 - 276 - 60))^" -gravity South -extent 1242x2208+0-276 \) \
-delete 0 \
-flatten \
,home.png
magick -background None -gravity Center -virtual-pixel Edge \
@kana
kana / galaxyizer
Created July 22, 2021 06:31
Generate "galaxy" gif for Slack emoji.
#!/bin/bash
set -euo pipefail
trap "rm -f ,$$,*" EXIT
border=3
colors=256
delay=8
frames=24
@kana
kana / sunriser
Last active May 27, 2023 07:09
Generate "sunrise" gif for Slack emoji.
#!/bin/bash
set -euo pipefail
trap "rm -f ,$$,*" EXIT
border=4
colors=256
delay=6
frames=30
@kana
kana / add rounded border.sh
Last active October 15, 2020 15:02
ImageMagick usage
# Tweaked http://www.imagemagick.org/Usage/thumbnails/#rounded_border
convert -size 500x500 -alpha transparent xc:none -fill none -stroke black -strokewidth 4 -draw 'roundrectangle 1,1 498,498 12,12' ,border.png
convert -size 500x500 -alpha transparent xc:white -fill black -stroke transparent -strokewidth 4 -draw 'roundrectangle 0,0 499,499 12,12' ,mask.png
convert -background black src.jpg -resize '500^x500^' -gravity center -extent 500x500 -alpha set \
,mask.png -compose DstIn -composite \
,border.png -compose Over -composite \
bordered.jpg
@kana
kana / 4k.sh
Last active September 24, 2020 14:52
convert m.png -gravity west -resize 3840x2160 -extent 10x ,left.png
convert m.png -gravity east -resize 3840x2160 -extent 40x ,right.png
convert \
\( ,left.png -gravity west -resize '2160x2160!' -blur 0x20 \) \
\( m.png -gravity center -resize '3840x2160' \) \
\( ,right.png -gravity east -resize '2160x2160!' -blur 0x20 \) \
+append ,base.png
convert ,base.png -gravity center -extent 3840x2160 -quality 90 ,t.jpg
font=~/Library/Fonts/MyFavoriteFont.ttf
icon=apple-touch-icon.png
convert \
-background transparent \
-size 980x640 \
\( \
-background transparent -fill white \
-font "$font" \
-gravity center \