Skip to content

Instantly share code, notes, and snippets.

View masutaka's full-sized avatar

Takashi Masuda masutaka

View GitHub Profile
@masutaka
masutaka / sample.lkml
Last active September 2, 2022 08:30
[解決] なぜか特定の Measure が Explore に出てこない (Looker 22.14.44)
explore: sample {
join: sample2 {
type: left_outer
relationship: many_to_one
sql_on: ${sample.medium} = ${sample2.medium} ;;
}
}
view: sample {
derived_table: {
@masutaka
masutaka / README.md
Last active July 21, 2022 07:31
Example for managing BigQuery schema which the data source is Google Sheets

1. Create schema.json

See Specifying a schema

nametype は必須。mode のデフォルト値は Nullable

2. Create define.json

$ bq mkdef --noautodetect --source_format=GOOGLE_SHEETS \
@masutaka
masutaka / bigquery.sql
Last active November 26, 2021 07:00
The ranking of BigQuery total_bytes_billed on 11/18
select
job_type
, user_email
, referenced_tables.dataset_id
, round(sum(total_bytes_billed) / pow(10, 9), 2) AS total_gb_billed
from
`region-us.INFORMATION_SCHEMA.JOBS_BY_PROJECT`
, UNNEST(referenced_tables) AS referenced_tables
WHERE CAST(creation_time AS DATE) = DATE('2021-11-18')
group by job_type, user_email, referenced_tables.dataset_id
@masutaka
masutaka / Makefile
Last active February 10, 2022 01:56
mitamae Makefile
EXPIRE_SEC := $(shell expr 24 '*' 60 '*' 60)
KERNEL := $(shell uname | tr '[:upper:]' '[:lower:]')
MITAMAE_BIN_DIR := bin
MITAMAE_REPO := itamae-kitchen/mitamae
MITAMAE := $(MITAMAE_BIN_DIR)/mitamae
MITAMAE_ARCH_BIN := mitamae-x86_64-$(KERNEL)
MITAMAE_LATEST_TAR_BALL_URL := https://github.com/$(MITAMAE_REPO)/releases/latest/download/$(MITAMAE_ARCH_BIN).tar.gz
MITAMAE_LATEST_VERSION := $$(curl -s https://api.github.com/repos/$(MITAMAE_REPO)/releases/latest | jq -r .tag_name)

1. Create Dataset

$ bq mk sandbox_masutaka

2. Setup orders Table

$ bq mk --table --schema=./orders.json sandbox_masutaka.orders
--- Makefile.orig 2020-03-26 22:38:05.000000000 +0900
+++ Makefile 2020-03-26 22:39:57.000000000 +0900
@@ -1,9 +1,10 @@
+DIRENV := direnv
MAKE := make
TARGETS := aws heroku
define make-r
@for i in $(TARGETS); do \
- $(MAKE) -w -C terraform/$$i $(1) || exit $$?; \
@masutaka
masutaka / 00tree.txt
Last active March 26, 2020 14:34
Makefiles for terraform
.
├── Makefile # (1)
└── terraform
    ├── aws
    │   ├── Makefile # (2)
    │ └── main.tf
    └── heroku
    ├── Makefile # (3)
    └── main.tf
@masutaka
masutaka / .rubocop.yml
Created February 25, 2020 10:50
Forbid Dir.chdir using rubocop custom cop
require:
- ./lib/rubocop/cop/hoge
@masutaka
masutaka / oneshot_base_job.rb
Created December 11, 2019 15:54
sample one-shot job on Heroku
# @abstract One-shot 関連のジョブは必ずこの class を継承し、
# キーワード引数に :global_executions を要求する #perform を実装すること
class OneshotBaseJob < ApplicationJob
class << self
# Retry the One-shot job due to the exception
#
# @param job [OneshotBaseJob] A One-shot job class to retry
# @return [void]
#
# @note See ActiveJob::Exceptions::ClassMethods#retry_on for the parameters except to `job`
@masutaka
masutaka / test.js
Last active August 10, 2019 03:13
esa.io の通常カテゴリと、Archived カテゴリを行ったり来たりするブックマークレット
if (/esa\.io\/#path=%2FArchived%2F/.test(location.href)) {
location.href = location.href.replace(/#path=%2FArchived%2F/, '#path=%2F');
} else if (/esa\.io\/#path=%2F/.test(location.href)) {
location.href = location.href.replace(/#path=%2F/, '#path=%2FArchived%2F');
}