2014年11月12日 星期三

PHP开发框架

FuelPHP

http://fueldocs.ycnets.com/index.html

Laravel

http://kejyun.github.io/Laravel-4-Documentation-Traditional-Chinese/docs/introduction/

http://code.csdn.net/phpframework/#

Phalcon是用C语言实现的拥有高性能和低功耗等特点的PHP开发框架
http://phalconphp.com/zh/

ThinkPHP 是一个免费开源的
http://www.thinkphp.cn/document/index.html


在 Symfony2 建立一個部落格

http://twpug.net/docs/symblog/index.html

Symfony2中文文档

https://symfony-docs-chs.readthedocs.org/en/latest/

Linux Shell 脚本中字符串的连接方法

如果想要在变量后面添加一个字符,可以用一下方法:
$value1=home
$value2=${value1}"="
echo $value2
把要添加的字符串变量添加{},并且需要把$放到外面。
这样输出的结果是:home=,也就是说连接成功。
又如:
[root@localhost sh]# var1=/etc/
[root@localhost sh]# var2=yum.repos.d/
[root@localhost sh]# var3=${var1}${var2}
[root@localhost sh]# echo $var3
/etc/yum.repos.d/
shell 如何实现字符串不足N位自动补零
# 仅适用于数字
printf "%04d\n" 86
echo 86|awk '{printf("%04d\n",$0)}'


将echo的结果赋给一个变量
var=`echo aaa`

解決 "maximal mount count reached" 與硬碟檢測
檢查 mount 次數
$ tune2fs -l /dev/sdb1 | grep ^M
Mount count:              26
Maximum mount count:      22
取消最大 mount 次數檢查
$ tune2fs -c0 -i0 /dev/sdb1
tune2fs 1.39 (29-May-2006)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds
$ tune2fs -l /dev/sdb1 | grep ^M
Mount count:              26
Maximum mount count:      -1
檢查檔案系統
$ umount /dev/sdb1

當 mount 硬碟時老是出現
"EXT3-fs warning: maximal mount count reached, running e2fsck is recommended"
是提醒你該用 e2fsck 做檔案系統的檢查,請依下列步驟處理:
1. 查看目前的 mount 次數及限制
2. 取消最大 mount 次數檢查
3. 查看目前的 mount 次數及限制
1. 取消 mount,並做檔案系統檢查及自動修復處理

$ e2fsck -p /dev/sdb1

代碼對於標准bash而言沒有錯,因为Ubuntu为了加快開機速度,用dash代替了傳統的bash,是dash在搗鬼。
解决方法是取消dash:
sudo dpkg-reconfigure dash
在選擇項中選No,即可。



PC安裝Clover EFI與Hackintosh-準備安裝工具

http://megamo.logdown.com/posts/198831-black-apple-pc-install-clover-efi-hackintosh-and-ready-to-install-tools


SSH 使用金鑰連線的設定步驟

以下使用 ssh-keygen 產生 RSA2 的金鑰為範例,然後會得到兩個檔案分別為公鑰(id_rsa.pub)、私鑰 (id_rsa),原則上你可以只產生一份金鑰,然後將>該公鑰設定給多個主機,使用同一私鑰登入不同的主機。
  1. 在 Command Line 中使用 ssh-keygen 指令產生金鑰。
    $ ssh-keygen -t rsa1 -C "username@xxx.xxx"  # 產生 RSA1 金鑰
    $ ssh-keygen -t rsa -C "username@xxx.xxx"  # 產生 RSA2 金鑰
    $ ssh-keygen -t dsa -C "username@xxx.xxx"  # 產生 DSA 金鑰
    
    
  2. 將公鑰設定到欲連線的主機。
    $ scp ~/.ssh/id_rsa.pub [欲連線主機]:~/.ssh/
    
  3. 系統預設處理公鑰的檔案為 authorized_keys,因此要先登入欲連線的主機,再將公鑰附加於該檔案之中。
    $ ssh [欲連線的主機]
    # 將 public key 附加到檔案的最後面
    $ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
    # 調整 authorized_keys 的檔案權限
    $ chmod 644 ~/.ssh/authorized_keys

SSH隧道与端口转发及内网穿透

http://blog.creke.net/722.html

防止SSH連線逾時(timeout)

