Skip to content

Instantly share code, notes, and snippets.

def div_each(r)
b = []
p = [10_000, 5_000, 2_000, 1_000, 500, 100, 50, 10, 5, 1]
p.each_with_index{|d, index|
a, r = r.divmod(d)
b << a
b << r if p.size - 1 == index
}
return b
end
@kenzo0107
kenzo0107 / divmod_inject.rb
Last active November 22, 2019 06:01
Ruby inject
def div_inject(r)
[10_000, 5_000, 2_000, 1_000, 500, 100, 50, 10, 5, 1].inject(r){|(*a, r), d|
a + r.divmod(d)
}
end
p div_inject(123_456) # [12, 0, 1, 1, 0, 4, 1, 0, 1, 1, 0]
package utility
const (
defaultLength = 0
defaultCapacity = 64
)
// Configs ... elements of a slice
type Configs struct {
Length int
@kenzo0107
kenzo0107 / README.md
Created October 28, 2019 12:43
AWS Serverless Application Model with Go

environment

  • go version go1.13.3 darwin/amd64

Preparation

$ pip install awscli
$ pip install aws-sam-cli
@kenzo0107
kenzo0107 / README.md
Last active June 19, 2019 06:35
post rails metrics to datadog

rails-metrics-to-datadog

What's this project

This project provides an shell script that post rails metrics to datadog.

Usage

require 'benchmark'
require 'net/http'
require 'uri'
def post_metrics_datadog(metrics, val)
project = "hoge"
api_key = ENV['DATADOG_API_KEY']
current_time = Time.now.to_i
uri = URI.parse("https://api.datadoghq.com/api/v1/series?api_key=#{api_key}")
request = Net::HTTP::Post.new(uri)
#!/bin/sh
PROFILE=$1
TASK_DEFINITION=$2
r=$(aws ecs --profile $PROFILE list-task-definitions --family-prefix $TASK_DEFINITION --query 'taskDefinitionArns[]')
echo $r | jq -r '.[]' | while read task
do
rev=$(echo $task | sed -e's|^.*task-definition\/\(.*\)$|\1|g')
aws ecs --profile $PROFILE deregister-task-definition --task-definition $rev
@kenzo0107
kenzo0107 / hubot-github-comment.coffee
Created November 23, 2017 12:04
Slack DM to @mention in pull request comment or issue comment on Github
# Description:
# hubot monitoring git comments mention and slack DM
#
# Dependencies:
# "hubot-slack": "^4.4.0"
# "hubot-slack-attachement": "^1.0.1"
#
# Commands:
# None
#
slack() {
curl -X POST "https://hooks.slack.com/services/xxxxxxx/xxxxxxx/xxxxxxxxxxxxxxxx" -d "payload={
\"username\": \"<user_name>\",
\"icon_emoji\": \":outbox_tray:\",
\"attachments\": [{
\"color\": \"$1\",
\"title\": \"$2\",
\"text\": \"$3\"
}]
}"
function peco-git-atom() {
local dir=$(ghq list -p | peco)
if [ -n "$dir" ]; then
atom "$dir"
fi
}
alias opg='peco-git-atom'