This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 日本語の声をランダムに1つ選ぶ | |
| const voices = speechSynthesis.getVoices().filter(v=>/^ja-/.test(v.lang)) | |
| const voice = voices[Math.floor(voices.length*100000*Math.random())%voices.length] | |
| const ssu = new SpeechSynthesisUtterance() | |
| ssu.lang = 'ja-JP' // 言語 | |
| ssu.voice = voice // 発話に使用する音声(未設定の場合lang設定を見て適切な音声が選ばれる | |
| ssu.volume = 1 // 発話の音量 0~1、default=1 | |
| ssu.rate = 1 // 発話の速度 0.1~10、default=1 | |
| ssu.pitch = 1 // 発話の音程 0~2、default=1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e -o pipefail | |
| # HostedZone[].Id を保存 | |
| aws route53 list-hosted-zones | jq .HostedZones[].Id -r | tee HostedZoneIds.txt | |
| # 全HostedZoneのRecordSetを取得 | |
| while read id; do | |
| aws route53 list-resource-record-sets --hosted-zone-id "$id" | |
| done <HostedZoneIds.txt | tee rs.json.tmp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # コピペで使えてシンプルなやつ (動的なファイルディスクリプタ) | |
| # 2重起動防止 | |
| exec {lock}<"$0"; flock -n "$lock" || { | |
| echo "this script is already running" >&2 | |
| exit 1 | |
| } | |
| echo "なにかの処理" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const movingAverageFilter = (ws=3) => { | |
| if(!Number.isInteger(ws) || ws < 1) { | |
| throw new Error(`Invalid window size. ws must be >=1. You entered: ws=${ws}.`) | |
| } | |
| let win = [] | |
| let sum = 0 | |
| let pos = 0 | |
| let tail = 0 | |
| return (head) => { | |
| sum = sum + head - tail |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const beep = (duration=200, frequency=440, gain=1.0) => new Promise((resolve, reject) => { | |
| try { | |
| const audioCtx = new AudioContext() | |
| const oscNode = new OscillatorNode(audioCtx, {frequency, type:"square"}) | |
| const gainNode = new GainNode(audioCtx, {gain}) | |
| oscNode.onended = resolve | |
| oscNode.connect(gainNode).connect(audioCtx.destination) | |
| oscNode.start(audioCtx.currentTime) | |
| oscNode.stop(audioCtx.currentTime + duration / 1000) | |
| } catch(err){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // CloudFront Functions 内で利用可能なBASE64実装 | |
| function b64enc(b) { | |
| var b64codes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".split("").map(s=>s.charCodeAt(0)) | |
| var pad = [0, 2, 1][b.length % 3] | |
| // 入力バイト列(本来は 0xFF を超える charCode が含まれていたらエラーにすべきだが省略 | |
| var bCodes = (b + '\0'.repeat(pad)).split("").map(s=>s.charCodeAt(0)) | |
| // 出力用バイト列 | |
| var aCodes = new Uint8Array(bCodes.length / 3 * 4) | |
| for(var i=0,j=0; i<b.length; i+=3,j+=4){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/swift | |
| import AppKit | |
| let urls = CommandLine.arguments.dropFirst(1).map { URL(fileURLWithPath: $0) } | |
| NSWorkspace.shared.activateFileViewerSelecting(urls) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // おまじない | |
| ᡸ=ᡸᡸ=>ᡸ | |
| // SyntaxErrorはもちろん、ランタイムエラーすら出さずに実行可能 | |
| ᡸ``` | |
| ᡸhi | |
| ᡸ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ( set -ex -o pipefail && \ | |
| d="$(mktemp -d)" && \ | |
| cd "$d" && \ | |
| trap "$(printf "rm -rf %q" "$d")" EXIT && \ | |
| curl "https://awscli.amazonaws.com/awscli-exe-linux-$(uname -m).zip" -o awscliv2.zip && \ | |
| unzip awscliv2.zip && \ | |
| sudo ./aws/install --update ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # https://gist.github.com/kawaz/5aa9d792798ba49aace14d17b4e68b3e | |
| set -eo pipefail | |
| usage() { | |
| echo "Usage: $0 subcommand [args]" | |
| echo " $0 get [output|input|alert|mute] get volume settings" | |
| echo " $0 set [output|input|alert] 0-100 set volume" | |
| echo " $0 set mute [true|false] set mute status" | |
| echo " $0 help show this help" |