Skip to content

Instantly share code, notes, and snippets.

Avatar

Kensuke Nagae kyanny

View GitHub Profile
View 01_base.t
use JSTAPd::Suite;
sub client_script {
return <<'DONE';
tests(6);
ok(1, 'ok 1');
ok(!0, 'ok 0');
is('test', 'test', 'is');
isnt('test', 'dev', 'isnt');
like('test', new RegExp('es'), 'like');
View lcut.bash
lcut() {
local input
if [ -p /dev/stdin ]; then
input=$(cat -)
else
input=$(cat $1)
shift
fi
echo $input | perl -slane '@pairs = /(\w+=?(?:"[^"]*"|[^\s]*))/g;
@keys = split /\s+/, $args;
@kyanny
kyanny / gist:227a6a5e54abf3a0db95b6160260dd5e
Last active Aug 12, 2022
Prevent "`winsize': Inappropriate ioctl for device (Errno::ENOTTY)" error with irb bundled with ruby 3.1.2 https://github.com/ruby/irb/pull/353
View gist:227a6a5e54abf3a0db95b6160260dd5e
❯ ruby -v
ruby 3.1.2p20 (2022-04-12 revision 4491bb740a) [x86_64-darwin21]
❯ irb -v
irb 1.4.1 (2021-12-25)
❯ echo n=1 | irb | cat
Switch to inspect mode.
n=1
/Users/kyanny/.rbenv/versions/3.1.2/lib/ruby/3.1.0/irb/input-method.rb:43:in `winsize': Inappropriate ioctl for device (Errno::ENOTTY)
View slack-thread-full-screenshot.sh
#!/bin/bash
UUID=$(uuidgen)
WORKDIR="$HOME/Desktop/$UUID"
mkdir -p "$WORKDIR"
osascript -e 'activate application "Slack"'
sleep 0.5
i=0
@kyanny
kyanny / fib.exs
Created Mar 13, 2012
Elixir fibonacci #1
View fib.exs
defmodule Fib do
def fib(0) do 0 end
def fib(1) do 1 end
def fib(n) do fib(n-1) + fib(n-2) end
end
IO.puts Fib.fib(10)
@kyanny
kyanny / setup-actions-runner-controller.md
Created Apr 26, 2022
How to setup actions-runner-controller for testing
View setup-actions-runner-controller.md
View github-apps-call-rest-api.sh
#!/bin/bash
curl -sLO https://github.com/mike-engel/jwt-cli/releases/latest/download/jwt-linux.tar.gz
tar xzf jwt-linux.tar.gz
curl -sLO https://github.com/stedolan/jq/releases/latest/download/jq-linux64
mv jq-linux64 jq
chmod +x jq
app_id=157615
private_key_file=my-tiny-github-app.2021-12-09.private-key.pem
View download-cert.sh
#!/bin/bash
host=$1
if [[ -z $host ]]; then
echo "Usage: bash $0 HOSTNAME"
exit 1
fi
echo | openssl s_client -servername $host -connect $host:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > certificate.crt
@kyanny
kyanny / graphql.sh
Last active Oct 26, 2021
Call GraphQL API with curl.
View graphql.sh
#!/bin/bash
# Usage: bash graphql.sh < query.txt
query=$(cat - | sed -e 's/"/\\"/g' | tr -d '\n')
cat <<EOM> query.json
{"query":"$query"}
EOM
curl -H "Authorization: token $GITHUB_TOKEN" https://api.github.com/graphql -d @query.json
View server.py
# ref. https://gist.github.com/mdonkers/63e115cc0c79b4f6b8b3a6b797e485c7
# ref. https://stackoverflow.com/questions/54607547/read-http-request-data-in-python-3
import http.server
import socketserver
import logging
import os
import urllib.parse
PORT = os.getenv("PORT", 8080)