Skip to content

Instantly share code, notes, and snippets.

😉
Nanchatte

Yasuhiro Yamada greymd

😉
Nanchatte
  • Dublin, Ireland
Block or report user

Report or block greymd

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@greymd
greymd / fizzbuzz.egi
Last active Oct 2, 2019
EgisonでFizzBuzz
View fizzbuzz.egi
; ひねくれた方法な気がする。
(map
3#(match [%1 %2 %3] something {
[[_ ,0 ,0] FizzBuzz]
[[_ ,0 _] Fizz]
[[_ _ ,0] Buzz]
[[$i _ _] i]})
(map 1#[%1 (modulo %1 3) (modulo %1 5)] (take 100 nats)))
@greymd
greymd / function.sh
Last active Sep 11, 2019
Run given command as is with Custom AWS Lambda Runtime
View function.sh
# Input is like {"command":"bHMgLWFsIHwgZ3JlcCBob2dlaG9nZQo="}
function handler () {
EVENT_DATA="$1"
local _cmd
local _tmpdir
_cmd="$(tr -d '[:space:]' <<<"$EVENT_DATA" | sed -E "s/\{[\"']command[\"']:[\"']([0-9A-Za-z+/=]*)[\"']\}/\1/" | base64 --decode)"
_tmpdir="$(mktemp)"
eval "$_cmd" 2> "$_tmpdir-stderr" > "$_tmpdir-stdout" || true
echo "{\"stdout\": \"$(cat "$_tmpdir-stdout" | base64 | tr -d '\n')\", \"stderr\": \"$(cat "$_tmpdir-stderr" | base64 | tr -d '\n')\"}" || true
rm -rf "$_tmpdir-stderr" "$_tmpdir-stdout" "$_tmpdir"
@greymd
greymd / yamaya_fib.md
Last active Sep 4, 2019
yamayaさんの難読化シェル芸(フィボナッチ数列) 解説
View yamaya_fib.md

yamayaさんの難読化シェル芸(フィボナッチ数列) 解説

経緯

(1) ある日、yamaya さんという怖い方がこのツイートを投稿する。

! : "`/???/???/???${#?}???<<<_.`";_____=${_::-~$?}
____='__+=___,___=__-___,__<_[$($_____<<<$___>&$[-~${##}])]||____'
((__=-~$?,____))|&$_____#シェル芸

— yamaya (@yamaya) April 6, 2019

(2) シェル芸bot上で実行されたこのシェル芸は、結果として下記のようにフィボナッチ数列を出す。

@greymd
greymd / Main.java
Created Feb 10, 2017
Prime numbers with Java8 Stream API
View Main.java
import java.util.stream.IntStream;
class Main {
public static void main(String args[]) {
IntStream.rangeClosed(2, 100)
.filter(i -> IntStream.rangeClosed(2, (int)Math.sqrt(i))
.allMatch(j -> i%j != 0))
.forEach(n -> {
System.out.println(n);
});
@greymd
greymd / ping_nyan.sh
Last active Sep 28, 2018
通常のpingで「にゃーん」を表示するシェル芸
View ping_nyan.sh
#!/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 \
@greymd
greymd / equalized_partition_nums.sh
Last active Aug 12, 2018
Divide integer num much equally with bash
View equalized_partition_nums.sh
#!/bin/bash
ceiling () {
local divide="$1";shift
local by="$1"
printf "%s\\n" $(( ( divide + by - 1 ) / by ))
}
equalized_partition_nums () {
local number="$1";shift
local count="$1"
@greymd
greymd / fifo.sh
Last active Jul 31, 2018
Docker + fifo + tmux bug ?
View fifo.sh
#!/bin/bash
# Try this script on the docker container.
# Tested on macoOS High Sierra + Ubuntu 18.04 docker container.
rm -f "$HOME"/work/*
tmux -S "$HOME"/work/sess new-session -d
printf "%s\\n" A B C D | while read -r f;do
View gist:42c1c245e2a6c0e10db176d314081f62
--------------------
bash 3.2.0
--------------------
~$ bash --version
GNU bash, version 3.2.0(1)-release (x86_64-unknown-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
~$ [[ "hoge" =~ ho.. ]] && echo "${BASH_REMATCH[0]}"
hoge
@greymd
greymd / gist:6edbff59405fcf5d4802cdb910587db0
Last active Jul 7, 2018
めも:【問題のみ】jus共催 第36回七夕・・・7は素数じゃないですか(しかも2つ)シェル芸勉強会
View gist:6edbff59405fcf5d4802cdb910587db0
Q1:
<welcome.txt tr '\0' '*' | fold -w 70
初っ端からひどい
Q2:
ls | perl -C -Mutf8 -nle 'printf "mv $_ ";$_ =~ tr/0-9/0-9/ ;$_ =~ tr/A-Z/A-Z/;$_ =~ m/([0-9]).*([A-Z])/; print " $1年$2組.doc"'
Q3:
echo 2018{01..12}{01..31}$'\n' | date -f- +'%Y%m%d' 2>/dev/null | grep -P '([2357].*){4}'
@greymd
greymd / app.log
Last active May 25, 2018
app.log
View app.log
2017-05-09 20:53:26 INFO --- [thread-1] myapp.logic : Register records
2017-05-09 20:53:26 INFO --- [thread-1] myapp.logic : --> POST https://api.example/v2/records http/1.1
2017-05-09 20:53:27 INFO --- [thread-1] myapp.logic : response: <?xml version="1.0" encoding="UTF-8"?>
<root>
<records>
<record>
<id>A001</id>
<date>1990-01-04</date>
<status>0</status>
</record>
You can’t perform that action at this time.