Skip to content

Instantly share code, notes, and snippets.

@tatat
tatat / sample.ts
Last active June 4, 2018 12:41
sample.ts
type ResponseBase = {};
type SuccessResponse = ResponseBase & { data: any };
type ErrorResponse = ResponseBase & { error: string };
type Callback = (response: SuccessResponse | ErrorResponse) => void;
function call(callback: Callback) {
callback(<SuccessResponse> { data: {} });
}
call(response => {
export default {
/**
* @param {Vue} Vue
* @param {any} options
*/
install(Vue, options) {
/**
* @typedef {object} MessageBox
* @property {boolean} confirmed - To be set true if confirmed, otherwise false
* @property {VueComponent} instance - Instance of VueComponent for $msgbox()
const path = require('path')
const { spawn } = require('child_process')
const fs = require('fs')
const spawnPromise = (command, args = [], options = {}) => {
return new Promise((resolve, reject) => {
const cp = spawn(command, args, { stdio: 'inherit', ...options })
cp.on('error', error => reject(error))
cp.on('close', (code, signal) => code === 0 ? resolve() : reject(new Error(`Exited with code ${ code }`)))
})
const doAsync1 = () => client.get().then(doSomething1).catch(e => { onError1(e); throw e })
const doAsync2 = () => client.get().then(doSomething2).catch(e => { onError2(e); throw e })
const doAsync3 = () => client.get().then(doSomething3).catch(e => { onError3(e); throw e })
const doAsync4 = () => client.get().then(doSomething4).catch(e => { onError4(e); throw e })
const doAsync5 = () => client.get().then(doSomething5).catch(e => { onError5(e); throw e })
const doAsync6 = () => client.get().then(doSomething6).catch(e => { onError6(e); throw e })
const doAsyncSerial = () => doAsync1().then(() => doAsync2()).then(() => doAsync2()).then(doSomethingSerial).catch(e => { onErrorSerial(e); throw e })
const doAsyncParallel = () => Promise.all([doAsync4, doAsync5, doAsync6]).then(doSomethingParallel).catch(e => { onErrorParallel(e); throw e })
const doAsync = () => doAsyncSerial().then(doAsyncParallel)
@tatat
tatat / sample.yml
Last active October 25, 2017 13:10
cfn
AWSTemplateFormatVersion: 2010-09-09
Description: VPC + EB + RDS (MySQL) + Rails (Puma)
Parameters:
KeyName:
Description: Name of an existing EC2 KeyPair to enable SSH access to the bastion host and Elastic Beanstalk hosts
Type: AWS::EC2::KeyPair::KeyName
SSHLocation:
function isZip(path, callback) {
fs.open(path, 'r', (error, fd) => {
if (error)
return callback(error)
fs.read(fd, Buffer.alloc(4), 0, 4, 0, (error, bytesRead, buffer) => {
if (error)
return callback(error)
callback(null, buffer.readUInt32LE(0) === 0x04034b50)
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title></title>
<style>
.errors {
color: red;
}
</style>
@tatat
tatat / store-main.js
Last active April 10, 2017 19:02
Vuex on Electron
import { ipcMain, BrowserWindow } from 'electron'
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const state = {
count: 0
}
class F extends Promise {
onComplete(callback) {
this.then(callback, callback);
}
}
class P {
constructor() {
this.future = new F((resolve, reject) => {
this.trySuccess = resolve;
module Rescuer
class << self
attr_accessor :error_class
def error_matcher
error_class = self.error_class
Module.new do
define_singleton_method :=== do |e|
error_class === e