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
import * as zlib from 'minizlib';
new zlib.Gzip({});
@itchyny
itchyny / chsh-to-brew-zsh.sh
Created February 26, 2023 13:47
Change the login shell to zsh installed by Homebrew
#!/bin/bash
set -euo pipefail
echo "Checking zsh installed by Homebrew ..."
if version="$(brew list --versions zsh)"; then
echo "Found: $version"
else
echo "Could not find zsh installed by Homebrew"
exit 1
fi
@itchyny
itchyny / mackerel-plugin-filecount.zsh
Last active February 28, 2023 00:03
Mackerel plugin for file count
#!/bin/zsh
if [[ "$MACKEREL_AGENT_PLUGIN_META" == 1 ]]; then
cat <<EOF
# mackerel-agent-plugin
{
"graphs": {
"filecount.#": {
"label": "File count",
"unit": "integer",
#!/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 January 27, 2022 11:19
Lock-free snowflake-like id generator in Golang
package main
import (
"fmt"
"os"
"sync"
"sync/atomic"
"time"
)
@itchyny
itchyny / main.go
Created February 24, 2021 11:22
Performance comparison of implementations of strings.Join
package main
import (
"bytes"
"strings"
)
func main() {}
func JoinPlus(xs []string, sep string) string {
@itchyny
itchyny / check-go-repo.sh
Last active May 14, 2024 04:28
A checker for my own Go product repositories
#!/bin/bash
set -euo pipefail
git status >/dev/null || exit 1
err=
error_message() {
printf '%s\n\n' "$*" >&2
err=1
}
@itchyny
itchyny / buildvim.sh
Last active November 21, 2020 03:46
Build Vim from 7.3 to the latest with 100 patches step on macOS (x86_64) with clang 12 (clang-1200.0.32.27)
#!/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 July 5, 2020 03:56
Golang prepend implementation
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)
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})`;