Skip to content

Instantly share code, notes, and snippets.

View xtetsuji's full-sized avatar

OGATA Tetsuji xtetsuji

View GitHub Profile
@xtetsuji
xtetsuji / gh-noreply-address
Last active November 22, 2023 19:13
show my GitHub noreply address by gh-cli
#!/bin/bash
set -eu
gh api /user | jq -r '"\(.id)+\(.login)@users.noreply.github.com"'
#!/bin/bash
# https://docs.docker.com/engine/install/ubuntu/
set -eu
# root でなかったら終了
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root." 1>&2
exit 1
fi
@xtetsuji
xtetsuji / majide.js
Created June 21, 2023 02:45
MajiDe time-based event driven interface by Japanese named class and its methods.
class MajiDe {
/**
* MajiDe オブジェクトを作成する
* @param {Function} func - コールバック
*/
constructor(func) {
if ( !func || typeof func !== "function" ) {
throw new Error("第一引数は関数にして下さい");
}
this.func = func;
@xtetsuji
xtetsuji / defaultgw
Last active December 17, 2022 04:33
print default gateway. and open browser if argument has `-w`
#!/bin/bash
set -eu
browser=open
default_gw=$( route -n get 0.0.0.0 | grep gateway | sed -e 's/.*: //' )
if [ "_${1:-}" = "_-w" ] ; then
"$browser" "http://$default_gw/"
fi
@xtetsuji
xtetsuji / output.txt
Created November 28, 2022 05:03
square-sum-1128.pl
2^2 + 10^2 + 32^2 = 1128
2^2 + 32^2 + 10^2 = 1128
10^2 + 2^2 + 32^2 = 1128
10^2 + 32^2 + 2^2 = 1128
14^2 + 16^2 + 26^2 = 1128
14^2 + 26^2 + 16^2 = 1128
16^2 + 14^2 + 26^2 = 1128
16^2 + 26^2 + 14^2 = 1128
26^2 + 14^2 + 16^2 = 1128
26^2 + 16^2 + 14^2 = 1128
@xtetsuji
xtetsuji / recursive-spf.pl
Created January 21, 2021 13:16
count given domain "include" consider recursive "include"
#!/usr/bin/env perl
use strict;
use warnings;
my $check_mail_domain = shift;
if ( !$check_mail_domain || $check_mail_domain =~ / / ) {
die "1st argument is required as mail domain\n";
}
@xtetsuji
xtetsuji / add-music.js
Created December 30, 2020 11:03
Simple music files importer for Apple macOS new Music.app
#!/usr/bin/osascript -l JavaScript
function run(argv) {
const music = Application("Music");
for ( const file of argv ) {
console.log(`add: "${file}"`);
music.add(file);
}
}
@xtetsuji
xtetsuji / replace_sample.js
Last active November 26, 2020 13:50
Sample: convert from plural String#replace'es change to compact one reduce call. This script can be executed by GAS (some syntaxes require V8 engine support).
function ordinally_replace_sample() {
const content = getContent();
let replaced = content;
replaced = replaced.replace(/&/g, "&");
replaced = replaced.replace(/</g, "&lt;");
replaced = replaced.replace(/>/g, "&gt;");
replaced = replaced.replace(/"/g, "&quot;");
replaced = replaced.replace(/'/g, "&apos;");
console.log("ordinally: " + replaced);
}
@xtetsuji
xtetsuji / urlopen
Created September 21, 2020 08:32
URL filter and open from STDIN
#!/usr/bin/env perl
# urlopen - open (macOS) URL from STDIN
# SYNOPSIS:
# tail url_include_log | urlopen
# stdout-url-command | urlopen
# OPTIONS:
# urlopen [--pass-through|-p] : pass through STDOUT (default off)
# urlopen [--verbose|-v] : outout opend URL (default off)
use v5.12;
use Getopt::Long qw(:config posix_default no_ignore_case bundling auto_help);
@xtetsuji
xtetsuji / sqrt-newton.pl
Created September 17, 2020 16:01
Get square root by Newton's method.
#!/usr/bin/env perl
use v5.14;
use constant MAX_NEWTON_ITERATION_COUNT => 8;
print "平方根をニュートン法で求めます\n";
print "1より大きい自然数を入れて下さい: ";
my $input = <STDIN>;
chomp $input;
if ( !$input || $input <= 1 ) {
die "1より大きい自然数ではありませんでした\n";