Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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)