https://avatars.githubusercontent.com/u/6058558

程式狂想筆記

Fixing “The box ‘base’ could not be found.” (Vagrant)

vagrant box add base http://files.vagrantup.com/lucid32.box This is an indication that the the base virtual image is not configured, usually from forgetting to finish the installation. This image is copied, and modified to produce the desired virtualized environment. It’s easy to fix, by running the following: vagrant box add base http://files.vagrantup.com/lucid32.box It is also possible that you installed the box under a different name (the Vagrant website sometimes refers to lucid32). Instead of downloading a new box, in this case, you can edit Vagrantfile like so, changing the box name to whatever you called it on download:

[Raspberry Pi]使用Python查詢溫度

Raspberry Pi 的 CPU 溫度資訊儲存在系統的虛擬檔案中,可以透過讀取該檔案來取得目前的溫度數值。這在監控 Pi 的運行狀態,或判斷是否需要加裝散熱片時非常實用。 溫度資料來源 Linux 系統將 CPU 溫度儲存在以下路徑: 1 /sys/class/thermal/thermal_zone0/temp 這個檔案裡的數值單位是千分之一攝氏度(毫攝氏度),例如讀到 47500 代表 47.5°C。 原始 Python 2 程式碼 1 2 3 4 5 # cpuTemp.py (Python 2) f = open("/sys/class/thermal/thermal_zone0/temp", "r") for t in f: print "CPU temp:" + t[:2] + "." + t[2:5] f.close() 改良版 Python 3 程式碼 Python 3 的 print 改為函式,字串處理上也建議改用整數除法,以下是較完整的版本: 1 2 3 4 5 6 7 8 9 # cpuTemp.py (Python 3) def get_cpu_temperature(): with open("/sys/class/thermal/thermal_zone0/temp", "r") as f: temp_raw = int(f.

[Python] 查詢本機IP

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 import urllib,random,re ip_regex = re.compile("(([0-9]{1,3}\.){3}[0-9]{1,3})") def public_ip(): ''' Returns your public IP address. Output: The IP address in string format. None if not internet connection available. ''' # List of host which return the public IP address: hosts = """http://www.

Apache的autoindex風格設定

Apache Autoindex 功能說明 Apache Autoindex 是 Apache HTTP Server 的內建功能,當某個目錄下沒有 index 頁面(如 index.html)時,Apache 會自動產生該目錄的檔案清單,讓使用者可以瀏覽目錄內容。常用於建立簡易的檔案下載伺服器。 啟用 Autoindex 在 Apache 設定檔或 .htaccess 中加入: 1 Options +Indexes 若要啟用 Fancy Index(更豐富的樣式支援),需要載入 mod_autoindex 模組: 1 2 3 # Ubuntu/Debian sudo a2enmod autoindex sudo systemctl restart apache2 基本設定 1 2 3 4 5 <Directory "/var/www/html/files"> Options +Indexes +FollowSymLinks IndexOptions FancyIndexing HTMLTable VersionSort NameWidth=* DescriptionWidth=* IndexOrderDefault Descending Date </Directory> 常用 IndexOptions 選項: 選項 說明 FancyIndexing 啟用美化目錄列表 HTMLTable 用 HTML table 排版(比預設更好看) VersionSort 按版本號排序(如 file-1.

Linux預設帳號設定檔路徑

/etc/skel/ 目錄的用途 在 Linux 系統中,當使用 useradd 或 adduser 建立新使用者時,系統會自動將 /etc/skel/ 目錄下的所有檔案複製到新使用者的家目錄(Home Directory)。skel 是 skeleton(骨架)的縮寫,代表「帳號的基本骨架」。 預設包含的檔案 一般 /etc/skel/ 目錄下會有以下幾個隱藏設定檔: 1 2 3 4 /etc/skel/ ├── .bash_logout # 登出時執行的指令 ├── .bash_profile # 登入時執行(Bash 登入 Shell) └── .bashrc # 開啟互動式 Shell 時執行 不同的 Linux 發行版可能略有不同,例如 Ubuntu 還可能有 .profile。 建立新使用者時的流程 1 2 3 4 5 6 7 # 建立新使用者 sudo useradd -m newuser # 系統會自動: # 1. 建立 /home/newuser/ 目錄 # 2. 將 /etc/skel/ 的內容複製到 /home/newuser/ # 3.

[CSS]text-overflow - 文字太常溢出的字元替代為...

當文字內容超出容器寬度時,預設會換行或溢出容器。text-overflow 屬性可以讓溢出的文字以省略號(...)或其他方式顯示,提升使用者介面的整潔度。 基本語法 1 text-overflow: clip | ellipsis | string | initial | inherit; clip:預設值,直接裁切溢出的文字 ellipsis:以 ... 取代溢出的部分 string:自訂替代字串(瀏覽器支援度有限) 必要的搭配屬性 text-overflow 單獨使用無效,必須同時設定以下兩個屬性才能生效: 1 2 3 4 5 .truncate { white-space: nowrap; /* 禁止換行 */ overflow: hidden; /* 隱藏溢出內容 */ text-overflow: ellipsis; /* 顯示省略號 */ } 三個屬性缺一不可: white-space: nowrap — 讓文字不換行,才會產生溢出 overflow: hidden — 隱藏溢出的部分 text-overflow: ellipsis — 在隱藏處顯示 ... 單行省略範例 1 <div class="truncate">這是一段很長的文字,會被截斷並顯示省略號...</div> 1 2 3 4 5 6 .truncate { width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } 多行省略(-webkit-line-clamp) 若需要限制顯示行數(例如只顯示兩行),可使用 -webkit-line-clamp:

Linux 利用 usermod 修改使用者的參數和資料

修改使用者帳號資訊(管理者) usermod -l newname username # 變更使用者帳號名稱 usermod -o -u 101 username # 變更使用者 UID usermod -g users username # 變更使用者主要群組 usermod -G mis,sales username # 變更使用者次要群組 usermod -c “manager” username # 修改使用者註解內容 usermod -m -d /home/user username # 變更使用者家目錄路徑 usermod -s /usr/bin/ksh username # 變更使用者預設 Shell usermod -e 1/1/2010 username # 變更使用者過期期限 usermod -p FEeig.jYifke username # 變更使用者密碼 來源:http://blog.yam.com/gavint/article/23264761 Linux usermod -p 修改用户密码 passwd也可以修改口令,但是这是一种交互式的方式,需要用户干预。当然也可以使用重定向或者管道向passwd喂数据,暂且不提。 linux下增加用户的命令是useradd,修改用户的命令是usermod,二者都有一个参数 –p,这个参数可以直接指定用户的口令,但是需要注意的是,这个口令并不是明文,而是经过加密的一个字串。 linux下可以用python编辑器通过编程的方法得到加密字串(linux下用python命令启动编辑器): 下面是一个完整的过程,蓝色字体的是用户输入的命令,而红色的是系统输出。