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

以下のような感じで実装できるかも。

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

# ClientからServerへのKeepAlive要求
@mumoshu
mumoshu / function-retry.sh
Last active Aug 29, 2015
test-kitchenのdestroyやsetupが時々失敗するので、リトライをかける
View function-retry.sh
# ~/.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
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 = Logger.new(STDOUT)
class Author < ActiveRecord::Base
@mumoshu
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 => 'example.com' }
view_paths = Rails.application.config.paths["app/views"]
action_view = ActionView::Base.new(view_paths).tap do |av|
action_view.class_eval do
include ApplicationHelper
include Rails.application.routes.url_helpers
include JobOffersHelper
end
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 = Tryer.new(up_to: 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
end
You can’t perform that action at this time.