Skip to content

Instantly share code, notes, and snippets.

@tatat
tatat / as.rb
Created September 11, 2013 09:18
AutoScaling 一部抜粋(変数要脳内補完)
launch_configuration = auto_scaling.launch_configurations.create(
name,
ami.id,
as_instance_type,
key_pair: as_key_pair,
security_groups: as_security_groups,
)
auto_scaling_group = auto_scaling.groups.create(
name,
@tatat
tatat / replace_method.rb
Last active December 26, 2015 22:59
メソッド入れ替えマン
class Nyan
def replace_method(a, b)
(class << self; self end).module_exec do
alias_method "#{a}_backup", a
alias_method a, b
alias_method b, "#{a}_backup"
end
end
def method1
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)
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
@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メールアドレスが見つかった場合、本人確認についてのメールが数分以内に送られます。'
@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 / 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
Array::forEachAsync = (each, context) ->
copy = @slice()
index = -1
do next = ->
return if copy.length == 0
process.nextTick ->
item = copy.shift()
index += 1
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
#!/usr/bin/env ruby
require "json"
require "open-uri"
class LoveLiveQuiz
API_URL = 'https://lovelive-quiz-api.herokuapp.com/quiz'
def initialize
fetch