Skip to content

Instantly share code, notes, and snippets.

@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],
]
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|
#!/usr/bin/env ruby
require "json"
require "open-uri"
class LoveLiveQuiz
API_URL = 'https://lovelive-quiz-api.herokuapp.com/quiz'
def initialize
fetch
require 'active_model'
class ActiveModel::Errors
module HiddenEntity
attr_accessor :_entity
end
def generate_message_with_format(attribute, type = :invalid, options = {})
message = generate_message_without_format attribute, type, options
Array::forEachAsync = (each, context) ->
copy = @slice()
index = -1
do next = ->
return if copy.length == 0
process.nextTick ->
item = copy.shift()
index += 1
@tatat
tatat / e.rb
Last active August 29, 2015 14:00
こういうのやりたい
class Parent
enumerize :nyan, in: [:a, :b, :c], scope: true
end
class Child1 < Parent
enumerize :nyan, in: [:a], default: :a
end
class Child2 < Parent
enumerize :nyan, in: [:a, :b], default: :b
@tatat
tatat / proxy.js
Last active August 29, 2015 13:58
かんたん http proxy
#!/usr/bin/env node
var fs = require('fs')
, http_proxy = require('http-proxy')
, http = require('http')
, https = require('https')
, cert_file_path = '/path/to/server.crt'
, key_file_path = '/path/to/server.key';
var proxy = http_proxy.createProxyServer();
@tatat
tatat / devise.ja.yml
Last active August 29, 2015 13:57 — forked from kawamoto/devise.ja.yml
とある案件用にカスタマイズさせていただきましたやつ
#SOURCE https://gist.github.com/tatat/9526513
ja:
devise:
confirmations:
confirmed: 'アカウントを登録しました。'
# confirmed: 'Your account was successfully confirmed. You are now signed in.'
send_instructions: '登録方法を数分以内にメールでご連絡します。'
# send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
send_paranoid_instructions: 'もしあなたのEメールアドレスが見つかった場合、本人確認についてのメールが数分以内に送られます。'
module ApplicationHelper
# 私がやるとこうなる(ごたごたしてる)
def without_whitespaces(options = {})
captured = capture &Proc.new
captured = captured.gsub(%r{\A\s+|\s+\Z}, '').gsub(%r{(>)\s+(<)}, '\1\2')
captured = captured.gsub(%r{(>)\s*(.*?)\s*(<)}, '\1\2\3') if options[:trim]
captured.html_safe
end
class Nyan
def behave_method(target, source)
(class << self; self end).module_exec do
alias_method "#{target}_original", target unless method_defined? "#{target}_original"
alias_method "#{source}_original", source unless method_defined? "#{source}_original"
alias_method target, "#{source}_original"
end
end
def with_behaving_method(a, b)