Skip to content

Instantly share code, notes, and snippets.

View Himenon's full-sized avatar
😇
Working from home

K.Himeno Himenon

😇
Working from home
View GitHub Profile
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties":
{
"global":
{
"$ref": "#/definitions/global"
},
"profiles":
@Himenon
Himenon / @types-openapi-3.1.0.ts
Last active December 22, 2020 16:43
OpenAPI 3.1.0 type definition.
import { JSONSchema7 as JSONSchema } from "json-schema";
export type MapLike<K extends string, T> = {
[key in K]: T;
};
/**
* @see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#serverVariableObject
*/
export interface ServerVariable {
const dataSet = [
{
title: "top",
uri: "/top",
description: "このwebサイトのTOPページ",
tags: ["website"],
},
{
title: "about",
uri: "/about",
@Himenon
Himenon / updateQueryStringParameter.ts
Created November 29, 2019 01:51
特定のqueryパラメーターを更新する関数
const updateQueryStringParameter = (key: string, value: string): void => {
const searchParams = new URLSearchParams(window.location.search);
const params = {};
searchParams.forEach((v, k) => {
params[k] = v;
});
if (value === "") {
delete params[key];
} else {
params[key] = value;
@Himenon
Himenon / clone-instance.ts
Created October 23, 2019 12:41
すでに生成されたインスタンスから、新しいインスタンスを生成するFunction
/**
* すでに生成されたインスタンスから、新しいインスタンスを生成する
* https://stackoverflow.com/questions/41474986/how-to-clone-a-javascript-es6-class-instance
* @param instance
*/
const cloneInstance = <T>(instance: T): T => Object.assign(Object.create(Object.getPrototypeOf(instance)), instance);
@Himenon
Himenon / github-action-event-json-types.d.ts
Created October 20, 2019 15:12
`event.json` of Github Action Interface.
declare module namespace {
export interface Comments {
href: string;
}
export interface Commits {
href: string;
}
{
"schemaVersion": 2,
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"config": {
"mediaType": "application/vnd.docker.container.image.v1+json",
"size": 7753,
"digest": "sha256:451b716593e5f4b35826c8f869950135b925e74d0ed0a40b7c794b8a54ce9b39"
},
"layers": [
{
@Himenon
Himenon / evolute-argument-type-sample.ts
Last active May 10, 2019 09:50
Sample code that evolves in order of argument type.
// https://github.com/sindresorhus/type-fest/blob/master/source/omit.d.ts
type Omit<ObjectType, KeysType extends keyof ObjectType> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;
interface A1 {
type: "a1";
a1: string;
}
interface A2 extends Omit<A1, "type"> {
type: "a2";
const a = Array(100000).fill(Math.random());
const b = Array(100000).fill(Math.random());
const benchmark = (func, repeat) => {
const result = [];
Array(repeat)
.fill(1)
.map(() => {
const start = window.performance.now();
func();
@Himenon
Himenon / useOnResize.tsx
Last active March 26, 2019 10:41
Resize Event React hook
type OnResizeFunction = (size: { width: number; height: number }) => void;
export const useOnResize = <T extends React.MutableRefObject<any | null>>(ref: T, onResize: OnResizeFunction) => {
React.useEffect(() => {
const callback = () => {
if (ref.current) {
onResize({
width: ref.current.clientWidth,
height: ref.current.clientHeight,
});