tag:blogger.com,1999:blog-33390052158369745472024-03-14T03:02:05.783+08:00Linux學習個人在學習Linux過程當中的個人筆記,提供個人及有需要的人查閱,若有錯誤歡迎提供指正,謝謝。
This Blog recorded notes about my learning Linux and provides myself and others reference. If there are any incorrect information, welcome to leave a message to correct me, Thanks.Unknownnoreply@blogger.comBlogger152125tag:blogger.com,1999:blog-3339005215836974547.post-40352327209424497512023-10-20T10:45:00.001+08:002023-10-20T10:45:15.823+08:00壞軌硬碟抓資料紀錄<p> 用到的Tool</p><p>chkdsk (在ptt看到壞軌的話最好不要用chkdsk,忘記安全移除的分區表錯誤才用這個)</p><p>photorec裡面的disktest,用Ubuntu iso的try Ubuntu感覺成功率較高</p><p>------------</p><p>可以考慮的tool</p><p>ddrescue (這種感覺比較恰當,不會一直去讀原硬碟,有可能造成更多壞軌,但要準備跟原硬碟一樣大的空間)</p><p>又ddrescue dump出image後再用mount的方式抓出檔案。</p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-24411458361724142182021-01-29T11:38:00.003+08:002021-01-29T11:38:35.203+08:00tmux資源收集<p>https://larrylu.blog/tmux-33a24e595fbc<br />基本介紹</p><p>https://github.com/gpakosz/.tmux<br />把介面弄得很漂亮</p><p>https://github.com/rothgar/awesome-tmux<br />一堆awesome</p><p><br /></p>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-46022273276591124292020-12-14T15:07:00.003+08:002021-01-29T11:39:30.849+08:00用python的regular expression做文字取代<p><a href="https://docs.python.org/3/library/re.html#re.sub" target="_blank">https://docs.python.org/3/library/re.html#re.sub</a></p><p>把 \ 之前的文字全部刪除</p><p>re.sub(r'^\S* \\ ', '',the_string)</p><p>在單引號之前的r但表單引號裡面的字串是regular expression</p><p>^ 是match字串的開頭</p><p>\S是match非空白的字元</p><p>*是只match前面的東西(\S)0到任意個</p><p>\\前面的\是跳脫字元,用來跳脫後面的字元\,後面的\被跳脫後就是指\本身了,用來match \。若沒跳脫的話(如前面的\)就會發揮他在reqular expression的作用(跳脫後面的字元)</p><p>----------</p><p>*</p><p>Causes the resulting RE to match 0 or more repetitions of the preceding RE, as many repetitions as are possible. ab* will match ‘a’, ‘ab’, or ‘a’ followed by any number of ‘b’s.</p><dt style="background-color: white; color: #222222; font-family: "Lucida Grande", Arial, sans-serif; font-size: 16px;"><code class="docutils literal notranslate" style="background-color: #ecf0f3; border-radius: 3px; font-family: monospace, sans-serif; font-size: 15.44px; padding: 0px 1px;"><span class="pre" style="hyphens: none;">\S</span></code></dt><dd style="background-color: white; color: #222222; font-family: "Lucida Grande", Arial, sans-serif; font-size: 16px; hyphens: auto; line-height: 20.8px; margin-bottom: 10px; margin-left: 30px; margin-top: 3px; text-align: justify;"><p style="hyphens: auto; line-height: 22.4px; margin-top: 0px;">Matches any character which is not a whitespace character. This is the opposite of <code class="docutils literal notranslate" style="background-color: #ecf0f3; border-radius: 3px; font-family: monospace, sans-serif; font-size: 15.44px; padding: 0px 1px;"><span class="pre" style="hyphens: none;">\s</span></code>. If the <a class="reference internal" href="https://docs.python.org/3/library/re.html#re.ASCII" style="color: #0072aa; text-decoration-line: none;" title="re.ASCII"><code class="xref py py-const docutils literal notranslate" style="background-color: transparent; border-radius: 3px; font-family: monospace, sans-serif; font-size: 15.44px; padding: 0px 1px;"><span class="pre" style="hyphens: none;">ASCII</span></code></a> flag is used this becomes the equivalent of <code class="docutils literal notranslate" style="background-color: #ecf0f3; border-radius: 3px; font-family: monospace, sans-serif; font-size: 15.44px; padding: 0px 1px;"><span class="pre" style="hyphens: none;">[^</span> <span class="pre" style="hyphens: none;">\t\n\r\f\v]</span></code>.</p></dd>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-3339005215836974547.post-86907804444476147542019-10-23T13:41:00.000+08:002020-01-23T15:14:32.725+08:00Gatsby製作Blog<a href="https://www.gatsbyjs.org/docs/adding-a-list-of-markdown-blog-posts/">https://www.gatsbyjs.org/docs/adding-a-list-of-markdown-blog-posts/</a><br />
<a href="https://codinghero.netlify.com/" target="_blank">https://codinghero.netlify.com/</a><br />
<br />
<br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-15138136194882914212019-10-22T20:48:00.000+08:002019-10-22T20:48:00.522+08:00定時排程刪除超過一定天數的檔案<a href="https://softwareengineering.stackexchange.com/questions/149824/automatically-delete-files-after-they-expire">https://softwareengineering.stackexchange.com/questions/149824/automatically-delete-files-after-they-expire</a><br />
<a href="https://superuser.com/questions/1072679/bash-what-does-means">https://superuser.com/questions/1072679/bash-what-does-means</a><br />
<a href="http://linux.vbird.org/linux_basic/0430cron.php">http://linux.vbird.org/linux_basic/0430cron.php</a><br />
<br />
<span style="background-color: #eff0f1; color: #242729; font-family: "consolas" , "menlo" , "monaco" , "lucida console" , "liberation mono" , "dejavu sans mono" , "bitstream vera sans mono" , "courier new" , monospace , sans-serif; font-size: 13px; white-space: pre-wrap;">find $search_path -atime +3 -exec rm {} \;</span><br />
<br />
加到crontab裡面<br />
# crontab -e<br />
<br />
{}的意思就是find輸出的結果會帶到rm的參數,\;是確保command結束符號,可用+取代Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-58050970245690103032019-07-24T11:41:00.000+08:002019-07-24T13:22:20.339+08:00pyenv-win 安裝與移除<a href="https://github.com/pyenv-win/pyenv-win" target="_blank">https://github.com/pyenv-win/pyenv-win</a><br />
<br />
1. Install<br />
<code>pip install pyenv-win --target %USERPROFILE%/.pyenv</code><br />
<code><br /></code>
<code>2. Add following to PATH enviroment variable</code><br />
<code><code>%USERPROFILE%\.pyenv\pyenv-win\bin;%USERPROFILE%\.pyenv\pyenv-win\shims;</code></code><br />
<code><br /></code><code>3. Add installed path in file easy_install.pth to site-packages folder(ex: C:\Users\Jack_Lin\AppData\Local\Programs\Python\Python37-32\Lib\site-packages).</code><br />
<code>Need to add absolute path, ex:</code><br />
<code>C:\Users\Jack_Lin\.pyenv in file easy_install.pth</code><br />
<code><br /></code><code>4. pip list to check pyenv-win is installed and recognize by pip</code><br />
<code><br /></code>
<code>5. upgrade</code><br />
<code>pip install --upgrade pyenv-win</code><br />
<code><br /></code><code>6. uninstall</code><br />
<code>pip uninstall pyenv-win</code>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-75427050714509665882019-06-14T12:25:00.001+08:002019-06-14T12:27:51.455+08:00如何push本地branch並覆蓋remote branch<br />
git push -f --set-upstream origin master<br />
<code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 16.2px; padding: 2px 4px;">git push -f</code><span style="background-color: white; color: #303233; font-family: Lato, "PingFang TC", "Helvetica Neue", Helvetica, 微軟正黑體, 新細明體, Arial, sans-serif; font-size: 18px;"> </span><code style="background-color: #f9f2f4; border-radius: 4px; box-sizing: border-box; color: #c7254e; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 16.2px; padding: 2px 4px;">要小心使用</code>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-18208489344737299802019-05-20T18:40:00.000+08:002019-05-20T18:40:03.654+08:00Scrapy學習筆記若要整合Django和Scrapy,可利用<a href="https://github.com/scrapy-plugins/scrapy-djangoitem" target="_blank">DjangoItem</a>,可節省定義Item的部分,讓Scrapy的Item定義自動去參照Django model,也可在Item增加欄位。<br />
<br />
ItemLoader的部分,預設add_value後,postprocessor都會以list為最後輸出結果,可更感post processor為TakeFirst。<br />
<br />
在Pipeline裡,若應用到DjangoItem,要先save後,在以Django model來操作 Foreign Key或是ManyToManyField部分。DjangoItem無法直接取得Django model內容。DjangoItem只是取去參考Django model,省去寫 field_xxx = scrapy.Field()而已。Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-52664602511772809092019-04-24T18:22:00.000+08:002019-04-24T18:22:10.277+08:00pandas Dataframe操作import pandas as pd<br />
df = pd.read_excel('b.xlsx', 'Acceptance')<br />
df[df['Config 3'].notna()]<br />
<br />
裡面的df['Config 3'].notna()是filter的方式,結果是列出所有Config13欄位不是na的 rows<br />
<br />
Pandas的Series是縱向的,例如某個Column的值的列表<br />
<br />
pandas兩個主要的data structure<br />
DataFrame和Series<br />
DataFrame就是Series的容器<br />
Series就是純量的容器<br />
<h3 style="background-color: #d8dee3; color: #212224; font-family: Arial, sans-serif; font-size: 17.28px; font-weight: normal; margin: 30px 0px 10px; padding: 5px 0px 5px 10px; text-shadow: white 0px 1px 0px;">
Indexing / Selection<a class="headerlink" href="https://pandas.pydata.org/pandas-docs/stable/getting_started/dsintro.html#indexing-selection" style="color: #c60f0f; font-size: 0.8em; padding: 0px 4px; text-decoration-line: none; visibility: hidden;" title="Permalink to this headline"></a></h3>
<div style="background-color: white; color: #3e4349; font-family: Arial, sans-serif; font-size: 14.4px; line-height: 1.5em;">
The basics of indexing are as follows:</div>
<table border="1" class="colwidths-given docutils" style="background-color: white; border-collapse: collapse; border: 0px; color: #3e4349; font-family: Arial, sans-serif; font-size: 14.4px;"><colgroup><col width="50%"></col><col width="33%"></col><col width="17%"></col></colgroup><thead style="vertical-align: bottom;" valign="bottom">
<tr class="row-odd" style="border: none; line-height: normal; max-width: none; padding: 0.5em; vertical-align: middle;"><th class="head" style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; text-align: left; vertical-align: middle;">Operation</th><th class="head" style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; text-align: left; vertical-align: middle;">Syntax</th><th class="head" style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; text-align: left; vertical-align: middle;">Result</th></tr>
</thead><tbody valign="top">
<tr class="row-even" style="background: rgb(245, 245, 245); border: none; line-height: normal; max-width: none; padding: 0.5em; vertical-align: middle;"><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; vertical-align: middle;">Select column</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; vertical-align: middle;"><code class="docutils literal notranslate"><span class="pre" style="hyphens: none;">df[col]</span></code></td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; vertical-align: middle;">Series</td></tr>
<tr class="row-odd" style="border: none; line-height: normal; max-width: none; padding: 0.5em; vertical-align: middle;"><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; vertical-align: middle;">Select row by label</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; vertical-align: middle;"><code class="docutils literal notranslate"><span class="pre" style="hyphens: none;">df.loc[label]</span></code></td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; vertical-align: middle;">Series</td></tr>
<tr class="row-even" style="background: rgb(245, 245, 245); border: none; line-height: normal; max-width: none; padding: 0.5em; vertical-align: middle;"><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; vertical-align: middle;">Select row by integer location</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; vertical-align: middle;"><code class="docutils literal notranslate"><span class="pre" style="hyphens: none;">df.iloc[loc]</span></code></td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; vertical-align: middle;">Series</td></tr>
<tr class="row-odd" style="border: none; line-height: normal; max-width: none; padding: 0.5em; vertical-align: middle;"><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; vertical-align: middle;">Slice rows</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; vertical-align: middle;"><code class="docutils literal notranslate"><span class="pre" style="hyphens: none;">df[5:10]</span></code></td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; vertical-align: middle;">DataFrame</td></tr>
<tr class="row-even" style="background: rgb(245, 245, 245); border: none; line-height: normal; max-width: none; padding: 0.5em; vertical-align: middle;"><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; vertical-align: middle;">Select rows by boolean vector</td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; vertical-align: middle;"><code class="docutils literal notranslate"><span class="pre" style="hyphens: none;">df[bool_vec]</span></code></td><td style="border-bottom-color: rgb(170, 170, 170); border-bottom-style: solid; border-image: initial; border-left-color: initial; border-left-style: initial; border-right-color: initial; border-right-style: initial; border-top-color: initial; border-top-style: initial; border-width: 0px 0px 1px; line-height: normal; max-width: none; padding: 1px 8px 1px 5px; vertical-align: middle;">DataFrame</td></tr>
</tbody></table>
<br /><div>
如果要一個row一個row去做動作</div>
<div>
<a href="https://stackoverflow.com/questions/16476924/how-to-iterate-over-rows-in-a-dataframe-in-pandas">https://stackoverflow.com/questions/16476924/how-to-iterate-over-rows-in-a-dataframe-in-pandas</a></div>
<div>
df.iterrows()</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-56041715094989122192019-03-26T10:23:00.002+08:002019-03-26T10:23:30.089+08:00inotify-tools監測資料夾<a href="https://www.howtogeek.com/405468/how-to-perform-a-task-when-a-new-file-is-added-to-a-directory-in-linux/amp/" target="_blank">https://www.howtogeek.com/405468/how-to-perform-a-task-when-a-new-file-is-added-to-a-directory-in-linux/amp/</a><br />
<br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-4661761264856303982019-03-07T16:25:00.003+08:002019-03-07T16:25:58.124+08:00Delopy Django project on Ubuntu 1804 with mod_wsgi<span style="background-color: #fff9ee; color: #222222; font-family: Georgia, Utopia, "Palatino Linotype", Palatino, serif; font-size: 15.4px;">1. Install apache2 & postgresql</span><br style="background-color: #fff9ee; color: #222222; font-family: Georgia, Utopia, "Palatino Linotype", Palatino, serif; font-size: 15.4px;" /><span style="background-color: #fff9ee; color: #222222; font-family: Georgia, Utopia, "Palatino Linotype", Palatino, serif; font-size: 15.4px;">2. Install mod_wsgi</span><br style="background-color: #fff9ee; color: #222222; font-family: Georgia, Utopia, "Palatino Linotype", Palatino, serif; font-size: 15.4px;" /><span style="background-color: #fff9ee; color: #222222; font-family: Georgia, Utopia, "Palatino Linotype", Palatino, serif; font-size: 15.4px;"># sudo apt install libapache2-mod-wsgi-py3</span><br style="background-color: #fff9ee; color: #222222; font-family: Georgia, Utopia, "Palatino Linotype", Palatino, serif; font-size: 15.4px;" /><span style="background-color: #fff9ee; color: #222222; font-family: Georgia, Utopia, "Palatino Linotype", Palatino, serif; font-size: 15.4px;">3. Create a Python3 virtualenv</span><br style="background-color: #fff9ee; color: #222222; font-family: Georgia, Utopia, "Palatino Linotype", Palatino, serif; font-size: 15.4px;" /><span style="background-color: #fff9ee; color: #222222; font-family: Georgia, Utopia, "Palatino Linotype", Palatino, serif; font-size: 15.4px;"># mkvirtualenv -p $(which python3) django & psycopg2-binary</span><br style="background-color: #fff9ee; color: #222222; font-family: Georgia, Utopia, "Palatino Linotype", Palatino, serif; font-size: 15.4px;" /><span style="background-color: #fff9ee; color: #222222; font-family: Georgia, Utopia, "Palatino Linotype", Palatino, serif; font-size: 15.4px;">(django)# pip install django</span><br />
<span style="background-color: #fff9ee; color: #222222; font-family: Georgia, Utopia, "Palatino Linotype", Palatino, serif; font-size: 15.4px;">(django)# pip install psycopg2-binary</span><br />
4. Enter into project folder. /home/jack/Documents/Projects/myproject<br />
5. Install Requirement python package<br />
(django) # pip install -r requirements.txt<br style="background-color: #fff9ee;" /><span style="background-color: #fff9ee; color: #222222; font-family: Georgia, Utopia, "Palatino Linotype", Palatino, serif; font-size: 15.4px;">6. Note that the wsgi.py is put on /home/jack/Documents/Projects/myproject/myproject</span><br />
<span style="background-color: #fff9ee; color: #222222; font-family: Georgia, Utopia, "Palatino Linotype", Palatino, serif; font-size: 15.4px;">7. Edit settings.py in ./myproject</span><br />
Add ALLOWED_HOSTS = ['*',]<br />
(This is risky)<br />
Add STATIC_ROOT = '/home/jack/Documents/Projects/myproject/static'<br />
8. Setup Postgresql database correctly & create a database in it.<br />
9. Edit settings.py to meet the database you want to use.<br />
10. Database Migrate & collectstatic<br />
(django) # python manage.py migrate<br />
(django) # python manage.py collectstatic<br />
11. create a new conf in /etc/apache2/site-available myproject.conf with sudo<br />
<virtualhost></virtualhost><br />
ServerName myproject<br />
Alias /robots.txt /home/jack/Documents/Projects/myproject/static/static/robots.txt<br />
Alias /favicon.ico /home/jack/Documents/Projects/myproject/static/favicon.ico<br />
Alias /static/ /home/jack/Documents/Projects/myproject/static/<br />
<directory home="" jack="" myproject="" ocuments="" rojects="" static=""></directory><br />
Require all granted<br />
<br />
WSGIDaemonProcess django python-home=/home/jack/.virtualenvs/django/ python-path=/home/jack/Documents/Projects/myproject/<br />
WSGIScriptAlias / /home/jack/Documents/Projects/myproject/myproject/wsgi.py<br />
WSGIProcessGroup django<br />
<directory home="" jack="" myproject="" ocuments="" rojects=""></directory><br />
<files wsgi.py=""></files><br />
Require all granted<br />
<br />
<br />
<br />
<div>
12. Edit /etc/apache2/ports.conf, Add a line</div>
<div>
Listen 4002</div>
<div>
13. Enable the site & reload</div>
<div>
# sudo a2ensite myproject</div>
<div>
# sudo systemctl reload apache2</div>
<div>
14. Allow port 4002 in Firewall</div>
<div>
# sudo ufw allow 4002</div>
<div>
<br /></div>
<br />
Reference:<br />
<a href="https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/" target="_blank">https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/</a><br />
<a href="https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/" target="_blank">https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-41092848431879883432018-10-22T14:29:00.003+08:002018-10-22T14:29:36.963+08:00TestLink setup on CentOS 7#Install PostgreSQL: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-centos-7<br /># sudo yum install postgresql-server postgresql-contrib<br /># sudo postgresql-setup initdb<br /># sudo systemctl start postgresql<br /># sudo systemctl enable postgresql<br /><br /><a href="https://dotblogs.com.tw/jovepaterlab/2017/04/17/222958" target="_blank">https://dotblogs.com.tw/jovepaterlab/2017/04/17/222958</a><br />[root@localhost peter]# su - postgres<br />-bash-4.2$ psql -U postgres<br />psql (9.6.2)<br />Type "help" for help.<br /><br />postgres=# ALTER USER postgres WITH PASSWORD 'password'<br />postgres-# \q<br />-bash-4.2$ exit<br />logout<br /><br />Edit /var/lib/pgsql/data/pg_hba.conf<br />local all all md5<br />host all all 127.0.0.1/32 md5<br />host all all ::1/128 md5<br /><span id="goog_216088403"></span><br /><a href="https://www.tecmint.com/install-php-7-in-centos-7/" target="_blank">https://www.tecmint.com/install-php-7-in-centos-7/</a><span id="goog_216088404"></span><br /># yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm<br /># yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm<br /># yum-config-manager --enable remi-php72<br /># yum install php php-mcrypt php-cli php-gd php-curl php-pgsql php-ldap php-zip php-fileinfo <br /># php -v<br /><br />Enable Apache2<br /># systemctl start httpd<br /># systemctl enable httpd<br /><br />Edit /etc/php.ini<br />session.gc_maxlifetime = 2400<br />max_input_vars = 3000<br />memory_limit = 256M<br />upload_max_filesize = 20M<br />max_execution_time = 120<br /><br /><br />Set MySQL password<br />mysqladmin -u root password password<br /><br /># Copy Testlink source code<br /># wget -e use_proxy=yes -e https_proxy=jack_lin3.compal.com:3128 https://github.com/TestLinkOpenSourceTRMS/testlink-code/archive/testlink_1_9.zip<br /> 47 unzip<br /># unzip testlink_1_9.zip -d /var/www/html/<br /># cd /var/www/html/<br /># ls<br /># mv testlink-code-testlink_1_9/ testlink/<br /># ls<br /># chown -R apache:apache testlink<br />mkdir /var/testlink<br />mkdir /var/testlink/logs<br />mkdir /var/testlink/upload_area<br />chown apache:apache /var/testlink/logs<br />chown apache:apache /var/testlink/upload_area<br /><br /><br />Check firewall setting<br /><a href="https://linuxhint.com/list_open_ports_firewalld/" target="_blank">https://linuxhint.com/list_open_ports_firewalld/</a><br /><a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-using-firewalld-on-centos-7" target="_blank">https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-using-firewalld-on-centos-7</a><br /><br />Add http service in firewall<br /># sudo firewall-cmd --zone=public --permanent --add-service=http<br /><br /><a href="https://stackoverflow.com/questions/12416879/testlink-installation-failed-checking-if-var-testlink-logs-directory-exists">link1</a><br /><a href="https://blog.csdn.net/sapphire_sky/article/details/51088856" target="_blank">link2</a><br /># sudo chcon -Rv --type httpd_sys_rw_content_t /var/www/html/testlink/gui/templates_c<br />##### chcon -Rv --type httpd_sys_rw_content_t /var/www/html/testlink<br />https://tripal.info/tutorials/v3.x/installation/server-setup/centos7<br /># setsebool -P httpd_can_network_connect_db on<br /><br />Remove line 872~879<br />/install/sql/postgres/testlink_create_tables.sql<br /><a href="https://github.com/TestLinkOpenSourceTRMS/testlink-code/blob/testlink_1_9/install" target="_blank">https://github.com/TestLinkOpenSourceTRMS/testlink-code/blob/testlink_1_9/install</a>/sql/postgres/testlink_create_tables.sql<br /><br /><br />Open http://<ip>/testlink, Follow steps to install.<br /><br />YOU NEED TO RUN MANUALLY Following Script on your DB CLIENT Application<br /><br />/var/www/html/testlink/install/sql/postgres/testlink_create_udf0.sql<br /><br /><br />YOUR ATTENTION PLEASE:<br />To have a fully functional installation You need to configure mail server settings, following this steps<br /><br /> copy from config.inc.php, [SMTP] Section into custom_config.inc.php.<br /> complete correct data regarding email addresses and mail server.<br /><br /><br />Installation was successful!<br />You can now log in to Testlink (using login name:admin / password:admin - Please Click Me!).<br /><br /></ip>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-60903324761749367092018-10-18T14:19:00.002+08:002018-10-18T14:36:01.462+08:00Deploying Flask App with mod_wsgi (Python3) in Ubuntu 18041. Install apache2<br />
2. Install mod_wsgi<br />
# sudo apt install libapache2-mod-wsgi-py3<br />
3. Create a Python3 virtualenv with Flask installed<br />
# mkvirtualenv -p $(which python3) flask<br />
(flask)# pip install flask<br />
4. Create a .wsgi file for project (put in project folder)<br />
newsite.wsgi:<br />
<br />
activate_this = '/home/jack/.virtualenvs/flask/bin/activate_this.py'<br />
with open(activate_this) as file_:<br />
exec(file_.read(), dict(__file__=activate_this))<br />
import sys<br />
sys.path.insert(0, '/home/jack/Documents/Projects/newsite')<br />
from app import app as application<br />
<br />
5. Open Apache2 ports. Edit file /etc/apache2/ports.conf<br />
<br />
Listen 4002<br />
<br />
6. Create a file for new site in /etc/apache2/sites-available<br />
newsite.conf:<br />
<br />
<virtualhost><br /> ServerName newsite<br /><br /> WSGIDaemonProcess newsite user=jack group=jack threads=5<br /> WSGIScriptAlias / /home/jack/Documents/Projects/newsite/newsite.wsgi<br /><br /> <directory flaskr="" home="" jack="" ocuments="" rojects=""><br /> WSGIProcessGroup newsite<br /> WSGIApplicationGroup %{GLOBAL}<br /> Require all granted<br /> </directory></virtualhost><br />
<br />
7. Enable the newsite<br />
# sudo a2ensite newsite<br />
(a2dissite for disable)<br />
<br />
8. Reload the Apache2<br />
# sudo systemctl reload apache2<br />
<br />
9. Allow port 4002 by ufw<br />
# sudo ufw allow 4002<br />
(sudo ufw delete allow 4002) to disable<br />
<br />
10. Open broswer to browse http://<ip>:4002</ip><br />
<br />
Note1. Apache2 error log is in /var/log/apache2/error.log<br />
<br />
Note2. If you are using open() in app.py, need to instead to app.open_resource() to prevent FileNotFoundException<br />
<br />
Reference:<br />
http://flask.pocoo.org/docs/1.0/deploying/mod_wsgi/<br />
http://flask.pocoo.org/docs/0.12/api/#flask.Flask.open_resource <br />
<br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-87173353313414983492018-08-16T17:04:00.003+08:002018-08-16T17:04:54.526+08:00iSCSI target setup (Ubuntu)<a href="https://www.server-world.info/en/note?os=Ubuntu_18.04&p=iscsi&f=1" target="_blank">https://www.server-world.info/en/note?os=Ubuntu_18.04&p=iscsi&f=1</a><br />
<a href="https://wiki.archlinux.org/index.php/ISCSI/LIO" target="_blank">https://wiki.archlinux.org/index.php/ISCSI/LIO</a><br />
<br />
<div class="block" style="background-color: #191919; color: white; font-family: Consolas, "Courier New", Courier, Monaco, monospace; font-size: 14px; font-weight: 700; margin: 0px 0px 21px; padding: 0px;">
<div class="color2" style="color: lightpink; display: inline; margin: 0px; padding: 0px;">
# create a directory</div>
<br style="margin: 0px; padding: 0px;" />root@dlp:~# <div class="color1" style="color: palegreen; display: inline; margin: 0px; padding: 0px;">
<a href="https://www.server-world.info/en/command/html/mkdir.html" style="color: yellow; margin: 0px; padding: 0px; text-decoration-line: none;">mkdir</a> /var/lib/iscsi_disks </div>
</div>
<div class="color2" style="background-color: #191919; color: lightpink; display: inline; font-family: Consolas, "Courier New", Courier, Monaco, monospace; font-size: 14px; font-weight: 700; margin: 0px; padding: 0px;">
# enter the admin console</div>
<br style="background-color: #191919; color: white; font-family: Consolas, "Courier New", Courier, Monaco, monospace; font-size: 14px; font-weight: 700; margin: 0px; padding: 0px;" /><span style="background-color: #191919; color: white; font-family: Consolas, "Courier New", Courier, Monaco, monospace; font-size: 14px; font-weight: 700;">root@dlp:~# </span><br />
<div class="color1" style="background-color: #191919; color: palegreen; display: inline; font-family: Consolas, "Courier New", Courier, Monaco, monospace; font-size: 14px; font-weight: 700; margin: 0px; padding: 0px;">
targetcli </div>
<br style="background-color: #191919; color: white; font-family: Consolas, "Courier New", Courier, Monaco, monospace; font-size: 14px; font-weight: 700; margin: 0px; padding: 0px;" />
<pre style="background-color: #191919; color: white; font-family: Consolas, "Courier New", Courier, Monaco, monospace; font-size: 14px; font-weight: 700; letter-spacing: 0px; padding: 0px; white-space: pre-wrap; word-break: break-all;">targetcli shell version 2.1.fb43
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> <span class="color1" style="color: palegreen; display: inline; margin: 0px; padding: 0px;">cd backstores/fileio </span>
<span class="color2" style="color: lightpink; display: inline; margin: 0px; padding: 0px;"># create a disk-image with the name "disk01" on /var/lib/iscsi_disks/disk01.img with 10G</span>
/backstores/fileio> <span class="color1" style="color: palegreen; display: inline; margin: 0px; padding: 0px;">create disk01 /var/lib/iscsi_disks/disk01.img 10G </span>
Created fileio disk01 with size 10737418240
/backstores/fileio> <span class="color1" style="color: palegreen; display: inline; margin: 0px; padding: 0px;">cd /iscsi </span>
<span class="color2" style="color: lightpink; display: inline; margin: 0px; padding: 0px;"># create a target</span>
<span class="color2" style="color: lightpink; display: inline; margin: 0px; padding: 0px;"># naming rule : [ iqn.(year)-(month).(reverse of domain name):(any name you like) ]</span>
/iscsi> <span class="color1" style="color: palegreen; display: inline; margin: 0px; padding: 0px;">create iqn.2018-05.world.srv:dlp.target01 </span>
Created target iqn.2018-05.world.srv:dlp.target01.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> <span class="color1" style="color: palegreen; display: inline; margin: 0px; padding: 0px;">cd iqn.2018-05.world.srv:dlp.target01/tpg1/luns </span>
<span class="color2" style="color: lightpink; display: inline; margin: 0px; padding: 0px;"># set LUN</span>
/iscsi/iqn.20...t01/tpg1/luns> <span class="color1" style="color: palegreen; display: inline; margin: 0px; padding: 0px;">create /backstores/fileio/disk01 </span>
Created LUN 0.
/iscsi/iqn.20...t01/tpg1/luns> <span class="color1" style="color: palegreen; display: inline; margin: 0px; padding: 0px;">cd ../acls </span>
<span class="color2" style="color: lightpink; display: inline; margin: 0px; padding: 0px;"># set ACL (it's the IQN of an initiator you permit to connect)</span>
/iscsi/iqn.20...t01/tpg1/acls> <span class="color1" style="color: palegreen; display: inline; margin: 0px; padding: 0px;">create iqn.2018-05.world.srv:www.initiator01 </span>
Created Node ACL for iqn.2018-05.world.srv:www.initiator01
Created mapped LUN 0.
/iscsi/iqn.20...t01/tpg1/acls> <span class="color1" style="color: palegreen; display: inline; margin: 0px; padding: 0px;">cd iqn.2018-05.world.srv:www.initiator01 </span>
<span class="color2" style="color: lightpink; display: inline; margin: 0px; padding: 0px;"># set UserID for authentication</span>
/iscsi/iqn.20...w.initiator01> <span class="color1" style="color: palegreen; display: inline; margin: 0px; padding: 0px;">set auth userid=username </span>
Parameter userid is now 'username'.
/iscsi/iqn.20...w.initiator01> <span class="color1" style="color: palegreen; display: inline; margin: 0px; padding: 0px;">set auth password=password </span>
Parameter password is now 'password'.
/iscsi/iqn.20...w.initiator01> <span class="color1" style="color: palegreen; display: inline; margin: 0px; padding: 0px;">exit </span>
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/rtslib-fb-target/backup.
Configuration saved to /etc/rtslib-fb-target/saveconfig.json
</pre>
<div class="color2" style="background-color: #191919; color: lightpink; display: inline; font-family: Consolas, "Courier New", Courier, Monaco, monospace; font-size: 14px; font-weight: 700; margin: 0px; padding: 0px;">
# after configuration above, the target enters in listening like follows</div>
<br style="background-color: #191919; color: white; font-family: Consolas, "Courier New", Courier, Monaco, monospace; font-size: 14px; font-weight: 700; margin: 0px; padding: 0px;" /><span style="background-color: #191919; color: white; font-family: Consolas, "Courier New", Courier, Monaco, monospace; font-size: 14px; font-weight: 700;">root@dlp:~# </span><br />
<div class="color1" style="background-color: #191919; color: palegreen; display: inline; font-family: Consolas, "Courier New", Courier, Monaco, monospace; font-size: 14px; font-weight: 700; margin: 0px; padding: 0px;">
<a href="https://www.server-world.info/en/command/html/ss.html" style="color: yellow; margin: 0px; padding: 0px; text-decoration-line: none;">ss</a> -napt | grep 3260 </div>
<br style="background-color: #191919; color: white; font-family: Consolas, "Courier New", Courier, Monaco, monospace; font-size: 14px; font-weight: 700; margin: 0px; padding: 0px;" />
<pre style="background-color: #191919; color: white; font-family: Consolas, "Courier New", Courier, Monaco, monospace; font-size: 14px; font-weight: 700; letter-spacing: 0px; padding: 0px; white-space: pre-wrap; word-break: break-all;">LISTEN 0 256 0.0.0.0:3260 0.0.0.0:* </pre>
<br />
<h4 style="background: none rgb(255, 255, 255); border-bottom: 0px; color: #222222; font-family: sans-serif; font-size: 14px; line-height: 1.6; margin: 0.3em 0px 0px; overflow: hidden; padding-bottom: 0px; padding-top: 0.5em;">
<span class="mw-headline" id="Disable_Authentication">Disable Authentication</span></h4>
<div style="background-color: white; color: #222222; font-family: sans-serif; font-size: 14px; line-height: inherit; margin-bottom: 0.5em; margin-top: 0.5em;">
Navigate targetcli to your target (i.e. /iscsi/iqn.../tpg1) and:</div>
<pre style="background-color: #ebf1f5; border: 1px solid rgb(187, 204, 221); color: #222222; line-height: 1.3em; overflow: auto; padding: 1em; white-space: pre-wrap !important; word-break: break-all;">.../tpg1> set attribute authentication=0</pre>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-59702753525962326542018-07-12T13:09:00.001+08:002018-07-12T13:09:40.027+08:00Samba on Ubuntu<a href="https://linuxconfig.org/how-to-configure-samba-server-share-on-ubuntu-18-04-bionic-beaver-linux" target="_blank">Ref</a><br />
<br />
# apt install samba<br />
# edit /etc/samba/smb.conf<br />
create folder<br />
# mkdir /var/samba<br />
# chmod 777 /var/samba<br />
<br />
Add this:<br />
[public]<br />
comment = public anonymous access<br />
path = /var/samba/<br />
browsable =yes<br />
create mask = 0666<br />
directory mask = 0777<br />
writable = yes<br />
guest ok = yes<br />
<br />
# systemctl restart smbdUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-32197024913288332212018-07-10T14:58:00.002+08:002018-07-12T11:16:18.089+08:00HTTPS on Ubuntu 1804 (use default-ssl.conf)# sudo -i<br />
# apt install apache2<br />
# a2enmod ssl<br />
# a2ensite default-ssl.conf<br />
# systemctl restart apache2<br />
<br />
config files in /etc/apache2/sites-available<br />
log files in /var/log/apache2/<br />
<br />
use browser to browse https://<the-server-ip></the-server-ip>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-17025277829674065552018-06-28T14:01:00.001+08:002018-06-28T14:39:16.338+08:00用Flask-SQLAlchemy把Model定義獨立到models.py<a href="https://stackoverflow.com/questions/9692962/flask-sqlalchemy-import-context-issue/9695045#9695045">https://stackoverflow.com/questions/9692962/flask-sqlalchemy-import-context-issue/9695045#9695045</a><br />
<br />
models.py<br />
=====<br />
<div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;">
<div>
<span style="color: #c586c0;">from</span> flask_sqlalchemy <span style="color: #c586c0;">import</span> SQLAlchemy</div>
<div>
<span style="color: #c586c0;">from</span> datetime <span style="color: #c586c0;">import</span> datetime</div>
<br /><div>
db = SQLAlchemy()</div>
<br /><div>
<span style="color: #569cd6;">class</span> <span style="color: #4ec9b0;">User</span>(<span style="color: #4ec9b0;">db</span>.<span style="color: #4ec9b0;">Model</span>):</div>
<div>
<span style="color: #dcdcaa;">id</span> = db.Column(db.Integer, <span style="color: #9cdcfe;">primary_key</span>=<span style="color: #569cd6;">True</span>)</div>
<div>
username = db.Column(db.String(<span style="color: #b5cea8;">80</span>), <span style="color: #9cdcfe;">unique</span>=<span style="color: #569cd6;">True</span>, <span style="color: #9cdcfe;">nullable</span>=<span style="color: #569cd6;">False</span>)</div>
<div>
email = db.Column(db.String(<span style="color: #b5cea8;">120</span>), <span style="color: #9cdcfe;">unique</span>=<span style="color: #569cd6;">True</span>, <span style="color: #9cdcfe;">nullable</span>=<span style="color: #569cd6;">False</span>)</div>
<br /><div>
<span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">__repr__</span>(<span style="color: #9cdcfe;">self</span>):</div>
<div>
<span style="color: #c586c0;">return</span> <span style="color: #ce9178;">'<user span=""><span style="color: #569cd6;">%r</span><span style="color: #ce9178;">>'</span> % <span style="color: #569cd6;">self</span>.username</user></span></div>
<br /><div>
<span style="color: #569cd6;">class</span> <span style="color: #4ec9b0;">Post</span>(<span style="color: #4ec9b0;">db</span>.<span style="color: #4ec9b0;">Model</span>):</div>
<div>
<span style="color: #dcdcaa;">id</span> = db.Column(db.Integer, <span style="color: #9cdcfe;">primary_key</span>=<span style="color: #569cd6;">True</span>)</div>
<div>
title = db.Column(db.String(<span style="color: #b5cea8;">80</span>), <span style="color: #9cdcfe;">nullable</span>=<span style="color: #569cd6;">False</span>)</div>
<div>
body = db.Column(db.Text, <span style="color: #9cdcfe;">nullable</span>=<span style="color: #569cd6;">False</span>)</div>
<div>
json = db.Column(db.JSON)</div>
<div>
pub_date = db.Column(db.DateTime, <span style="color: #9cdcfe;">nullable</span>=<span style="color: #569cd6;">False</span>,</div>
<div>
<span style="color: #9cdcfe;">default</span>=datetime.utcnow)</div>
<br /><div>
category_id = db.Column(db.Integer, db.ForeignKey(<span style="color: #ce9178;">'category.id'</span>),</div>
<div>
<span style="color: #9cdcfe;">nullable</span>=<span style="color: #569cd6;">False</span>)</div>
<div>
category = db.relationship(<span style="color: #ce9178;">'Category'</span>,</div>
<div>
<span style="color: #9cdcfe;">backref</span>=db.backref(<span style="color: #ce9178;">'posts'</span>, <span style="color: #9cdcfe;">lazy</span>=<span style="color: #569cd6;">True</span>))</div>
<br /><div>
<span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">__repr__</span>(<span style="color: #9cdcfe;">self</span>):</div>
<div>
<span style="color: #c586c0;">return</span> <span style="color: #ce9178;">'<post span=""><span style="color: #569cd6;">%r</span><span style="color: #ce9178;">>'</span> % <span style="color: #569cd6;">self</span>.title</post></span></div>
<br /><div>
<span style="color: #569cd6;">class</span> <span style="color: #4ec9b0;">Category</span>(<span style="color: #4ec9b0;">db</span>.<span style="color: #4ec9b0;">Model</span>):</div>
<div>
<span style="color: #dcdcaa;">id</span> = db.Column(db.Integer, <span style="color: #9cdcfe;">primary_key</span>=<span style="color: #569cd6;">True</span>)</div>
<div>
name = db.Column(db.String(<span style="color: #b5cea8;">50</span>), <span style="color: #9cdcfe;">nullable</span>=<span style="color: #569cd6;">False</span>)</div>
<br /><div>
<span style="color: #569cd6;">def</span> <span style="color: #dcdcaa;">__repr__</span>(<span style="color: #9cdcfe;">self</span>):</div>
<div>
<span style="color: #c586c0;">return</span> <span style="color: #ce9178;">'<category span=""><span style="color: #569cd6;">%r</span><span style="color: #ce9178;">>'</span> % <span style="color: #569cd6;">self</span>.name</category></span></div>
</div>
<br />
<br />
app.py<br />
======<br />
<div style="background-color: #1e1e1e; color: #d4d4d4; font-family: Consolas, "Courier New", monospace; font-size: 14px; line-height: 19px; white-space: pre;">
<div>
<span style="color: #c586c0;">from</span> flask <span style="color: #c586c0;">import</span> Flask</div>
<div>
<span style="color: #608b4e;"># from flask_sqlalchemy import SQLAlchemy</span></div>
<div>
<span style="color: #c586c0;">from</span> flask_admin <span style="color: #c586c0;">import</span> Admin</div>
<div>
<span style="color: #c586c0;">from</span> flask_admin.contrib.sqla <span style="color: #c586c0;">import</span> ModelView</div>
<div>
<span style="color: #c586c0;">from</span> models <span style="color: #c586c0;">import</span> db, User, Post, Category</div>
<br /><div>
app = Flask(<span style="color: #9cdcfe;">__name__</span>)</div>
<div>
<span style="color: #608b4e;">#app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'</span></div>
<div>
app.config[<span style="color: #ce9178;">'SQLALCHEMY_DATABASE_URI'</span>] = <span style="color: #ce9178;">'postgresql:///jack'</span></div>
<div>
app.config[<span style="color: #ce9178;">'SQLALCHEMY_TRACK_MODIFICATIONS'</span>] = <span style="color: #569cd6;">False</span></div>
<div>
<span style="color: #608b4e;"># db = SQLAlchemy(app)</span></div>
<div>
db.init_app(app)</div>
<div>
admin = Admin(app, <span style="color: #9cdcfe;">name</span>=<span style="color: #ce9178;">'flask-sql'</span>, <span style="color: #9cdcfe;">template_mode</span>=<span style="color: #ce9178;">'bootstrap3'</span>)</div>
<br /><div>
admin.add_view(ModelView(User, db.session))</div>
<div>
admin.add_view(ModelView(Post, db.session))</div>
<div>
admin.add_view(ModelView(Category, db.session))</div>
</div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-80651369677902584252018-06-22T11:23:00.000+08:002018-06-22T11:23:07.872+08:00Ubuntu install postgresql & flask-sqlalchemy# sudo apt install postgresql<br />
# sudo systemctl enable postgresql<br />
# sudo -i -u postgres<br />
# createuser --interactive<br />
jack<br />
y<br />
Note. already have a user named jack<br />
# createdb jack<br />
Note. create a database named jack.<br />
logout from postgres<br />
#logout<br />
<br />
Edit the Flask app.py<br />
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///jack'<br />
<br />
You can save JSON type now<br />
json = db.Column(db.JSON)Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-52488872795399147382018-06-21T16:49:00.000+08:002018-06-21T16:49:51.672+08:00遇到密碼對 可是登不進sshCheck the log in /var/log/auth.log<br />
$ grep sshd /var/log/auth.log | less<br />
看到<br />
sshd[2110]: User jack not allowed because shell /usr/bin/zsh does not exist<br />
<br />
可能是之前有安裝過zsh但是沒有移乾淨<br />
下env | grep SHELL看到的確是/usr/bin/zsh<br />
<br />
用chsh指令改<br />
$ sudo chsh -s /bin/bash jack<br />
解決不能登入ssh問題<br />
<div>
<br /></div>
Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-3118274486569688302018-06-21T09:53:00.000+08:002018-06-21T09:53:46.929+08:00Robotframework 變數檔案使用-V <yaml file=""> 參數</yaml><br />
<br />
# robot -V vars.yaml a.robot<br />
<br />
vars.yaml內容<br />
BMC_IP: 172.16.1.16<br />
<br />
For using "Library Dialogs"<br />
apt-get install python3-tk<br />
pip intall tkinterUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-86975236129756371172018-05-18T15:52:00.000+08:002019-03-23T13:12:20.151+08:00Setup Python3 develop environment on Ubuntu Server 18041. Install Ubuntu Server 1804<br />
2. Install pip3 & python3-dev<br />
# sudo apt install python3-pip python3-dev<br />
3. update pip<br />
# python3 -m pip install -U pip<br />
4. logout and login<br />
5. Install virtualenvwrapper<br />
# python3 -m pip install --user virtualenvwrapper<br />
6. add variable in .bashrc<br />
export VIRTUALENVWRAPPER_PYTHON=$(which python3)<br />
7. include virtualenvwrapper in .bashrc<br />
Add following in tail of .bashrc<br />
# set ~/.local/bin in PATH<br />
if [ -d "$HOME/.local/bin" ] ; then<br />
PATH="$HOME/.local/bin:$PATH"<br />
fi<br />
<br />
# virtualenvwrapper<br />
source $(which virtualenvwrapper.sh)<br />
8. logout & login again<br />
9. create a virtualenv<br />
# mkvirtualenv env1<br />
<br />
for APT proxy setting: /etc/apt/apt.conf<br />
Acquire::http::Proxy "http://yourproxyaddress:proxyport";<br />
<br />
for pip proxy setting per-user: ~/.config/pip/pip.conf<br />
[global]<br />
proxy = http://127.0.0.1:3128<br />
<br />
<a href="https://medium.com/@gitudaniel/installing-virtualenvwrapper-for-python3-ad3dfea7c717">https://medium.com/@gitudaniel/installing-virtualenvwrapper-for-python3-ad3dfea7c717</a><br />
<br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-24055751610102807412018-05-16T13:38:00.002+08:002018-05-16T13:38:57.800+08:00Increase upload file size limit of TestLinkEdit /etc/php.ini file<br />
<br />
upload_max_filesize = 100M<br />max_execution_time = 600<br />
<br />
Edit<br />
/var/html/www/testlink/config.inc.php<br />
$tlCfg->import_file_max_size_bytes (config.inc.php): 8192000<br />$tlCfg->import_max_row (config.inc.php): 100000<br />$tlCfg->repository_max_filesize (config.inc.php): 8 // MB<br />
<br />
restart Apache<br />
service apache2 restart<br />
or<br />
service httpd restartUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-35237419590300974072018-03-29T15:23:00.000+08:002018-03-29T15:23:48.732+08:00Use mkvirtualenv of virtualenvwrapper-win to create diffenrent Python version of env<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">應用Python的virtualenv和virtualenvwrapper可方便建立Python的virtual enviroment,方便在不同的environment切換,各env有獨立的pip list和Python版本</span></div>
<b id="docs-internal-guid-df51a023-70a3-a3d9-8c00-a5b51abc1322" style="font-weight: normal;"><br /></b>
<div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">首先要安裝Python (Linux已有內建Python2)</span></div>
<br />
<ol style="margin-bottom: 0pt; margin-top: 0pt;">
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">Windows安裝完後要將PATH設定包含到C:\Python27</span></div>
</li>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">安裝pip套件 </span><a href="https://pip.pypa.io/en/stable/installing/" style="text-decoration: none;"><span style="-webkit-text-decoration-skip: none; background-color: transparent; color: #1155cc; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration-skip-ink: none; text-decoration: underline; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">https://pip.pypa.io/en/stable/installing/</span></a></div>
</li>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">安裝virtualenv, pip install virtualenv</span></div>
</li>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">安裝virtualenvwrapper或是virtualenvwrapper-win (Windows版)</span></div>
</li>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">建立virtualenv</span></div>
</li>
<ol style="margin-bottom: 0pt; margin-top: 0pt;">
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: lower-alpha; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">mkvirtualenv env01</span></div>
</li>
</ol>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">查看pip list, pip list</span></div>
</li>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">跳出env01, deactivate</span></div>
</li>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">查看目前有多少virtualenv, workon</span></div>
</li>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">進入virtualenv env01, workon env01</span></div>
</li>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">若要建立Python3的virtualenv, 先安裝Python3</span></div>
</li>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">確認Pyhon3的python.exe位置 (</span><span style="background-color: transparent; color: black; font-family: 'Times New Roman'; font-size: 12pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">C:\Users\Jack_Lin\AppData\Local\Programs\Python\Python35\python.exe), 若是Linux, 可用which python3指令查看</span></div>
</li>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: decimal; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">建立一Python3的virtualenv</span></div>
</li>
<ol style="margin-bottom: 0pt; margin-top: 0pt;">
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: lower-alpha; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">mkvirtualenv </span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 700; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">-p</span><span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;"> C:\Users\Jack_Lin\AppData\Local\Programs\Python\Python35\python.exe python35</span></div>
</li>
<li dir="ltr" style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; list-style-type: lower-alpha; text-decoration: none; vertical-align: baseline; white-space: pre;"><div dir="ltr" style="line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt;">
<span style="background-color: transparent; color: black; font-family: Arial; font-size: 11pt; font-style: normal; font-variant: normal; font-weight: 400; text-decoration: none; vertical-align: baseline; white-space: pre-wrap; white-space: pre;">python -V</span></div>
</li>
</ol>
</ol>
<br />Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-91216567759151457992018-02-08T19:26:00.002+08:002018-02-08T19:26:38.024+08:00ipmitool ipmi-raw ipmiutil cmd (icmd) raw command formatipmitool:<br />
ipmitool -I lanplus -H 192.168.1.123 -U admin -P password raw 0x06 0x01<br />
<br />
ipmi-raw:<br />
ipmi-raw -D LAN_2_0 -h 192.168.1.123 -u admin -p password 0x00 0x06 0x01<br />
<br />
icmd:<br />
icmd -J 3 -N 192.168.1.123 -U admin -P password 00 20 18 01Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-3339005215836974547.post-22054221018281657102018-02-08T16:41:00.002+08:002018-04-16T16:15:18.574+08:00redfishtool on ubuntu1. apt-get update<br />
2. apt-get install python python3 python-pip<br />
3. make a file /etc/pip.conf if you need proxy setting for pip<br />
[list]<br />
format=columns<br />
[global]<br />
trusted-host = pypi.python.org<br />
proxy = http://127.0.0.1:3128<br />
4. pip install virtualenvwrapper<br />
5. login with normal user (not root)<br />
6. add one line in tail of .bashrc<br />
source $(which virtualenvwrapper.sh)<br />
7. re-login<br />
8. create a virtualenv of python3<br />
mkvirtualenv -p $(which python3) redfish<br />
9. pip install redfishtool<br />
<br />
redfishtool commands:<br />
<br />
redfishtool -u admin -p password -r 192.168.1.123 -S Always System<br />
redfishtool -u admin -p password -r 192.168.1.123 -S Always System -a<br />
redfishtool -u admin -p password -r 192.168.1.123 -S Always raw /redfish/v1/xxxx/xxxx<br />
<br />
======<br />
For Ubuntu 17.10, before step5<br />
Need to add ~/.local/bin to PATH, edit ~/.bashrc<br />
# set PATH ~/.local/bin<br />
if [ -d "$HOME/.local/bin" ] ; then<br />
PATH="$HOME/.local/bin:$PATH"<br />
fiUnknownnoreply@blogger.com0