Skip to content

Instantly share code, notes, and snippets.

@oukayuka
oukayuka / lint-staged-around
Last active March 31, 2021 01:23
Execute each lint-staged entry in sub-directories projects recursively
#!/bin/sh
# lint-staged-around
# execute each lint-staged entry in sub-directories projects recursively
#
# Riakuto! Project by Klemiwary Books
fileTypes="js|jsx|ts|tsx|html|css|less|sass|scss|gql|graphql|json"
target="src|public"
@oukayuka
oukayuka / sailormoon-transform.ts
Last active May 28, 2020 13:11
TypeScript Functions OverLoads Sample
class Brooch {
pentagram = 'Silver Crystal';
}
type Compact = {
silverCrystal: boolean;
};
class CosmicCompact implements Compact {
silverCrystal = true;
@oukayuka
oukayuka / result-type.ts
Last active May 1, 2020 03:59
TypeScript higher order function which wraps async fetcher and returns with Result<T,E> like Rust
/* eslint-disable max-classes-per-file, no-useless-constructor, lines-between-class-members */
type Result<T, E extends Error> = Ok<T, E> | Err<T, E>;
export class Ok<T, E extends Error> {
constructor(readonly val: T) {}
isOk = (): this is Ok<T, E> => true;
isErr = (): this is Err<T, E> => false;
}
export class Err<T, E extends Error> {
@oukayuka
oukayuka / stylelint.config.js
Created March 21, 2020 09:29
styled-components 用に JSX ファイルを振り分ける設定
const { argv } = require('yargs');
const glob = argv._ && argv._[0];
const isJsxFile = glob && /.{jsx,tsx}/.test(glob);
if (isJsxFile) {
module.exports = {
extends: [
'stylelint-config-standard',
'stylelint-config-styled-components',
@oukayuka
oukayuka / findBooks.ts
Created December 10, 2019 11:04
Firestore のスナップショットをいい感じにキャッシュしてくれるライブラリの構想
import { getByQuery, strategies } from 'firestore-snapbox';
const maxEntries = 100;
const maxAgeSeconds = 60 * 60;
const expiredDate = new Date(2020, 0, 10, 15);
const snap = await getByQuery(query, strategies.CacheFirst, { maxEntries, maxAgeSeconds, expiredDate });
const books = snap.docs.map(doc => { ...doc, id: doc.id } as Book);
@oukayuka
oukayuka / use-find-book.ts
Last active December 7, 2019 09:30
findBook() をコールする Custom Hook
import { useContext, useEffect, useRef, useState } from 'react';
import { Book } from 'domains/mangarel/models/book';
import findBook from 'domains/mangarel/services/find-book';
import { FirebaseContext } from 'contexts';
const useFindBook = (id: string) => {
const [book, setBook] = useState<Book>();
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState<Error | null>(null);
@oukayuka
oukayuka / InfinitScroll.tsx
Last active November 9, 2019 01:51
Infinit scroll component sample with React Hooks
import React, { FC, useEffect, useRef } from 'react';
import ListLoader from '../atoms/ListLoader';
type InfinitScrollProps = {
loadMore?: () => void;
hasMore?: boolean;
isLoading?: boolean;
threshold?: number;
};
@oukayuka
oukayuka / axiosInterceptor.ts
Last active April 9, 2019 09:17
axios のレスポンスからスネークケースのキーをキャメルケースに変換して、日付をDateTimeオブジェクトにする
import { AxiosResponse } from 'axios';
import { camel } from 'change-case';
import { isArray, isObject, isString } from 'lodash';
import { DateTime } from 'luxon';
export const reform = (
obj: object,
keyConverter: (k: string) => string,
): any => {
if (isArray(obj)) {
@oukayuka
oukayuka / keybindings.json
Last active April 26, 2018 06:23
VSCode Vim plugin undo / redo settings
[
{
"key": "ctrl+]",
"command": "extension.vim_escape",
"when": "editorTextFocus"
},
{
"key": "ctrl+e",
"command": "workbench.action.toggleSidebarVisibility"
},
@oukayuka
oukayuka / tslint.json
Created February 12, 2018 05:34
My TSLint configuration
{
"extends": [
"tslint:latest",
"tslint-config-airbnb",
"tslint-config-prettier",
"tslint-eslint-rules",
"tslint-react"
],
"rulesDirectory": [
"tslint-plugin-prettier"