Skip to content

Instantly share code, notes, and snippets.

View knu's full-sized avatar

Akinori Musha knu

  • Tokyo, Japan
  • 12:15 (UTC +09:00)
  • X @knu
View GitHub Profile
@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);
}
}
@knu
knu / git-clean-with-selector
Created July 8, 2019 10:43
Interactive git clean using a selector tool like peco or fzf
#!/bin/sh
set -e
while getopts 'x' opt; do
case "$opt" in
x)
flags=--ignored
;;
*)
require 'net/protocol'
class Net::Protocol
module ForceSNI
def ssl_socket_connect(*)
@sock.hostname = @host if @sock.respond_to? :hostname=
super
end
end
prepend ForceSNI