Skip to content

Instantly share code, notes, and snippets.

View yureative's full-sized avatar

Yu Yamanaka yureative

View GitHub Profile
@yureative
yureative / promise_seq.js
Last active September 14, 2017 09:09
Sequential execution of promises
const a = (n, timeout) =>
() =>
new Promise((resolve, reject) => {
setTimeout(
() => {
console.log(n)
resolve(n)
},
timeout)
})
@yureative
yureative / NotifyToSlack.js
Last active October 18, 2015 15:28 — forked from vgeshel/function.js
AWS Lambda function for forwarding SNS notifications to Slack
console.log('Loading function');
const https = require('https');
const url = require('url');
// to get the slack hook url, go into slack admin and create a new "Incoming Webhook" integration
const slack_url = 'https://hooks.slack.com/services/...';
const slack_req_opts = url.parse(slack_url);
slack_req_opts.method = 'POST';
slack_req_opts.headers = {'Content-Type': 'application/json'};
@yureative
yureative / ec2_tags.rb
Last active October 8, 2015 11:26
A sensu mutator to add EC2 instance's tags to event data
#!/usr/bin/env ruby
require 'json'
require 'aws-sdk-core'
module Sensu::Extension
class EC2Tags < Mutator
def name
'ec2_tags'
end
#!/bin/bash
branch=`git branch | grep '^\*' | cut -d ' ' -f 2`
merge_branch=${GITHUB_DEFAULT_BRANCH:-master}
git checkout $merge_branch && git pull && git branch -d $branch
git branch
@yureative
yureative / circusd.init
Created April 15, 2015 02:20
init.d script of circus
#!/bin/bash
### BEGIN INIT INFO
# Provides: circusd
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: circus master control daemon
# Description: This is a daemon that controls the circus minions
@yureative
yureative / gist:a9958da1b7188a5dc637
Created April 15, 2015 02:12
Starting circusd with Itamae
INFO : service[circusd] running will change from 'false' to 'true'
DEBUG : service[circusd] enabled will not change (current value is 'true')
DEBUG : Executing `service circusd start`...
DEBUG : exited with 0
DEBUG : stdout | Starting circusd daemon: /usr/lib64/python2.7/dist-packages/Crypto/Util/number.py:57: PowmInsecureWarning: Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.
DEBUG : stdout | _warn("Not using mpz_powm_sec. You should rebuild using libgmp >= 5 to avoid timing attack vulnerability.", PowmInsecureWarning)
DEBUG : stdout | [60G[[0;32m OK [0;39m]
DEBUG : This resource is updated.
@yureative
yureative / c
Created March 3, 2015 06:47
SSH login to EC2 instances by Name Tag
#!/bin/bash
if [ $# -lt 1 ]
then
echo 'Usage: c INSTANCE_NAME [REMOTE_COMMANDS...]'
exit 1
fi
pdns=`aws ec2 describe-instances --filters "Name=tag:Name,Values=$1" | jq -r '.Reservations[].Instances[].PrivateDnsName'`
@yureative
yureative / recipe_ec2_tags.rb
Created November 26, 2014 02:44
Distribute Custom Ohai plugin and use it immediately with lazy block.
ohai 'reload_ec2_tags' do
plugin 'ec2/tags'
action :nothing
end
cookbook_file "#{node[:ohai][:plugin_path]}/ec2_tags.rb" do
notifies :reload, 'ohai[reload_ec2_tags]', :immediately
end
log 'Ohai plugin ec2/tags' do
@yureative
yureative / ec2_tags.rb
Last active August 29, 2015 14:09
A custom Ohai plugin which provides EC2 instance tags
require 'json'
Ohai.plugin(:EC2Tags) do
provides "ec2/tags"
depends "ec2"
collect_data do
region = ec2['placement_availability_zone'].chop
instance_id = ec2['instance_id']
@yureative
yureative / start_docker_containers.sh
Last active August 29, 2015 14:07
/var/lib/cloud/scripts/per-boot/start_docker_containers.sh
#!/bin/bash
# for fig's bug (https://github.com/docker/fig/issues/553#ref-pullrequest-46182758)
export HOME=/root
cd /root && /usr/local/bin/fig start 2>&1 | logger