Skip to content

Instantly share code, notes, and snippets.

View mryoshio's full-sized avatar

YOSHIOKA A mryoshio

View GitHub Profile
def generate_tgz(filepath, contents)
tar = StringIO.new
Gem::Package::TarWriter.new(tar) do |writer|
writer.add_file(filepath, 0600) do |f|
f.write(contents)
end
end
tar.seek(0)
gz = Zlib::GzipWriter.open("#{filepath}.tar.gz") do |gz|
gz.write(tar.read)
# sample task model
#
# > rails c
# irb(main):004:0> t.finish
# "-------> notify_done with 0"
# "-------> notify_done with 1"
# "-------> notify_done with 2"
# "-------> notify_done end"
# => true
class Task < ActiveRecord::Base
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

Gemfile

gem 'jquery-rails'

app/assets/javascripts/application.js

"""
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 October 24, 2018 01:59
RSA encryption/decryption
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 April 27, 2016 12:16
Terraform Sample Configuration
#
# aws
#
# declare variables
variable "aws_access_key" {}
variable "aws_secret_access_key" {}
# connection
@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
@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 / 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|