Skip to content

Instantly share code, notes, and snippets.

View RouterWrapper.ts
type ParamValue = string | number | boolean;
export interface ParamsObject {
[key: string]: ParamValue | ParamValue[];
}
export class RouterWrapper {
private _location: Location;
private _URL: typeof URL;
@ovrmrw
ovrmrw / swaggerYamlToTypeScriptInterfaces.ts
Created Mar 23, 2018
Generate TypeScript interfaces from swagger.yaml
View swaggerYamlToTypeScriptInterfaces.ts
import * as jsyaml from 'js-yaml';
import * as path from 'path';
import * as fs from 'fs';
interface PropertyStructure {
required: string[];
properties: Record<string, { type: string }>;
}
class Definition {
@ovrmrw
ovrmrw / setup-ionic-jest-boilerplate.js
Last active Mar 4, 2018
Create files for Jest testing for Ionic project
View setup-ionic-jest-boilerplate.js
const fs = require('fs');
const path = require('path');
const root = path.resolve();
// Create jest.config.js
const jestConfigJS = `module.exports = {
preset: 'jest-preset-angular',
roots: ['src'],
testRegex: '\\\\.spec\\\\.ts$',
View Namespace.ts
import { WindowWrapper } from './WindowWrapper';
let _namespace: Namespace | undefined;
export class Namespace {
private readonly key: string;
static fromName(key: string): Namespace {
if (!_namespace) {
_namespace = new Namespace(key);
@ovrmrw
ovrmrw / mp3-rename-util.ts
Created Apr 18, 2017
Re-name MP3 files from its ID3 tag's title.
View mp3-rename-util.ts
import * as fs from 'fs-extra'
import * as nodeID3 from 'node-id3'
import * as path from 'path'
const TARGET = 'au_kaiwa_1705_A'
const filePaths = fs.readdirSync(TARGET)
.map((file) => path.join(process.cwd(), TARGET, file))
.filter((filePath) => fs.existsSync(filePath))
@ovrmrw
ovrmrw / main.ts
Created Feb 21, 2017
redux dev tools
View main.ts
require('setimmediate')
const asap = require('asap') as (func: Function) => void
const cloneDeep = require('lodash.clonedeep') as <T>(obj: T) => T
import { createStore, applyMiddleware, Store } from 'redux'
import { Observable } from 'rxjs/Observable'
import { Subject } from 'rxjs/Subject'
import { BehaviorSubject } from 'rxjs/BehaviorSubject'
import 'rxjs/add/observable/of'
import 'rxjs/add/observable/from'
@ovrmrw
ovrmrw / simple-redux.ts
Last active Dec 29, 2016
Simple concept for easy Redux
View simple-redux.ts
import 'core-js';
import { Observable, Subject, BehaviorSubject } from 'rxjs';
type Action = {
key: string;
value: any;
}
type State = {
@ovrmrw
ovrmrw / resolveAllPromise.ts
Last active Sep 21, 2016
An example to get an object which is resolved all (even nested) promises in Zone.
View resolveAllPromise.ts
import 'babel-polyfill';
import 'zone.js/dist/zone-node';
declare const Zone: any;
Zone.current.fork({}).run(async () => {
// (async () => {
const obj = {
increment: Promise.resolve({
@ovrmrw
ovrmrw / chokidar-file-watch.ts
Last active Aug 24, 2016
chokidarで任意のフォルダのファイル追加・変更を監視するサンプル
View chokidar-file-watch.ts
import chokidar from 'chokidar'; // @types/chokidar
import parse from 'csv-parse'; // @types/csv-parse
import fs from 'fs'; // @types/node
chokidar.watch('S:/chokidar', { ignored: /[\/\\]\./ }).on('all', (event: string, path: string) => {
if (event === 'add' || event === 'change') {
if (new RegExp(/\.(csv|txt)$/).test(path)) {
console.log(event, path);
fs.readFile(path, 'utf8', (err, data: string) => {
@ovrmrw
ovrmrw / hapi-swagger-server-sample.js
Created Aug 22, 2016
Hapi-Swagger sample - Run and open "http://localhost:3000/documentation" in order to be shown the documents of your APIs.
View hapi-swagger-server-sample.js
const Hapi = require('hapi');
const Inert = require('inert');
const Vision = require('vision');
const Joi = require('joi');
const HapiSwagger = require('hapi-swagger');
const Pack = require('./package.json');
const server = new Hapi.Server();
server.connection({
host: 'localhost',