Skip to content

Instantly share code, notes, and snippets.

View tonkotsuboy's full-sized avatar
😸
I want another myself.

Takeshi Kano tonkotsuboy

😸
I want another myself.
View GitHub Profile
@tonkotsuboy
tonkotsuboy / main.ts
Last active February 9, 2018 02:18
Promiseで複数のデータを流したい(TypeScript)
// FooData型とBarData型の値を流すことを考えてみる
interface FooData {
foo: string;
}
interface BarData {
bar: number;
}
@tonkotsuboy
tonkotsuboy / main.ts
Last active February 9, 2018 05:25
await/async
async function main() {
const response = await fetch(url1);
const arrayBuffer1 = await response.arrayBuffer();
const response2 = await fetch(arrayBuffer1.url);
const arrayBuffer2 = await response2.arrayBuffer();
console.log(arrayBuffer1, arrayBuffer2);
}
main();
@tonkotsuboy
tonkotsuboy / IteratorUtil.ts
Created April 20, 2018 06:21
引数の配列を無限にループするイテレータの生成
export class IteratorUtil {
/**
* 引数の配列を無限にループするイテレータの生成
* @param {Array<T>} array
* @param {boolean} skipNullValue: nullの値をスキップするかどうか
* @returns {Iterator<T>}
*
* 使い方
*
* const myArray = [1, 2, 3];
@tonkotsuboy
tonkotsuboy / 人生リセット.css
Last active June 26, 2018 12:28
人生リセット.css
* {
accelerator: true !important;
azimuth: center !important;
background: red !important;
background-attachment: scroll !important;
background-color: red !important;
background-image: linear-gradient(to bottom, red, blue);
background-position: 2000cm 2000cm !important;
background-position-x: 2000cm !important;
background-position-y: 2000cm !important;
@tonkotsuboy
tonkotsuboy / Easing.ts
Last active September 5, 2018 05:15
イージング定数
/**
* イージング定数。cubic-bezier()で使用する
*
* # 使用例
* const fooElement = document.querySelector(".foo") as HTMLElement;
* fooElement.style.transitionTimingFunction = `cubic-bezier(${Easing._6_ExpoOut})`;
*
* # 参考
* アニメーションをデザインしよう! 知っておきたいCSSイージングのお手本
* ICS MEDIA https://ics.media/entry/18730
@tonkotsuboy
tonkotsuboy / Easing.js
Created September 5, 2018 05:24
イージング定数(JavaScript版)
/**
* イージング定数。cubic-bezier()で使用する
*
* # 使用例
* const fooElement = document.querySelector(".foo");
* fooElement.style.transitionTimingFunction = `cubic-bezier(${Easing._6_ExpoOut})`;
*
* # 参考
* アニメーションをデザインしよう! 知っておきたいCSSイージングのお手本
* ICS MEDIA https://ics.media/entry/18730
@tonkotsuboy
tonkotsuboy / parseJsonWithoutCache.ts
Last active January 9, 2019 14:09
Node.jsでキャッシュなしにJSONを読み込む
import fs from "fs";
/**
* Node.jsでキャッシュなしにJSONを読み込む
*
* 使用例
* import path from "path";
*
* const myStubJson = parseJsonWithoutCache(
* path.resolve(__dirname, "relative_path_to_json")
@tonkotsuboy
tonkotsuboy / ServerSideMock.ts
Created January 17, 2019 12:24
Hybrid Typesでモックを作る
// クライアント環境では次のように使っているライブラリのモックを作りたい
// const library = myLibrary();
// library.foo();
// Hybrid Typesでモックを作る
interface IMyLibrary {
(): void;
foo(): void;
bar(buz: number): string;
}
@tonkotsuboy
tonkotsuboy / MyFate.js
Created February 6, 2019 05:21
EventTargetのクラス継承可能化
/** EventTargetを継承したクラス */
class MyClass extends EventTarget {
start() {
// 2秒後に「運命の出逢い」イベントを発生させる
setTimeout(() => {
this.dispatchEvent(new CustomEvent("運命の出逢い"));
}, 2000);
}
}
@tonkotsuboy
tonkotsuboy / privateFieldTest.js
Created April 25, 2019 10:54
プライベートフィールドの挙動確認
class MyClass {
foo = "パブリックなフィールド";
#bar = "プライベートなフィールド";
constructor() {
console.log(this.foo);
console.log(this.#bar); // クラス内からはアクセス可能
}
}