Skip to content

Instantly share code, notes, and snippets.

Avatar
😉
Nanchatte

Yasuhiro Yamada greymd

😉
Nanchatte
  • Dublin, Ireland
View GitHub Profile
View MyViewController.swift
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
override func viewDidLoad() {
view.backgroundColor = .white
let s1 = generateLabel()
let s2 = generateLabel()
let s3 = generateLabel()
@greymd
greymd / sudoku_nodejs_oneliner.sh
Last active Jan 26, 2020
Toriumi-san's sudoku solver
View sudoku_nodejs_oneliner.sh
## 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 / MyViewController.swift
Last active Jan 21, 2020
Scroll text animation in Swift
View MyViewController.swift
import UIKit
import PlaygroundSupport
class MyViewController : UIViewController {
var label:UILabel!
var label2:UILabel!
let gap:CGFloat = 50
let rep:Float = Float.infinity
let shape:CAShapeLayer = {
return CAShapeLayer()
@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 Apr 10, 2020
yamayaさんの難読化シェル芸(フィボナッチ数列) 解説
View yamaya_fib.md

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

経緯

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

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

— yamaya (@yamaya) April 6, 2019

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

@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 / script.sh
Last active May 16, 2018
Convert app.log to csv
View script.sh
sed '/response:/{:loop;N;/<\/root>/!b loop;s/\n//g}' app.log | \
# 特定の時間帯のログだけをgrep
grep '^2017-05-09 20:5[0-9]' | \
# あとはgrepなりsedなりawkなりで自由に抽出
grep -oP '<record> *\K.*?(?= *</record>)' | sed 's/<\/[^>]*> *<[^>]*>/,/g;s/<[^>]*>//g'
# 同じディレクトリにapp.logを置いて実行
# $ bash script.sh
# 出力結果:
# A001,1990-01-04,0
You can’t perform that action at this time.