Skip to content

Instantly share code, notes, and snippets.

@kana
kana / add rounded border.sh
Last active Oct 15, 2020
ImageMagick usage
View add rounded border.sh
# 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
View 4k.sh
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
View hatokurandom-ogp.sh
font=~/Library/Fonts/MyFavoriteFont.ttf
icon=apple-touch-icon.png
convert \
-background transparent \
-size 980x640 \
\( \
-background transparent -fill white \
-font "$font" \
-gravity center \
@kana
kana / algorithm comparison.md
Last active Sep 10, 2019
Hatokura random sampling memo
View algorithm comparison.md
Algorithm Card set Times Elapsed Note
A-Res FG only 100k 18,741ms Acceptable speed for small card set
A-Chao FG only 100k 8,561ms Broken probability
Uniform FG only 100k 8,145ms Current implementation
A-Chao All 100k 11,215ms Broken probability
Uniform All 100k 11,774ms Current implementation
A-Res / sort All 100k 163,021ms Simple implementation but heavy
A-Res / heap(A) All 100k 31,068ms Push all cards then pop N cards
A-Res / heap(W) All 100k 23,028ms The same as described in Wikipedia
@kana
kana / nes-ize
Created May 23, 2019
NES-ish image color reduction
View nes-ize
#!/bin/bash
if ! [ "$#" = 1 ]
then
echo "Usage: $0 FILE"
exit 1
fi
d="$(identify "$1" | cut -d' ' -f3)"
width="${d/x*/}"
@kana
kana / t-right-to-left-2-up.sh
Last active May 15, 2019
Rearrange PDF pages
View t-right-to-left-2-up.sh
# Original PDF:
# 1. Front cover
# 2. content 1
# 3. content 2
# 4. ...
# 5. content -2
# 6. content -1
# 7. Back cover
#
# Resulting PDF:
View slack-review-counter.js
const bodyParser = require('body-parser')
const express = require('express')
const moment = require('moment-timezone')
const slack = require('slack')
const VERIFICATION_TOKEN = process.env.VERIFICATION_TOKEN
const OAUTH_ACCESS_TOKEN = process.env.OAUTH_ACCESS_TOKEN
const app = express()
View nicegif
#!/bin/bash
colors=256
fps=30
half=
while true
do
case "$1" in
'-c')
View fukusayou.php
<?php
$a = 1;
debug_zval_dump($a);
//==> long(1) refcount(2)
// Novice: Huh? Why is refcount 2? The value is only pointed by $a, so refcount must be 1!
// Tatsujin: PHP uses copy-on-write. The value is passed by value to debug_zval_dump.
// It doesn't modify the passed value. The value is shared by $a and debug_zval_dump.
// Therefore refcount is 2.
You can’t perform that action at this time.