iframeを使っているのを悟られたくない。document.write()したかのように見せたい!!
<iframe src="https://xxxxxxxxxx" scrolling="no" frameborder="0" style="width:100%;max-width:100%;min-height:500px;overflow-y:visible;"></iframe>
iframeを使っているのを悟られたくない。document.write()したかのように見せたい!!
<iframe src="https://xxxxxxxxxx" scrolling="no" frameborder="0" style="width:100%;max-width:100%;min-height:500px;overflow-y:visible;"></iframe>
Split Viewを利用すると、Macの画面に2つのAppを並べて表示できるようになります。Macの標準機能なのがいいですね。
この機能のせいでウルトラワイドモニターが欲しくなりました。
34インチのウルトラワイドモニターの価格が4万弱。
LG モニター ディスプレイ 34UM59-P 34インチ/21:9 ウルトラワイド/IPS非光沢/HDMI×2
画面が湾曲すると+2万円で6万弱です。
LG ゲーミング モニター ディスプレイ 34UC79G-B 34インチ/21:9 曲面 ウルトラワイド/IPS 非光沢/144Hz/DisplayPort×1,HDMI×2
Laravelで作成したアプリの動かした際に、次のようなRuntimeExceptionが出た。
RuntimeException No application encryption key has been specified.
どうやら、.envファイルにAPP_KEYの指定が無い模様。
php artisan key:generate php artisan config:cache
php artisan key:generate
だけでは設定が反映されないため、php artisan config:cache
を実行する必要がある。
PHPのフレームワークの雄であるLaravelで、非同期処理をJobで書いた後、動作確認を行いたいときがある。その場合、賢い皆様はテストコードを書いたり、ダミーのコントローラーを書いたりするのだろうが、いずれも面倒だ。今回は、Jobを対話的シェルのtinkerで実行する方法を紹介する。
$ php artisan tinker Psy Shell v0.9.6 (PHP 7.1.7 — cli) by Justin Hileman >>> Bus::dispatch(new \App\Jobs\ InvoiceEmail()); => 58 >>> exit Exit: Goodbye $ php artisan queue:listen [2018-06-21 19:08:46] Processing: App\Jobs\ReceivedMail [2018-06-21 19:08:46] Processed: App\Jobs\ReceivedMail ^C
QNAP社が、Btrfsファイルシステム(≒Synology社のNAS)のことをサイト上で批判しています。
QNAP社のサイトを見ると、
QNAP NASがBtrfsファイルシステムを使用しないのはなぜですか?
(QNAPが採用している)ext4は、より高速で、安定しています
Btrfsは、低速です
のように、Synology社のNASと比較した際の優位性を述べています。日本の企業ではこのような相手を名指しで批判するマーケティングはお目にかかることが無いので、とても興味深いです。
私はファイルシステムの専門家ではないため、どちらのファイルシステムが優れている等を論ずることはできませんが、実際のところはどうなのでしょうか。とりあえず、Synology社のNASを買ってみたいと思います。
Clojureで「言語処理100本ノック 2015」を解いてみようの続き。
hightemp.txtは,日本の最高気温の記録を「都道府県」「地点」「℃」「日」のタブ区切り形式で格納したファイルである.以下の処理を行うプログラムを作成し,hightemp.txtを入力ファイルとして実行せよ.さらに,同様の処理をUNIXコマンドでも実行し,プログラムの実行結果を確認せよ.
行数をカウントせよ.確認にはwcコマンドを用いよ.
(require '[clojure.string :as str]) (count (str/split (slurp "hightemp.txt") #"\n")) ; => 24
$ wc -l hightemp.txt 24 hightemp.txt
slurp
便利すぎ。(slurp "http://clojuredocs.org/")
のようにHTTPもHTTPSも対応しているのね。
タブ1文字につきスペース1文字に置換せよ.確認にはsedコマンド,trコマンド,もしくはexpandコマンドを用いよ.
(require '[clojure.string :as str]) (map #(println %) (map #(str/replace % #"\t" " ")(str/split (slurp "http://www.cl.ecei.tohoku.ac.jp/nlp100/data/hightemp.txt") #"\n"))) ; 高知県 江川崎 41 2013-08-12 ; 埼玉県 熊谷 40.9 2007-08-16 ; 岐阜県 多治見 40.9 2007-08-16
各行の1列目だけを抜き出したものをcol1.txtに,2列目だけを抜き出したものをcol2.txtとしてファイルに保存せよ.確認にはcutコマンドを用いよ.
(require '[clojure.string :as str]) (def hightemp (map #(str/split % #"\t") (str/split (slurp "http://www.cl.ecei.tohoku.ac.jp/nlp100/data/hightemp.txt") #"\n"))) (defn save-file [file-name file-body] (with-open [f-out (clojure.java.io/writer file-name :append true)] (.write f-out file-body))) (def col1-body (str/join "\n" (map #(first %) hightemp))) (def col2-body (str/join "\n" (map #(second %) hightemp))) (save-file "col1.txt" col1-body) (save-file "col2.txt" col2-body)
12で作ったcol1.txtとcol2.txtを結合し,元のファイルの1列目と2列目をタブ区切りで並べたテキストファイルを作成せよ.確認にはpasteコマンドを用いよ.
(require '[clojure.string :as str]) (def col1 (str/split (slurp "col1.txt") #"\n")) (def col2 (str/split (slurp "col2.txt") #"\n")) (println (str/join "\n" (map #(str/join "\t" %) (partition 2 (interleave col1 col2))))) ;; => 高知県 江川崎 ;; 埼玉県 熊谷 ;; 岐阜県 多治見 ;; 山形県 山形 ;; (以下略)
自然数Nをコマンドライン引数などの手段で受け取り,入力のうち先頭のN行だけを表示せよ.確認にはheadコマンドを用いよ.
(require '[clojure.string :as str]) (def hightemp-txt (str/split (slurp "http://www.cl.ecei.tohoku.ac.jp/nlp100/data/hightemp.txt") #"\n"))) (defn head [no input] (map #(println (str %)) (take no input))) (head 5 hightemp-txt) ;; => 高知県 江川崎 41 2013-08-12 ;; 埼玉県 熊谷 40.9 2007-08-16 ;; 岐阜県 多治見 40.9 2007-08-16 ;; 山形県 山形 40.8 1933-07-25 ;; 山梨県 甲府 40.7 2013-08-10
自然数Nをコマンドライン引数などの手段で受け取り,入力のうち末尾のN行だけを表示せよ.確認にはtailコマンドを用いよ.
(defn tail [no input] (map #(println (str %)) (take-last no input))) (tail 3 hightemp-txt) ;; => 山梨県 大月 39.9 1990-07-19 ;; 山形県 鶴岡 39.9 1978-08-03 ;; 愛知県 名古屋 39.9 1942-08-02
自然数Nをコマンドライン引数などの手段で受け取り,入力のファイルを行単位でN分割せよ.同様の処理をsplitコマンドで実現せよ.
(require '[clojure.string :as str]) (def hightemp-seq (str/split (slurp "http://www.cl.ecei.tohoku.ac.jp/nlp100/data/hightemp.txt") #"\n")) (defn split-no [no] (/ (count hightemp-seq) no)) (defn division [no] (map #(println % "\n") (map #(str/join "\n" %) (partition (split-no no) hightemp-seq))))
1列目の文字列の種類(異なる文字列の集合)を求めよ.確認にはsort, uniqコマンドを用いよ.
(require '[clojure.string :as str]) (def hightemp (map #(str/split % #"\t") (str/split (slurp "http://www.cl.ecei.tohoku.ac.jp/nlp100/data/hightemp.txt") #"\n"))) (distinct (map #(first %) hightemp))
各行を3コラム目の数値の逆順で整列せよ(注意: 各行の内容は変更せずに並び替えよ).確認にはsortコマンドを用いよ(この問題はコマンドで実行した時の結果と合わなくてもよい).
(require '[clojure.string :as str]) (def hightemp (map #(str/split % #"\t") (str/split (slurp "http://www.cl.ecei.tohoku.ac.jp/nlp100/data/hightemp.txt") #"\n"))) (map println (map #(str/join "\t" %) (reverse (sort-by #(nth % 2) hightemp)))) ;; user => 高知県 江川崎 41 2013-08-12 ;; 岐阜県 多治見 40.9 2007-08-16 ;; 埼玉県 熊谷 40.9 2007-08-16 ;; 山形県 山形 40.8 1933-07-25 ;; 山梨県 甲府 40.7 2013-08-10
sort-by
の使い方にハマった。(sort-by keyfn coll)
なので、3コラム目を取得するような関数を渡せば良い。
各行の1列目の文字列の出現頻度を求め,その高い順に並べて表示せよ.確認にはcut, uniq, sortコマンドを用いよ.
(def hightemp (map #(str/split % #"\t") (str/split (slurp "http://www.cl.ecei.tohoku.ac.jp/nlp100/data/hightemp.txt") #"\n"))) (reverse (sort-by second (frequencies (map #(first %) hightemp)))) ;; user => (["山梨県" 3] ["埼玉県" 3] ["群馬県" 3] ["山形県" 3] ["愛知県" 2] ["岐阜県" 2] ["静岡県" 2] ["千葉県" 2] ["和歌山県" 1] ["高知県" 1] ["大阪府" 1] ["愛媛県" 1])
frequencies
関数はこの問題のためにあるような関数ですね。
簡単なアルゴリズムならCojureで書けるようになった。 100本ノックは、一旦終わりにする。
今後は、並列処理を中心に細かいトピックを拾っていきたいのと、どこかで使っていきたい。
Clojureで「言語処理100本ノック 2015」を解いてみようの続き。
"paraparaparadise"と"paragraph"に含まれる文字bi-gramの集合を,それぞれ, XとYとして求め,XとYの和集合,積集合,差集合を求めよ.さらに,'se'というbi-gramがXおよびYに含まれるかどうかを調べよ.
(require '[clojure.string :as str]) (use 'clojure.set) (defn n-gram [n target & cond] (if (= (first cond) "word") (map #(apply str %) (partition n 1 (str/split target #"\W+"))) (map #(apply str %) (partition n 1 (seq target))))) (def x (set (n-gram 2 "paraparaparadise"))) (def y (set (n-gram 2 "paragraph"))) x ; => #{"ad" "di" "is" "ap" "se" "ra" "ar" "pa"} y ; => #{"ph" "ap" "ag" "gr" "ra" "ar" "pa"} ; 和集合 (union x y) ; => #{"ad" "di" "is" "ph" "ap" "se" "ag" "gr" "ra" "ar" "pa"} ; 差集合 (difference x y) ; => #{"ad" "di" "is" "se"} ; 積集合 (intersection x y) ; => #{"ap" "ra" "ar" "pa"} ; 'se'というbi-gramがXおよびYに含まれるかどうか (contains? x "se") ; => true (contains? y "se") ; => false
引数x, y, zを受け取り「x時のyはz」という文字列を返す関数を実装せよ.さらに,x=12, y="気温", z=22.4として,実行結果を確認せよ.
(defn nlp07 [x y z] (println (str x "時の" y "は" z))) (nlp07 12 "気温" 22.4) ; => 12時の気温は22.4
与えられた文字列の各文字を,以下の仕様で変換する関数cipherを実装せよ.
英小文字ならば(219 - 文字コード)の文字に置換 その他の文字はそのまま出力 この関数を用い,英語のメッセージを暗号化・復号化せよ.
(require '[clojure.string :as str]) (defn cipher [input] (apply str (map #(cipher-convert %) (str/split input #"")))) (defn cipher-convert [input] (if-let [c (re-find #"[a-z]" input)] (char (- 219 (first (.getBytes c)))) input)) (cipher "Hello, world!") ; => "Hvool, dliow!" (cipher (cipher "Hello, world!")) ; => "Hello, world!"
スペースで区切られた単語列に対して,各単語の先頭と末尾の文字は残し,それ以外の文字の順序をランダムに並び替えるプログラムを作成せよ.ただし,長さが4以下の単語は並び替えないこととする.適当な英語の文(例えば"I couldn't believe that I could actually understand what I was reading : the phenomenal power of the human mind .")を与え,その実行結果を確認せよ.
Typoglycemiaとは、単語を構成する文字を並べ替えても、最初と最後の文字が合っていれば読めてしまう現象
らしい。
(require '[clojure.string :as str]) ; 先頭と最後を除く (defn middle [input] (rest (butlast input))) ; 各単語の先頭と末尾の文字は残し,それ以外の文字の順序をランダムに並び替える (defn typoglycemia-word [word] (str (first word) (apply str (shuffle (middle word))) (last word))) (defn typoglycemia [input] (if (>= (count input) 4) (typoglycemia-word input) input)) (str/join " " (map typoglycemia (str/split "I couldn't believe that I could actually understand what I was reading : the phenomenal power of the human mind ." #" "))) ; => "I clno'dut bleeive taht I cloud atclluay urntasednd waht I was ridneag : the peheaonnml poewr of the huamn mnid ."
以上で1章は終わり。
Clojureの基本的な文法にも慣れ、これくらいの処理であれば簡単にかけるようになった。