by shigemk2

当面は技術的なことしか書かない

未解決 Ubuntu 18.04 video

動画サイトもろもろ再生されない。動画の最初の一コマから動画が進まない。Flashはもう使ってないから、Flashの問題じゃないと思われる。Ubuntu 18.04に引き上げたら発生したので、たぶんUbuntuアップデートが原因だと思われる。

入れたけど解決しない。

sudo apt-get install ubuntu-restricted-extras

タスク。こっちを再確認する。 https://www.youtube.com/html5

16.04 - Fireofx 57.0a1 64-bit - YouTube HTML5 Video Player - Ask Ubuntu

Ubuntu 18.04メモ

  • Ubuntuを17.10から18.04に引き上げたところローディング画面っぽいところで止まってログインできない
  • alt + printscreenでCUIログインしたところ、流れてくるログにlightdm display manager failed なる文字列
  • systemctl start lightdmしたところ失敗 gnomeが見つからないみたいなことを言われる
  • ubuntu-desktopインストール→いちおうログインできた

https://ja.wikipedia.org/wiki/LightDM

Python unicodeな文字列でreplaceとかformatとかやったときの挙動

unicodeな文字列でreplaceとかformatとかやったときの挙動

>>> a = "日本語".decode("utf-8")
>>> a
u'\u65e5\u672c\u8a9e'
>>> b = "{}".format(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)

Python KeyError in format

ソースコードを追っかけても原因がよくわからなかったけどドキュメントを読んだらなんとなくわかった

>>> a = "{} {'alpha': 1234, 'omega': 5678}".format("test")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: "'alpha'"
>>> a = "{} {{'alpha': 1234, 'omega': 5678}}".format("test")
>>> a
"test {'alpha': 1234, 'omega': 5678}"

Format strings contain “replacement fields” surrounded by curly braces {}. Anything that is not contained in braces is considered literal text, which is copied unchanged to the output. If you need to include a brace character in the literal text, it can be escaped by doubling: {{ and }}.

https://docs.python.org/2/library/string.html#format-string-syntax

Presto row_number/rank/dense_rank

  • prestoにもrank/desne_rank/row_numberがある
    • row_number 機械的にidを割り振る
    • rank 重複値は同順位だが、次の順位は重複ぶんだけ飛ばす
    • dense_rank 重複値は同順位だが、次の順位は+1

クエリ。

WITH dataset AS
  ( SELECT *
   FROM (
         VALUES 10,
                100,
                500,
                500,
                1000,
                1500 ) AS t(num))
SELECT num,
       ROW_NUMBER() OVER( ORDER BY num) as row_number,
       RANK() OVER( ORDER BY num) as rank,
       DENSE_RANK() OVER( ORDER BY num) as dense_rank
FROM dataset;

結果。

NUM ROW_NUMBER RANK DENSE_RANK
10 1 1 1
100 2 2 2
500 3 3 3
500 4 3 3
1000 5 5 4
1500 6 6 5

6.15. Window Functions — Presto 0.202 Documentation

Data Sampling In Presto

http://itref.fc2web.com/oracle/function/row_number.html