Skip to content

Instantly share code, notes, and snippets.

@a2ikm
a2ikm / post-checkout
Created November 24, 2015 03:29
git checkoutしたらgit submodule updateする
#!/usr/bin/env ruby
# Put me at .git/hooks/post-checkout
root_dir = File.expand_path("../../..", __FILE__)
Dir.chdir(root_dir) do
system "git submodule update"
end
@a2ikm
a2ikm / USAGE
Created October 4, 2015 14:58
Custom ActiveYaml::Base generator for ActiveHash
マスターのファイルを生成します。
使い方:
$ rails g master ship_type
=> app/models/ship_type.rb
=> db/master/ship_types.yml
@a2ikm
a2ikm / filterable.rb
Last active September 9, 2015 13:13
配列とかに使えるscopeみたいなやつ
module Filterable
def self.included(base)
fail "#{base} MUST include Enumerable to include #{name}" unless base.include?(Enumerable)
base.extend ClassMethods
base.const_set(base.filter_chain_class_name, base.filter_chain_class)
end
def filter_chain
self.class.filter_chain_class.new(self)
@a2ikm
a2ikm / rolled_back_releases.rake
Created August 5, 2015 12:48
Cleanup rolled-back-release archives created by capistrano
namespace :deploy do
desc "List rolled-back-release archives"
task :rolled_back_releases do
on release_roles(:all) do
within deploy_path do
archives = capture(:ls, "-xt").split.select do |path|
path.start_with?("rolled-back-release-")
end
if archives.any?
@a2ikm
a2ikm / gist:64b768748ba4f73b4e57
Created July 31, 2015 08:55
git clone --depth

--depthオプションのテストをしてみました。

git clone --depth Nとするときにとしたあとに、Nコミット前よりもさらに前に枝分かれしたブランチをマージしてからpullしてくると全コミットが落ちてきました。なのでマージコミットが発生した段階で

  C  ← Cがmaster
D | ← Dがfeature
|/  
B
|
15/7/28 14:12:38.869 Terminal[1949]: AppleEvents/sandbox: Returning errAEPrivilegeError/-10004 and denying dispatch of event ESIM/load from process 'SIMBL Agent'/0x0-0x11011, pid=340, because it is not entitled to send an AppleEvent to this process.
@a2ikm
a2ikm / captime.rb
Created July 6, 2015 09:23
capistranoの各タスクごとの所要時間を計測し、`平均\t最長\t最短\t呼び出し回数\tタスク`で出力する
#!/usr/bin/env ruby
if ARGV.count == 0
puts "Usage: captime <file> [<host>]"
end
data = Hash.new { |h, k| h[k] = {} }
logfile = File.expand_path(ARGV[0])
host = ARGV[1]

mysqldumpをgzipでバックアップとリストア

  • ディスク容量と転送時間をちょっとでも短縮させたい時にgz形式が便利。

dumpでバックアップ取るとき

timestamp=$(date +"%Y%m%d%H%M%S")
mysqldump --single-transaction -u $user -h $host --password=$password $dbname | gzip --fast > $dbname.$timestamp.sql.gz 
@a2ikm
a2ikm / calendar_helper.rb
Created May 29, 2015 06:59
middlemanでカレンダーを生成するヘルパ
require "date"
#
# <%= calendar year: 2015, month: 4 do |date, is_this_month|
# <td>
# <%- if is_this_month %>
# <%= date.day %>
# <%- else %>
# <span class="text-muted"><%= date.day %></span>
# <%- end %>
@a2ikm
a2ikm / Rakefile
Last active May 27, 2016 21:27
Rake tasks for Terraform
task :environment do
errors = []
%w(
TF_VAR_dnsimple_email
TF_VAR_dnsimple_token
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION
).each do |name|
errors << name if ENV[name].nil?