Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Fujiwara Takuya tyru

🏠
Working from home
View GitHub Profile
View .zshrc
is_screen_running() {
# tscreen also uses this varariable.
[ ! -z "$WINDOW" ]
}
is_tmux_runnning() {
[ ! -z "$TMUX" ]
}
is_screen_or_tmux_running() {
is_screen_running || is_tmux_runnning
}
@tyru
tyru / calibre-server.service
Created Oct 31, 2015
/etc/systemd/system/calibre-server.service
View calibre-server.service
[Unit]
Description=Calibre Content Server
After=network.target
[Service]
Type=simple
User=tyru
Group=tyru
ExecStart=/usr/bin/calibre-server --with-library /mnt/server/calibre --port 8080
@tyru
tyru / promise-is-resolved.js
Last active Mar 12, 2022
Check whether a promise is finished / resolved / rejected
View promise-is-resolved.js
function delay(msec, value) {
return new Promise(done => window.setTimeout((() => done(value)), msec));
}
function isResolved(promise) {
  return Promise.race([delay(0, false), promise.then(() => true, () => false)]);
}
function isRejected(promise) {
  return Promise.race([delay(0, false), promise.then(() => false, () => true)]);
@tyru
tyru / gist:376501
Created Apr 23, 2010
Zimbu introduction - translation in Japanese
View gist:376501
もしあなたが新しいプログラム、例えばテキストエディタを作るとしたら、どの言語で作る?
Suppose you want to write a new program, something like a text editor. What language would you write it in?
* できるだけ速く。なのでインタプリタ言語はダメ。
* It has to be as fast as possible, so interpreted languages are out.
* ちまちまメモリ管理なんてしたくない。だからCはダメ。
* You don't want to micro manage memory, so C is out.
* プログラマに学位をとれなんて言いたくない。だからC++はダメ。
* You don't want to require programmers to have a degree, so C++ is out.
* できるだけ起動は速いほうがいいし、ランタイムには依存させたくない。だからJavaはダメ。
@tyru
tyru / SingularToPlural.java
Last active May 29, 2021
英語の単数形を複数形に変換 (近々使えそうなので発掘)
View SingularToPlural.java
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 Aug 24, 2020
ssh-agent configuration
View .bashrc.ssh-agent
#!/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 Jun 17, 2020
WIP: [Preview] Chrome Debugging Protocol in Vim script
View client.vim
" 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 Apr 2, 2020
[AutoHotkey] Remap Alt + [A-Z] to Ctrl + [A-Z]
View remap-alt-to-ctrl.ahk
!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 / windows-like-word.json
Created Mar 25, 2020
[Karabiner Elements][macOS] Windows-like word movement/selection/deletion
View windows-like-word.json
{
"title": "[macOS] Windows-like word movement/selection/deletion",
"rules": [
{
"description": "Ctrl + Arrow Keys to Option + Arrow Keys",
"manipulators": [
{
"from": {
"key_code": "up_arrow",
"modifiers": {
@tyru
tyru / camelcase.pl
Created Apr 7, 2010
camelize/decamelize in Perl without String::CamelCase.
View camelcase.pl
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Test::More;
sub camelize {
my ($s) = @_;