Skip to content

Instantly share code, notes, and snippets.

Avatar

Yoshiaki Kawazu kawaz

View GitHub Profile
@kawaz
kawaz / vpn-control.sh
Created Oct 26, 2016
maxOS の VPN をCLIで一覧したり接続・切断したりするスクリプト
View vpn-control.sh
#!/usr/bin/env bash
set -e
usage() {
local name
name=$(basename "$0")
echo "Usage: $name command [options]"
echo " $name list"
echo " $name connect ID"
echo " $name disconnect ID"
@kawaz
kawaz / DefaultKeyBinding.dict
Last active May 14, 2021
macOSのテキスト系コンポーネントでのキーカスタマイズ
View DefaultKeyBinding.dict
// https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/EventOverview/TextDefaultsBindings/TextDefaultsBindings.html
// ^ for Control
// $ for Shift
// ~ for Option
// @ for Command
// # for numeric keypad
{
// home/end
"\UF729" = "moveToBeginningOfLine:";
@kawaz
kawaz / superInterval.js
Last active Mar 11, 2021
タブがバックグラウンドになってもサボらない setInterval
View superInterval.js
const superInterval = (cb, interval=1000, ...args) => {
try {
const code = `self.addEventListener('message', msg=>{setInterval(()=>self.postMessage(null), msg.data)})`
const w = new Worker(`data:text/javascript;base64,${btoa(code)}`)
w.onmessage = () => cb(...args)
w.postMessage(interval)
return {stop:()=>w.terminate()}
} catch(_){
// 実装の問題またはCSPによる拒否などで Worker が使えなければ普通の setInterval を使う
const id = setInterval(cb, interval, ...args)
@kawaz
kawaz / install-fonts-HackGen.sh
Last active Jan 23, 2021
HackGen フォントを入れる(最近はもう `brew install --cask homebrew/cask-fonts/font-hackgen` だけで行ける)
View install-fonts-HackGen.sh
#!/bin/bash
set -e
latest_zip=$(curl -sL https://api.github.com/repos/yuru7/HackGen/releases/latest | jq -r '.assets|map(select(.name|test("^HackGen_v.*\\.zip$")))[].browser_download_url')
d=$(mktemp -d "${TMPDIR:-/tmp}/${1:-install-fonts-HackGen.sh}.XXXXXXXXXX")
curl -sL "$latest_zip" | tar xz -C "$d"
mv "$d"/*.ttf ~/Library/Fonts
rm -rf "$d"
fc-cache -vf
@kawaz
kawaz / dumpCurrentKeyboardInputSource.swift
Created Mar 30, 2020
macOSでIME(日本語入力)の情報を取得する
View dumpCurrentKeyboardInputSource.swift
#!/usr/bin/swift
import Carbon
// Carbon.h -> HIToolbox.h -> TextInputSources.h
// grep "extern const" /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/TextInputSources.h
let props: [CFString] = [
kTISPropertyInputSourceCategory,
kTISPropertyInputSourceType,
kTISPropertyInputSourceIsASCIICapable,
kTISPropertyInputSourceIsEnableCapable,
View build-qpac.sh
#!/bin/bash
set -e
set -o pipefail
t=$(mktemp -d -p "${TMPDIR:-/tmp/}" -t build-qpac.XXXXXXXXXX)
dist="$t/dist"
build="$t/build"
yum install -y gcc zlib-devel
git clone --depth=1 https://github.com/gpac/gpac.git "$build"
cd "$build"
@kawaz
kawaz / tmux-color256.sh
Last active Aug 27, 2020
これはtmuxの色指定で使う256カラーの見本を表示するスクリプトです。tmuxの色指定方法は default, 色名, colour255, '#ffffff' の形が使えます。
View tmux-color256.sh
#!/bin/bash
function echo_color() {
local colors=(black red green yellow blue magenta cyan white brightblack brightred brightgreen brightyellow brightblue brightmagenta brightcyan brightwhite)
local fg="\e[38;5;" bg="\e[48;5;" rs="\e[0m"
local color=$1; shift
local n=$(printf %3d $color) n2=""
if [[ -n ${colors[$color]} ]]; then
n2=" $(printf %-13s ${colors[$color]})"
fi
for arg in "$@";do
@kawaz
kawaz / install-docker-compose.sh
Last active Jun 9, 2020
install docker-compose
View install-docker-compose.sh
#!/bin/bash
set -e
set -o pipefail
[[ -x /usr/bin/docker-compose ]] && exit
if ! [[ -f /usr/bin/docker-compose ]]; then
t=$(mktemp)
curl -sLo "$t" "$(curl -s https://api.github.com/repos/docker/compose/releases/latest | jq -r '.assets[].browser_download_url' | grep "/docker-compose-$(uname -s)-$(uname -m)$")"
chmod 755 "$t"
mv "$t" /usr/local/bin/docker-compose
@kawaz
kawaz / parallel.js
Last active May 28, 2020
Promiseの配列を {ok:true, value} か {ok:false, err} の配列にする関数。Promise.all とか Promise.race だとどれか一つのPromiseがrejectとかされた時点で全部中断されちゃうのが使いにくい時があるので。→ ES2020に入ってくる Promise.allSettled() がほぼ同じ感じの関数になるので今後はそっちを使う事を推奨。
View parallel.js
parallel = promises => Promise.all(promises.map(p=>new Promise(done=>{try{p.then(value=>done({ok:true,value})).catch(err=>done({ok:false,err}))}catch(err){done({ok:false,err})}})))
@kawaz
kawaz / install-daemontools.sh
Last active May 21, 2020
install daemontools (AmazonLinux2,CentOS7, etc...)
View install-daemontools.sh
#!/bin/bash
set -e
set -o pipefail
cd "$(mktemp -d)"
trap "rm -rf $PWD" EXIT
# install daemontools
curl -s https://cr.yp.to/daemontools/daemontools-0.76.tar.gz | tar xz
cd ./admin/daemontools-0.76/