Skip to content

Instantly share code, notes, and snippets.

Avatar

Kensuke Nagae kyanny

View GitHub Profile
@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
@kyanny
kyanny / server.ts
Created Oct 7, 2021
Deno HTTP server for debug/echo
View server.ts
#!/usr/bin/env deno run --allow-net
// https://deno.land/manual/examples/http_server
// Start listening on port 8080 of localhost.
const server = Deno.listen({ port: 8080 });
console.log(`HTTP webserver running. Access it at: http://localhost:8080/`);
// Connections to the server will be yielded up as an async iterable.
for await (const conn of server) {
View post.py
import urllib.request
import os
import json
token = os.getenv('GITHUB_TOKEN')
data = {
'text': '**hello** __world__',
}
headers = {
'Content-Type': 'application/json',
View get.py
import urllib.request
import os
import json
token = os.getenv('GITHUB_TOKEN')
headers = {
'Authorization': f'token {token}'
}
url = 'https://api.github.com/user/repos'
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)
@kyanny
kyanny / hello_world.py
Created Aug 31, 2021
Hello World Examples
View hello_world.py
class HelloWorld:
def __init__(self, name):
self.name = name.capitalize()
def sayHi(self):
print "Hello " + self.name + "!"
hello = HelloWorld("world")
hello.sayHi()
View my-tempfile.py
import tempfile
with tempfile.NamedTemporaryFile() as tmp:
print(tmp.name)
tmp.write(b'Hello\nWorld')
tmp.seek(0)
with open(tmp.name) as f:
print(f.read())
with tempfile.NamedTemporaryFile(mode='w+t') as tmp: