Skip to content

Instantly share code, notes, and snippets.

View knu's full-sized avatar

Akinori Musha knu

View GitHub Profile
@knu
knu / open-chrome-in-profile.applescript
Last active June 21, 2022 03:18
Open a Google Chrome window in a specified profile
if application "Google Chrome" is not running then
tell application "Google Chrome" to activate
end if
tell application "System Events" to tell process "Google Chrome"
set frontmost to true
click (menu item 1 where its name contains "****") of (menu 1 where its name is "プロファイル" or its name is "Profiles") of menu bar 1
end tell
@knu
knu / README.md
Last active September 13, 2024 15:52
Audio Input fixer for AirPods users

Audio Input fixer for AirPods users

This is a Hammerspoon snippet to fix the common problem with the AirPods where connecting AirPods to a MacBook forcibly switches the audio input device to the AirPods mic when you have a better mic on it.

Requirements

brew install hammerspoon
@knu
knu / git-delete-merged
Created February 5, 2022 17:05
git-delete-merged - delete local branches that have been merged on GitHub
#!/bin/sh
#
# git-delete-merged - delete local branches that have been merged on GitHub
#
# Copyright (c) 2022 Akinori MUSHA
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
@knu
knu / .gitconfig
Last active January 26, 2022 13:38
git-rails-db-rollback: Run rails db:rollback before switching to another branch
[alias]
main = "!set -e; p=refs/remotes/origin; if r=\"$(git symbolic-ref $p/HEAD 2>/dev/null)\"; then echo \"${r#$p/}\"; exit; fi; printf %s \"Fixing the broken ref $p/HEAD... \" >&2; if r=\"$(git remote show origin | awk '/^ HEAD branch: /{print $3}')\"; then echo done. >&2; echo \"$r\"; git symbolic-ref \"$p/HEAD\" \"$p/$r\"; else echo failed. >&2; exit 1; fi"
rails-db-rollback = "!sh -ec 'git diff --name-only --diff-filter=A \"${1-$(git main)}\" -- db/migrate | ruby -e \"puts \\$<.read.scan(%r{/([0-9]+)_})\" | sort -r | while read v; do rake db:migrate:down VERSION=$v; done' ."
@knu
knu / GoogleDriveFileStream.sh
Last active January 13, 2021 03:30
Running Google Drive File Stream on macOS 11 Big Sur (Intel)
#!/bin/sh
set -ex
sudo rsync -av /Applications/Google\ Drive\ File\ Stream.app/Contents/MacOS/dfsfuse.kext /Library/Extensions/
sudo kextload /Library/Extensions/dfsfuse.kext
killall Google\ Drive\ File\ Stream || :
while pgrep -q Google\ Drive\ File\ Stream; do
sleep 1
done
@knu
knu / README.md
Last active December 23, 2022 07:56
knuスタイルAZIK for ATOK
@knu
knu / barrier_karabiner.lua
Last active April 26, 2024 17:58
Barrier and Karabiner-Elements integration using Hammerspoon
knu = require("knu") -- https://github.com/knu/hs-knu
-- Switch between Karabiner-Elements profiles as Barrier enters a different host
do
-- Configure Barrier (https://github.com/debauchee/barrier) to output log to ~/Library/Logs/barrier.log
local logFile = os.getenv("HOME") .. "/Library/Logs/barrier.log"
local lineNo = 1
local host = nil
local defaultProfile = "Default"
local profileForHost = function (host)
@knu
knu / benchmark.rb
Last active March 16, 2020 13:54
Computing age in Ruby
# frozen_string_literal: true
require 'benchmark/ips'
require 'date'
Benchmark.ips do |x|
x.config(time: 5, warmup: 2)
funcs = [
->(a, b) {
@knu
knu / my-lsp-search-node_modules.el
Last active February 28, 2020 12:41
Using flow installed under node_modules in lsp-mode
(with-eval-after-load 'lsp
(defun my-lsp-search-node_modules ()
(and buffer-file-name
(lsp-clients-flow-activate-p buffer-file-name major-mode)
(let* ((flow-location "node_modules/.bin/flow")
(root (locate-dominating-file buffer-file-name flow-location)))
(if root
(set (make-local-variable 'lsp-clients-flow-server)
(expand-file-name flow-location root))))))
@knu
knu / index.js
Created August 6, 2019 07:05
babel-preset-minify bug reproduction
function unLoad() {
const { events } = this.props;
const { editor } = this.state;
if (!editor) return;
const { change, ...eventsSansChange } = events;
for (const [event, handler] of Object.entries(eventsSansChange)) {
editor.on(event, handler);
}
}