2013年9月4日 星期三

[資訊安全] Debug information

今天正想在某個網站採購一些東西, 網頁載入到一半突然噴出這樣的訊息, 這樣甘好?
2006 MySQL server has gone away
in:
[select c.categories_id, cd.categories_name from categories c, categories_description cd where c.categories_id=cd.categories_id and c.parent_id= '0' and cd.language_id='1' and c.categories_status='1' order by c.sort_order, cd.categories_name ]
2006 MySQL server has gone away
in:
[select count(*) as total from sessions where sesskey = '98937f53e2395dcc174f66449017743b']

哪個網站就不說了

2013年9月3日 星期二

[Wordpress] Crayon Syntax Highlighter

開始要在wordpress上面放扣了, 就胡亂找了一些plugin來用一下, 反正就是評比高的就拿來試用看看, 目前是用Crayon Syntax Highlighter感覺很讚, 使用起來也很簡單

安裝後看要不要改設定, Settings > Crayon的Theme有一堆可以用, 還有Font, Toolbar, Code一堆選項可以改

使用上就是在純文字模式下輸入
<pre lang="LANG">
// code here
</pre>
可用的LANG在langs目錄下都查得到, 於是乎範例就像
<pre lang="c">
#include <stdio.h>

void main()
{
    printf("Hello World");

    return;
}
</pre>


配合Ultimate Tinymce寫起blog很順手, 再附贈一個教學

reference:
* Top 5 Syntax Highlighter WordPress Plugins
* Learn How To Use The Ultimate TinyMCE Plugin  

2013年8月29日 星期四

[Python] module & class

最近寫python遇到很笨的問題

$ vi serial.py
import serial
                                                  
ser = serial.Serial('/dev/ttyUSB0', 9600)
ser.write("hello world!")
錯誤訊息
Traceback (most recent call last):
  File "serial.py", line 1, in 
    import serial
  File "/home/user/python/serial.py", line 4, in 
    ser = serial.Serial('/dev/ttyUSB0', 9600)
AttributeError: 'module' object has no attribute 'Serial'
如果照stackoverflow的講法, 應該改為from serial import serial
#import serial                                                                   
from serial import serial

ser = serial.Serial('/dev/ttyUSB0', 9600)
ser.write("hello world!")
錯誤訊息
Traceback (most recent call last):
  File "serial.py", line 2, in 
    from serial import serial
  File "/home/user/python/serial.py", line 2, in 
    from serial import serial
ImportError: cannot import name serial
又有人說, 應該改為from serial import *
#import serial                                                                   
#from serial import serial
from serial import *

ser = serial.Serial('/dev/ttyUSB0', 9600)
ser.write("hello world!")
錯誤訊息
Traceback (most recent call last):
  File "serial.py", line 2, in 
    from serial import serial
  File "/home/user/python/serial.py", line 2, in 
    from serial import serial
ImportError: cannot import name serial
最後把檔名serial.py改掉, 隨便改成foo.py就可以了
import serial
                                                  
ser = serial.Serial('/dev/ttyUSB0', 9600)
ser.write("hello world!")
如果再改成
#import serial                                                                   
from serial import serial

ser = serial.Serial('/dev/ttyUSB0', 9600)
ser.write("hello world!")
錯誤訊息
Traceback (most recent call last):
  File "s.py", line 2, in 
    from serial import serial
ImportError: cannot import name serial
如果改回
#import serial
#from serial import serial
from serial import *

ser = serial.Serial('/dev/ttyUSB0', 9600)                                       
ser.write("hello world!")
錯誤訊息
Traceback (most recent call last):
  File "s.py", line 4, in 
    ser = serial.Serial('/dev/ttyUSB0', 9600)
NameError: name 'serial' is not defined
好吧, 我還沒搞懂python的語法就在亂搞了...

2013年3月31日 星期日

[RPi] 在Raspberry Pi上使用HDMI轉VGA接頭

話說家中總是有老舊螢幕還是使用VGA介面(D-Sub),那就需要買一個HDMI轉VGA的接頭,再修改Raspberry Pi的/boot/config就可以使用了

簡單說明一定要改的地方有hdmi_drive=2表示強制從HDMI輸出,hdmi_group=2和hdmi_mode=16這兩個參數就視螢幕的解析度調整了

詳細參數可參考官網
# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1024
#framebuffer_height=768

# uncomment if hdmi display is not detected and composite is being output
hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
hdmi_group=2
hdmi_mode=16

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
arm_freq=1000

# for more options see http://elinux.org/RPi_config.txt
gpu_mem=64
core_freq=500
sdram_freq=600
over_voltage=6

2013年2月25日 星期一

[RPi] Disable Screen Blanking in X Window

如果想要把Raspberry Pi當作展示機, 那Raspbian預設10分鐘沒動作畫面就會暗掉就蠻令人困擾的, 通常修改xinitrc就會有作用
$ sudo vi -p ~/.xinitrc /etc/X11/xinit/xinitrc
xset s off         # don't activate screensaver
xset -dpms         # disable DPMS (Energy Star) features.
xset s noblank     # don't blank the video device
exec /etc/alternatives/x-session-manager      # start lxde
如果再不行的話就要再lightdm.conf新增一個屬性了
$ sudo vi /etc/lightdm/lightdm.conf
[SeatDefaults]
xserver-command=X -s 0 -dpms

reference:
* Disable screen blanking in X-Windows on Raspbian
* How do I prevent the screen from going blank?

2013年1月6日 星期日

[Embedded] 最近很夯的開發板

最近跟一個朋友聊天, 他推薦了幾個最近很夯的開發板
1.Cubieboard, 由cubieTech所製作
2.UNO.Net, 國人自製

目前我的結論是, 好玩的東西太多了, 可是不同的東西的SDK常常都不相同, 每一種都買來玩玩看當然可以, 可是這就會花很多的時間在重複性的事情(比如說建立環境或是軟硬體整合), 但是產品最重要的價值是在解決問題, 而不是只是玩玩看而已, 希望大家不要陷入這種迷失, 共勉之

2012年12月9日 星期日

[RPi] Setting up Wifi with Raspberry Pi

要購買Raspberry Pi的週邊最好是參考這裡,才不會踩到地雷,買到不支援的東西,話說我是買ASUS USB-N10當作無線網路卡,畢竟總是要支持一下國貨

在Raspbian的環境設定無線網路的方法一個是透過GUI,也就是桌面上的WiFi Config,啟動後選擇Adapter為wlan0,然後點選下面的scan,搜尋完畢後點選適合的WiFi,選擇適合的加密方式與輸入正確的金鑰,最後connect就可以快樂的連上網路了

不然就是要透過command,流程大概是這樣
1.更新套件
$ sudo apt-get update && sudo apt-get upgrade

2.檢查USB是否有偵測到新的裝置(用的是RTK RTL8188SU的晶片)
$ lsusb
...
Bus 001 Device 004: ID 0b05:1786 ASUSTek Computer, Inc. USB-N10 802.11n Network Adapter [Realtek RTL8188SU]
...

3.檢查是否有載入無線網路模組
$ lsmod
Module                  Size  Used by
...
r8712u                165407  0 
...

4.安裝wireless工具
$ sudo apt-get install wireless-tools

5.根據加密方式做適合的設定 如果是WEP加密
$ sudo vi /etc/network/interfaces
auto lo

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
iface wlan0 inet dhcp
wireless-essid <ssid>
wireless-key s:<password>

#wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
wireless-power off
iface default inet dhcp

如果是WPA加密
$ sudo vi /etc/network/interfaces
allow-hotplug wlan0
auto wlan0
iface wlan0 inet dhcp
wpa-ssid <ssid>
wpa-psk s:<password>

另外一種方法是安裝WPA的設定工具(在有線網路的情況下)
$ sudo apt-get install wpasupplicant

然後就可以透過不同的設定檔管理不同的加密WiFi(要加雙引號)
$ sudo vi /etc/wpa_supplicant/wpa_supplicant.conf
network={
ssid="YOUR SSID"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
psk="YOUR PASSWORD"
}

指定無線網卡讀取適當的設定檔
$ sudo vi /etc/network/interfaces
auto wlan0
iface wlan0 inet dhcp
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

最後,有幾個指令常常用到:
看無線網卡讀到的無線網路資訊,可以確認無線網卡是否有作用
$ iwlist wlan0 scan
重新向DHCP Server要IP
$ dhclient wlan0

 reference:
* WiFi on Rasspberry Pi with ASUS USB N10
* Setting up Wifi under Debian on Raspberry Pi