Skip to content

Instantly share code, notes, and snippets.

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|
@tatat
tatat / gacha.rb
Last active January 17, 2016 20:53
ITEMS_BASIC = [
[:R, 82],
[:SR, 15],
[:SSR, 3],
]
ITEMS_SPECIAL = [
[:SR, 97],
[:SSR, 3],
]
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
class F extends Promise {
onComplete(callback) {
this.then(callback, callback);
}
}
class P {
constructor() {
this.future = new F((resolve, reject) => {
this.trySuccess = resolve;
@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
}
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title></title>
<style>
.errors {
color: red;
}
</style>
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)
@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:
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)
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 }`)))
})