2017/10/15

[AmebaRTL8195A] 玩玩網路功能

今天玩了一些範例:
CheckMac 可以印出Ameba8195的mac位址
ChackAP 可以連接附近的AP
ScanNetworks 可以掃描附近可以連接的AP

不過當USB斷線時,連接AP的狀態也會斷掉




在ScanNetworks裡面看到RSSI,查了資料以後發現在 wifi 和 802.11兩個關鍵字當中是個重要的參數呢

以下為資料節錄

--------------------------

From Metageek

What is RSSI and what does it mean for a WiFi network?

  • RSSI, or “Received Signal Strength Indicator”, is a measurement of how well your device can hear a signal from an access point or router. It’s a value that is useful for determining if you have enough signal to get a good wireless connection.
  • Note: Because an RSSI value is pulled from the client device’s WiFi card (hence “received” signal strength), it is not the same as transmit power from a router or AP.

From WIKI
  • the higher the RSSI number, the stronger the signal. Thus, when an RSSI value is represented in a negative form (e.g. −100), the closer the value is to 0, the stronger the received signal has been.



---------------------------
資料來源:

2017/7/9

clang簡介

昨天在練習c語言的時候,無聊的想查一下電腦的gcc版本是什麼,
使用的是 gcc --version 這個指令。
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 8.1.0 (clang-802.0.38)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
一查才知道原來電腦裡裝的是另一個代替gcc的編譯器---clang

[ 關於clang ]
是一個C、C++、Objective-C和Objective-C++程式語言的編譯器前端。它採用了底層虛擬機(LLVM)作為其後端。它的目標是提供一個GNU編譯器套裝(GCC)的替代品。作者是克里斯·拉特納,在蘋果公司的贊助支援下進行開發,而原始碼授權是使用類BSD的伊利諾伊大學厄巴納-香檳分校開源碼許可。
Clang專案包括Clang前端和Clang靜態分析器等。

這個軟體專案在2005年由蘋果電腦發起,是LLVM編譯器工具集的前端(front-end),目的是輸出代碼對應的抽象語法樹(Abstract Syntax Tree, AST),並將程式碼編譯成LLVM Bitcode。接著在後端(back-end)使用LLVM編譯成平台相關的機器語言 。Clang支援C、C++、Objective C。
在Clang語言中,使用Stmt來代表statement。Clang程式碼的單元(unit)皆為語句(statement),語法樹的節點(node)類型就是Stmt。另外Clang的運算式(Expression)也是語句的一種,Clang使用Expr來代表Expression,Expr本身繼承自Stmt。節點之下有子節點列表(sub-node-list)。
Clang本身效能優異,其生成的AST所耗用掉的記憶體僅僅是GCC的20%左右。FreeBSD 10將Clang/LLVM作為預設編譯器。

[ 效能 ]
測試證明Clang編譯Objective-C代碼時速度為GCC的3倍,還能針對使用者發生的編譯錯誤準確地給出建議


來源 : wikipedia

-----------------------
註:
在stackexchange上面查到可以找出電腦gcc的指令(但不知是取自哪)
gcc -dumpversion | cut -f1,2,3 -d. 


我的是4.2.1 (改-fl後面的1,2,3可選擇顯示版本小數點數 如 -fl1 輸出為4)

2017/7/2

從「處理球」的觀點來談籃球能力

摘錄自 http://tw.basketball.biji.co/index.php?q=news&act=info&id=668&subtitle

有一些跑不快、跳不高甚至投籃不準的人,上場時間比那些又會跑又會飛的體能怪物來的多。照道理說這些人是無法存在那充滿碰撞與速度的籃球場上的,只是好像他們能夠憑藉著一些「什麼」而讓他們被需要,甚至不會在關鍵與不能出錯的倒數階段被教練換下來。關於這個「什麼」到底是什麼?「處理球」這三個字或許就是很好的一個答案。


籃球是一個比賽得分的運動,其次是數據,但是在這些光鮮亮麗的數字背後,處理球往往是被忽略的。
處理球指的是當一個籃球選手在籃球比賽時,接球前、接球時、接球後、甚至是在接到球的過程中的每一個決定與反應。此決定與反應的合理性與時間長短決定了這位選手處理球能力的好壞。
處裡球無法用現有的籃球統計數字來表示,就連我們認為是無私象徵的助攻數據,也不能說明處理球的能力。


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