Skip to content

Instantly share code, notes, and snippets.

View papiron's full-sized avatar

Katsuya TASHIRO papiron

  • Fukuoka, Japan
View GitHub Profile
@greymd
greymd / sudoku_nodejs_oneliner.sh
Last active July 20, 2022 11:45
Toriumi-san's sudoku solver
## original:
## https://twitter.com/hid_tori/status/1221415626465349635
## https://twitter.com/hid_tori/status/1221415683289780225
## https://twitter.com/hid_tori/status/1221415737375412224
## https://twitter.com/hid_tori/status/1221415770795728898
cat sudoku | node -e 'console.log((f=>(u=>u(u))(x=>f(y=>x(x)(y))))(f=>a=>((a,b)=>a.map(x=>x[3]).includes("*")?f(a.map(x=>x[3]!=="*"?x:[...x.slice(0,4),[...Array(9)].map((v,i)=>String(i+1)).filter(y=>!b[0][x[0]].concat(b[1][x[1]]).concat(b[2][x[2]]).includes(y))]).map(x=>x.length===4?x:x[4].length===1?[x[0],x[1],x[2],x[4][0]]:x.slice(0,4))):a)(a,a.reduce((x,y)=>(x[0][y[0]].push(y[3]),x[1][y[1]].push(y[3]),x[2][y[2]].push(y[3]),x),[...Array(3)].map(x=>[...Array(9)].map(y=>[]))).map(x=>x.map(y=>y.filter(z=>z!=="*")))))(require("fs").readFileSync("/dev/stdin","utf8").trim().split("\n").map((v,i)=>[i,v]).map(x=>[x[0],[...x[1].split("").entries()]]).flatMap(x=>x[1].map(y=>[x[0],...y])).map(x=>[x[0],x[1],Math.floor(x[0]/3)%3*3+Math.floor(x[1]/3),x[2]])).reduce((x,y)=>(x[
@greymd
greymd / ping_nyan.sh
Last active June 11, 2022 23:36
通常のpingで「にゃーん」を表示するシェル芸
#!/bin/bash
# From: https://twitter.com/grethlen/status/906154326975905793
sudo ping -i 0 -c 1400 pong4.kooshin.net \
| grep -oP "icmp_seq=\K\d+" \
| cat - <(seq 1 1400) \
| sort -n \
| uniq -c \
| awk '{printf $1}' \
| fold -w70 \
@ryuichiueda
ryuichiueda / tex_to_plain.bash
Created February 18, 2017 15:33
tex to plain
#!/bin/bash
###文献リスト###
cat ../rpim_book.bbl |
grep '^\\bibitem' |
sed 's/bibitem/cite/' |
awk '{print "s/\\"$1"/["NR"]/g"}' > ./cite.sed
cat ../rpim_book.bbl |
sed 's/bibitem/cite/' |
@greymd
greymd / powcompare.sh
Last active November 15, 2016 10:33
シェル上での冪乗計算の速さ比較
# ruby
$ time bash -c 'ruby -e "print 12345**54321"' >/dev/null
bash -c 'ruby -e "print 12345**54321"' > /dev/null 0.57s user 0.37s system 91% cpu 1.027 total
# bc
$ time bash -c 'echo "12345^54321" | bc' >/dev/null
bash -c 'echo "12345^54321" | bc' > /dev/null 3.15s user 0.06s system 81% cpu 3.942 total
# python
$ time bash -c 'echo "print pow(12345,54321)" | python' >/dev/null
@MasWag
MasWag / bi_funct.c.patch
Last active June 19, 2016 17:06
patch for mawk to fix rand in BSD (apply to bi_funct.c)
887c887
< sp->dval = ((double) value) / RAND_MAX;
---
> sp->dval = ((double) value) / (unsigned long)(MAWK_RAND_MAX);
@kunst1080
kunst1080 / gist:3706d19a2bc948611d39ecb490a917ec
Last active November 7, 2017 14:47
マイナンバーシェル芸(文字列結合ではなく数値計算でチェックデジットを計算する) のメモ
seq 1 99999999999 | awk '{
for(i=1;i<=11;i++){
a=int($0/(10^(i-1)));
b=a-int(a/10)*10;
if(i<=6){
sum+=b*(i+1)
} else {
sum+=b*(i-5)
}
};
@ttdoda
ttdoda / kcodecheck.rb
Last active March 31, 2017 02:45
端末の漢字コード設定の判別
#!/usr/bin/env ruby
# encoding: ascii-8bit
#
# 端末の漢字コード設定判別のサンプルスクリプト
#
# コンセプトとしてはUTF-8, EUC-JP, Shift_JISのどれと解釈しても正しい、
# しかしどのエンコーディングとして解釈したかで端末での表示幅が変わる
# バイト列を送信し、その時のカーソル位置で端末がどのエンコーディング
# として解釈したかを判別する。
#
@s-hiiragi
s-hiiragi / get_termsize.rb
Last active May 1, 2023 16:22
端末のサイズ(列数,行数)を取得
# @name get_termsize.rb
# @desc 端末のサイズ(列数,行数)を取得
=begin
man
http://linuxjm.sourceforge.jp/html/LDP_man-pages/man4/tty_ioctl.4.html
/usr/include/sys/termios.h
@valvallow
valvallow / marquee.scm
Created June 17, 2013 15:32
marquee in the shell
#!/usr/local/bin/gosh
(use gauche.parseopt)
(use gauche.process)
(use srfi-1)
(use srfi-13)
(define (usage cmd)
(print "usage: " cmd " [option] ... input")
(print " options:")