Skip to content

Instantly share code, notes, and snippets.

@namikingsoft
namikingsoft / useIntersection.tsx
Created December 3, 2022 10:26
use-intersection
import { useEffect, useState } from 'react'
type ReturnType = {
setRef: (elm: Element | null) => void
done: boolean
}
export const useIntersection = (): ReturnType => {
const [element, setElement] = useState<Element | null>(null)
const [done, setDone] = useState(false)
@namikingsoft
namikingsoft / repeat-seconds.sh
Last active January 4, 2021 22:09
Repeat seconds
TIMEOUT_UNIXTIME="$(($(date +%s)+10))"
while [ "$(date +%s)" -lt "$TIMEOUT_UNIXTIME" ]; do
echo test
done
# bash
$TIMEOUT_SECONDS=$((SECONDS+10))
while [ $SECONDS -lt $TIMEOUT_SECONDS ]; do
echo test
done
@namikingsoft
namikingsoft / repeat-count.sh
Last active January 4, 2021 22:08
Repeat count snipet
seq 10 | while read; do
echo "close local variable"
done
# bash
<<(seq 10) while read; do
echo "open variable"
done
@namikingsoft
namikingsoft / webpack-bundle-analyzer-to-github-statuses.sh
Last active January 6, 2021 23:32
Post reports of webpack-bundle-analyzer to GitHub statuses on CircleCI
#!/bin/sh -eu
# ## Post bundle analyzer to github statuses
#
# ### Environment Variables
#
# - `REPORT_JSON_PATH`: By webpack-bundle-analyzer
# - `REPORT_HTML_PATH`: By webpack-bundle-analyzer
# - `GITHUB_TOKEN`: GitHub Access Token
# - `CIRCLE_SHA1`: Defined by CircleCI
@namikingsoft
namikingsoft / base_branch_sha1.sh
Last active December 16, 2020 20:50
Fetch base sha1 from github pull request number
GITHUB_PR_NUMBER=1234
base_branch_sha1() {
MERGED_BRANCH="pull/${GITHUB_PR_NUMBER}/merge"
git fetch origin "${MERGED_BRANCH}:${MERGED_BRANCH}" > /dev/null
git log "${MERGED_BRANCH}" --oneline | head -n1 | sed -e 's/^.* into //'
}
@namikingsoft
namikingsoft / testcafe-report-json-to-xunit-for-timings.sh
Last active May 24, 2021 08:14
Testcafe report of json to xunit for split by timings on CircleCI
#!/bin/sh -eu
#
# Testcafe report of json to xunit for split by timings on CircleCI
#
# refs.
# https://github.com/DevExpress/testcafe-reporter-xunit
# https://github.com/DevExpress/testcafe-reporter-json
#
# required packages:
# base64
@namikingsoft
namikingsoft / notify-wiplimit-of-github-project.sh
Last active May 10, 2019 04:51
Notify Exceeded WIP Limit on GitHub Project via Slack (Experimental)
#!/bin/sh -eu
#
# required env:
# GITHUB_ACCESS_TOKEN
# GITHUB_PROJECT_ID
# GITHUB_PROJECT_SETTING_CARD_ID
# SLACK_INCOMING_WEBHOOK_URL
#
# required packages:
# base64
@namikingsoft
namikingsoft / notify-audit-to-slack.sh
Last active February 28, 2019 21:28
Scripts of yarn audit
#!/bin/sh -eu
#
# required env:
# SLACK_TEXT: Description, Build URL of CI
# SLACK_INCOMING: Slack Incoming Webhook URL
#
# required stdin:
# json text of `.data.advisory` on yarn audit
#
# required packages:
@namikingsoft
namikingsoft / waffle_wip_judge.sh
Last active December 4, 2018 02:28
Judge Exceeded WIP Limit on Waffle.io (Experimental)
#!/bin/sh -eu
#
# required env:
# WAFFLE_ACCESS_TOKEN
# WAFFLE_ORG_NAME
# WAFFLE_PROJECT_NAME
#
# required packages:
# base64
# curl
@namikingsoft
namikingsoft / hunho2markdown.sh
Last active June 27, 2018 10:09
[殴り書き] Slack 分報から日報用マークダウン生成 for MacOSX
#!/bin/sh -eu
# Usage: hunho2markdown.sh <2010-01-02>
# required: export SLACK_TOKEN="(e.g. https://api.slack.com/custom-integrations/legacy-tokens)"
# required: brew install pandoc
date="${1:-undefined}"
# slack variables
slack_domain="${SLACK_DOMAIN:-f**df****e}" # ****.slack.com
slack_userid="${SLACK_USERID:-U********}"