Skip to content

Instantly share code, notes, and snippets.

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

Fujiwara Takuya tyru

🏠
Working from home
View GitHub Profile
@tyru
tyru / SingularToPlural.java
Last active May 29, 2021 07:39
英語の単数形を複数形に変換 (近々使えそうなので発掘)
public class SingularToPlural {
private SingularToPlural() {
}
/*
・末尾が s, sh, ch, o, x のいずれかである英単語の末尾に es を付ける
・末尾が f, fe のいずれかである英単語の末尾の f, fe を除き、末尾に ves を付ける
・末尾の1文字が y で、末尾から2文字目が a, i, u, e, o のいずれでもない英単語の末尾の y を除き、末尾に ies を付ける
・上のいずれの条件にも当てはまらない英単語の末尾には s を付ける
@tyru
tyru / .bashrc.ssh-agent
Last active August 24, 2020 14:14
ssh-agent configuration
#!/bin/bash
# Based on http://www.snowelm.com/~t/doc/tips/20030625.ja.html
[[ -f ~/.ssh-agent-info ]] && source ~/.ssh-agent-info >/dev/null
ssh-add -l >&/dev/null
if [ $? == 2 ]; then
# unable to contact the authentication agent
echo -n "ssh-agent: Restarted..."
ssh-agent >~/.ssh-agent-info
source ~/.ssh-agent-info
@tyru
tyru / client.vim
Last active June 17, 2020 14:42
WIP: [Preview] Chrome Debugging Protocol in Vim script
" Run:
" 1. mkdir tmp
" 2. {chrome} --remote-debugging-port=9222 --no-first-run --no-default-browser-check --user-data-dir=tmp
"
" In another shell:
" 1. vim -S client.vim
"
" ref. https://developer.mozilla.org/ja/docs/Tools/Remote_Debugging/Chrome_Desktop
@tyru
tyru / remap-alt-to-ctrl.ahk
Last active April 2, 2020 02:28
[AutoHotkey] Remap Alt + [A-Z] to Ctrl + [A-Z]
!a::Send, ^a
!b::Send, ^b
!c::Send, ^c
!d::Send, ^d
!e::Send, ^e
!f::Send, ^f
!g::Send, ^g
!h::Send, ^h
!i::Send, ^i
!j::Send, ^j
@tyru
tyru / camelcase.pl
Created April 7, 2010 09:45
camelize/decamelize in Perl without String::CamelCase.
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Test::More;
sub camelize {
my ($s) = @_;
@tyru
tyru / list-func.vim
Last active March 3, 2020 05:57
fold() and flatmap() implementation in Vim script
function! s:fold(list, f, init) abort
let ref = {'result': a:init}
return map(copy(a:list), {_,v -> extend(ref, {'result': a:f(ref.result, v)})})[-1].result
endfunction
function! s:fold2(list, f, init) abort
let l = a:list + [a:init]
let end = len(a:list)
return map(l, {i,v -> i is# end ? l[i-1] : a:f(l[i-1], v)})[-1]
endfunction
@tyru
tyru / fun.sh
Created December 31, 2019 21:18
clear
echo -n -e "\x1b7"
while :; do
# 2>/dev/null: hide python stacktrace when Ctrl-C
output=$(echo -n -e "あけましておめでとうこざいます。\n本年も日経Linuxとラズパイマガジンをご愛読のほど、\n何卒よろしくお願いいたします。" | boxes -d mouse | lolcat -F 1 -f 2>/dev/null)
echo -n -e "\x1b8$output"
sleep 0.5s
done
@tyru
tyru / bench.vim
Created November 19, 2019 07:16
Benchmark for parsing SKK dictionary
function! s:run() abort
let skkdict = expand('~/Dropbox/config/skkdict/system-dict')
" for memory cache
call readfile(skkdict)
let start = reltime()
call readfile(skkdict)
let b1 = reltimestr(reltime(start, reltime()))
@tyru
tyru / main.rs
Last active August 25, 2019 09:24
JSON Parser in Rust
#![feature(slice_patterns)]
use std::io;
use std::fmt;
use std::str;
use std::result;
use std::iter::Iterator;
// TODO: take deparse option from command-line arguments
fn main() {
@tyru
tyru / detect_dirty_worktree.go
Created September 22, 2017 16:16
Try to detect worktree (currently not working)
package main
import (
"fmt"
"io/ioutil"
"os"
"os/user"
"path/filepath"
"strings"