Skip to content

Instantly share code, notes, and snippets.


Akinori MUSHA knu

View GitHub Profile
knu / .gitconfig
Last active Jan 26, 2022
git-rails-db-rollback: Run rails db:rollback before switching to another branch
View .gitconfig
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 /
Last active Jan 13, 2021
Running Google Drive File Stream on macOS 11 Big Sur (Intel)
set -ex
sudo rsync -av /Applications/Google\ Drive\ File\ /Library/Extensions/
sudo kextload /Library/Extensions/dfsfuse.kext
killall Google\ Drive\ File\ Stream || :
while pgrep -q Google\ Drive\ File\ Stream; do
sleep 1
knu / knu-azik.txt
Created Sep 26, 2020
knuスタイルAZIK for ATOK
View knu-azik.txt
' ー
, 、
- ー
. 。
/ ・
; っ
[ 「
knu / barrier_karabiner.lua
Last active Sep 17, 2021
Barrier and Karabiner-Elements integration using Hammerspoon
View barrier_karabiner.lua
knu = require("knu") --
-- Switch between Karabiner-Elements profiles as Barrier enters a different host
-- Configure 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 / benchmark.rb
Last active Mar 16, 2020
Computing age in Ruby
View benchmark.rb
# frozen_string_literal: true
require 'benchmark/ips'
require 'date'
Benchmark.ips do |x|
x.config(time: 5, warmup: 2)
funcs = [
->(a, b) {
knu / my-lsp-search-node_modules.el
Last active Feb 28, 2020
Using flow installed under node_modules in lsp-mode
View my-lsp-search-node_modules.el
(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 / index.js
Created Aug 6, 2019
babel-preset-minify bug reproduction
View index.js
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);
knu / git-clean-with-selector
Created Jul 8, 2019
Interactive git clean using a selector tool like peco or fzf
View git-clean-with-selector
set -e
while getopts 'x' opt; do
case "$opt" in
View force_sni.rb
require 'net/protocol'
class Net::Protocol
module ForceSNI
def ssl_socket_connect(*)
@sock.hostname = @host if @sock.respond_to? :hostname=
prepend ForceSNI
knu / ruby-configure
Created Mar 29, 2019
RUBY_CONFIGURE script for rbenv on FreeBSD
View ruby-configure
# This script is for rbenv to configure ruby like Ports does.
# (amd64 instead of x86_64)
# RUBY_CONFIGURE=ruby-configure
rsync -av /usr/ports/Templates/config.* tools/
exec ./configure "$@"