Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

itchyny itchyny

🏠
Working from home
  • Cybozu, Inc.
  • Kyoto, Japan
View GitHub Profile
@itchyny
itchyny / mackerel-plugin-filecount.bash
Last active May 22, 2022
Mackerel plugin for file count
View mackerel-plugin-filecount.bash
#!/bin/bash
if [[ "$MACKEREL_AGENT_PLUGIN_META" = 1 ]]; then
cat <<'EOF'
# mackerel-agent-plugin
{
"graphs": {
"filecount.#": {
"label": "File count",
"unit": "integer",
View go-cover.sh
#!/bin/bash
set -euo pipefail
cmdname="${BASH_SOURCE[0]##*/}"
temp=$(mktemp -t "$cmdname")
trap 'unlink "$temp"' EXIT
go test -cover -coverprofile="$temp" "$@"
go tool cover -html="$temp"
@itchyny
itchyny / main.go
Last active Jan 27, 2022
Lock-free snowflake-like id generator in Golang
View main.go
package main
import (
"fmt"
"os"
"sync"
"sync/atomic"
"time"
)
@itchyny
itchyny / main.go
Created Feb 24, 2021
Performance comparison of implementations of strings.Join
View main.go
package main
import (
"bytes"
"strings"
)
func main() {}
func JoinPlus(xs []string, sep string) string {
@itchyny
itchyny / check-go-repo.sh
Last active Jun 12, 2022
A checker for my own Go product repositories
View check-go-repo.sh
#!/bin/bash
set -euo pipefail
git status >/dev/null || exit 1
err=
error_message() {
echo "$@" >&2
echo >&2
err=1
@itchyny
itchyny / buildvim.sh
Last active Nov 21, 2020
Build Vim from 7.3 to the latest with 100 patches step on macOS (x86_64) with clang 12 (clang-1200.0.32.27)
View buildvim.sh
#!/bin/bash
set -euxo pipefail
git clone https://github.com/vim/vim.git /tmp/vim
cd /tmp/vim
BACKUP_DIR=/tmp/vim-backup
mkdir -p "$BACKUP_DIR"
while true; do
@itchyny
itchyny / prepend.go
Created Jul 5, 2020
Golang prepend implementation
View prepend.go
type Xs struct {
xs []*X
idx int
}
func (xs *Xs) prepend(x *X) *Xs {
if xs.idx == 0 {
ys := make([]*X, (len(xs.xs)+1)*2)
xs.idx = len(xs.xs) + 1
copy(ys[xs.idx+1:], xs.xs)
View re.js
const opt = (s) => `${group(s)}?`;
const chars = (s) => `[${s}]`;
const group = (s) => /^\[[^\]]+\][*+]$/.test(s) ? s : `(?:${s})`;
const or = (...xs) => xs.join('|');
const many = (s) => group(`${s}*`);
const many1 = (s) => group(`${s}+`);
const integer = or('0', `[1-9]${many('[0-9]')}`);
const name = (n, s) => `(?<${n}>${s})`;
@itchyny
itchyny / go114-regression.md
Last active Apr 8, 2020
Go 1.14の主なregression
View go114-regression.md

Go 1.14 の主なregressionです。1.14.1で修正されると思われます。

@itchyny
itchyny / git-ssh-key.sh
Last active Nov 27, 2019
shell alias to use specific identity file on git push
View git-ssh-key.sh
# 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 \