Skip to content

Instantly share code, notes, and snippets.

View miyarappo's full-sized avatar
:octocat:

Minoru Miyata miyarappo

:octocat:
  • Tokyo, Japan
  • 15:26 (UTC +09:00)
View GitHub Profile
const ouraBaseUrl = 'https://api.ouraring.com/v1/'
const ouraAccessToken = 'xxxx'
const slackProfileUrl = 'https://slack.com/api/users.profile.set'
const slackAccessToken = 'xxxx'
const slackHooksUrl = 'xxxx'
function main() {
const readinessScore = getReadinessScore()
@miyarappo
miyarappo / reverse_besearch_threshold.rb
Created May 22, 2020 06:39
配列を末尾から検査して、ブロックで与えた条件が成り立つ限界の要素番号を返す
def reverse_besearch_threshold(array)
head = 0
tail = array.length - 1
while head <= tail
center = (head + tail) / 2
success = yield(center, array[center])
if success
@miyarappo
miyarappo / reduce_array_by_binary_search.rb
Created May 22, 2020 05:58
二分探索で指定したサイズの閾値までまで配列を切り取る
def reduce_array_by_binary_search(numbers, bytesize)
head = 0
tail = numbers.length - 1
length = numbers.length - 1
while head <= tail
center = (head + tail) / 2
if numbers[center..length].to_s.bytesize <= bytesize
tail = center - 1
else
@miyarappo
miyarappo / binary_search.rb
Created May 22, 2020 04:28
ベーシックな二分探索
def binary_search(numbers,value)
head = 0
tail = numbers.length - 1
while head <= tail do
center = (head + tail) / 2
if numbers[center] == value
return numbers[center]
elsif numbers[center] < value
head = center + 1
else
@miyarappo
miyarappo / rake_task_template.rb
Created May 11, 2020 07:58
Rakeタスクのテンプレート
# frozen_string_literal: true
namespace :rake_task_template do
desc 'desciption'
task :run, %w[dryrun] => :environment do |_task, args|
logger = Logger.new(STDOUT)
dryrun = args[:dryrun] != 'false'
logger.info "#{Time.zone.now} (dryrunモード=#{dryrun}"
@miyarappo
miyarappo / compose.rb
Last active April 12, 2020 15:09
オブジェクト指向設計実践ガイド p.225の写経。小さなオブジェクトを組み合わせてオブジェクトをつくるコンポーズの例。
class Bicycle
attr_reader :size, :parts
def initialize(args={})
@size = args[:size]
@parts = args[:parts]
end
def spares
parts.spares
@miyarappo
miyarappo / ObjectEntries.js
Last active April 7, 2020 02:42
Object.fromEntries()のサンプルコード
const products = {
gold: {
name: '金',
price: 100
},
silver: {
name: '銀',
price: 50
},
copper: {
@miyarappo
miyarappo / hook_method.rb
Last active April 6, 2020 10:07
オブジェクト指向設計実践ガイド p.175の写経。テンプレートメソッドとフックメソッドを用いて結合度を下げた抽象クラスの例。
class Bicycle
attr_reader :size, :chain, :tire_size
def initialize(args={})
@size = args[:size]
@chain = args[:chain] || default_chain
@tire_size = args[:tire_size] || default_tire_size
post_initialize(args)
end