プログラミング中に話しかけられると、集中力の回復に時間がかかるのは何故? 短い時間のチャットやメールが集中力を奪う。「注意残余」とは。 #Slack #生産性 #ディープワーク

プログラミング中に話しかけられると、集中力の回復に時間がかかるのは何故? 短い時間のチャットやメールが集中力を奪う。「注意残余」とは。

Slack #生産性 #ディープワーク

大事なことに集中する―――気が散るものだらけの世界で生産性を最大化する科学的方法

image

知的作業には中断されない環境が必要

image

タスクの切替時に注意残余が起こり、集中力を取り戻すまでに時間がかかる

image

ごく短時間でのメールチェック、チャットの確認でも注意残余は起こる

image

https://github.com/YumaInaura/YumaInaura/issues/555

IFTTTを使って、Twitterにハッシュタグつきでツイートしたら、はてなブログに自動投稿する例。画像表示もインライン対応。

IFTTTを使って、Twitterハッシュタグつきでツイートしたら、はてなブログに自動投稿する例。画像表示もインライン対応。

はてなのメール投稿用のアドレスをゲット

メルアドは 設定 > 詳細から取得可能

こんなURL

https://blog.hatena.ne.jp/yumainaura/yumainaura.hateblo.jp/config/detail

メールで記事を投稿する - はてなブログ ヘルプ

はてなの設定を、見たままモードにしておく

Twitter埋め込みのHTMLが、そのまま使えるようにしておく

image

IFTTTでハッシュタグつきツイートをトリガーにする<<

image image

Gmail 送信をアクションにする

image

ToAdress に はてなブログの投稿用メールアドレスを入れる

Subject とか Text とか調整する






<br>
from Twitter https://twitter.com/<br>
<br>
<br>
via <a href="https://ifttt.com/?ref=da&site=gmail">IFTTT</a>

結果の例

ツイートをリプライで連鎖させていると、ひとつ親のツイートまで表示してくれるっぽい。

image image

http://yumainaura.hateblo.jp/entry/2019/02/02/205113

はてな編集画面の例

image

はてなに投稿されたHTMLの例

image

NOTE

Gmail送信のAttachmentにTwitterの First Link を指定しても、うまく動かなかった。Twitterはそもそも画像URLの扱いが厳しそうな。

メールでMarkdownを強制指定できるかどうかは、はてなに問い合わせてみた。結果待ち。

image

Markdown or はてな記法をデフォルト設定にしていて、変えたくない場合は、とりあえず、Twitter連携用の別ブログを作っておいても良いかもしれない。

https://github.com/YumaInaura/YumaInaura/issues/551

Twitterでつぶやくだけで、はてなブログに投稿してみるテスト。 #はてな

Twitterでつぶやくだけで、はてなブログに投稿してみるテスト。 #はてな

— いなうらゆうま🤖マインドフルネス (@YumaInaura) February 2, 2019

from Twitter https://twitter.com/YumaInaura

February 02, 2019 at 08:13PM via IFTTT

Zappier で Github Issue 作成をトリガーにして、pythonスクリプトからGoogle翻訳APIを叩き、翻訳済みの新しいGithub Issue を作成する例。日本語から英語へバージョン。

Zappier で Github Issue 作成をトリガーにして、pythonスクリプトからGoogle翻訳APIを叩き、翻訳済みの新しいGithub Issue を作成する例。日本語から英語へバージョン。

補足

Googleトークンの有効期限などは確認していない。とりあえず動いた。

Google翻訳API用に GCP の認証トークンを取得しておく

Google Cloud の認証トークンを gcloud コマンドで取得する。環境変数でサービスアカウントファイルを指定する例。 · Issue #545 · YumaInaura/YumaInaura

Issue 作成をトリガーにする

image

Code By Zapier

Github の title と description を 入力リソースに指定する

image

Script

先程取得したトークンをスクリプト内に埋め込む Google 翻訳で Markdownが崩れるので、pythonで適当に整形。

import requests
import re

data = {
  'q': [
        input["title"],
        input["body"],
    ],
  'source': 'ja',
  'target': 'en',
  'format': 'text'
}

