Skip to content

Instantly share code, notes, and snippets.

@terashim
terashim / install-docker-kubectl-completion-for-fish-shell.sh
Created March 4, 2019 02:11
fishシェルにdocker, docker-compose, kubectlのコマンド補完をインストールする
mkdir -p ~/.config/fish/completions
# docker
curl https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/fish/docker.fish -o ~/.config/fish/completions/docker.fish
# docker-compose
curl https://raw.githubusercontent.com/docker/compose/master/contrib/completion/fish/docker-compose.fish -o ~/.config/fish/completions/docker-compose.fish
# kubectl (非公式)
curl https://raw.githubusercontent.com/evanlucas/fish-kubectl-completions/master/completions/kubectl.fish -o ~/.config/fish/completions/kubectl.fish
@terashim
terashim / bq-example.R
Created April 18, 2019 01:32
bigQueryRでINSERT
library(tidyverse)
library(lubridate)
library(googleAuthR)
library(bigQueryR)
options(
googleAuthR.client_id = Sys.getenv("GOOGLE_CLIENT_ID"),
googleAuthR.webapp.client_id = Sys.getenv("GOOGLE_CLIENT_ID"),
googleAuthR.client_secret = Sys.getenv("GOOGLE_CLIENT_SECRET"),
googleAuthR.webapp.client_secret = Sys.getenv("GOOGLE_CLIENT_SECRET"),
@terashim
terashim / summarise_all-with-optional-arguments.R
Created April 25, 2019 03:35
summarise_allで適用する関数にオプション引数を与える実験
# summarise_allで適用する関数にオプション引数を与える実験
library(tidyverse)
data <- read_csv('
a,x
A,1
A,2
A,3
B,
@terashim
terashim / tail-shiny-server-latest-log.sh
Created May 24, 2019 09:58
Shiny Serverの最新ログファイルをtail表示するワンライナー
ls -d --sort=time /var/log/shiny-server/* | head -n1 | xargs tail
@terashim
terashim / time-example.R
Last active May 29, 2019 09:47
10日おきに12:00の時刻ベクトルを生成
# サンプルコード: 10日おきに12:00の時刻ベクトルを生成
library(tidyverse)
library(lubridate)
# 日付のベクトルを作成
sent_time <- seq(as_date("2018-01-01"), as_date("2019-12-31"), by = "10 days")
# POSIXct型に変換
sent_time <- as_datetime(sent_time)
@terashim
terashim / gcloud-create-preemtible-cluster.sh
Created July 14, 2019 21:42
GKEでプリエンプティブインスタンスのクラスタを作成するgcloudコマンドの例
gcloud container clusters create experiment-cluster \
--machine-type=n1-standard-1 \
--preemptible \
--enable-autoscaling --max-nodes=3 --min-nodes=0
@terashim
terashim / minikube_setup.fish
Created July 18, 2019 11:30
fish shellでMinikubeを起動・設定する関数
# fish shellでMinikubeを起動・設定する関数
# Minikubeを起動、dockerコマンドでMinikubeのDockerデーモンを使うよう設定する
#
# インストール:
# ~/.config/fish/functions/minikube_setup.fish
# に保存する
#
function minikube_setup
echo "Minikubeのバージョンを調べます"
echo "コマンド> minikube version"
@terashim
terashim / bigquery-date-sequence.sql
Created July 30, 2019 02:40
BigQueryで連番の日付を生成する例
-- BigQueryで連番の日付を生成する例
-- Standard SQL を使用
-- 2019-04-01 から 2020-03-31 まで
SELECT
DATE_ADD(start_date.start_date, INTERVAL n.n DAY) AS date
FROM (
SELECT
DATE('2019-04-01') AS start_date) AS start_date
LEFT JOIN (
SELECT
@terashim
terashim / bq-select-deleting-bom.sql
Created September 19, 2019 09:40
BigQueryでデータからBOMを削除する
-- BigQueryで列 my_column のBOM (Byte Order Mark) を削除
SELECT
REGEXP_REPLACE(my_column, '''\ufeff''', '')
FROM
my_table
@terashim
terashim / docker-desktop-k8s-config-set-credentials-default-token.sh
Last active September 23, 2019 14:38
k8s で default-token を取得するワンライナー
#!/bin/bash
# 応用例
# Docker Desktopのk8sのconfigにdefault-tokenを設定する
kubectl config set-credentials docker-desktop --token="$(kubectl -n kube-system get secret | grep default-token | awk '{print $1}' | xargs -IXXX kubectl -n kube-system get secret XXX -o jsonpath='{.data.token}' | base64 --decode)"