[smarty]smarty裡直接樣版宣告變數方式

參考網址:https://sites.google.com/site/wanyutang/smarty/smartylizhijieyangbanxuangaobianshufangshi

{{assign var=xx value=0}}

or

{{assign var=xx value=$xx+3}}

 

在樣板中,Smarty 也可以直接拿PHP的函數來用,我們稱之為「變數修飾器」,例如:
變數後面要加上 |
| 後面加上函數名稱,函數需要的參數用 : 格開

例:得到檔案名稱

{{$SCRIPT_NAME|basename}}

{{$ulist.gov_allname|strlen}} 得到全銜的長度

 

發表於 程式設計 | 發表迴響

[mysql]留個紀錄好辦事 – Mysql Log (日誌紀錄)

參考網址:https://ithelp.ithome.com.tw/m/articles/10263180
 

查詢日誌- general log
注意點: 因為執行的所有行為操作都會紀錄到日誌中,log累積量會佔用很大的disk空間,請求量一多會產生不小的系統開銷影響效能! 所以在環境上通常不會啟用此日誌。

相關配置: my.cnf設定檔(/etc/mysql/my.cnf)

[mysqld]

#general log是否開啟(default:0禁用 / 1啟用)
general_log = 1
#查詢日誌路徑&檔名
general_log_file = /mnt/mysql_data/mysql/general.log
#指定日誌輸出目的地(default:FILE=記錄到general.log / TABLE=紀錄到mysql.general_log表)
log-output=TABLE

 

慢查詢日誌- slow log
注意點: 在開發的時候寫的SQL指令就算有測過執行時間,但如果遇到資料量不足的問題,雖然看起來沒問題但上線後資料量一大所造成的影響,執行秒數差異會越來越明顯。可能是表結構索引關係設計上又或者是SQL語法本身問題,透過slowlog能找出這些語法發現問題並做優化。
 

相關配置: my.cnf設定檔(/etc/mysql/my.cnf)

[mysqld]

#slow log是否開啟(1啟用/0禁用)
slow-query-log = 1
#慢查詢日誌路徑&檔名
slow_query_log_file=/mnt/mysql_data/mysql/slow.log
#執行超過x秒就紀錄 (EX: 1s)
long_query_time = 1

二进制日志

记录了所有对数据库执行更改的操作。不包括Select 和show等操作命令,想要查看只能通过查询日志。

 

發表於 程式設計 | 發表迴響

[flag]旗標書附程式下載

參考網址:https://www.flag.com.tw/VIP/Bonus

https://www.flag.com.tw/books/product/F2034
Python ✕ Excel 高效率打造辦公室作業+數據分析自動化

Ch07 Excel + Word 辨公室自動化與輸出 PDF

發表於 軟體使用 | 發表迴響

[python]用Python批量生成word版邀請函

參考網址:https://www.getit01.com/p20190616061067027/

發表於 程式設計, 軟體使用 | 發表迴響

[photo]XnView

參考網址:https://www.xnview.com/en/xnview/#downloads

看line下載的圖片常會出現 windows相片檢視器無法開啟/無法顯示的錯誤
索性把它換掉

發表於 Windows系統, 軟體使用 | 發表迴響

[sport]產生一些色碼當背景用

//文字為黑色,避免全黑,全白,背景儘量淡一些
//黑色 #000000    白色#ffffff

//ca color array
//$ca=array("22","44","66","88","aa","cc","ee"); 
//$ca=array("11","22","33","44","55","66","77","88","99","aa");
$ca=array("66","77","88","99","aa","bb","cc","dd","ee","ff");
//cn   color number-1
$cn=count($ca)-1;

for($i=0;$i<50;$i++)  {
    $c="#";
    for($j=0;$j<3;$j++)  {
        $c .= $ca[rand(0,$cn)];
    }

    $bgcolor_arr[$i]=$c;
    echo  "<span style='background-color:{$c}'>$c</span> ";
}
echo "<br><br>";
foreach ($bgcolor_arr as $k => $v) {
	echo '"'.$v.'",';
}
echo "<br><br>";

 

發表於 程式設計 | 發表迴響

[excel][python]用python操控excel

參考書籍:python 操作excel 深智數位 洪錦魁 著 https://www.books.com.tw/products/0010929648

# ch5_1.py
import openpyxl

fn = "data5_1.xlsx"
wb = openpyxl.load_workbook(fn)
ws = wb.active

ws.insert_rows(4,1)
ws.insert_rows(6,1)
ws.insert_rows(8)       # 省略amount參數
ws.insert_rows(10)      # 省略amount參數
wb.save("out5_1.xlsx")

 

使用Python程式處理Excel檔案

Python 自动化操作 Excel 看这一篇就够了

發表於 程式設計, 軟體使用 | 發表迴響

[sport]混合運動定名為全能運動

sport_function.php 尋找混合-->全能
update  `play_item` set play_item_name='全能運動' WHERE `play_item_id`=23
work\race_im.php

 

發表於 程式設計 | 發表迴響

[ubuntu]awstats install

參考網址:alvinchen

整理如下:環境 lubuntu 22.04 cubi
 

步驟一: 安裝Awstats
apt-get install awstats libgeo-ipfree-perl libnet-ip-perl

步驟二: 設定Awstats
cp /etc/awstats/awstats.conf /etc/awstats/awstats.sp.idv.tw.conf
vi /etc/awstats/awstats.sp.idv.tw.conf
改這些地方
LogFormat=1
SiteDomain="sp.idv.tw"
HostAliases="localhost 127.0.0.1 sp.idv.tw"
DNSLookup=0
Lang="tw"

