分類
好用軟體

如何利用vi快速刪除所有文字檔案內容?

在 linux 下最常用, 最好用, 最快速的文字編輯器是 vi, 不過要如何快速地將所有檔案內容刪除呢?

大家應該都知道指令 dd, 就是刪去一行, 刪去全部行則為先進入指令模式, 並下達 :1,$d 即可, 說明如下:

: 指令

1,$ 為指定行, 由 1 到 $ (指最後一行)

d 指令為刪除

所以若是要保留前 3行與最後 2行, 可以使用指令 :4,$-2d 即可.

參考資料:

https://unix.stackexchange.com/questions/161821/how-can-i-delete-all-lines-in-a-file-using-vi

Spotify Premium Family小小漲價了-不過有回饋一個月耶

收到了這封 mail:

你好:

 

自 2021 年 4 月 30 日起,我們將調漲 Premium Family 的價格,以便持續為你帶來全新內容與功能,如此一來,無論你是自己使用,或與家人一同使用,都能享受其中的便利*。

Premium Family 的價格將由每月 NT$240.00 調整至每月 NT$268.00。由於你已是 Premium Family 訂閱者,因此能以現有價格額外再使用 1 個月的服務**。 也就是說,新價格在 6 月的收費日期才會生效。
感謝你持續使用 Premium。

 

Spotify 團隊

原來是 Spotify Premium Family 漲價, 由於原來就是用家庭方案的 240元每月, 也就漲到了 268元每月, 不過官網上還沒有更新, 可以參考這裡: https://www.spotify.com/tw/premium/#plans

這次漲幅不算大約 11.67%, 但 Spotify 的服務真的很棒. (倒是不知個人版本有沒有漲到..)

分類
程式技術

因為url過長而導致破版的調整方式

由於在現行 css 預設結構下, url 不會主動斷行, 也就是有時過長的 url 會導致破版或出版的狀況.

如何解決這個問題, 可以利用 css 的手法來調整, 利用以下參數:

.dont-break-out {

  /* These are technically the same, but use both */
  overflow-wrap: break-word;
  word-wrap: break-word;

  -ms-word-break: break-all;
  /* This is the dangerous one in WebKit, as it breaks things wherever */
  word-break: break-all;
  /* Instead use this non-standard one: */
  word-break: break-word;

  /* Adds a hyphen where the word breaks, if supported (No Blink) */
  -ms-hyphens: auto;
  -moz-hyphens: auto;
  -webkit-hyphens: auto;
  hyphens: auto;

}

參考資料: https://css-tricks.com/snippets/css/prevent-long-urls-from-breaking-out-of-container/

分類
好用軟體

CapRover – 快速建立開發環境的 opensource PaaS

在架構系統時, 尤其現在有許多 opensource 程式架構, 可以很方便快速地部署環境, 不過若想要更容易、更方便一些, 可以參考這個架構 – CapRover: https://caprover.com/

基於快速建立開發環境與管理, 使用 CapRover 這個 PaaS 架構是十分方便好用的, 官網上寫著:

CapRover is an extremely easy to use app/database deployment & web server manager for your NodeJS, Python, PHP, ASP.NET, Ruby, MySQL, MongoDB, Postgres, WordPress (and etc…) applications!

而對於一個開發者來說:

  1. A developer who does not like spending hours and days setting up a server, build tools, sending code to server, build it, get an SSL certificate, install it, update nginx over and over again.
  2. A developer who uses expensive services like Heroku, Microsoft Azure and etc. And is interested in reducing their cost by 4x (Heroku charges 25$/month for their 1gb instance, the same server is 5$ on DigitalOcean!!)
  3. A developer who prefers to write more of showResults(getUserList()) and not much of apt-get install libstdc++6 > /dev/null
  4. A developer who enjoys a platform where installing MySQL, MongoDB and etc on their server is done by selecting from a dropdown and clicking on install!
  5. A developer who likes to enjoy the power of Docker and nginx without having to learn them or deal with their settings scripts to make things work!!
  6. A developer who knows Docker and nginx inside out, and enjoys a platform where basic operations are done, yet allowing them to customize any specific settings if they need to

以上的情境都是適合用這個 CapRover 來達成的測試與開發環境的建置的, 不需要花太多時間管理與維護, 隨時可以打開與關閉這些環境.

來看看介紹的影片:

(引用自: https://www.youtube.com/watch?v=VPHEXPfsvyQ)

很不錯吧, 快來試看看囉:

https://caprover.com/docs/get-started.html

分類
好用軟體

更輕量的CMS

在找看有沒有更輕量的CMS時, 發現有完全不用資料庫型態的CMS, 目前試了兩個:

其中 pico cms 還不是 html 而是使用了 md (markdown) 的靜態檔案的內容上架方式, 沒有管理介面.

而 WonderCMS 則是有管理介面, 可以做 page / blog post 型態的內容管理.

基本上這兩組 CMS 都不依賴資料庫, 訴求為快速又方便地做內容管理, 除了程式很小外, 也都有 theme / plugin 可供安裝擴充使用.

分類
懶得分類

國曆與農曆同日的計算-為什麼農曆每19年有7個閏月

由於國曆(陽曆)是以地球繞行一週為一年, 而農曆(陰曆)則是以月亮繞行一週為一個月, 而日的單位則為地球自轉一週為一日, 所以若需要同一日的算法如下:

平均一年為 365.2422日, 一個農曆月為 29.5306日, 以現行農曆每19年7個閏月來看, 共計 (19*12+7) * 29.5306 = 6939.691日.

而以19年國曆來看, 共計 19 * 365.2422 = 6939.608日, 所以若以農曆每19年7閏月來看, 則很有機會會同一日期, 若有前後差, 基本上與閏年有關, 所以會有一點落差.

可以參考:

分類
數學

pi (π)的一百萬位與找出你的 pi day

今天是圓週率日, 3/14, 來看看 python 下取得更多位數的圓週率 pi.

可以參考這篇: https://pypi.org/project/math-pi/

程式實作如下:

https://colab.research.google.com/drive/1K1tmZF7Uf2AyKRWVUvdsozQ7VP0eC0td?usp=sharing

不過它不是用計算的, 而是利用了另一個專案: https://pypi.org/project/pi-1mp/ 這個 pi 的 1百萬位數字來的, 所以無法取得多於 1百萬位.

另外比較有趣的是這個 find your pi day. 大家都知道 pi 是無理數, 所以各式各樣的數字排列都可以有機會被找到, 例如找自己的生日, 以周杰倫生日為例: 1979/1/18 可以利用:

分類
懶得分類

18TB的硬碟

這裡看來的:

https://www.techbang.com/posts/84544

單顆硬碟18TB了啊, 好大耶…

來看看一些之前的小記錄:

1TB的SD卡: https://diary.tw/archives/1554

1TB硬碟: https://diary.tw/archives/422

2TB硬碟: https://diary.tw/archives/746

分類
好用軟體

快速好用的大型文字記錄檔案檢視器-klogg

klogg 是基於 glogg 的一個分支開發專案, 有完整的圖型化介面與跨平台特性, 可以開啟大型的文字記錄檔, 非常快速方便, 尤其是在查找特定內容時, 可以利用 regular expression 的方式進行, 非常方便快速.

另外也可以當做即時的記錄檔檢視器, 因為在更新內容時, 會直接加入尾端, 方便檢視即時的記錄.

來看看他的介面吧:

上方為開啟的文字記錄檔, 下方則利用了 regular expression \/wp-cron 來查找 wordpress cron 的執行呼叫, 而右邊的紅色則是出現的頻次, 由於 cron 執行的算頻繁, 所以會整面紅紅的. 下方則是查找比對的結果, 而在檔案標籤上右側出現的藍色往下箭頭, 則是表示有新內容產生了.

官方網站: https://klogg.filimonov.dev/

而 glogg 可以參考這篇: https://edoswaldgo.com/software/glogg-best-free-multiplatform-log-viewer/

參考資料: https://stackoverflow.com/questions/159521/text-editor-to-open-big-giant-huge-large-text-files

 

 

[PHP]使用file_get_content來進行post request

在 php 程式中, 使用 curl 來進行 web request 是常用的方式, 不過由於在 https://repl.it/ 這個服務中, php webserver 並未安裝 curl, 所以需要改用 file_get_content()這個函數來進行 web request, 然而若為一般的 get request, 直接將網址傳入即可, 但若需要進行 post request 要如何操作呢?

這時會用到一個 http context options:

https://www.php.net/manual/en/context.http.php

範例程式如下:

<?php

$postdata = http_build_query(
    array(
        'var1' => 'some content',
        'var2' => 'doh'
    )
);

$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-Type: application/x-www-form-urlencoded',
        'content' => $postdata
    )
);

$context  = stream_context_create($opts);

$result = file_get_contents('http://example.com/submit.php', false, $context);

?>

也就是利用了 http context options 來組合出要傳遞的參數. 如此一來便能很快速地應用在僅有 file_get_contents() 環境而沒有 curl 的 php webserver 環境來進行 post request.

參考資料:

https://stackoverflow.com/questions/2445276/how-to-post-data-in-php-using-file-get-contents

https://www.php.net/manual/en/context.http.php