My note on Installing OpenWRT on Banana Pi R1 (BPi-R1)

Today, I just got my Banana Pi R1.  Here is a simple guide to set it up as an OpenWRT router.

Step 1: Flash the TF(microSD) card.

  • Goto the download page of BPi-R1 (
  • Find and download the latest OpenWRT Image, which is version 4.0 (01/09/2015) as I write this.
  • Write the OpenWRT image to the TF card. I use OS X, here is the code I used in Terminal:
  • Find the disk number of your TF card. Mine is disk2[Bold number may varies on your computer, wrong number will cause serious problem, you will lose your data on the wrong disk]:
    diskutil list

    Unmount it:

    diskutil unmountDisk /dev/disk<strong>2</strong>

    Write the image:

    sudo dd bs=1m if=~/Downloads/BPI-R1_OpenWrt_V4.0.img of=/dev/rdisk<strong>2</strong>
  • If you are using other OS, follow the guide here (From Raspberry Pi, their are all the same except the image)
  • Eject the TF card  from your computer and insert it into Banana Pi.

Step 2: Power On your Banana Pi R1.

  • Plug in the 5V power cord to the correct port, it will power on by itself.
  • HDMI is not working on OpenWRT(only works few seconds while booting)
  • Connect the BPI-R1’s WAN to your home router/switch’s LAN (Assume DHCP is enabled )
  • Find the BPI-R1’s IP address. You may find it in the web management interface of your home router. Scan port 80 and 22 for the whole subnet other wise.
  • use root/admin to login BPI-R1
  • Mostly Done.

After that, I found only 80M(VFAT) + 150M(EXT4) was used on BPI-R1, which waste pretty much space on my 32GB TF card.

Extra Step: Expand the ext4 partition. (Inspired by SaruMaaz)

  • Download Gparted Live
  • Write Image to a Flash Drive (Assume the flash drive is disk2)
    sudo dd bs=4m if=~/Downloads/gparted-live-0.24.0-2-i586.iso of=/dev/rdisk<strong>2</strong>;sync
  • Restart OS X and hold Option key while booting,
  • Chooes ‘EFI Disk’
  • Enter your language code
  • Enter 0 and get to the GUI
  • Plug in the TF card, Find the TF card (mine is sdd)
  • Find the 150M partition, right click, change the size…
  • Apply
  • Done

How to get a certification to sign PDFs

I’m trying to get a certification to sign my PDF files these days.

My Goal:

  1. It is a certification signed by a trusted CA in Adobe Acrobat (of course it can’t be self-signed)
  2. It is cheap

What I did:

Check the current list of Adobe Approved  Trusted CA (

Check those CA’s website.

Many of those CA are used inside their company/organization only, Some “Widely known CA” like DigiCert, GlobalSign, Entrust cost a lot(200-800 USD/year) for the certification, and you maybe asked for purchasing a USB device for the cert, PLUS, some of them limit the number of files you signed.

Finally I found “CERTUM (Unizeto Technologies)” in Porland, they supply a certification for a low cost(~10USD/year)

Read More

Netbeans 无法显示中文之解决方案


经过测试,使用最常用的英文字体,例如Arial, New Times Roman 都可以正常显示中文。其余字体,比如编程常用的MonoSpace,Consolas,Monaco什么的会无法显示中文。如图:


经过一番搜索,找到原因,简单地说,原因在于这些字体里面不包含中文,fallback font也没有中文.







[Apache] Rewrite subdomain as subfolder

What You Want:

—————–/123/index.php ===>
—————–/www/index.php ===>
—————–/blog/index.php ===>
—————–/email/main/index.php ===>

Set dns:

A (may be AAAA) * to your server’s IP address.

This is the rewrite code you should use:

RewriteEngine On
RewriteMap lowercase int:tolower
RewriteCond %{HTTP_HOST} ^(.*)\.yourwebsite\.com$
RewriteRule ^(.*)$     /path/to/www/root/${lowercase:%1}/$1 [L]


Options -Indexes

Will not working in this case. Since Apache can not find the subfolder if you hide them. All subdomains will return a 404 error.

isset() vs empty() vs is_null()

PHP has different functions which can be used to test the value of a variable. Three useful functions for this are isset()empty() and is_null(). All these function return a boolean value. If these functions are not used in correct way they can cause unexpected results.

isset() and empty() are often viewed as functions that are opposite, however this is not always true. In this post I will explain the differences between these functions.



From PHP manual – isset():

isset — Determine if a variable is set and is not NULL

In other words, it returns true only when the variable is not null.

From PHP Manual – empty():

empty — Determine whether a variable is empty

In other words, it will return true if the variable is an empty string, false, array(), NULL, “0?, 0, and an unset variable.

From PHP Manual – is_null():

is_null — Finds whether a variable is NULL

In other words, it returns true only when the variable is null. is_null() is opposite of isset(), except for one difference that isset() can be applied to unknown variables, but is_null() only to declared variables.

The table below is an easy reference for what these functions will return for different values. The blank spaces means the function returns bool(false).
Value of variable ($var) isset($var) empty($var) is_null($var)
“” (an empty string) bool(true) bool(true)
” ” (space) bool(true)
FALSE bool(true) bool(true)
TRUE bool(true)
array() (an empty array) bool(true) bool(true)
NULL bool(true) bool(true)
“0″ (0 as a string) bool(true) bool(true)
0 (0 as an integer) bool(true) bool(true)
0.0 (0 as a float) bool(true) bool(true)
var $var; (a variable declared, but without a value) bool(true) bool(true)
NULL byte (“\ 0″) bool(true)
Copy From  By Virendra on January 21, 2012

Practice it CSE142 MT 06au 的一道题

Write a method named hasMidpoint that accepts three integers as parameters and returns true if one of the integers is the midpoint between the other two integers; that is, if one integer is exactly halfway between them. Your method should return false if no such midpoint relationship exists.
The integers could be passed in any order; the midpoint could be the 1st, 2nd, or 3rd. You must check all cases.
Calls such as the following should return true:
hasMidpoint(4, 6, 8)
hasMidpoint(2, 10, 6)
hasMidpoint(8, 8, 8)
hasMidpoint(25, 10, -5)
Calls such as the following should return false:
hasMidpoint(3, 1, 3)
hasMidpoint(1, 3, 1)
hasMidpoint(21, 9, 58)
hasMidpoint(2, 8, 16)

public static boolean hasMidpoint(int a,int b,int c){
    int e=a+b+c;
    if (e/3==a||e/3==b||e/3==c)
        return true;
    return false;


# name expected return your return result
1 hasMidpoint(1, 2, 3) true true pass
2 hasMidpoint(2, 10, 6) true true pass
3 hasMidpoint(0, -50, -25) true true pass
4 hasMidpoint(21, 9, 58) false false pass
5 hasMidpoint(-2, 9, 27) false false pass

public class test{
public static void main(String[] args){
public static boolean hasMidpoint(int a,int b,int c){
int e=a+b+c;
if (e/3==a||e/3==b||e/3==c)
return true;
return false;



if ((e/3==a||e/3==b||e/3==c)&&e%3==0)




[C/C++]关于void main和int main的问题

void main与int main之间的区别是什么?”这是一个常见的问题。我们来探讨一下这个问题,并深入研究一些有关main()函数不同版本的更多的东西。



在C89标准中,main() 的形式是可以接受的,当然使用如下的C99标准更明智,因为在这个标准中只有如下格式才能被接受:

int main ( void )
int main ( int argc, char *argv[] )




main()函数的返回类型必须为int;返回的整形值作为传递给调用者的一个返回码。(this allows a return code to be passed to the invoker)



int main ( int argc, char *argv[] )
int main ()

第一种格式遵从C99标准;第二种格式在不需要通过命令行向程序传递参数时使用,与C99标准中规定的格式int main(void)效果相同。

(C)int main()与int main(void)之间的区别:


int foo();


转自: < type="text/javascript">document.write(‘’)
void main()函数是如何处理的?


void foo(void);

一个常见的误解是,这种逻辑同样适用于main()函数。呵呵,事实并非如此,main()函数是很特殊的,无论何时你都应该依照标准定义main()函数(译:即使用int main()的形式!),并把返回值定义为int。有时void main()的例外形式是可以出现的,但这仅限于某些特定的系统。如果你不敢肯定正在使用这些系统,那么答案很简单,不能使用void main()的形式。

如果你在论坛上写了像“void main”这样的代码而被警告,那么最好改过来。不要用”我的老师告诉我这么做是对的”之类的话来为自己开脱;老师们总是习惯犯错误(teachers have a bad habit of being wrong)。写安全的,合乎标准的代码,大家就可以专注于你程序中其它的问题而不是在这种规范方面的东西上浪费时间。

但是int main(int argc, char *argv[], char *envp[])又是怎么回事呢?

好比是标准的扩展版,main()函数可以在一些系统中提取一个额外的参数用来访问环境变量。这个用法不能保证在每个编译环境中都行得通,所以使用 envp 这个参数是还是谨慎为妙。

最后,关于为什么void main(void)是一种错误的用法,这个链接提供了一些更细节化的背景资料:
总之,尽量用int main()这个更标准,程序也会更安全。

1。在C++标准中main函数是int的而不是void的。标准C++要求main有int型返回值。而在C中允许void main()即main()无返回值 。C++标准虽然不允许 main为void型,但是在一些编译器比如VC6上允许main为void型, 头文件申明为#include(C++中.h的头文件是对C的支持,是非模板化的) 。但效率低!


int main()
int main(int argc, char *argc[])

using namespace std;
void main()