Linux Commands

print work directory: $ pwd

disk free: $ df

change owner: $ chown

change group: $ chgrp

change mode: $ chmod

$ timedatectl

local$ tar zcvf name.tar.gz directory 压缩

local$ scp localfile user@ip:~/

To copy file from remote server: scp username@remote:/file/to/send /where/to/put

$tar zxvf name.tar.gz 解压缩

To print run-level: $systemctl get-default

To print system version: $cat /etc/redhat-release

MAMP and phpMyAdmin at Mac

Apache and PHP are included by default in Mac OS.

Enable Apache on Mac OS X:
sudo apachectl start

Apache htdoc at Mac OS:
REMEMBER to change the permission of this folder in Finder.
Let apache own the permission:
sudo chown -R _www /Library/WebServer/Documents/wedance

Enable PHP for Apache:
sudo vim /etc/apache2/httpd.conf
Uncomment the following line (remove #):
LoadModule php5_module libexec/apache2/

Restart apache:
sudo apachectl restart

Install MySQL: The DMG Archive.
Open System Preferences -> MySQL -> Ensure the MySQL Server is running.

cd /usr/local/mysql/bin
This program enables you to improve the security of your MySQL installation:

To get started, log into MySQL’s root (administrative) account by issuing this command:
mysql -u root -p
Exit: exit

If failed, try:
mysql -u root -p --connect-expired-password
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('mySuperSecretPassword');

Download phpMyAdmin:
$cfg['Servers'][$i]['host'] = '';


JVM (Java Virtual Machine), to run Java bytecode.
JRE (Java Runtime Environment) = JVM + Java Core Library.
JDK (Java Development Kit) = JRE + Java Compiler.

Java SE (Java Standard Edition) = JDK
Java EE (Java Enterprise Edition)
Java ME (Java Micro Edition): Mobile device, TV, etc.

The conversion of dp units to screen pixels is simple: px = dp * (dpi / 160). You should always use dp units when defining your application’s UI, to ensure proper display of your UI on screens with different densities.
public static int px_from_dp(int dp) {
return (int) (dp * Resources.getSystem().getDisplayMetrics().density);
public static int dp_from_px(int px) {
return (int) (px / Resources.getSystem().getDisplayMetrics().density);

Setup Smart HTTP for Git + Gitweb in CentOS 7

I want my project url something like this:

So the clone command can be in this format: $ git clone

Create separate config file for Git: /etc/httpd/conf.d/git.conf

SetEnv GIT_PROJECT_ROOT /opt/git
ScriptAlias /git/ /usr/libexec/git-core/git-http-backend/

<LocationMatch "^/git/*">
AuthType Basic
AuthName "Git Access"
AuthUserFile /opt/git/.htpasswd
Require valid-user

Remember to grant permission: $ chown -R apache /opt/git

Create password for authentication: $ htpasswd /opt/git/.htpasswd andy

$ systemctl restart httpd

You can init a demo repository for testing:

$ cd /opt/git
$ mkdir myproject.git
$ cd myproject.git
$ git init --bare

$ git clone to test



Setup Gitweb:

$ yum install gitweb

  • The html resource: /var/www/git
  • The config file: /etc/gitweb.conf

Now we need to modify the config file to set project root:

our $projectroot = "/opt/git";

Start tracking existing project:
cd <localdir>
git init
git add .
git commit -m 'message'
git remote add origin <url>
git push -u origin master



  1. Download CodeIgniter
  2. Place the folder into apache htdoc, delete the “user_guide” folder.
  3. Copy .htaccess to root directory to remove index.php in URL, also edit $config[‘index_page’].
  4. Edit config.php to set timezone, base_url, encryption key, session, cookie, etc.
  5. Setting CodeIgniter’s ENVIRONMENT constant in index.php to a value of ‘production’ before publishing.


Web security with CodeIgniter

URL Security:

XSS attacks: xss-filtering

$data = $this->security->xss_clean($data);

Bitmap injection:

if ($this->security->xss_clean($file, TRUE) === FALSE)
// file failed the XSS test

The function returns TRUE if the image is safe, and FALSE if it contained potentially malicious information that a browser may attempt to execute.

SQL injection: escaping-queries

The secondary benefit of using binds is that the values are automatically escaped, producing safer queries. You don’t have to remember to manually escape data; the engine does it automatically for you.

Web development

Cookie: a small amount of information sent by a server to a browser, and then sent back by the browser on future page requests.
If your server has previously sent any cookies to the browser, the browser will send them back on subsequent requests.
Alternate model: client-side JavaScript code can set/get cookies.
  • Cookies are only data, not program code.
  • Cookies cannot erase or read information from the user’s computer.
  • Cookies are usually anonymous (do not contain personal information).
  • Cookies CAN be used to track your viewing habits on a particular site.

Security issues:

XSS attacks, SQL injection, bitmap injection, CSRF

Man-in-the-middle attack (network sniffing)

Session hijacking

Form validation scenario:

  1. A form is displayed.
  2. You fill it in and submit it.
  3. If you submitted something invalid, or perhaps missed a required item, the form is redisplayed containing your data along with an error message describing the problem.
  4. This process continues until you have submitted a valid form.

On the receiving end, the script must:

  1. Check for required data.
  2. Verify that the data is of the correct type, and meets the correct criteria. For example, if a username is submitted it must be validated to contain only permitted characters. It must be of a minimum length, and not exceed a maximum length. The username can’t be someone else’s existing username, or perhaps even a reserved word. Etc.
  3. Sanitize the data for security.
  4. Pre-format the data if needed (Does the data need to be trimmed? HTML encoded? Etc.)
  5. Prep the data for insertion in the database.

In order to implement form validation you’ll need three things:

  1. A View file containing a form and displaying error message in correct place.
  2. A View file containing a “success” message to be displayed upon successful submission.
  3. A controller method to receive and process the submitted data.


Encoding, and encryption too, are two-way processes. Passwords are secrets that must only be known to their owner, and thus must work only in one direction. Hashing does that – there’s no un-hashing or de-hashing, but there is decoding and decryption.

DO NOT use weak or broken hashing algorithms like MD5 or SHA1. These algorithms are old, proven to be flawed, and not designed for password hashing in the first place. Only use strong password hashing algorithms like BCrypt (which has a limit of 72 characters), which is used in PHP’s own Password Hashing functions.



香港賽馬會 ﹣ 賽馬資訊

噴射飛航 -港澳碼頭船期表「港澳連城」通行證








iOS development

iOS7 default blue: R:0.0 G:122.0 B:255.0; #007AFF

Asynchronous image downloader with cache support as a UIImageView category:

ProgressHUD is a lightweight and easy-to-use HUD for iOS 8 (written in Objective-C):

The Reachability sample application demonstrates how to use the System Configuration framework to monitor the network state of an iOS device:

iPhone resolutions guide:

The Ultimate Guide To iPhone Resolutions

iOS versions statistic:

SVN notes

Official Website

Official Documentation


= = This document is written for people who intend to build Subversion from source code. Normally, the only people who do this are Subversion developers and package maintainers.

find binary packages:

For OS X:

For windows:

Copy-modify-merge model

The copy-modify-merge model may sound a bit chaotic, but in practice, it runs extremely smoothly. Users can work in parallel, never waiting for one another. When they work on the same files, it turns out that most of their concurrent changes don’t overlap at all; conflicts are infrequent. And the amount of time it takes to resolve conflicts is usually far less than the time lost by a locking system.

When Locking Is Necessary

The copy-modify-merge model is based on the assumption that files are contextually mergeable—that is, that the majority of the files in the repository are line-based text files (such as program source code). But for files with binary formats, such as artwork or sound, it’s often impossible to merge conflicting changes. In these situations, it really is necessary for users to take strict turns when changing the file.

Working Copy & Repository

In Subversion, the client-side object which every user of the system has—the directory of versioned files, along with metadata that enables the system to track them and communicate with the server—is called a working copy. Although other version control systems use the term“repository” for the client-side object, it is both incorrect and a common source of confusion to use the term in that way in the context of Subversion.
A Subversion working copy is an ordinary directory tree on your local system, containing a collection of files.

Atomic transaction

A Subversion client commits (that is, communicates the changes made to) any number of files and directories as a single atomic transaction. By atomic transaction, we mean simply this: either all of the changes are accepted into the repository, or none of them is. Subversion tries to retain this atomicity in the face of program crashes, system crashes, network problems, and other users’ actions.


Each time the repository accepts a commit, this creates a new state of the filesystem tree, called a revision. Each revision is assigned a unique natural number, one greater than the number assigned to the previous revision. Unlike most version control systems, Subversion’s revision numbers apply to the entire repository tree, not individual files. Each revision number selects an entire tree, a particular state of the repository after some committed change. Notice that in general, revisions N and M of a file do not necessarily differ!

How the working copy works

four states of a working file:
  • Unchanged, and current
  • Locally changed, and current
  • Unchanged, and out of date
  • Locally changed, and out of date. – where conflict happens

Mixed revisions

The things you just committed are marked as having larger working revisions than everything else. After several commits (with no updates in between), your working copy will contain a whole mixture of revisions, even if you’re the only person using the repository.
You cannot commit the deletion of a file or directory that isn’t fully up to date.

$svn import

Note that after the import is finished, the original local directory is not converted into a working copy. To begin working on that data in a versioned fashion, you still need to create a fresh working copy of that tree.

$svn checkout

Most of the time, you will start using a Subversion repository by performing a checkout of your project.

$svn update

it’s best to have the latest versions of all your project’s files and directories before making new changes of your own.

In addition to all of the previous commands, you can use the –revision (-r) option with svn update to take an entire working copy “back in time”.

If you decide that you don’t need to merge any changes, but just want to accept one version of the file or the other, you can either choose your changes (a.k.a. “mine”) by using the “mine-full” command (mf) or choose theirs by using the “theirs-full” command (tf).

$svn status

If you run svn status at the top of your working copy with no additional arguments, it will detect and report all file and tree changes you’ve made.

  • ? item
    The file, directory, or symbolic link item is not under version control.
  • A item
    The file, directory, or symbolic link item has been scheduled for addition into the repository.
  • C item
    The file item is in a state of conflict. That is, changes received from the server during an update overlap with local changes that you have in your working copy (and weren’t resolved during the update). You must resolve this conflict before committing your changes to the repository.
  • D item
    The file, directory, or symbolic link item has been scheduled for deletion from the repository.
  • M item
    The contents of the file item have been modified.

$svn checkout

Most of the time, you will start using a Subversion repository by performing a checkout of your project.

$svn log

To find information about the history of a file or directory, use the svn log command.

$svn list

The svn list command shows you what files are in a repository directory without actually downloading the files to your local machine.

Recommended Repository Layout

  • Most projects have a recognizable “main line”, or trunk, of development; //check out the trunk
  • some branches, which are divergent copies of development lines;
  • some tags, which are named, stable snapshots of a particular line of development.

Directory Changes

But sometimes you need to add, remove, copy and move files and directories—the svn add, svn delete, svn copy, andsvn move commands handle those sorts of structural changes within the working copy.
These changes may take place immediately in your working copy, but no additions or removals will happen in the repository until you commit them.


Customizes things without effecting the main line, since they do things slightly differently.
Let’s say that you’ve been given the task of implementing a large software feature. It will take a long time to write, and will affect all the files in the project. The immediate problem is that you don’t want to interfere with Sally, who is in the process of fixing small bugs here and there. She’s depending on the fact that the latest version of the project (in /calc/trunk) is always usable. If you start committing your changes bit by bit, you’ll surely break things for Sally (and other team members as well).

The better solution is to create your own branch, or line of development, in the repository. This allows you to save your not-yet-completed work frequently without interfering with others’ changes and while still selectively sharing information with your collaborators.

Copying a directory on the server, however, is a constant-time operation, and it’s the way most people create branches.

$ svn copy ^/calc/trunk ^/calc/branches/my-calc-branch \
-m “Creating a private branch of /calc/trunk.”

Subversion’s repository has a special design. When you copy a directory, you don’t need to worry about the repository growing huge—Subversion doesn’t actually duplicate any data. Instead, it creates a new directory entry that points to an existing tree. In fact, this feature is the basis of how commits work in Subversion: each revision is a “cheap copy” of the previous revision, with a few items lazily changed within. Make branches as often as you want. It’s cheap – both time and space.

Now that you’ve created a branch of the project, you can check out a new working copy to start using it.

And when you’re completely finished with your branch, your entire set of branch changes can be copied back into the trunk.

Apple Events

Date, Description, Remark

2016/03/21, 9.7-inch iPad Pro\, beautiful new bands for Apple Watch\, and iPhone SE, –

2015/09/10, iPhone 6s & iPhone 6s Plus\, the all-new Apple TV with tvOS\, iPad Pro\, WatchOS 2 and iOS 9, –

2015/06/08, Apple Music\, OS X El Capitan\, watchOS 2\, iOS 9\, News app and updates to Apple Pay, Apple WWDC 2015

2015/03/09, Apple Watch and unveil the all-new MacBook\, ResearchKit and HBO, –

2014/10/16, iPad Air 2 and 27-inch iMac with Retina 5K Display\, Macmini7, –

2014/09/09, iPhone 6 & iPhone 6 Plus\, Apple Pay\, and Apple Watch,-

2014/06/02, OS X Yosemite\, iOS 8 with iCloud Photo Library\, new Messages features\, the new Health app\, and more, Apple WWDC 2014

2013/10/22, new iPad Air\, iPad mini with Retina display\, updated MacBook Pro with Retina display and next generation iWork and iLife Apps for OS X and iOS, –

2013/09/10, new iPhone 5c and iPhone 5s, –

2013/06/10, iTunes Radio\, iOS 7\, next generation Mac Pro and updated MacBook Air, Apple WWDC 2013

2012/10/23, new iPad mini\, fourth generation iPad with Retina display\, new iMac\, and the 13-inch MacBook Pro with Retina display\, Macmini6, –

2012/09/12, iPhone 5\, iOS 6\, iTunes\, iPod touch\, and iPod nano, –

2012/06/11, Mac OS X Mountain Lion\, iOS 6\, and the all-new MacBook Pro with Retina display, Apple WWDC 2012

2012/03/07, third generation iPad\,The new Apple TV, –

2012/01/19, iBooks 2 for iPad featuring iBooks textbooks\, along with iBooks Author\, and iTunes U app, Apple Education Event

2011/10/04, iPhone 4S\, iOS 5 and iCloud,  –

2011/06/06, Mac OS X Lion\, iOS 5\, and iCloud, Apple WWDC 2011

Mac mini: October 16, 2014 (current release, Intel core i5)

Macbook: April 10, 2015 (current release)

Install set for OS X

The unarchiver: Appstore

Input source:

Photoshop CC for Mac 2015:

MPlayerX 1.1.1:

Office 2016:

CentOS 7 Setup

Apache config: /etc/httpd/conf/httpd.conf

Including config: /etc/httpd/conf.d/ssl.conf


Step by step to setup CentOS 7 server:

1. Initial Server Setup with CentOS 7

2. How To Configure SSH Key-Based Authentication on a Linux Server

DO remember to change permission for the file and directory:
chmod 700 .ssh
chmod 600 .ssh/authorized_keys

More information about “chmod”: Linux and Unix chmod command

3. Additional Recommended Steps for New CentOS 7 Servers

4. How To Install Linux, Apache, MySQL, PHP (LAMP) stack On CentOS 7


5. PHP 7 on CentOS via Yum

then, remove the repo:

$ cd /etc/yum.repos.d
$ ls
$ yum remove rpmforge-release

6. How To Install and Secure phpMyAdmin with Apache on a CentOS 7 Server

7. How To Install WordPress on CentOS 7Giving WordPress Its Own Directory

WordPress theme: Nisarg

8. How To Create an SSL Certificate on Apache for CentOS 7

Remember to backup ssl directory to recover certificates!

ssl: etc/httpd/ssl

9. Httpd Wiki RedirectSSL (redirect all http request to https)

10. How To Protect your Server Against the POODLE SSLv3 Vulnerability

11. Check your SSL/TLS certificate installation

12. My SSL Lock is not displaying properly

13. SSL/TLS Strong Encryption: How-To

14. How To Install Subversion On CentOS 7