ubuntu的SSH連線預設只要一段時間沒有輸入文字,伺服器會逾時(timeout)而自動斷線
所以我們必需修改OpenSSH Server的設定,讓sshd每隔5秒就送出小封包,以維持連線不中斷.
防止SSH連線逾時的方法有以下幾種。

方法一:
修改/etc/ssh/ssh_config
加上
ServerAliveInterval 5
然後,重啟SSH服務:
#sudo /etc/init.d/ssh restart 或
#sudo service ssh restart
方法二:
編輯 /etc/ssh/sshd_config
加上
KeepAlive yes
ClientAliveInterval 60
然後,重啟SSH服務:
#sudo /etc/init.d/ssh restart 或
#sudo service ssh restart
方法三:
若是從linux環境連上server,可以修改使用者個人的ssh設定檔:
編輯 ~/.ssh/config
加上
ServerAliveInterval 60

hokag_user@hokag:~$ netstat -tnl | grep 127.0.0.1


http://portable.easylife.tw/entry/Reverse-SSH-Tunnel%E5%AF%A6%E9%9A%9B%E9%81%8B%E7%94%A8%EF%BC%8C%E6%90%AD%E9%85%8Dauotssh%E6%B0%B8%E4%B8%8D%E6%96%B7%E7%B7%9A%EF%BC%8Cputty%E5%BB%BA%E7%AB%8B%E5%8F%8D%E5%90%91tunnel



使用 Git 管理源代码

http://www.ibm.com/developerworks/cn/linux/l-git/

官方教程的中文版
http://git-scm.com/book/zh/v1

Where can I find the serial number of the Raspberry Pi I am currently using?
http://raspberrypi.stackexchange.com/questions/2086/how-do-i-get-the-serial-number
pi@raspberrypi:~$ cat /proc/cpuinfo
grep -Po '^Serial\s*:\s*\K[[:xdigit:]]{16}' /proc/cpuinfo

crc驗證
http://www.cppblog.com/smagle/archive/2014/05/29/74119.html


在linux c使用openssl/md5.h加密
#include<stdio.h>
#include<openssl/md5.h>
#include<string.h>

int main( int argc, char **argv )
{
unsigned char *data = "123";
unsigned char md[16];
int i;
char tmp[3]={'\0'},buf[33]={'\0'};
MD5(data,strlen(data),md);
for (i = 0; i < 16; i++){
    sprintf(tmp,"%02x",md[i]);
    strcat(buf,tmp);
}
printf("%s\n",buf);
return 0;
输出:
sudo apt-get install openssl libssl-dev libssl-doc libcurl4-openssl-dev
gcc MD5test.c -lcrypto -o MD5test
202cb962ac59075b964b07152d234b70 

1. %02X或%02x强制输出两位(分别对应大写字符串和小写字符串)。
2.一定要使用unsigned char,虽然是char,其实就是个int,当然,它只有一个字节,和char的区别是,unsigned char 0~255 ,char -127~127。使用char会出问题。这个md5加密函数,返回16个十进制数,范围在0~255间,把它format为十六进制就是32为md5编码了。
3.gcc编译的时候,后面加上参数 -lcrypto 如果系统没有安装libcrypto,是不能用这个方法的。

4. 可以使用strtol来转换16位进制的字符串为long型整数 具体请man strtol 有示例代码

ssh 的話加個 -v 去連 看看卡在哪邊 03/16 18:55
CP64:個人的情形是去 sshd_config 把 GSSAPI 關掉就好了 03/16 18:55
感謝:) 加了-v後看到卡在 debug1: SSH2_MSG_SERVICE_ACCEPT received google後看到在sshd_config設定 UseDNS no 即可。 GSSAPI 還在研究他的作用。但至少加了UseDNS no 就不會卡在那了。

sudo tzselect
sudo /usr/sbin/ntpdate tock.stdtime.gov.tw
date


為你的 Raspberry Pi 裝上 Watchdog

http://coldnew.github.io/blog/2013/12/13_b1756.html

How to automatically reconnect WiFi?

http://raspberrypi.stackexchange.com/questions/4120/how-to-automatically-reconnect-wifi

Well, there is a very simple solution:
  1. Go to /etc/ifplugd/action.d/ and rename the ifupdown file to ifupdown.original
  2. Then do: cp /etc/wpa_supplicant/ifupdown.sh ./ifupdown
  3. Finally: sudo reboot
