Skip to content

Instantly share code, notes, and snippets.

Working from home

KUOKA Yusuke mumoshu

Working from home
Block or report user

Report or block mumoshu

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
mumoshu /
Created Feb 28, 2014
Test which sed is installed on your system
testfile="/tmp/$(basename $0).$$.tmp"
echo test > $testfile
out=$(sed -e "s/^//" -i "" $testfile 2>&1)
$(echo $out | grep "sed: can't read : No such fil or directory")
echo $grep_exit_status
if [ $sed_exit_status -ne 0 ]; then
echo GNU sed
/usr/libexec/java_home -V 2>&1 \
| awk -F',' '$1 ~ /1.[678].0(_[a-z0-9\-]+)?$/ { gsub(/^ +/, ""); print $1 }'
# 1.8.0
# 1.7.0_06
# Usage:
# source
function select_java_home
local java_home_cmd=/usr/libexec/java_home
View ec2-ipaddr
# 前提
# awscliとjqをインストールしておくこと
# Mac OS Xならそれぞれbrew install awscliとbrew install jqでOK
# DEBUG=1 ec2-ipaddr hoge
# などと実行すると、デバッグモードになる


# ServerからClientへのKeepAliveに対する応答
connection.on_global_request("") do |data, want_reply|
  puts "data: #{data.inspect}"
  puts "want_reply: #{want_reploy}"

# ClientからServerへのKeepAlive要求
mumoshu /
Last active Aug 29, 2015
# ~/.bash_profileなどに追加しておくと便利
retry () {
echo retry: Running $@ with retries
local label=retry:
local temp_file=$(mktemp -t temp_file.tmp)
local exit_status_file=$(mktemp -t exit_status.tmp)
local trial_num=
local exit_status=
local max_trial_num=5
local re='^[0-9]+$'
View s3-access-control-with-source-ip-and-username.json
"Version": "2008-10-17",
"Id": "Policy<UNIQUE_ID>",
"Statement": [
"Sid": "Stmt<UNIQUE_ID>",
"Effect": "Deny",
"NotPrincipal": {
"AWS": "arn:aws:iam::アカウントID:user/Wercker向けIAMユーザ名"
mumoshu / ar_relation_test.rb
Created Aug 26, 2014
bundle exec ruby ar_relation_test.rb
View ar_relation_test.rb
require 'active_record'
require 'mysql2'
require 'minitest/autorun'
require 'logger'
puts "ActiveRecord: #{ActiveRecord::VERSION::STRING}"
ActiveRecord::Base.establish_connection(adapter: "mysql2", host: "localhost", database: "test")
ActiveRecord::Base.logger =
class Author < ActiveRecord::Base
mumoshu / action_view_and_partial_templates_in_rails_console.rb
Created Oct 16, 2014
ActionView・Partial TemplatesをRails Consoleでテストする方法
View action_view_and_partial_templates_in_rails_console.rb
Rails.application.routes.default_url_options = { :host => '' }
view_paths = Rails.application.config.paths["app/views"]
action_view = do |av|
action_view.class_eval do
include ApplicationHelper
include Rails.application.routes.url_helpers
include JobOffersHelper
end; nil
View reliable.rb
module Reliable
def retries(method, up_to:, on:, delay: Tryer.delay, before_retry: Tryer.before_retry, after_call: Tryer.after_call)
original_method = :"#{method}_without_reliable"
alias_method original_method, method
tryer = up_to, on: on, delay: delay, before_retry: before_retry, after_call: after_call)
define_method method do |*args|
tryer.reliably do
__send__ original_method, *args
You can’t perform that action at this time.