步驟三:手動執行一次
/usr/lib/cgi-bin/awstats.pl -config=sp.idv.tw -update

步驟四:設定定期自動執行
vi /etc/cron.d/awstats
新增一行
*/10 * * * * root /usr/lib/cgi-bin/awstats.pl -config=sp.idv.tw -update > /dev/null

步驟五:設定Apache Config,讓網頁可以看到資料
vi /etc/apache2/sites-available/awstats.conf

Alias /awstatsclasses "/usr/share/awstats/lib/"
Alias /awstats-icon/ "/usr/share/awstats/icon/"
Alias /awstatscss "/usr/share/doc/awstats/examples/css"
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
ScriptAlias /awstats/ /usr/lib/cgi-bin/
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch


步驟六:開啟apache cgi mode,並重新啟動
a2enmod cgi
service apache2 restart

打開瀏覽器就可以看到網站的流量數字啦
http://sp.idv.tw/cgi-bin/awstats.pl?config=sp.idv.tw


統計圖會有破圖(步驟五的Alias /awstats-icon/ 似乎沒有作用)
直接把/usr/share/awstats/icon/. 複製到 /var/www/html/awstats-icon/.
mkdir /var/www/html/awstats-icon
cd /var/www/html/awstats-icon
cp /usr/share/awstats/icon/. . -Rp

另一篇文章參考Ubuntu 18.04 安裝 AWStats 來統計網站流量

發表於 Linux系統 | 發表迴響

[ubuntu]dnsmasq安裝(輕量化DNS服務)

參考網址:如何在Ubuntu 20.04上使用Dnsmasq設置本地DNS解析器

dnsmasq安裝(輕量化DNS服務)

 

Dnsmasq使用参考入门 http://www.freeoa.net/osuport/servap/dnsmasq-use-intro-refer_2480.html

 

Dnsmasq – Lightweight Name Resolution For Your Home Lab
https://dev.to/joeneville_/dnsmasq-lightweight-name-resolution-for-your-lab-2gim

 

在lubuntu 22.04安裝過程
參考書籍:O'REILLY Linux錦囊妙計 第二版 碁峯 P401~426
roki.tw tni設置
在系統中禁用Systemd解析的服務

systemctl disable --now systemd-resolved
rm -rf /etc/resolv.conf #需先刪除,它原本是一個link
echo "nameserver 192.168.1.9" > /etc/resolv.conf
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
apt-get install dnsmasq dnsutils ldnsutils -y

/etc/NetworkManager/NetworkManager.conf 的[main]加入
dns=none
否則/etc/resolv.conf會一直被改掉
client端亦同
改完後要系統reboot才會生效
 

先把兩片網路卡裝好
eth0 192.168.1.19 負責對外
eth1 192.168.66.1 負責內部網路
兩片網卡透通 iptables -t nat -A POSTROUTING -o eth0 -s 192.168.66.0/24 -j MASQUERADE


vi /etc/dnsmasq.conf

##########DNS
resolv-file=/etc/resolv.conf
domain-needed
bogus-priv
expand-hosts
#no-host的項目預設是關閉的,這個啟用的話會變成最先去找local端的host檔案。
no-hosts

#通常與no-hosts對應的是addn-hosts設定檔部分,
#這個就不是讀取/etc/hosts,而是自己定義要對應到哪個檔案去。
#(這邊的格式要跟/etc/hosts的一樣)
#addn-hosts=/etc/add_hosts

#domain=sp.idv.tw
#local=/sp.idv.tw/ #這兩行設了反而無法連線到sp.idv.tw
listen-address=127.0.0.1
listen-address=192.168.1.19

server=8.8.8.8

#要擋掉的網站
address=/tw.yahoo.com/192.168.1.19
address=/edition.cnn.com/192.168.1.19
address=/pchome.com.tw/192.168.1.19
address=/facebook.com/192.168.1.19

###########DHCP
dhcp-leasefile=/var/lib/misc/dnsmasq.leases
listen-address=192.168.66.1
dhcp-option=eth1,3,192.168.66.1  #router
dhcp-option=eth1,1,255.255.255.0 #mask
dhcp-option=eth1,6,192.168.66.1  #dns-server
dhcp-range=eth1,192.168.66.100,192.168.66.200,24h
#dhcp-host=08:00:27:3c:da:1a,192.168.1.101
# Always give the host with Ethernet address 11:22:33:44:55:66
# the name fred and IP address 192.168.0.60 and lease time 45 minutes
#dhcp-host=11:22:33:44:55:66,fred,192.168.0.60,45m

 

service dnsmasq restart

netstat -rn 查詢gateway

dnsmasq –help dhcp 查詢服務的選項編號

https://thekelleys.org.uk/dnsmasq/doc.html 官方文件

client端的/etc/resolv.conf 設定
nameserver 192.168.1.9
nameserver 8.8.8.8

nslookup 指定server的用法
 

#先執行nslookup 出現>後再輸入server 192.168.1.9
nslookup
>server 192.168.1.9

dig指定server的用法
dig @192.168.1.9

目前問題
1.dnsmasq server中的/etc/hosts 無法直接下放給windows 10 client使用
  (nslookup可以查到該網站的對應,瀏覽器卻出不去。在ubuntu系統是可行的)
2.address=/tw.yahoo.com/192.168.1.19 檔不住網站,但address=/pchome.com.tw/192.168.1.19 卻可以檔掉

發表於 Linux系統 | 發表迴響