Skip to content

Instantly share code, notes, and snippets.

View Quramy's full-sized avatar
👾

Yosuke Kurami Quramy

👾
View GitHub Profile
@Quramy
Quramy / ts-angular-boilerplate.sh
Created January 4, 2016 08:02
Angular2 TypeScript boilerplate
#!/bin/sh
APP_NAME=$1
[ -z "$APP_NAME" ] && echo "1 args required" && exit 1
[ -d "$APP_NAME" ] && echo "$APP_NAME exists" && exit 1
which tsc || npm install -g typescript
which browser-sync || npm install -g browser-sync
which watchify || npm install -g watchify
@Quramy
Quramy / pluginModuleFactory.ts
Created March 21, 2017 20:50
TS 2.3 Language Service Plugin for completion GraphQL Query
import * as ts from 'typescript/lib/tsserverlibrary';
const { buildClientSchema } = require('graphql');
const { getAutocompleteSuggestions } = require('graphql-language-service-interface');
// TODO replace the result by introspection query
const introspectionJson = require('../schema.json');
const schema = buildClientSchema(introspectionJson.data);
function findNode(sourceFile: ts.SourceFile, position: number): ts.Node | undefined {
@Quramy
Quramy / params.json
Created September 22, 2017 02:38
get commit id from tagname
{
"owner": "Quramy",
"repository": "tsuquyomi",
"tag": "v0.8.0"
}
@Quramy
Quramy / schema_gen.ts
Created January 4, 2018 09:42
Generate .d.ts from JSON schema using @ngtools/json-schema
import { SchemaClassFactory } from '@ngtools/json-schema';
// Input JSON schema json file
const factory = SchemaClassFactory<any>(require('@angular/cli/lib/config/schema.json'));
const schemaClass = new factory(null);
// Output .d.ts
console.log(schemaClass.$$serialize('text/x.dts'));
@Quramy
Quramy / main.ts
Created February 5, 2018 07:10
Value mocking example using type inference in conditional types
type RT<F> = F extends (...args: any[]) => infer R ? R : never;
interface Proxy<T, K extends keyof T> {
returnValue(value: RT<T[K]>): this;
}
declare function spyOn<T, K extends keyof T>(obj: T, methodName: K): {
and: Proxy<T, K>;
};
const serviceToTest = {
@Quramy
Quramy / combineLatest.ts
Created September 21, 2018 16:17
Example of TS 3.1 Mapped Tuple Type
interface Observable<T> {
subscribe(cb: (v: T) => void): void;
}
type StreamValue<S> = S extends Observable<infer T> ? T : never;
type Unwrap<S> = { [P in keyof S]: StreamValue<S[P]> };
declare function combineLatest<U extends Observable<any>[]>(...streams: U): Observable<Unwrap<U>>;
@Quramy
Quramy / _readme.md
Created November 14, 2018 01:56
extract identifiers and split files

I want a tsssercmd to extract a selected identifier (function, const, class, type, etc...) to other new file.

{
  command: "extractAndCreateFile",
  file: "./main.js",
  location: {
    line: 2, col: 10
  },
 toFile: "./sum.js"
@Quramy
Quramy / how-to-fix.js
Last active January 15, 2019 05:36
minimal reproducer for nested dispatching error with spork / thunk
require('babel-polyfill');
const { createStore, applyMiddleware, bindActionCreators, compose } = require('redux');
const { enableBatching, batchActions, batchDispatchMiddleware, BATCH } = require('redux-batched-actions');
const thunk = require('redux-thunk').default;
const { fork, createMiddleware } = require('redux-spork');
function main() {
// reducer
const count = (prev = 0, action) => {
@Quramy
Quramy / ama_answers.md
Last active May 20, 2019 02:06
InsideFE2019 A-5のAMAで時間内にできなかった質問に対する回答

実際にBFFの開発向けUIは、開発者以外に使ってもらってどのようなコメントがありましたか?

「便利」と言ってもらえたのがやはり一番うれしかったですね。 別の事例だと、社外のシステムへの外接部分について、必ずしもテスト環境から接続可能とは限らないケースで、API呼び出しをフックできる機能としても使えた、というのが好評でした。

フロントエンドが使いやすいように API を定義することで、バックエンド側の実装に影響を与えてしまうことはありましたか?

BFFの存在意義の1つに「マイクロサービスを開発しやすく」がある以上、なるべくそういうケースとならないように注意はしていますが、満足にできているかはわからないですね。。。 もしかしたら、より良いAPI粒度が存在するのに、バックエンドがある程度我慢してくれている部分もあるかもしれませんね。。。

@Quramy
Quramy / main.ts
Last active July 18, 2019 18:29
How to get ESLint result from TypeScript AST using @typescript-eslint/typescript-estree
import * as ts from "typescript";
import { SourceCode, Linter, AST } from "eslint";
import { Extra } from "@typescript-eslint/typescript-estree/dist/parser-options";
import convert from "@typescript-eslint/typescript-estree/dist/ast-converter";
function initExtra() {
return {
tokens: null,
range: false,
loc: false,