Skip to content

Instantly share code, notes, and snippets.

View mryoshio's full-sized avatar

YOSHIOKA A mryoshio

View GitHub Profile
double comp4(vector<double>& v) // vが十分大きい場合に多くのタスクを開始
{
if (v.size() < 10000) // concurrencyにする価値があるか?
return;
accum(v.begin(), v.end(), 0.0);
auto v0 = &v[0];
auto sz = v.size();
auto f0 = async(accum, v0, v0 + sz/4, 0.0); // 1st quarter
@mryoshio
mryoshio / sidekiq_init_script.sh
Last active August 29, 2015 14:03
sidekiq init script sample
#!/bin/sh
#
# sidekiq_tkikaku Init script for Sidekiq tkikaku
#
# chkconfig: 345 75 25
# description: Starts and Stops Sidekiq message processor for Stratus application.
# processname: sidekiq_tkikaku
# user-specified exit parameters used in this script:
#
# Exit Code 5 - Incorrect User ID
@mryoshio
mryoshio / check_poodle.rb
Created October 15, 2014 10:59
check your elbs if against SSLv3 (POODLE)
require 'aws'
AWS.config(
:access_key_id => 'xxx',
:secret_access_key => 'xxx',
:region => 'ap-northeast-1'
)
elb = AWS::ELB.new
@mryoshio
mryoshio / fibonacci_dp.cpp
Created November 12, 2014 11:15
Fibonacci number with DP
#include <iostream>
#include <vector>
using namespace std;
int main() {
long n;
cout << "n: "; cin >> n;
if (n == 0 || n == 1) {
cout << "fibo(" << n << ") is " << n << endl;
@mryoshio
mryoshio / lod.cpp
Created November 12, 2014 11:48
lod with DP
#include <iostream>
#include <algorithm>
using namespace std;
int prices[] = { 0, 1, 5, 8, 9, 10, 17, 17, 20, 24, 30 };
int N;
void solve() {
for (int i = 1; i <= N; i++) {
int v = 0;
@mryoshio
mryoshio / create_ec2_image.rb
Last active August 29, 2015 14:10
Create EC2 Image (AMI) of running instances
require 'aws-sdk'
def main
ec2 = AWS::EC2.new
ec2.regions.each do |r|
puts "# region: #{r.name}"
r.instances.each do |i|
puts "## instance: #{i.id} #{i.tags[:Name]}"
if i.status != :running
puts "- [skipped] name: #{i.tags[:Name]} because it's not running."
@mryoshio
mryoshio / update_elb_certificate.rb
Created January 27, 2015 07:27
Update ELB SSL Certificate
require 'aws-sdk'
NEW_CERT_NAME = 'xxx'
REGIONS = AWS::EC2.new.regions.map(&:name)
NEW_CERT = AWS::IAM.new.server_certificates[NEW_CERT_NAME]
REGIONS.each do |r|
puts "# region: #{r}"
elb = AWS::ELB.new(region: r)
@mryoshio
mryoshio / switch_opsworks_auto_healing.rb
Created January 30, 2015 09:54
update OpsWorks Layers' enable_auto_healing
require 'aws-sdk'
TO=false
def main
client = AWS::OpsWorks::Client.new(region: 'us-east-1')
client.describe_stacks[:stacks].each do |s|
puts "## #{s[:stack_id]}: #{s[:name]}"
puts "##### [begin] at #{Time.now}"
client.describe_layers(stack_id: s[:stack_id])[:layers].each do |l|
@mryoshio
mryoshio / add_cloudwatch_alarms.rb
Created March 28, 2015 07:45
Add two CloudWatch alarm
require 'aws-sdk'
REGION = 'ap-northeast-1'
WAIT_INTERVAL = 1
def put_alarms(instance_id)
cloudwatch = Aws::CloudWatch::Client.new(region: REGION)
cloudwatch.put_metric_alarm(
alarm_name: "cpu-mon-#{instance_id}",
@mryoshio
mryoshio / how_to_use_pageble_response.rb
Created March 31, 2015 01:14
How to use PagebleResponse in AWS SDK for Ruby version 2
require 'aws-sdk'
REGION = 'ap-northeast-1'
cloudwatch = Aws::CloudWatch::Client.new(region: REGION)
res = cloudwatch.describe_alarms
while true
res.metric_alarms.each do |al|
# some logic for each alarm