This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_model' | |
class ActiveModel::Errors | |
module WithSymbol | |
attr_accessor :symbol_value | |
end | |
def add_with_symbol(attribute, message = :invalid, options = {}) | |
add_without_symbol(attribute, message, options).tap do |messages| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ITEMS_BASIC = [ | |
[:R, 82], | |
[:SR, 15], | |
[:SSR, 3], | |
] | |
ITEMS_SPECIAL = [ | |
[:SR, 97], | |
[:SSR, 3], | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class F extends Promise { | |
onComplete(callback) { | |
this.then(callback, callback); | |
} | |
} | |
class P { | |
constructor() { | |
this.future = new F((resolve, reject) => { | |
this.trySuccess = resolve; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ipcMain, BrowserWindow } from 'electron' | |
import Vue from 'vue' | |
import Vuex from 'vuex' | |
Vue.use(Vuex) | |
const state = { | |
count: 0 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="UTF-8"> | |
<title></title> | |
<style> | |
.errors { | |
color: red; | |
} | |
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }`))) | |
}) |