Invoke a method call from AppDelegate via Notification

Think of a scenario here:

You have a class LoginViewController, while Facebook login api call is keep on AppDelegate.m, and you want to perform some action after success login via Facebook.

Read More

Get JSON using PHP cURL from web service

This example is to show how to detect user’s country

For GET request

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
<?php

// set HTTP header
$headers = array(
'Content-Type: application/json',
);

// query string
$fields = array(
'key' => '<your_api_key>',
'format' => 'json',
'ip' => $_SERVER['REMOTE_ADDR'],
);
$url = 'http://api.ipinfodb.com/v3/ip-country?' . http_build_query($fields);

// Open connection
$ch = curl_init();

// Set the url, number of GET vars, GET data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

// Execute request
$result = curl_exec($ch);

// Close connection
curl_close($ch);

// get the result and parse to JSON
$result_arr = json_decode($result, true);

print_r($result_arr);
/*
* output:
* Array
* (
* [statusCode] => "OK",
* [statusMessage] => "",
* [ipAddress] => "123.13.123.12",
* [countryCode] => "MY",
* [countryName] => "MALAYSIA",
* )
*/
?>

Read More

iOS - Get the radius of MKMapView

Some time we might have too much locations want to show to user, unfortunately, it may cause some performance issue if load all locations in one short.

Read More

iOS - Handle UISearchBar keyboard show/hide issue

I have experienced that when you focus on UISearchBar, the keyboard occupied half of the screen. The question is, “Under what condition should the keyboard hide?”.

Read More

RSA Decryption on iOS

I’ve been googled for few days and struggling on “How to decrypt cipher text in iOS”, unfortunately there is no solution were found.

Read More

Show chinese subtitle on VLC player in OS X

I’ve facing an issue on display the chinese character in not readable form.

I googled and found this blog to show in windows platform.

Read More

ZendFramework 2 - Construct SQL with subquery

A scenario here:

A Q & A website that allow user to ask question and put several tags to that question.

Read More

ZendFramework 2 - Construct AND OR SQL

I believe that almost all the web applications have a function Search, thus you might need to construct a query like:

1
2
3
4
SELECT *
FROM foo INNER JOIN bar ON foo.id = bar.foo_id
WHERE (foo.attr_1 LIKE '%abc%' OR foo.attr_2 LIKE '%abc%')
AND (bar.attr_1 LIKE '%xyz%' OR bar.attr_2 LIKE '%xyz%')

Read More

ZendFramework 2 - Create a custom view helper

For many situations, we need some helper functions to be used in view.

i.e. When you want to debug, probably you will write

./module/Application/view/application/index/foo.phtml

Read More

Ubuntu server allow login via ssh with key

The environment:

  • Ubuntu server 12.04 LTS is running on VMWare Fusion with IP address 192.168.1.101 as Host
  • Mac OS X Mountain Lion as Client

Read More