Skip to content

Instantly share code, notes, and snippets.

Avatar

Takashi Masuda masutaka

View GitHub Profile
@masutaka
masutaka / sample.lkml
Last active Sep 2, 2022
[解決] なぜか特定の Measure が Explore に出てこない (Looker 22.14.44)
View sample.lkml
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 Jul 21, 2022
Example for managing BigQuery schema which the data source is Google Sheets
View README.md

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 Nov 26, 2021
The ranking of BigQuery total_bytes_billed on 11/18
View bigquery.sql
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 Feb 10, 2022
mitamae Makefile
View 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)
View README.md

1. Create Dataset

$ bq mk sandbox_masutaka

2. Setup orders Table

$ bq mk --table --schema=./orders.json sandbox_masutaka.orders
View direnv.patch
--- 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 Mar 26, 2020
Makefiles for terraform
View 00tree.txt
.
├── Makefile # (1)
└── terraform
    ├── aws
    │   ├── Makefile # (2)
    │ └── main.tf
    └── heroku
    ├── Makefile # (3)
    └── main.tf
@masutaka
masutaka / .rubocop.yml
Created Feb 25, 2020
Forbid Dir.chdir using rubocop custom cop
View .rubocop.yml
require:
- ./lib/rubocop/cop/hoge
@masutaka
masutaka / oneshot_base_job.rb
Created Dec 11, 2019
sample one-shot job on Heroku
View oneshot_base_job.rb
# @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 Aug 10, 2019
esa.io の通常カテゴリと、Archived カテゴリを行ったり来たりするブックマークレット
View test.js
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');
}