Skip to content

Instantly share code, notes, and snippets.

View 2019_pull_requests_per_org_repo.rb
require 'csv'
require 'octokit'
require 'pry'
BEGIN_OF_2019 = Time.new('2019-01-01 00:00:00 UTC')
def client
@client ||= Octokit::Client.new(access_token: ENV['GITHUB_ACCESS_TOKEN'], per_page: 100)
end
View ga_rails_example.md

Gemfile

gem 'jquery-rails'

app/assets/javascripts/application.js

View export-issues.py
"""
ref. https://gist.github.com/mike-ward/23dab967feaf71bde2c1
Exports Issues from a specified repository to a CSV file
- Github API v3: https://developer.github.com/v3/gists/
- ZenHub API: https://github.com/ZenHubIO/API
"""
import csv
import requests
@mryoshio
mryoshio / rsa_enc_dec.rb
Last active Oct 24, 2018
RSA encryption/decryption
View rsa_enc_dec.rb
require 'base64'
require 'openssl'
def enc(der, msg)
rsa = OpenSSL::PKey::RSA.new(der)
rsa.private_encrypt(msg)
end
def dec(der, msg)
rsa = OpenSSL::PKey::RSA.new(der)
@mryoshio
mryoshio / sample.tf
Created Apr 27, 2016
Terraform Sample Configuration
View sample.tf
#
# aws
#
# declare variables
variable "aws_access_key" {}
variable "aws_secret_access_key" {}
# connection
@mryoshio
mryoshio / how_to_use_pageble_response.rb
Created Mar 31, 2015
How to use PagebleResponse in AWS SDK for Ruby version 2
View how_to_use_pageble_response.rb
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
@mryoshio
mryoshio / add_cloudwatch_alarms.rb
Created Mar 28, 2015
Add two CloudWatch alarm
View add_cloudwatch_alarms.rb
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 / switch_opsworks_auto_healing.rb
Created Jan 30, 2015
update OpsWorks Layers' enable_auto_healing
View switch_opsworks_auto_healing.rb
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 / update_elb_certificate.rb
Created Jan 27, 2015
Update ELB SSL Certificate
View update_elb_certificate.rb
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 / create_ec2_image.rb
Last active Aug 29, 2015
Create EC2 Image (AMI) of running instances
View create_ec2_image.rb
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."
You can’t perform that action at this time.