Skip to content

Instantly share code, notes, and snippets.

@matsub
matsub / createUser.sh
Created October 30, 2023 03:25
obtain an access token of AWS Cognito
#!/bin/bash
USER_POOL_ID=<user pool ID>
CLIENT_ID=<application client ID>
CLIENT_SECRET=<client secret>
COGNITO_USERNAME=<any user name>
COGNITO_TEMP_PASSWORD=<temporary password>
COGNITO_PASSWORD=<any user password>
SECRET_HASH=$(echo -n "${COGNITO_USERNAME}${CLIENT_ID}" | openssl dgst -sha256 -hmac "${CLIENT_SECRET}" -binary | base64)
@matsub
matsub / event.ts
Created August 31, 2020 05:22
Typed Event Emitter
import { EventEmitter } from "events";
interface TypedEventEmitter<T> {
addListener<K extends keyof T>(event: K, listener: (arg: T[K]) => void): this;
on<K extends keyof T>(event: K, listener: (arg: T[K]) => void): this;
once<K extends keyof T>(event: K, listener: (arg: T[K]) => void): this;
removeListener<K extends keyof T>(
event: K,
listener: (arg: T[K]) => void
): this;
@matsub
matsub / objectify.js
Last active August 3, 2020 08:39
convert a serial array to an object in JavaScript and TypeScript
function objectify(arr) {
return Object.fromEntries(arr.reduce((acc, cur, idx) => (idx%2 ? acc[acc.length-1].push(cur) : acc.push([cur])) && acc, []));
}
<span></span>
<script>
const span = document.querySelector("span");
function step(timestamp) {
const date = new Date();
const d = {
h: date.getHours().toString().padStart(2, '0'),
m: date.getMinutes().toString().padStart(2, '0'),
s: date.getSeconds().toString().padStart(2, '0'),
ms: Math.floor(date.getMilliseconds() / 100),
@matsub
matsub / redis-sentinel.yml
Created March 18, 2020 05:06
k8s manifest YAML for redis-sentinel set
apiVersion: v1
kind: Service
metadata:
name: redis-sentinel
labels:
app: redis-sentinel
spec:
clusterIP: None
ports:
- name: redis-sentinel
@matsub
matsub / noise.html
Last active March 18, 2020 05:10
static noise with javascript
<canvas width="854" height="480"></canvas>
<script>
const canvas = document.querySelector("canvas");
const ctx = canvas.getContext("2d");
const imageData = ctx.createImageData(canvas.width, canvas.height);
let offsetY = 0;
// draw like a scanner
const gradient = ctx.createLinearGradient(0, 0, 0, canvas.height);
gradient.addColorStop(0, "rgba(0,0,0,0.6)");
@matsub
matsub / test.js
Created December 28, 2018 06:08
testcafeがLoose equalityをstrict equalityとして評価しているように見える
import { Selector } from 'testcafe'
fixture `Loose Equality`
.page `http://localhost:8000/`
test('Say Hello', async t => {
const btn = Selector("button")
await t.click(btn)
// assertion
@matsub
matsub / Dockerfile
Created December 8, 2018 12:41
GitHub Apps
FROM python:3.6-alpine3.7
LABEL "com.github.actions.name"="Assign Reviewer"
LABEL "com.github.actions.description"="Assign a PR reviewer when it does not have enough reviewers"
LABEL "com.github.actions.icon"="edit"
LABEL "com.github.actions.color"="blue"
LABEL "repository"="https://github.com/matsub/try-github-actions"
LABEL "maintainer"="matsub <matsub.rk@gmail.com>"
@matsub
matsub / Dockerfile
Created December 8, 2018 05:49
GitHub Actions
FROM alpine:3.8
LABEL "com.github.actions.name"="Hello World"
LABEL "com.github.actions.description"="Write arguments to the standard output"
LABEL "com.github.actions.icon"="anchor"
LABEL "repository"="https://github.com/matsub/try-github-actions"
LABEL "maintainer"="matsub <matsub.rk@gmail.com>"
ADD entrypoint.sh /entrypoint.sh
@matsub
matsub / VolumeController.html
Created November 16, 2018 06:15
WebRTC+WebAudio
<!doctype html>
<input type="range" value="1" min="0" max="1" step="0.05">
<script src="VolumeController.js"></script>
<script>
async function main() {
const input = document.querySelector("input")
const stream = await navigator.mediaDevices.getUserMedia({
video: false,
audio: true
})