Skip to content

Instantly share code, notes, and snippets.

@aoyama-val
aoyama-val / _cargo
Created March 24, 2024 04:34
zsh cargo completion that only meets my needs
#compdef cargo
_cargo() {
local context curcontext=$curcontext state line
declare -A opt_args
local ret=1
local -a common_options
_arguments -C \
'(-h --help)'{-h,--help}'[show this help message and exit]' \
@aoyama-val
aoyama-val / columns.c
Created January 16, 2024 22:04
The COLUMNS game for UNIX terminal
/* COLUMNS for UNIX 1998.9.13 version */
/* by AKIKAWA,Hisashi (icb49250 @ nifty.ne.jp) */
/* ported to macOS/Linux by Shotaro Aoyama */
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<unistd.h>
#include<termios.h>
#include<sys/time.h>
@aoyama-val
aoyama-val / _awslogs
Last active October 21, 2023 00:34
zsh completion function for jorgebastida/awslogs
#compdef awslogs
_awslogs() {
local context curcontext=$curcontext state line
declare -A opt_args
local ret=1
local -a common_options
_arguments -C \
'(-h --help)'{-h,--help}'[show this help message and exit]' \
openapi: 3.0.0
info:
title: Objects in parameters
version: 1.0.0
servers:
- url: https://httpbin.org
paths:
/get:
get:
parameters:
@aoyama-val
aoyama-val / uds-vs-tcp-result.md
Created June 22, 2018 03:03
UnixドメインソケットとTCPソケットのベンチマーク結果
  • AMIは同一(ami-db710fa3 / Ubuntu Server 16.04 LTS (HVM), SSD Volume Type)
  • t2.micro, c4.large, i3.metalでの実行結果とsysctl -aの結果
git clone https://github.com/rigtorp/ipc-bench.git
cd ipc-bench
make
make run
@aoyama-val
aoyama-val / modify_security_group.rb
Last active June 13, 2018 23:52
セキュリティグループで許可するIPアドレスを入れ替えるスクリプトのサンプル
require "aws-sdk"
require "aws-sdk-core/errors"
# セキュリティグループで許可するIPアドレスを入れ替えるスクリプトのサンプル
#
# 許可すべきIPアドレスをホワイトリスト指定しているが、そのリストがときどき変わる
# というような場合に利用する。
#
# 対象のセキュリティグループに存在するルールを全て削除し、
# new_ip_addressesで指定されたIPアドレスを許可するルールを追加する。
@aoyama-val
aoyama-val / format-line.zsh
Created May 1, 2018 15:48
A zsh widget that formats current command line
# format current command line
format-line() {
local words=("${(z)BUFFER}")
local buf=""
for (( i = 1; i <= $#words; i++ )); do
if [ $i = 1 ]; then
buf=$'\n'"${words[$i]}"
else
buf="$buf \\"$'\n'" ${words[$i]}"
@aoyama-val
aoyama-val / smart-no-clobber.zsh
Created May 1, 2018 04:26
I believe most Unix users have experiences in their newbie days in which they did something like `sed -e "s/foo/bar/g" infile > infile` and overwritten invaluable files. This zsh function prevents it. Unlike 'setopt noclobber', it refuses to execute the command line only when the destination filename appears before the redirect sign (>).
accept-line-smart-no-clobber() {
setopt localoptions noksharrays
local words=("${(z)BUFFER}")
local last_word="${words[$#words]}"
local last_word2="${words[$(($#words - 1))]}"
if [ "$last_word2" = ">" -a -e "$last_word" ]; then
for (( i = 1; i <= $#words - 2; i++ )); do
local w="${words[$i]}"
if [ "$w" = "$last_word" ]; then
zle -M "Destination file already exists. If you want to overwrite it, use '>|' instead of '>'."
@aoyama-val
aoyama-val / curl_builder.rb
Created April 24, 2018 05:48
Build curl command lines with Ruby
require "uri"
require "open3"
class CurlBuilder
def build(base_url:, method: "GET", params: {}, headers: {}, body_filename: nil, verbose: true, silent: true, options: "")
url = base_url
url += "?" + URI.encode_www_form(params) unless params.empty?
cmd = "curl -X #{method} '#{url}'"
cmd += " -d '@#{body_filename}'" if body_filename
cmd += " " + headers.map {|k, v| "-H '#{k}: #{v}'"}.join(" ") + " " unless headers.empty?
@aoyama-val
aoyama-val / proxy.rb
Last active February 24, 2016 07:55 — forked from torsten/proxy.rb
A quick HTTP proxy server in Ruby.
#!/usr/bin/env ruby
# A quick and dirty implementation of an HTTP proxy server in Ruby
# because I did not want to install anything.
#
# Copyright (C) 2009-2014 Torsten Becker <torsten.becker@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,