Posts

[Safari] Cookies for iFrame domain not set

Image
The Problem Apple's Safari web browser is configured to block third-party cookies by default, unless the user has had prior interactions with the third-party domain: http://webpolicy.org/2012/02/17/safari-trackers/ The Solution The idea is simple, just make sure the user visits the iframe domain (in this example, B.com) at least once. One way is to run a popup that visits B.com (and set the P3P header ), then close the popup. On the parent window: var win = window.open(' http://B.com /startsession.php', '_blank', 'height=200,width=150'); setTimeout(function() { win.close(); // close it after 1 second :) }, 1000); Then in the startsession.php , just set the header will do <?php header('P3P: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"'); session_start(); Done. References: http://webpolicy.org/2012/02/17/safari-trackers/ http://anantgarg.com/2010/02/18/cross-domain-cookies-in-safari/ http://anantgarg...

Android ChatHead Tutorial - (1) Setup ChatHead

Image
Source code: Github (branch "step-1") Step 1: Setup an Android Project Android ChatHead requires " SYSTEM_ALERT_WINDOW " permission which is available since  API level 1 , so minimum API 7 is fine. Just next, next next... and create a blank activity :) Step 2: Add ChatHead Service If you want to know more details about ChatHead service. Read this article by Pierre-Yves Ricau . Create a ChatHead Class that extends Service . /java/com/ gbinghan /androidchathead/ChatHeadService.java Create ChatHead layout file. /res/layout/service_chat_head.xml Add ChatHeadService to AndroidManifest.xml <service android:name="com. gbinghan .androidchathead.ChatHeadService" ></service> Add SYSTEM_ALERT_WINDOW to AndroidManifest.xml <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> Your AndroidManifest.xml should look like this . Step 3: Add a button to launch the service :) ...

[Google Maps v3] Get Rectangle area with computeArea

Been searching for ways to calculate rectangle area with google.maps.geometry.spherical.computeArea(), but hard to find. Here's the snippet of the code I found on stackoverflow . Hope this helps those who are looking for the ways to use computeArea() without resolving to ugly/complex self-created methods. :)

Android Studio - android-4.2.2/dx failed when importing Facebook Android SDK

Image
Problem Got this error in Android Studio while following Getting Started with the Facebook SDK for Android (Android Studio)  tutorial on Facebook. Gradle: Execution failed for task ':HelloWorldAndroid:dexDebug'. > Running /Applications/Android Studio.app/sdk/build-tools/android-4.2.2/dx failed. See output Solution 1. Use latest Android Gradle Plugin First, in order to use the most recent version of the Android Gradle Plugin, change all occurences of Gradle classpath in build.gradle file. buildscript {   dependencies {     classpath 'com.android.tools.build:gradle:0.4'   } } to buildscript {   dependencies {     classpath 'com.android.tools.build:gradle:0.4 .+ '   } } 2. Install Android Repositories Make sure the following components of Android SDK are installed: Android Support Repository Google Repository 3. Change the reference for Android Support library The correct way to reference to...

Google Maps CSS not displaying correctly (when using Twitter Bootstrap)

Image
The image of the zoom Control Set tools were distorted after introducing Twitter Bootstrap Was wondering why the Google Maps Control Set tools works displaying correctly on standalone page but not when the same snippet pasted in my project site. Took me a while to figure out its because of Twitter Bootstrap CSS interfering with Google Maps images. The simple workaround was posted in  Twitter Bootstrap Github Issue . <style type="text/css"> /** FIX for Bootstrap and Google Maps Info window styes problem **/ img[src*="gstatic.com/"], img[src*="googleapis.com/"] { max-width: none; } </style> Hope this helps! :)

Install MongoDB for PHP5.4 on MAMP

Image
1. Download mongo.so from  https://github.com/stennie/mongo-php-driver/downloads 2. Copy mongo.so to MAMP PHP folder. For example, mine is at /Applications/MAMP/bin/php/ php5.4.10 /lib/php/extensions/no-debug-non-zts-20100525/ Remember to select the correct PHP version. You can check your PHP version from your MAMP start page, e.g http://localhost/MAMP/phpinfo.php 3. Enable the extension in PHP Configuration file (php.ini). You can find the path to the file from the PHPInfo (see above example). To enable, add the following line in the " Dynamic Extension " section. extension=mongo.so 4. Restart your MAMP. You should see " mongo " section in PHPinfo .

[Solution] Wordpress "An error occurred in the upload. Please try again later" error.

Image
Got this weird " An error occurred in the upload. Please try again later " error whenever I try to do media uploads in Wordpress. I've checked the folder permission, its correct. In fact, the files were uploaded successfully to wp-content > upload folder. I've tried all kinds of suggestion in forums (disable all plugins, enable them one by one... etc), but still no avail. In the end, I decided to do a "Re-install", and that... worked! And all the uploaded files were intact. ----- Didn't dig deep into finding out what causes the issue. But a wild guess would be something to do with the PHP codes. Because the uploaded files were stored in DB, although the upload status indicated "failed". Most likely something to do with the permission issue highlighted in this blog post .