How to use Apache .htpasswd

In order to prevent your site from outsider, you may need to add a password prompt so that only authenticated user can access.

Password prompt

Read More

iOS - Customize UITabBar appearance

Final look will be

Desired appearance

Read More

Lazy way for web application staging deployment

When comes to deployment, usually what we do is copy modified files over the server. It may takes some time on doing so.

I’ve discover an easy way to do deployment.

Read More

Bootstrap 3 dropdown menu not showing on mobile browser

I believe that most of you had face this kind of problem. Bootstrap 3 dropdown menu
is clickable on desktop browser, but when comes to mobile, then it has no effect at all.

Read More

PHP - replace certain lines in a file

I’ve come across such a scenario, to duplicate a project when a new user sign up, some of the settings in config.php have to change accordingly.

Read More

PHP - create database with PDO

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
define('DB_HOST', '127.0.0.1'); // use ip address instead of `localhost`
// existing user that has permission to create database and grant access
define('DB_ROOT_USER', 'root');
define('DB_ROOT_PASS', 'rootpass');

// the database you want to create
$dbname = 'my_new_db';
// specific user for this particular database
$dbuser = 'my_new_db_user';
$dbpass = 'new_dbpassword';

try {
// login with root user
$dbh = new PDO('mysql:host='.DB_HOST, DB_ROOT_USER, DB_ROOT_PASS);

// create database
$dbh->exec(
"CREATE DATABASE `$dbname`;
CREATE USER '$dbuser'@'localhost' IDENTIFIED BY '$dbpass';
GRANT ALL ON `$dbname`.* TO '$dbuser'@'localhost';
FLUSH PRIVILEGES;"
)
or die(print_r($dbh->errorInfo(), true));

// use database
$dbh = new PDO('mysql:host='.DB_HOST.';dbname='.$dbname, DB_ROOT_USER, DB_ROOT_PASS);

// optional: import existing sql file if you have
$imported = $dbh->exec(file_get_contents('existingdata.sql'));
if ($imported === false) { // even if success, it may also return some code
die(print_r($dbh->errorInfo(), true));
}

} catch (PDOException $e) {
die("DB ERROR: ". $e->getMessage());
}

Read More

Infinite scroll using on UITableView

If we have 100 records, perhaps we can GET them in one short. But what if, we have 1000 or even 10k records?

Thus, here I shows an example on implement lazy loading on iOS app, as well as pull to refresh.

Read More

Distribute iOS app via website

The first time I seen this is emu4ios.net. Then I found this is very useful and convenient for my beta tester.

Read More

Running multiple nodejs app in ONE server using Nginx

Environment

This is running on Ubuntu 13.10

Here I would like to use Sails.js framework (version 0.9.13) to create node.js app.

Read More

UIImageView animation fade in &amp; out between images

To animate between images (not .gif) in a UIImageView like the example below

Original images

First image

Read More