Skip to content

Instantly share code, notes, and snippets.

@sue445
sue445 / datadog_dashboard_isucon12.json
Last active Jul 24, 2022
ISUCON12で使ったDatadogダッシュボード
View datadog_dashboard_isucon12.json
{
"title": "ISUCON",
"description": "https://app.datadoghq.com/dash/integration/30268/ruby-runtime-metrics?tpl_var_service=isucon\nhttps://app.datadoghq.com/dashboard/dzb-2ps-nyf?tpl_var_service=isucon\n\n* [Continuos Profiler](https://app.datadoghq.com/profiling/aggregation?query=service%3Aisucon)\n* [Database Monitoring](https://app.datadoghq.com/databases/queries?query=service%3Aisucon%20-query_signature%3A%2829e4c5d3e6caa593%20OR%20f8ae1cfee57d2d0b%20OR%20946d3a847b4979d5%20OR%203d26034e89167423%20OR%20dfa53796cd30e3e7%29&dbType=MySQL)\n",
"widgets": [
{
"id": 3153889567518422,
"definition": {
"title": "sinatra",
"type": "group",
"background_color": "vivid_green",
@sue445
sue445 / sample1_spec.log
Last active Jun 19, 2022
subject!とbeforeの順番が気になったので調べてみた
View sample1_spec.log
$ rspec --version
2.13.1
$ rspec -- sample1_spec.rb
before(:all)
subject!
let!
before(:each)
it
after(:each)
@sue445
sue445 / uses_temp_dir.rb
Created Jun 5, 2014
Example of using temporary directory at rspec
View uses_temp_dir.rb
shared_context :uses_temp_dir do
around do |example|
Dir.mktmpdir("rspec-") do |dir|
@temp_dir = dir
example.run
end
end
attr_reader :temp_dir
end
@sue445
sue445 / isucon.tf
Last active Oct 26, 2021
ISUCONの素振りの環境構築用Terraform (c.f. https://sue445.hatenablog.com/entry/2021/08/22/213634 )
View isucon.tf
resource "aws_vpc" "isucon" {
cidr_block = "172.31.0.0/16"
tags = {
Name = "isucon VPC"
}
}
resource "aws_subnet" "isucon_public_a" {
vpc_id = aws_vpc.isucon.id
@sue445
sue445 / equal_with_indifferent_access.rb
Last active Oct 22, 2021
[RSpec custom matcher] match hashes with indifferent access
View equal_with_indifferent_access.rb
# match hashes with indifferent access
#
# example)
# expect({"key1" => 1, :key2 => 2}).to equal_with_indifferent_access(key1: 1, key2: 2)
RSpec::Matchers.define :equal_with_indifferent_access do |expected|
match do |actual|
actual.with_indifferent_access == expected.with_indifferent_access
end
@sue445
sue445 / db_migrate_monkey_patch.rake
Last active May 29, 2020
A monkey patch to switch the connection destination from pgbouncer to PostgreSQL only when `rake db:migrate`
View db_migrate_monkey_patch.rake
# A monkey patch to switch the connection destination from pgbouncer to PostgreSQL only when `rake db:migrate`
#
# Usage: Put this file to `lib/tasks/db_migrate_monkey_patch.rake`
#
# https://gist.github.com/sue445/e82bbc8b626e4681f87182aa5981b68d
require "tmpdir"
require "fileutils"
module DbMigrateMonkeyPatch
@sue445
sue445 / README.md
Last active Apr 22, 2020
俺のitamaeの実行方法
View README.md

roleとnodeを設定しておけばいい感じにrake taskを生成します

前提

下記のようなディレクトリ構成を想定しています

  • roles/
    • <role名>.rb
  • nodes/
    • <node名>.yml
  • spec/
View docker-compose.yml
version: '3.7'
services:
redis:
restart: always
image: sameersbn/redis:4.0.9-2
command:
- --loglevel warning
deploy:
@sue445
sue445 / service_account-datadog.tf
Created Feb 17, 2020
Service account for datadog
View service_account-datadog.tf
# Service account for datadog
# c.f. https://docs.datadoghq.com/ja/integrations/google_cloud_platform/?tab=datadogussite#setup
resource "google_service_account" "datadog" {
account_id = "datadog"
display_name = "datadog"
}
# Compute Viewer
resource "google_project_iam_binding" "datadog_compute_viewer" {
View deploy.rb
# envリポジトリのcurrent
set :env_current, "/home/deploy/docker-gitlab-env/current"
set :stack_name, "gitlab"
namespace :stack do
desc "docker stack deploy"
task :deploy do
on roles(:app) do
within release_path do