本篇文章參考自 G. T. Wang的文章 , 以及 samwhelp/book-ubuntu-qna 此兩篇應該是參考自Ubuntu社群討論區: 解壓縮zip檔,產生亂碼,如何解決的心得
因為常常遇到
所以乾脆記錄下來
自己忘記也可以翻找
常常在Windows壓縮zip檔案後
拿到Linux環境解壓縮會是亂碼
因為Windows利用Big5編碼將中文檔名壓縮
解壓縮時通常是用UTF-8的編碼解壓縮
因為編碼不一樣所以解壓縮出來的檔名就變成亂碼
目前看到有兩種作法
(以下用Debian系列(Debian, Ubuntu, Mint, Lubuntu...)的系統做示範)
1. 第一種作法比較簡單直接用unzip設定編碼類型
首先先確定已經安裝了unzip
unzip -h
如果出現command not found 就安裝一下
sudo apt install unzip
安裝好後利用以下指令確認編碼是不是Big5
unzip -O big5 -l <target file>
target file請輸入想要解壓縮的檔案名稱
-l 代表示查看檔案內容而不解壓縮
如果可以看見正確的中文檔名代表的確是用big5編碼的
接下來就可以使用
unzip -O big5 <target file>
來解壓縮檔案
2. 另外也可以用convmv這個套件來將big5編碼的檔名轉換程UTF8
首先一樣確認convmv有無安裝
convmv --help
如果出現Command not found就安裝一下
sudo apt-get install convmv
利用unzip解壓縮zip檔為C語言編碼
LANG=C unzip <target file>
LANG=C代表使用C語言的 ASCII code方式編碼
(也可以把LANG=C 改成 LANG=zh_TW.Big-5)
target file為你要解壓縮的檔案名稱
解壓縮完之後再用convmv來轉換編碼
convmv -f big5 -t utf8 -r --notest *
2018年7月17日 星期二
2018年7月15日 星期日
使用Kivy實作資料夾同步工具 --- 3. 設計UI 界面
Kivy的UI界面可以利用kv language來實作
kv language的副檔名為.kv
這是目前我想到的UI界面
kv language的副檔名為.kv
這是目前我想到的UI界面
folder_syncer.kv
app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#:import os os | |
#:import getuser getpass.getuser | |
#:import resource_find kivy.resources.resource_find | |
[FileListEntry@FloatLayout+TreeViewNode]: | |
locked: False | |
entries: [] | |
path: ctx.path | |
is_selected: self.path in ctx.controller().selection | |
orientation: 'horizontal' | |
size_hint_y: None | |
height: '48dp' if dp(1) > 1 else '24dp' | |
is_leaf: not ctx.isdir or ctx.name.endswith('..' + ctx.sep) or self.locked | |
on_touch_down: self.collide_point(*args[1].pos) and ctx.controller().entry_touched(self, args[1]) | |
on_touch_up: self.collide_point(*args[1].pos) and ctx.controller().entry_released(self, args[1]) | |
BoxLayout: | |
pos: root.pos | |
size_hint_x: None | |
width: root.width - dp(10) | |
Label: | |
id: filename | |
text_size: self.width, None | |
halign: 'left' | |
shorten: True | |
text: ctx.name | |
font_name: resource_find("ukai.ttc") | |
Label: | |
text_size: self.width, None | |
size_hint_x: None | |
halign: 'right' | |
text: '{}'.format(ctx.get_nice_size()) | |
font_name: resource_find("ukai.ttc") | |
<SrcChooser>: | |
size_hint: (0.47, 1) | |
FileChooserListView: | |
id: src_chr | |
size_hint: (1, 0.95) | |
pos_hint: {'top': 0.95} | |
path: os.path.join("/home", getuser()) | |
Label: | |
text: src_chr.path | |
size_hint: (1, 0.05) | |
pos_hint: {'top': 1} | |
font_size: 16 | |
font_name: resource_find("ukai.ttc") | |
<DstChooser>: | |
size_hint: (0.47, 1) | |
FileChooserListView: | |
id: fc_dst | |
size_hint: (1, 0.95) | |
pos_hint: {'top': 0.95} | |
path: os.getcwd() | |
Label: | |
text: fc_dst.path | |
size_hint: (1, 0.05) | |
pos_hint: {'top': 1} | |
font_size: 16 | |
font_name: resource_find("ukai.ttc") | |
<Folder_Syncer> | |
StackLayout: | |
size: root.size | |
Label: | |
size_hint: (0.5, 0.05) | |
font_size: 30 | |
text: '[color=#4286f4]Source[/color]' | |
markup: True | |
Label: | |
size_hint: (0.5, 0.05) | |
font_size: 30 | |
text: '[color=#4286f4]Destination[/color]' | |
markup: True | |
SrcChooser | |
BoxLayout: | |
pos_hint: {'x': 0.47, 'top': 0.95} | |
size_hint: (0.06, 0.5) | |
orientation: "vertical" | |
Button: | |
id: sync_btn | |
size_hint: (1, 0.1) | |
text: "Sync" | |
Button: | |
id: add_btn | |
size_hint: (1, 0.1) | |
text: "Add >>" | |
DstChooser: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from kivy.app import App | |
from kivy.uix.widget import Widget | |
from kivy.uix.floatlayout import FloatLayout | |
from kivy.uix.relativelayout import RelativeLayout | |
from kivy.uix.button import Button | |
from kivy.properties import ObjectProperty | |
from kivy.uix.filechooser import FileChooserListView | |
class SrcChooser(RelativeLayout): | |
pass | |
class DstChooser(RelativeLayout): | |
pass | |
class Folder_Syncer(Widget): | |
fc_src = ObjectProperty(None) | |
fc_dst = ObjectProperty(None) | |
sync_btn = ObjectProperty(None) | |
add_btn = ObjectProperty(None) | |
class Folder_SyncerApp(App): | |
def build(self): | |
app = Folder_Syncer() | |
return app | |
if __name__ == '__main__': | |
Folder_SyncerApp().run() |
2018年7月11日 星期三
2018年7月8日 星期日
在Blogger使用gist顯示程式碼
在Blogger上因為沒有markdown的格式資源
使得要顯示程式碼需要不少麻煩步驟才能達成
一開始嘗試的是StackEdit , 但發現他發佈文章的方式不是我想要的
後來發現自己常用的GitHub中的gist就可以輕鬆的嵌入程式碼在Blogger中
以下是簡單的教學
先在GitHub註冊後
登入 https://gist.github.com/
應該可以看到這個畫面
最上方是這個gist的描述
第二格是檔名
然後再下來的大格子就是放上你的程式碼
填好之後就像這樣
之後按下右邊的 "Create public gist"
(意思是大家都可以公開的看到這份程式碼)
點完之後會看到這個畫面
在右上方Download ZIP的左邊有個Embed區塊
右邊的
圖案代表複製到剪貼簿
然後到你的Blogger準備發新文章
為了方便辨認哪個區塊放了gist 我先增加了兩行字
然後按左上角紅框的地方
會看到像下面這樣
把剛剛複製的gist貼上
然後按右上方的預覽確認看看
看到中間有程式碼就是完成囉~
使得要顯示程式碼需要不少麻煩步驟才能達成
一開始嘗試的是StackEdit , 但發現他發佈文章的方式不是我想要的
後來發現自己常用的GitHub中的gist就可以輕鬆的嵌入程式碼在Blogger中
以下是簡單的教學
先在GitHub註冊後
登入 https://gist.github.com/
應該可以看到這個畫面
最上方是這個gist的描述
第二格是檔名
然後再下來的大格子就是放上你的程式碼
填好之後就像這樣
之後按下右邊的 "Create public gist"
(意思是大家都可以公開的看到這份程式碼)
點完之後會看到這個畫面
在右上方Download ZIP的左邊有個Embed區塊
右邊的
圖案代表複製到剪貼簿
然後到你的Blogger準備發新文章
為了方便辨認哪個區塊放了gist 我先增加了兩行字
然後按左上角紅框的地方
會看到像下面這樣
把剛剛複製的gist貼上
然後按右上方的預覽確認看看
看到中間有程式碼就是完成囉~
2018年7月6日 星期五
使用Kivy實作資料夾同步工具 --- 2. 小試身手 First Application
接下來是我們的第一個App
(參考自官方的手冊)
我們先新增一個檔案名叫main.py
以下為檔案內容
用 python3 main.py執行檔案
即可看到以下畫面
右下角即為我們第一個Hello World App
(參考自官方的手冊)
我們先新增一個檔案名叫main.py
以下為檔案內容
import kivy
kivy.require('1.10.0') # replace with your current kivy version !
from kivy.app import App
from kivy.uix.label import Label
class Hello_world(App):
def build(self):
return Label(text='Hello world')
if __name__ == '__main__':
Hello_world().run()
用 python3 main.py執行檔案
即可看到以下畫面
右下角即為我們第一個Hello World App
使用Kivy實作資料夾同步工具 --- 1. 在Ubuntu下安裝Kivy
這一系列的文章是源自於自己學校的作業檔案太多
不同台電腦要搬東西的時候麻煩
所以乾脆自己寫一個工具來用
會選Kivy來用的原因是因為他是開源的
因為支持開源文化 而且省麻煩
發現有bug也可以自己改
以下進入正題~
首先先安裝Python3的pip 以及一些相依的套件
sudo apt install -y python3-pip build-essential git ffmpeg libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev zlib1g-dev
如果要有音樂跟影片的功能的話要安裝(我也不懂 總之就先裝了)
sudo apt-get install -y libgstreamer1.0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good
然後把pip wheel更新到最新版本
sudo python3 -m pip install --upgrade pip wheel setuptools
以下為安裝kivy v1.10.0的流程
若版本不一樣 請自行參照官方文件來安裝
然後安裝 Cython 25.0.2 (根據官方手冊)
sudo python3 -m pip install Cython==0.25.2
然後安裝kivy
sudo python3 -m pip install kivy==1.10.0
確認安裝完成
python3 -c 'import kivy'
可以看到類似下圖的結果

會看到倒數第三行有
[INFO ] [Kivy ] v1.10.0
如果版本跟你安裝的一樣就是完成了~
不同台電腦要搬東西的時候麻煩
所以乾脆自己寫一個工具來用
會選Kivy來用的原因是因為他是開源的
因為支持開源文化 而且省麻煩
發現有bug也可以自己改
以下進入正題~
首先先安裝Python3的pip 以及一些相依的套件
sudo apt install -y python3-pip build-essential git ffmpeg libsdl2-dev libsdl2-image-dev libsdl2-mixer-dev libsdl2-ttf-dev libportmidi-dev libswscale-dev libavformat-dev libavcodec-dev zlib1g-dev
如果要有音樂跟影片的功能的話要安裝(我也不懂 總之就先裝了)
sudo apt-get install -y libgstreamer1.0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good
然後把pip wheel更新到最新版本
sudo python3 -m pip install --upgrade pip wheel setuptools
以下為安裝kivy v1.10.0的流程
若版本不一樣 請自行參照官方文件來安裝
然後安裝 Cython 25.0.2 (根據官方手冊)
sudo python3 -m pip install Cython==0.25.2
然後安裝kivy
sudo python3 -m pip install kivy==1.10.0
確認安裝完成
python3 -c 'import kivy'
可以看到類似下圖的結果

會看到倒數第三行有
[INFO ] [Kivy ] v1.10.0
如果版本跟你安裝的一樣就是完成了~
訂閱:
文章 (Atom)
Go lang 學習筆記 - 17 Pointers
``` package main import "fmt" func zeroval(n int) { n = 0 } func zeroptr(n *int) { *n = 0 } func main() { ...
-
``` package main import ( "fmt" "time" ) func main() { i := 2 switch i { case ...
-
``` package main import "fmt" func intSeq() func() int { i := 0 return func() int { i++ ...
-
由於網路上幾乎找不到關於libchewing原始程式碼的介紹 然後我又對於這個每天都會用到的輸入法有興趣 (想修掉一些bug) 所以就一邊trace code一邊把一些心得寫成文章記錄下來 目前沒有規劃多久出一篇 也沒有規劃要寫多久 一切隨緣看心情 哈哈