Skip to content

Instantly share code, notes, and snippets.

Avatar
😉
Nanchatte

Yasuhiro Yamada greymd

😉
Nanchatte
  • Dublin, Ireland
View GitHub Profile
@greymd
greymd / base64sh.sh
Created Nov 3, 2016
base64 encoder given by build-in linux commands.
View base64sh.sh
base64sh() {
local input=${1:-$(cat)}
paste <(seq 0 63 | sed 's/^/obase=2;ibase=10;/' | bc | sed 's/^/00000/' | grep -oE '.{6}$') \
<(echo {A..Z} {a..z} {0..9} + / | xargs -n 1) | \
awk '{print "s|"$1"|"$2"|"}' | \
sed -f - <(echo -n $input| perl -ne 'print unpack("B*", $_)."0000"' | \
fold -w 6 | grep -oE '.{6}$') | tr -d '\n' | fold -w 4 | sed 's/$/===/' | grep -oE '^.{4}' | tr -d '\n' | awk 1
}
# Usage: base64sh
@greymd
greymd / osc_copy.vim
Last active Aug 22, 2020
OSC52 copy with Vim
View osc_copy.vim
" Clipboard integration by Operating System Controls from Vim
" Usage:
" Yank something and run :OscCopy
" or
" Copy range in visual mode and run :'<,'>OscCopyRange
" From: https://stackoverflow.com/questions/1533565/how-to-get-visually-selected-text-in-vimscript
function! GetVisualSelection()
let [lnum1, col1] = getpos("'<")[1:2]
@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上で実行されたこのシェル芸は、結果として下記のようにフィボナッチ数列を出す。

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 / 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 / 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 \
You can’t perform that action at this time.