This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TablePrinter | |
# Initialize data | |
# @param data [Array] printing data as array of hash. | |
# @param labels [Hash] column labels hash. | |
# @example | |
# data = [ | |
# { name: "foo", installed_versions: ["5.15.5_3"], current_version: "5.15.7" }, | |
# { name: "bar", installed_versions: ["7.0.4"], current_version: "7.0.5" }, | |
# { name: "baz", installed_versions: ["3.2.5"], current_version: "3.2.7" }, | |
# ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
APP_ROOT = File.expand_path "#{File.dirname(__FILE__)}/.." | |
pid_file = "#{APP_ROOT}/tmp/pids/app.pid" | |
if File.exist?(pid_file) | |
puts 'Found puma pid file!' | |
puts 'Puma may have been already started!' | |
exit | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 並列実行 | |
;(async () => { | |
const sleepTimes = [1000, 2000, 3000] | |
// この時点で実行開始される | |
const promises = sleepTimes.map((num) => new Promise((resolve, _reject) => { | |
setTimeout(() => { | |
const now = new Date() | |
console.log(`${num} msec later. ${now}`) | |
resolve(now) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ref. https://railsguides.jp/caching_with_rails.html | |
# ref. https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html | |
# write/read/fetch | |
Rails.cache.write('test_cache_key', Time.zone.now, expires_in: 10.seconds) | |
Rails.cache.read('test_cache_key', expires_in: 10.seconds) | |
Rails.cache.fetch('test_cache_key', expires_in: 10.seconds) { Time.zone.now } | |
class Model | |
def self.hoge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
require 'net/http' | |
module TestSlackNotifier | |
extend self | |
def send | |
uri = URI.parse('https://slack.com/api/chat.postMessage') | |
params = { | |
channel: '#channel_name', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# headless chromeでスクリーンショットを撮るやつ | |
# ref. https://developers.google.com/web/updates/2017/04/headless-chrome?hl=ja | |
alias chrome='/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome' | |
# shot! | |
chrome --headless --disable-gpu --screenshot="./screenshot/hoge.png" --window-size=1280,4000 https://example.com/hoge | |
# shot!shot!shot! | |
pages=(hoge fuga piyo) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Amazon Transcribe で出力されたjsonファイルから話者ごとのセンテンスを抽出してtxtファイルに保存 | |
require 'json' | |
def convert(input_file, output_file) | |
input = JSON.parse(File.read(input_file)) | |
results = input['results'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
puts "__FILE__: #{__FILE__}" | |
puts "__dir__: #{__dir__}" | |
puts "File.dirname(__FILE__): #{File.dirname(__FILE__)}" | |
puts "File.expand_path('.', __FILE__): #{File.expand_path('.', __FILE__)}" | |
puts "File.expand_path('.', __dir__): #{File.expand_path('.', __dir__)}" | |
# スクリプトが1階層下にある場合 | |
APP_ROOT = File.expand_path('..', __dir__) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100.times do |i| | |
str = '' | |
str += 'Fizz' if i % 3 == 0 | |
str += 'Buzz' if i % 5 == 0 | |
str += i.to_s if str == '' | |
puts str | |
end | |
100.times do |i| | |
print 'Fizz' if i % 3 == 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# usage: | |
# 1. Install aws-sdk | |
# $ echo "source 'https://rubygems.org'\ngem 'aws-sdk'" > Gemfile | |
# $ bundle install --path vendor/bundle | |
# # or | |
# $ gem install aws-sdk | |
# 2. Setup AWS credentials | |
# $ eval $(assume-role hoge) | |
# # or | |
# $ export AWS_PROFILE=hoge |
NewerOlder