That's all. Test this by turning off/on your AP; you should see that your Raspberry Pi properly reconnects.

Wifi Reconnect on drop

http://www.raspberrypi.org/forums/viewtopic.php?f=91&t=16054&start=25

2014年10月29日 星期三

Raspberry Pi 上小米随身wifi的无线网卡应用

RUN rpi-update
创建src目录:
mkdir rpi_src
下载rpi-linux头文件:
cd rpi_src
git clone --depth 1 git://github.com/raspberrypi/linux.git rpi-linux
下载firmware
git clone --depth 1 git://github.com/raspberrypi/firmware.git rpi-firmware
下载小米随身wif驱动源码,小米的芯片是ralink的MT7601U,去官网(http://www.mediatek.com/en/downloads/)
下载,我这下的是DPO_MT7601U_LinuxSTA_3.0.0.4_20130913.tar.bz2,
a)解压:
tar -xjvf DPO_MT7601U_LinuxSTA_3.0.0.4_20130913.tar.bz2 得到DPO_MT7601U_LinuxSTA_3.0.0.4_20130913
b) cd DPO_MT7601U_LinuxSTA_3.0.0.4_20130913
c) 修改common/rtusb_dev_id.c文件,
  添加小米wifi的pid(可以通过lsusb得到:“Bus 001 Device 004: ID 2717:4106 ”):
{USB_DEVICE(0x2717,0x4106)}, /* Xiaomi Wifi */
d)修改Makefile:
   找到ifeq ($(PLATFORM),PC)处的 “LINUX_SRC”,把它改成指向 "rpi-linux" 的目录,这个很关键,我是从文件
“sta_ate_iwpriv_usage.txt” 中看到的;
编译、安装:
 cd ../rpi-linux
make mrproper
zcat /proc/config.gz > .config
make modules_prepare
cp ../rpi-firmware/extra/Module.symvers .
cd ../DPO_MT7601U_LinuxSTA_3.0.0.4_20130913
make
sudo make install
sudo modprobe mt7601Usta
运行iwconfig,看到它了:
ra0       Ralink STA  ESSID:"11n-AP"  Nickname:"MT7601STA"
          Mode:Auto  Frequency=2.412 GHz  Access Point: Not-Associated
          Bit Rate:1 Mb/s
          RTS thr:off   Fragment thr:off
          Link Quality=10/100  Signal level:0 dBm  Noise level:0 dBm
          Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
          Tx excessive retries:0  Invalid misc:0   Missed beacon:0
lo        no wireless extensions.
eth0      no wireless extensions.
配置Raspberry Pi无线网卡:
修改 /etc/network/interfaces 文件(这个文件是定义网络配置的):
sudo vim /etc/network/interfaces
auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto ra0
allow-hotplug ra0
iface ra0 inet dhcp
wpa-ssid "wifi"
wpa-psk "passwd"
TIPS:
auto lo //表示使用localhost
iface eth0 inet dhcp //表示如果有网卡ech0, 则用dhcp获得IP地址 (这个网卡是本机的网卡,而不是WIFI网卡)
auto ra0 //表示如果有wlan设备,使用ra0设备名
allow-hotplug ra0 //表示ra设备可以热插拨
iface ra0 inet dhcp //表示如果有WLAN网卡ra0 (就是WIFI网卡), 则用dhcp获得IP地址
wpa-ssid "wifi" //表示连接SSID名为 wifi的WIFI网络。 JoStudio是我的WIFI网SSID名称,如果是别的,请更改
wpa-psk "passwd" //表示连接WIFI网络时,使用wpa-psk认证方式,认证密码是passwd。如果是别的密码,请更改
设完restart,ifconfig就可看到ra0的连接,enjoy it!

Raspberry Pi – hiding boot messages on screen

http://ananddrs.com/2013/09/18/rpi-hide-boot-msg/

https://github.com/Mashpy/Qt-MySQL-Driver-For-Windows





























fromhttp://www.raspberrypi.org/phpBB3/viewtopic.php?t=13807&p=153177


Qt入門篇(3):連結SQLITE資料庫

http://chenglearning.blogspot.tw/2013/11/qt3sqlite.html

MySQL跨主機查詢
在mysql 裏,預設的帳號所在的主機都是 localhost,這在db和web同一台主機時沒問題,但是如果資料庫是在不同的主機,就需要給予適當的權限。

例如:

web 主機的ip是 192.168.0.2

mysql 主機 ip 是 192.168.0.3

0,先確認雙方的防火牆沒有檔到3306 post!

1,先確認192.168.0.3的3306 port是不是打開?

使用nestat命令查看3306 port狀態:

~# netstat -an | grep 3306

tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN

由此可以看出3306 port只是在IP 127.0.0.1上監聽,拒絕其他IP的訪問。

3,請修改/etc/mysql/my.cnf文件:

# Instead of skip-networking the default is now to listen only on

# localhost which is more compatible and is not less secure.

bind-address = 127.0.0.1

把上面這一行註釋掉或者把127.0.0.1換成合適的IP,或直接註釋掉。

/etc/init.d/mysql restart
重新啟動後,重新使用netstat檢測:

~# netstat -an | grep 3306

tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN

由此可看到MySQL已開始監聽3306 post所有對外的封包。

4,在[192.168.0.2]使用下面命令測試:

 ~# mysql -h 192.168.0.3 -u root -p

Enter password:

ERROR 1130 (00000): Host 'Ubuntu_pc.local' is not allowed to connect to this MySQL server

則還需要mysql把用戶權限分配各遠端用戶。

請登錄到mysql所在伺服器,使用grant命令分配權限

mysql> grant all on database_name.* to user_name@'%' identified by 'user_password';

其中database_name、user_name和user_password根據實際情況設置。

完成後使用mysql命令連接,提示成功,為了確保正確可以再遠端登錄測試一下。

# mysql -u root -p

grant all on db_name.* to db_user@192.168.0.2 identified by 'db_pass';

quit

退出mysql,那麼在 192.168.0.2 的 db_user 這個帳號就可以存取 192.168.0.3 上的 db_name 資料庫

而在 mysql_connect() 裏的 localhost ,就用 192.168.0.3 來取代就可以了 !

如果遇到登入過久的問題,則可以把MySQL的DNS反查功能關閉!
sudo vim /etc/mysql/my.cnf
在[mysqld]下面新增一行:
skip-name-resolve 
sudo /etc/init.d/mysql restart
重開即可解決!

Qt is now configured for building. Just run mingw32-make.
To reconfigure, run mingw32-make confclean and configure.

C:\Qt\4.7.2>configure -qt-sql-mysql -plugin-sql-mysql -nomake demos -nomake examples
                     configure -debug-and-release -qt-sql-mysql
C:\Qt\4.7.2>mingw32-make

用 root 登入 MySQL
  mysql -u root -p
 Enter password:  
 
mysql> GRANT all ON db35.* TO s35@'localhost' IDENTIFIED BY 's35'; 
   把 db35 這個資料庫(含其下的所有資料表),授權給 s35,從 localhost 上來,密碼為s35
 
mysql> GRANT all ON *.*  把所有資料庫及資料表授權給別人,太危險了!
 
mysql> GRANT all??? ON www.* TO '*'@'*' IDENTIFIED BY '';
    把 www 這個資料庫(含其下的所有資料表),授權給 任何機器任何人,無密碼(通常給不特定人士使用)
 
mysql> FLUSH PRIVILEGES;   (最後一定要強迫更新權限)

 
mysql>create database TestDB;

 mysql>grant all on TestDB.* to U517@'%' IDENTIFIED BY 'Abc123';

首先使用 root 的權限
visudo  ( vi /etc/sudoers )
將最後一行的
%admin ALL=(ALL) ALL
改成

%admin ALL=(ALL) NOPASSWD: NOPASSWD: ALL
存檔退出,即可。

2. 7z命令的使用
2.1 解压缩7z文件
7za x phpMyAdmin-3.3.8.1-all-languages.7z -r -o./
参数含义:
x  代表解压缩文件,并且是按原始目录树解压(还有个参数 e 也是解压缩文件,但其会将所有文件都解压到根下,而不是自己原有的文件夹下)
phpMyAdmin-3.3.8.1-all-languages.7z  是压缩文件,这里我用phpadmin做测试。这里默认使用当前目录下的phpMyAdmin-3.3.8.1-all-languages.7z
-r 表示递归解压缩所有的子文件夹
-o 是指定解压到的目录,-o后是没有空格的,直接接目录。这一点需要注意。

