Skip to content

Instantly share code, notes, and snippets.

View holysugar's full-sized avatar

HORII Keima holysugar

  • Aiming, Inc
  • Tokyo
View GitHub Profile
@holysugar
holysugar / onlyonce.rb
Last active August 29, 2015 14:16
Test::Unit で一度しか呼ばれない startup / shutdown (試作版)
require 'test/unit'
require 'active_support/all'
module OnlyOnce
extend ActiveSupport::Concern
included do
class << self
def inherited_with_onlyonce(sub)
inherited_without_onlyonce(sub)
@holysugar
holysugar / onlyonce.rb
Created March 10, 2015 09:32
Test::Unit で一度しか呼ばれない startup / shutdown その2, startuponce / shutdownonce 編
require 'test/unit'
require 'active_support/all'
module OnlyOnce
extend ActiveSupport::Concern
included do
def self.singleton_method_added(method_name)
if method_name == :startup || method_name == :shutdown
@holysugar
holysugar / before_after_all.rb
Last active August 29, 2015 14:17
Test::Unit で一度しか呼ばれない startup / shutdown その3 これでよかった…
require 'test/unit'
require 'active_support/all'
module BeforeAfterAll
extend ActiveSupport::Concern
included do
class << self
def beforeall(&block)
@_beforeall = block
@holysugar
holysugar / assert_change.rb
Created March 17, 2015 10:12
assert_change 試作版
require 'test/unit/assertions'
module AssertChange
# fixme message?
def assert_change(value_proc, options = {}, &event_proc)
change = Change.new(value_proc)
change.perform(event_proc)
case
@holysugar
holysugar / dockerbuild.thor
Last active August 29, 2015 14:18
手元で手抜き docker build
#!/usr/bin/env ruby
# vim: ft=ruby
#
# Simple Dockerfile build tasks
# https://gist.github.com/holysugar/0a78f58d02e52f1af9f2
#
# set environment variables before execute:
#
# - DOCKER_REGISTRY=192.168.xxx.xxx
# - DOCKER_PREFIX=yourprefix
@holysugar
holysugar / tag.bash
Last active August 29, 2015 14:22
GCEでタグ情報を環境変数に持ってくる
#!/bin/bash
while read tag; do
upper_tag=${tag^^}
upper_underscore_tag=${upper_tag//-/_}
export GCE_TAG_${upper_underscore_tag}=1
done < <( curl \
-H "X-Google-Metadata-Request: True" \
@holysugar
holysugar / search_instance
Last active August 29, 2015 14:22
GCEでメタデータからインスタンス名を引く
#!/bin/sh
# ここでは environment と role というメタデータがあると仮定
environment=$1
role=$2
if [ -z "$role" ]; then
echo "[usage] $0 environment role"
exit 1
fi
@holysugar
holysugar / gce.rb
Created June 9, 2015 12:06
GCE 用の ansible dynamic inventory 手抜き版
require 'json'
class GCE
def initialize(project_id, env)
@project_id = project_id
@env = env
end
def instance_list
@holysugar
holysugar / cloudsql_acl.sh
Created June 18, 2015 03:26
GCE でインスタンス名からCloudSQLにアクセス許可するワンライナー(手抜き版)
gcloud compute instances list |
grep '^projectname-web' |
awk '{print $5}' |
tr "\n" " " |
xargs gcloud sql instances patch dbinstancename --authorized-network
# 本来はタグとかメタデータとかから取る方針にしたいのでこれは手抜き。
# CloudSQL 側でもっと (GAEではなく) GCEなどから受け取れる前提で設定を簡単にできるようにならないのかな…
@holysugar
holysugar / homebrew-init.sh
Created July 6, 2015 03:37
homebrew-init.sh
#!/bin/sh
sudo xcodebuild -license
xcode-select --install
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew doctor
brew update