OS X Mavericks - left click not working

I believe most of you have faced such a problem. Left-click & touchpad is not working.

I googled for an hour, found some possible solution in Apple Support Communities. But none of them work.

Read More

iOS - Change QR code color in UIImage

Original QR code

Original QR code

Read More

iOS - Countdown to milliseconds

#import “CountdownViewController.h”

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// default countdown time in seconds
static int defaultBufferSeconds = 10;

@interface CountdownViewController ()

@property (nonatomic, strong) UILabel *timerLabel;

@end

@implementation CountdownViewController {
// to keep a reference for current counting
int countdownMilliseconds;
}

@synthesize timerLabel = _timerLabel;

- (void)viewDidLoad
{
[super viewDidLoad];

// display countdown on this label
self.timerLabel = [[UILabel alloc] initWithFrame:CGRectMake(40, 40, 240, 40)];
self.timerLabel.textAlignment = NSTextAlignmentCenter;
[self.countdownView addSubview:self.timerLabel];

// start countdown
[self startTimer];
}

- (void)startTimer
{
countdownMilliseconds = defaultBufferSeconds * 1000; // reset the current counting value
// NSTimeInterval is in "second", now schedule it to every 10 milliseconds
[NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(updateCountdown:) userInfo:nil repeats:YES];
}


- (void)updateCountdown:(NSTimer *)timer
{
int seconds, milliseconds;

// don't forget to update the current counting value
countdownMilliseconds -= (timer.timeInterval * 1000);

seconds = countdownMilliseconds / 1000;

// since we only want to show 2 digits in milliseconds, so have to divide by 10
milliseconds = countdownMilliseconds % 1000;
milliseconds /= 10;

self.timerLabel.text = [NSString stringWithFormat:@"Countdown: %02d seconds %02d milliseconds", seconds, milliseconds];

// once current counting value reach 0, then stop the timer
if (countdownMilliseconds <= 0) {
[timer invalidate];
timer = nil;
}
}

@end

Read More

Restructure a series of numbers

Example:

1
2
3
4
5
+-----------------+----------------------------------------+
| Input | 2, 4, 2, 5, 8, 7, 7, 6, 13, 11, 11, 12 |
+-----------------+----------------------------------------+
| Expected result | 1, 2, 1, 3, 6, 5, 5, 4, 9, 7, 7, 8 |
+-----------------+----------------------------------------+

Read More

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