2.2 压缩文件/文件夹

7za a -t7z -r Mytest.7z /opt/phpMyAdmin-3.3.8.1-all-languages/*
参数含义:
a  代表添加文件/文件夹到压缩包
-t 是指定压缩类型,这里定为7z,可不指定,因为7za默认压缩类型就是7z。
-r 表示递归所有的子文件夹
Mytest.7z 是压缩好后的压缩包名
/opt/phpMyAdmin-3.3.8.1-all-languages/*:是压缩目标。
注意:7za不仅仅支持.7z压缩格式,还支持.tar.bz2等压缩类型的。如上所述,用-t指定即可。

Install lamp with 1 command in Ubuntu 12.10, 13.04

http://www.unixmen.com/install-lamp-with-1-command-in-ubuntu-1010-maverick-meerkat/

    Qt SQL Database Drivers 設定

    http://qt-project.org/doc/qt-4.8/sql-driver.html

Qt5程序在Windows 7/8上部署注意事项


http://www.aiuxian.com/article/p-496281.html

http://blog.csdn.net/zgj10086/article/details/19681633
http://blog.csdn.net/listenape/article/details/22039619
  • WpaSupplicant
    • http://wiki.centos.org/zh-tw/HowTos/Laptops/WpaSupplicant

      http://qt-project.org/forums/viewthread/16378

2014年10月18日 星期六

node.js教學-操作MySQL資料庫

http://blog.allenchou.cc/nodejs-tuts-5-use-mysql-db/

Qt入門篇(1)

http://chenglearning.blogspot.tw/2013/11/qt1-qt-gui-application.html

Raspberry Pi – hiding boot messages on screen

There may be a time when one would want to hide boot messages that show up on the screen (or monitor or TV). The trick is to edit /boot/cmdline.txt file.
One may use the following command
sudo nano /boot/cmdline.txt
Then make the following changes to the file:
- Replace "console=tty1" by "console=tty3" to redirect boot messages to the third console.
- Add "loglevel=3" to disable non-critical kernel log messages.
After changing, to get to the console simply press Alt + F3 during or after boot. However, if text cursor needs to be hidden also then add “vt.global_cursor_default=0″ to the /boot/cmdline.txt file. In my case, I prefer to have text cursor as an indicator that it is actually booting.
Here is the content of my /boot/cmdline.txt
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty3 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait logo.nologo loglevel=3
This is a quick and dirty solution for an unanimated custom splash screen during boot.
First of all, you need to install fbi:
apt-get install fbi
Copy your custom splash image to /etc/ and name it “splash.png”.
Next, create an init.d script called “asplashscreen” in “/etc/init.d/”.
I chose “asplashscreen” with an “a” at the beginning to be sure it starts first.
#! /bin/sh
### BEGIN INIT INFO
# Provides:          asplashscreen
# Required-Start:
# Required-Stop:
# Should-Start:      
# Default-Start:     S
# Default-Stop:
# Short-Description: Show custom splashscreen
# Description:       Show custom splashscreen
### END INIT INFO

do_start () {

    /usr/bin/fbi -T 1 -noverbose -a /etc/splash.png    
    exit 0
}

case "$1" in
  start|"")
    do_start
    ;;
  restart|reload|force-reload)
    echo "Error: argument '$1' not supported" >&2
    exit 3
    ;;
  stop)
    # No-op
    ;;
  status)
    exit 0
    ;;
  *)
    echo "Usage: asplashscreen [start|stop]" >&2
    exit 3
    ;;
esac
Then make that script executable and install it for init mode rcS:
chmod a+x /etc/init.d/asplashscreen
insserv /etc/init.d/asplashscreen
Reboot and watch your custom splash screen:
reboot

Linux下MySQL 5.5的修改字符集编码为UTF8(彻底解决中文乱码问题)

http://www.ha97.com/5359.html

sudo cp mt7601Usta.ko /lib/modules/3.12.28+/kernel/drivers/net/wireless/
sudo depmod -a
sudo reboot

Install Adminer manually on Ubuntu 14.04

http://www.leaseweblabs.com/2014/06/install-adminer-manually-ubuntu-14-04/


How To Install Linux, Apache, MySQL, PHP (LAMP)  on buntu

https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu