2017/6/17

使用dd指令備份sd卡遇到問題[已解決]

今天想說來備份一下sd卡
結果沒想到會出現一個網路上也找不到解決辦法的問題

我輸入dd指令後出現了以下訊息:
sudo dd if=/dev/disk4 of=~/Desktop/170617_rpi3_backup.img bs=1m
dd: ~/Desktop/170617_rpi3_backup.img: No such file or directory  


不知道該怎麼辦啊...



-

[ 20170617 - 更新 ] 

把問題發到樹莓派的stackexchange之後,有人發現我的錯誤了:P
點此

原來使用sudo時,必須要輸入所謂的full path路徑才會被系統認可,不然就是要cd到目的路徑才可正常執行。
原因猜測是因為sudo代表最高使用者的權限,如果輸入~ (代表$HOME)的路徑,他會搞不清楚是哪個使用者吧。
 


2017/6/4

安裝binary檔案到osx/linux並使用其terminal指令

有時候我們在網路上找到的程式是binary檔而不是osx上常見的dmg,這時候就要將其移動到系統當中的一個特定地點 /usr/local/bin,osx/linux只會從這些資料夾查看可以使用的程式。

安裝方法:
將下載來的binary檔案移動到 /usr/local/bin 即可在terminal中使用其指令。

可以使用 mv 或者 cp 這兩個指令
用法:
mv [source] [destination]
cp [source] [destination]


說明:
When you type commands like ngrok in the terminal, Macs (and other Unix OSs) look for these programs in the folders specified in your PATH. The PATH is a list of folders that's specified by each user. To check your path, open the terminal and type: echo $PATH.
You'll see output that looks something like: /usr/local/bin:/usr/bin:/bin. This is a : separated list of folders.
So when you type ngrok in the terminal, your Mac will look for this executable in the following folders: /usr/local/bin, /usr/bin/ and /bin.


像我目前如果在terminal中輸入 echo $PATH 則會出現:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Library/TeX/texbin
代表這些地方都有存放可在terminal中執行指令的程式


各個path的比較:

  1. /bin (and /sbin) were intended for programs that needed to be on a small / partition before the larger /usr, etc. partitions were mounted. These days, it mostly serves as a standard location for key programs like /bin/sh, although the original intent may still be relevant for e.g. installations on small embedded devices.
  2. /sbin, as distinct from /bin, is for system management programs (not normally used by ordinary users) needed before /usr is mounted.
  3. /usr/bin is for distribution-managed normal user programs.
  4. There is a /usr/sbin with the same relationship to /usr/bin as /sbin has to /bin.
  5. /usr/local/bin is for normal user programs not managed by the distribution package manager, e.g. locally compiled packages. You should not install them into /usr/bin because future distribution upgrades may modify or delete them without warning.
  6. /usr/local/sbin, as you can probably guess at this point, is to /usr/local/bin as /usr/sbin to /usr/bin.

      In addition, there is also /opt which is for monolithic non-distribution packages, although before they were properly integrated various distributions put Gnome and KDE there. Generally you should reserve it for large, poorly behaved third party packages such as Oracle.





參考資料:
https://stackoverflow.com/questions/30188582/ngrok-command-not-found
https://unix.stackexchange.com/questions/8656/usr-bin-vs-usr-local-bin-on-linux 
https://linux.die.net/man/7/hier

2017/5/19

[python]整理圖片程式

常常拍了很多照片、搜集很多圖片之後,
由於拍照來源不同或圖片來源不同而造成檔案整理時的困擾,
因此萌發寫出這個程式的念頭,讓相片利用內定拍攝日期自動排列。

以下為程式碼


##Picture_Sort
#20160516
import os
import shutil

#Get all the filenames of the current directory
filenames = os.listdir(".")
#Identify the picture
def is_image(filenames):
 return os.path.splitext(filenames)[-1] in [".png",".jpg"]
#Get the filenames of all pictures
images = filter(is_image, filenames)


from datetime import datetime

#Get time
def get_time(filenames):
 timestamp = os.path.getmtime(filenames)
 return datetime.fromtimestamp(timestamp)

#Sort by time
filenames.sort(key=get_time)

last_modified = None
for filename in filenames:
 modified = get_time(filename)

 #number
 if last_modified and last_modified.date() == modified.date():
  num += 1
 else:
  num = 1

 #name the file according to time and number
 targetname = "{}.{}.jpg".format(modified.strftime("%Y-%m-%d"), num)

 #rename
 shutil.move(filename, targetname)

 last_modified = modified 

2017/4/29

安全的關閉你的RPI

這裡的RPI為Raspberry Pi 的簡稱。

-

對於一個製造精細的機器來說,如果在他內部有程式仍在運行就強行將電源關閉是一件有風險的事情,因為這麼做可能會導致硬碟內部檔案系統毀損,造成檔案的遺失,所以我們在每次使用完畢要關機時都必須確保所有的程式都停止運作了。

如何安全地關閉你的raspberry pi呢?

只要打開終端機,輸入以下指令即可。
sudo shutdown -h now




參考資料:
http://raspi.tv/2012/how-to-safely-shutdown-or-reboot-your-raspberry-pi

rpi - 安裝opencv3.2和python3

2017/4/14

將youtube外觀改為Darkmode

要體驗這個模式,必須要開啟youtube的測試者功能。



-
首先登入你的youtube帳號,
在youtube的任一畫面中開啟瀏覽器的 [開發人員工具]  (在空白處點右鍵,在選單中可以找到),
我用的是firefox中的附加元件 [firebug] ,功能是一樣的。

接著點選 [主控台] 視窗
在下方">"後面輸入以下文字:
    document.cookie="VISITOR_INFO1_LIVE=fPQ4jCL6EiE"







輸入後按"Enter"
出現以下畫面即代表成功





重新整理網頁後你應該會看到你的youtube長得不一樣了,
如下圖,這是還沒開啟深色模式的樣子。





對著右上角的個人帳號設定點下去,可以找到一個 [深色模式] 的設定區,開啟他吧!
下圖即是開啟深色模式的樣子





註:
對著右下角的小人圖案點下去,即可離開測試者模式,回到原本的youtube囉



-
參考資料:
http://www.playpcesor.com/2017/04/youtube-dark-mode.html