Skip to content

Instantly share code, notes, and snippets.

View nokazn's full-sized avatar
🏎️
ㅤ💨💨💨

nokazn nokazn

🏎️
ㅤ💨💨💨
  • ap-northeast-1
View GitHub Profile
import { type MutableRefObject, useEffect, useRef } from "react";
type Props<T> = {
elementRef: MutableRefObject<T | null>;
callback: (entry: IntersectionObserverEntry) => void;
options?: IntersectionObserverInit;
};
export const useIntersectionObserver = <T extends HTMLElement>({
elementRef,
#!/usr/bin/env bash
set -eu -o pipefail
function _sed() {
if sed --version >/dev/null 2>&1; then
# GNU版sed (Linux等)
sed -i "$@"
else
# BSD版sed (macOS等)
use std::{fs, path::Path};
pub fn copy_dir(source: impl AsRef<Path>, destination: impl AsRef<Path>) -> anyhow::Result<()> {
let destination = destination.as_ref().to_path_buf();
fs::create_dir_all(&destination)?;
for entry in fs::read_dir(source)? {
let entry = entry?;
let source = entry.path();
let destination = destination.join(entry.file_name());
if source.is_dir() {
import { useState } from "react"
type PromiseFunction<Succeeded> = (...parameters: never[]) => Promise<Succeeded>
type UseAsync<Succeeded, Failed, F extends PromiseFunction<Succeeded>> = {
data: Succeeded | null
error: Failed | null
execute: (...parameters: Parameters<F>) => void
pending: boolean
}
@nokazn
nokazn / boilerplate.sh
Last active July 23, 2022 08:49
シェルスクリプトの書き始め
#!/usr/bin/env bash
set -eu -o pipefail
# FIXME: プロジェクトの構成に応じて変更する
ROOT_DIR=$(cd "$(dirname "$0")"; pwd)
readonly ROOT_DIR
function usage() {
cat <<EOF

fd --glob "**.md" | xargs -I {} sed -i "1i ---\nlayout: ../../layouts/index.astro\n---" {}

@nokazn
nokazn / conf.user.json
Created January 8, 2022 13:53
Typora advanced settings
/** For advanced users. */
{
"defaultFontFamily": {
"standard": null, //String - Defaults to "Times New Roman".
"serif": null, // String - Defaults to "Times New Roman".
"sansSerif": null, // String - Defaults to "Arial".
"monospace": null // String - Defaults to "Courier New".
},
"autoHideMenuBar": false, //Boolean - Auto hide the menu bar unless the `Alt` key is pressed. Default is false.
@nokazn
nokazn / extractUrlFromHar.ts
Created August 5, 2021 04:05
.har ファイルから URL を取り出して出力する
import * as fs from 'fs';
import { z } from 'zod';
const SCHEMA = z.object({
log: z.object({
entries: z.array(
z.object({
request: z.object({
url: z.string(),
}),
@nokazn
nokazn / Makefile
Created June 4, 2021 07:03
Display help information for make commands
#!/usr/bin/make -f
.DEFAULT_GOAL := help
.PHONY: help
help: # Show all commands.
@echo "📗 Displays help information for make commands."
@echo "Commands:"
# コマンド一覧 -> ":" で改行 -> ":" を含む行 (前半) の \s を ", " に置換、"#" を含む行 (後半) からコメントを抽出 -> ":" で分けた個所を再連結 -> column で整形
@grep -E '^[a-zA-Z]\S+(\s\S+)*:.*' ./Makefile \

まとめ

前回の文字列の章の残りと、文字列と Unicode、ラッパーオブジェクトの章を読み進めました。

文字列と正規表現どちらを使うべきか

正規表現
  • 曖昧な検索に強い
  • コードの意図が伝わりにくい