Skip to content

Instantly share code, notes, and snippets.

@Yama-Tomo
Yama-Tomo / index.js
Last active December 18, 2021 14:10
dataloaderの仕組みを理解するための簡易コード
function enqueuePostPromiseJob(fn) {
// Promise.resolve().then(fn)
// でも似たような動きになるが別のpromiseの解決に依存してexecを呼ばなければならない関数が同一の実行スケジュールから漏れてしまうため
// 次のフェーズの最速で呼ばれる nextTick で実行したほうが同一スケジュールでより多くの処理をすることができる。
// これをコメントインすると `dependOtherAsyncFuncExec` が別のバッチスケジュールで呼ばれることが確認できる
// フェーズについて: https://blog.hiroppy.me/entry/nodejs-event-loop
Promise.resolve().then(() => {
// nextTick の理由: https://github.com/graphql/dataloader/issues/180
process.nextTick(fn);
@Yama-Tomo
Yama-Tomo / main.go
Created August 19, 2021 06:02
transform struct to map for firestore
package main
import (
"cloud.google.com/go/firestore"
"time"
"fmt"
"reflect"
"strings"
)
@Yama-Tomo
Yama-Tomo / atomic_file_mv.ts
Created June 4, 2021 04:35
GCS 上のファイルをアトミックに mv する
import { Bucket, File } from '@google-cloud/storage';
type AtomicFileMvReturnType = [{ src: File; dest: File }, Error | undefined];
const atomicFileMv = async (
bucket: Bucket,
srcPath: string,
destPath: string
): Promise<AtomicFileMvReturnType> => {
const src = bucket.file(srcPath, { generation: 0 });
const dest = bucket.file(destPath, { generation: 0 });
@Yama-Tomo
Yama-Tomo / content.md
Created February 26, 2021 02:39
cloud scheduler で VM インスタンスを定期的に起動・停止する

cloud scheduler で以下のような設定をする

停止は下記画像の例のURLの最後を stop にする

example

@Yama-Tomo
Yama-Tomo / example.rb
Created July 2, 2020 00:29
pipeline operator like in ruby
def pipe(arg)
->(fn = nil) { !fn.nil? && fn.is_a?(Proc) ? pipe(fn.call(arg)) : arg }
end
# usage
pipe(1)
.call(->(arg) { arg + 1 })
.call(->(arg) { arg * 3 })
.call
@Yama-Tomo
Yama-Tomo / 0.Convert_ttf_format_to_Noto.md
Last active April 19, 2020 02:07
Convert ttf format to Noto
  • 上記ファイルを同じディレクトリに配置してビルドする
$ docker build -t convertNotoToTTF .
  • otf ファイルがあるディレクトリ上で先ほどの docker image を実行する
    • otf の拡張子を除いたファイル名がフォント名としてセットされるようになっている
    • ライセンス上オリジナルのフォント名から変更しなければいけないので otf ファイル名を予め別の名前にリネームしておく
// ジェネレータを使うとイテレートしているリストを増やしたり逆に減らしたりすることができるのでキュー管理と並列実行をテーマとしたサンプル
const pararell = 2
const queues = [1, 2, 3, 4]
const runner = (taskManager) =>
new Promise(r => {
const queue = taskManager.next()
if (queue.done) {
r()
@Yama-Tomo
Yama-Tomo / extract_props_type_of_styled-componets.d.ts
Last active June 21, 2020 07:14
extract props type of styled-componets
import * as React from 'react';
import { StyledComponent, StyledComponentProps } from 'styled-components';
export type ExtractStyledComponentProps<SC> = SC extends StyledComponent<
infer C,
infer T,
infer O,
infer A
>
? StyledComponentProps<C, T, O, A> & {
@Yama-Tomo
Yama-Tomo / display_error_on_dev_plugin.js
Last active March 26, 2020 03:51
display error on development in storybook with CRA
const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin')
const typescriptFormatter = require('react-dev-utils/typescriptFormatter')
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages')
const chalk = require('chalk')
const formatter = (message) => `${message.file}\n${typescriptFormatter(message, true)}`
// reference `react-dev-utils/WebpackDevServerUtils.js`
module.exports = function(options) {
return function() {