url = 'https://translation.googleapis.com/language/translate/v2'
token = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'

headers = {
 'Authorization': 'Bearer {}'.format(token),
 'Content-Type': 'application/json',
}

res = requests.post(url, headers=headers, json=data)

# Title
output_title = res.json()['data']['translations'][0]['translatedText']
# For twitter in English 240 upper limit characters
output_title = output_title[:200]

# Fix Body: Image Markdown tag spaces
output_body = res.json()['data']['translations'][1]['translatedText']
output_body = re.sub(r'! \[image\] ', "![image]", output_body)


output = [
  {
    "title": output_title,
    "body": output_body
  }
]

Find or Create Issue をアクションにする

  • いろいろ記入する
  • Github ISsueを探して、なければ作成することも可能」という謎の仕様なので、検索対象として、絶対に入力しないような Search value を指定しておく。

image

image

結果

https://github.com/YumaInaura/issue/issues/63

image

画像もバッチリ

image

おまけ。必要なら Zapier の Detect Language / Only Continue if

で、日本語判定された場合にだけ、アクションが走るようにしておく。

image

https://github.com/YumaInaura/YumaInaura/issues/548

Google翻訳APIをpythonスクリプトで叩いて英語を日本語に翻訳する。

Google翻訳APIpythonスクリプトで叩いて英語を日本語に翻訳する。

script

import requests
import os

data = {
  'q': 'The Grate Great Pyramid of Giza (also known as the Pyramid of
Khufu or the Pyramid of Cheops) is the oldest and largest of the three
pyramids in the Giza pyramid complex.',
  'source': 'en',
  'target': 'ja',
  'format': 'text'
}

url = 'https://translation.googleapis.com/language/translate/v2'
token = os.environ['TOKEN']

headers = {
 'Authorization': 'Bearer {}'.format(token),
 'Content-Type': 'application/json',
}

res = requests.post(url, headers=headers, json=data)

print(res.json())

実行例

TOKEN=xxxxxxxxxxxxx python example.py

結果

{'data': {'translations': [{'translatedText':
'ギザのグレート大ピラミッド(クフのピラミッドまたはチープのピラミッドとしても知られています)は、ギザピラミッド複合体の3つのピラミッドの中で最も古く、最も大きいピラミッドです。'}]}}

Ref

Google Cloud の認証トークンを gcloud コマンドで取得する。環境変数でサービスアカウントファイルを指定する例。 · Issue #545 · YumaInaura/YumaInaura

https://github.com/YumaInaura/YumaInaura/issues/547

Google翻訳APIをシェルスクリプトで叩いて英語を日本語に翻訳する。ほとんど公式チュートリアルのまま。

Google翻訳APIシェルスクリプトで叩いて英語を日本語に翻訳する。ほとんど公式チュートリアルのまま。

Google Translate API を有効化しておく

チュートリアルのとおりに。

https://cloud.google.com/translate/docs/quickstart

トークンの取得

Google Cloud の認証トークンを gcloud コマンドで取得する。環境変数でサービスアカウントファイルを指定する例。 · Issue #545 · YumaInaura/YumaInaura

Script

key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

curl "https://translation.googleapis.com/language/translate/v2" \
  -H "Authorization: Bearer $key" \
  -s -X POST -H "Content-Type: application/json" \
  --data "{ 'q': 'The Great Pyramid of Giza (also known as the Pyramid
of Khufu or the Pyramid of Cheops) is the oldest and largest of the
three pyramids in the Giza pyramid complex.', 'source': 'en',
'target': 'ja', 'format': 'text' }"

結果

$ sh example.sh
{
  "data": {
    "translations": [
      {
        "translatedText":
"ギザの大ピラミッド(クフのピラミッドまたはチープのピラミッドとしても知られています)は、ギザピラミッド複合体の3つのピラミッドの中で最も古く、最も大きいピラミッドです。"
      }
    ]
  }
}

Ref

Cloud Translation API ドキュメント  |  Cloud Translation API  |  Google Cloud

クイックスタート  |  Cloud Translation API  |  Google Cloud

https://github.com/YumaInaura/YumaInaura/issues/546