Skip to content

Instantly share code, notes, and snippets.

View itchyny's full-sized avatar
🏠
Working from home

itchyny itchyny

🏠
Working from home
  • Cybozu, Inc.
  • Kyoto, Japan
View GitHub Profile
@itchyny
itchyny / git-ssh-key.sh
Last active November 27, 2019 01:46
shell alias to use specific identity file on git push
# Example: git-ssh-key ~/path/to/identity-file git push origin master
git-ssh-key() {
ssh_key=${1:?Usage: git-ssh-key identity-file commands...}
shift
GIT_SSH_COMMAND=" \
ssh -F /dev/null \
-o IdentitiesOnly=yes \
-o IdentityFile=\"$ssh_key\" \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
package main
import (
"encoding/binary"
"errors"
"fmt"
"io"
"os"
"strconv"
)
SCRIPT /usr/local/Cellar/vim/8.1.1500/share/vim/vim81/scripts.vim
Sourced 1 time
Total time: 0.001107
Self time: 0.001107
count total (s) self (s)
" Vim support file to detect file types in scripts
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Last change: 2018 Feb 03
def skip_loop:
.input[.cursor:.cursor+1] as $c |
.cursor += 1 |
if $c == "[" then .depth += 1 | skip_loop
elif $c == "]" then .depth -= 1 | if .saved_depth > .depth then . else skip_loop end
elif $c == "" then error("unmatching loop")
else skip_loop
end;
def backward_loop:
@itchyny
itchyny / json_format.jq
Created May 10, 2019 03:32
JSON formatter written in jq
{ source: ., depth: 0, indent: false, first_elem: false, output: "" } |
until(
.source == "";
if .source[:1] | inside(" \t\n\r") then
.source |= .[1:]
else
.output +=
(if .first_elem and (.source[:1] | inside("]}")) then ""
else (if .first_elem then "\n" else "" end) +
(if .indent then " " * .depth
@itchyny
itchyny / main.go
Created February 24, 2019 13:47
Golang tsort implementation
package main
import (
"errors"
"fmt"
"os"
)
type edge struct{ from, to int }
@itchyny
itchyny / atomic-test.go
Created January 21, 2019 07:06
Atomic write testing in Golang (why this fails on Windows?)
package main
import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
@itchyny
itchyny / .md
Last active March 13, 2018 13:46
詰将棋 gif生成
diff --git a/util/image/generate.go b/util/image/generate.go
index 81c69f7..9635b87 100644
--- a/util/image/generate.go
+++ b/util/image/generate.go
@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"image"
 	"image/color"
+	"image/color/palette"
@itchyny
itchyny / loadavg.c
Last active October 15, 2017 04:26
loadavg statistics on Darwin using sysctl(3)
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/sysctl.h>
int main(int argc, char const* argv[])
{
struct loadavg load;
size_t size = sizeof(load);
if (sysctlbyname("vm.loadavg", &load, &size, 0, 0) == -1) {
@itchyny
itchyny / main.c
Created October 15, 2017 00:31
Swap usage on Darwins
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/sysctl.h>
int main(int argc, char const* argv[])
{
struct xsw_usage swap;
size_t size = sizeof(swap);
if (sysctlbyname("vm.swapusage", &swap, &size, 0, 0) == -1) {