Skip to content

Commit

Permalink
[bq,mysql,ruby] Add Ruby pages, partially copied from progrhymetechwiki
Browse files Browse the repository at this point in the history
  • Loading branch information
progrhyme committed Jun 25, 2020
1 parent 25c20ec commit 82fe6f4
Show file tree
Hide file tree
Showing 7 changed files with 839 additions and 3 deletions.
9 changes: 9 additions & 0 deletions content/ja/a/google/gcp/bq.md
Expand Up @@ -23,6 +23,15 @@ https://cloud.google.com/bigquery/pricing
- データセット ... プロジェクトに属し、テーブルやビューを管理する最上位のコンテナ
- データセットの概要 | BigQuery | Google Cloud

## 仕様
### `0000-00-00 00:00:00` は取り扱えない

MySQLサーバで `NO_ZERO_DATE` modeが有効でないと入ってくるデータだが、BQでは扱えない。

関連項目:

- [MySQL#SQL-Mode]({{<ref "/a/software/mysql.md">}}#sql-mode)

## How-to
### Colaboratoryから使う

Expand Down
11 changes: 10 additions & 1 deletion content/ja/a/google/gcp/cli.md
Expand Up @@ -48,7 +48,10 @@ BigQuery操作CLI

### load

https://cloud.google.com/bigquery/docs/reference/bq-cli-reference?hl=ja#bq_load
ドキュメント:

- https://cloud.google.com/bigquery/docs/reference/bq-cli-reference?hl=ja#bq_load
- [Cloud Storage からの CSV データの読み込み | BigQuery | Google Cloud](https://cloud.google.com/bigquery/docs/loading-data-cloud-storage-csv?hl=ja)

Examples:

Expand All @@ -58,8 +61,14 @@ bq load --source_format=CSV --encoding=UTF-8 --field_delimiter="\t" [dataset].[t
# ↑SOURCEはファイルでもGCSバケットでもいい
```

Specs:

- 要素が改行を含むデータを取り込むには、該当要素を `--quote` 文字(デフォルトは `"` )で囲み、 `--allow_quoted_newlines` (デフォルトfalse)を指定する
- 更に、該当要素が元々 `"` を含む場合、 `""` でエスケープする必要がある。

参考:

- [bq loadのCSVにダブルクォーテーションや改行を含むときの対処法 | ppoohh 's blog](https://www.ppoohh.info/post-331/)
- [bigqueryでtsvをインポート | ハックノート](https://hacknote.jp/archives/32117/)

### mk
Expand Down
57 changes: 57 additions & 0 deletions content/ja/a/program/ruby/_index.md
@@ -0,0 +1,57 @@
---
title: "Ruby"
linkTitle: "Ruby"
description: https://www.ruby-lang.org/
date: 2020-06-25T15:19:13+09:00
weight: 770
---

## About

リポジトリ:

- 公式: https://git.ruby-lang.org/
- ミラー: https://github.com/ruby/ruby
- 2019-04-22まではSVNだった

参考:

- [リポジトリガイド](https://www.ruby-lang.org/ja/documentation/repository-guide/)

## Topics
### 標準入出力

Rubyではインタプリタ起動時に標準入出力に対応するオブジェクトが定数に格納される。
それらは以下の通り:

| 定数 ||
|--------|----|
| STDIN | rubyプロセス起動時の標準入力。$stdinのデフォルト値 |
| $stdin | 標準入力 |
| STDOUT | rubyプロセス起動時の標準出力。$stdoutのデフォルト値 |
| $stdout | 標準出力 |
| STDERR | rubyプロセス起動時の標準エラー出力。$stderrのデフォルト値 |
| $stderr | 標準エラー出力 |

- STDIN, STDOUT, STDERRは[Objectクラス](https://docs.ruby-lang.org/ja/latest/class/Object.html)で定義されている。
- $stdin, $stdout, $stderrは[Kernelモジュール](https://docs.ruby-lang.org/ja/latest/class/Kernel.html)で定義されているグローバルスコープの変数。
- $stdinにIOオブジェクトを代入することで、入力をリダイレクトできる。
- $stdout, $stderrにIOオブジェクトを代入することで、出力をリダイレクトできる。

参考:

- [Rubyアソシエーション: 入出力](https://www.ruby.or.jp/ja/tech/development/ruby/tutorial/060_in_output.html)
- [Ruby で標準入出力のテスト - Qiita](https://qiita.com/key-amb/items/a134e2c3bea172b3deeb)

#### プロコンにおける標準入力の処理

```ruby
# 1行入力の場合
input = gets.chomp

# 複数行入力の場合
lines = $stdin.readlines # 各要素は末尾に改行コードを含む
lines = $stdin.read.lines # 上に同じ
```

## Child Pages

0 comments on commit 82fe6f4

Please sign in to comment.