Friday 17 October 2014

How to start MySQL server via XAMPP on OSX 10.10 (Yosemite)

I just upgraded my Mac to the new OS Yosemite and everything works perfectly except I cannot start mysql server on XAMPP.

I've been google-ing for fixes provided by others but I can hardly find the proper solution. Thanks to the post here I finally got it working again.

Here are steps:

1. Install Homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

2. Allow homebrew to install duplicates of system software

brew tap homebrew/dupes

3. Install libiconv and sqlite3

brew install libiconv
brew link libiconv -force
brew install sqlite3
brew link sqlite3 -force

4. Delete dylib from XAMPP package

cd /Applications/XAMPP/xamppfiles/lib
sudo rm libsqlite3.dylib libsqlite3.0.8.6.dylib libiconv.2.dylib libiconv.dylib

5. Start MySQL server from the manager-osx.app in /Applications/XAMPP

Tuesday 12 August 2014

How to Uninstall Mac Server on OS X Maverick

I been play with the OS X Server application for a while trying to setup a server environment at home for development use. It is super easy to install the server, however, there isn't a guide of how to uninstall the server.

I was constantly changing the hostname and testing OpenLDAP to setup single sign on environment and eventually some services refused to start. So I decided to re-install the server app and re-configure it from scratch.

After digging google for a while I don't find any place clearly gives you the exact steps to uninstall it - unfortunately.

So I document it here to save your time, here we go:


1. Launch the Server app and connect to your OS X Server and stop all services.

2. Delete the data folder - /Library/Server

3. Delete configuration files:
/Library/Preferences/com.apple.serverd.plist
/Library/Preferences/com.apple.servermgr_accounts.plist
/Library/Preferences/com.apple.servermgrd.plist

4. delete logs from /var/log directory

5. If you don't need the server app any more, delete it from Applications folder. If you want to reconfigure the Server from scratch then you can launch the Server app now to reconfigure a brand new server environment.

Friday 18 April 2014

Use spotlight to open Apps

In your daily life with a Mac machine, how many times do you open applications from the Application folder or the Launchpad? If your answer is all the time then you need start thinking to utilise the very powerful spotlight - just click the search icon at the top right corner.

The keyboard shortcut to open spotlight search is by press Ctl + Space.

To open an application you have already installed, just simple type the name of the application in the search box, for example iPhoto and then press enter. It's that simple and just take you seconds to launch an app. If it saves you 5 seconds a time, then image how much of your life could be saved in a year :-)

Here are some other shortcuts I use all the time:


  1. cmd + left/right arrow key - move cursor to left/right of a text line
  2. cmd + up/down arrow key - move cursor to top/bottom of a page
  3. cmd + ,  - open application preferences
  4. cmd + shift + 4 - take a screenshoot, you do not need any snap applications to do it for you
  5. cmd + shift + 3 - take a full screenshot
  6. cmd + shift + /  - show help menu, and then you can type the menu name to quickly locate the menu option from the top menu
  7. cmd + w to close tabs/windows on any apps (btw, the alt+F4 key in windows system is just no use, the two keys are too far away)
  8. cmd + q to quit a application
If you know any handy & useful shortcuts on Mac, please let me know in the comment.

 

Sunday 13 April 2014

How to use Gmail as your mail agency

First, I'm back. very sad to say that I left away due to other things plus taking care of my little boy.

I'm now running my own company to provide software development/solution to other companies. It's a fresh start for me, lots of challenges ahead.

Right, back to the main purpose of this post. As I'm running a company therefor I need to keep my personal emails and business emails separately. So I setup a domain and purchased couple of years online web service to start building my website, and I also need to setup emails accounts base on my domain to promote my business.

There are four main issues come across to me:
  1. I need to keep all my emails at least for 6+ years but there is no guarantee the web hosting provider will last that long and I need to manage email backups myself which could be a extra task and painful. 
  2. I may decide to change my business web domain then I'm running a risk of loosing the previous emails. Plus I want to keep all emails together so I don't have to setup multiple email accounts on my Mac.
  3. I need to setup multiple email account on my lovely iPhone/iPad which i don't like to do it either.
  4. I want to have just one mail account to view/compose/reply to all my emails but with different domains that's not possible.
Certainly people will say - why not consider Google mail for business? Yes, that resolved issues of point 1 & 2, but it doesn't resolve point 3 & 4.

Eventually after very carefully scan through the Gmail settings I come up a perfect solution to address theses issues and I think you may need it as well. Here are the steps:

Prepare:

For people who needs to implement this solution I'm sure it won't be a issue to have these ready:
  • register and domain and purchase a web host with email support features (most of the web hosting does this)
  • get a gmail account, if you are a dedicated Yahoo!, Micrsoft mail user you can still keep reading it cause you might be able to do it on these email accounts. (I only use Gmail, the best ever)
  • configure couple of email accounts on you domain and make sure you can send/receive emails
Let's assume the business email is:   support@one-tech-a-day.com
and the Gmail account is:  personal@gmail.com

Web Hosting Email forwarding setup:

First we need to let the hosted mail server forward all received emails on support@one-tech-a-day.com to personal@gmail.com. To do that you need to (here is just a example):

Login to your web hosting admin console and find the forwarder setting


Click Add forwarder to add a new forwarding email address:



Now enter your support email address and gmail address to the correct fields, then click add:

Once the new config is added you can view it on the list:

Now, that's the email forwarding setup on your purchased domain and you should be able to receview all emails send to support@one-tech-a-day.com from now. 

Once you're happy it's working, let's config the gmail account.

Setup Gmail to Send Emails:

 Goto Gmail settings => Accounts and Import, then you will see then the send mail as section:


click the add another email address your own to add a new email address:


click next step and make sure you choose Send through SMTP server option otherwise your client will see the text mail was sent on behalf xxx@yyy.com from xxx@gmail.com


click Add Account  to finalise it. make sure you choose the option Reply from the same address to which the message was sent otherwise you will need to manually choose which email address you're going to reply to email.


That's all setup and you can now send/receive emails from your Gmail account. The last thing you might want to do is to label your business emails so you can easily view/search them.

Organise your business mails within Gmail

Go to Gmail settings => filter to create two filters, one for send and one for receive, please see the screenshots and then the mails will be auto organised when they arrive your gmail account.

for received emails:



for sent emails:






You can setup multiple email accounts to forward received mails to your gmail account and also setup multiple accounts to allow gmail to send emails out. Now gmail becomes your cloud base mail agency. It keeps all emails for you for years and years and you never needed to worry about backup and loss your important business emails.

Once these all setup then the settings automatically pushed to the gmail application on our iphone/ipad/android phone. From now one you only need to setup one mail account on your iPhone. That's really cool.

That's it. I'm hoping this helps you. Please let me know in the comments :-)



Thursday 11 July 2013

Work around to fix the wifi issue on OS X Mavericks (DP versions)


Since Apple released the developer preview of the next OS X system Mavericks I cannot wait to try it on my old Mac Book Pro (2010 version). Although lots of people complaining that they constantly keep dropping wifi connection I had no issues at all until I upgraded the system to the DP 3 - wifi connection keeps dropping on my Mac.

There isn't a solution to fix the wifi issue after searching google for the solutions and I definitely don't want to rollback to Mountain Lion because the new memory compression feature works great on my machine with 8G memory. Usually I don't switch off the Mac but only put it to sleep mode and over time the 8G memory will be 100% used plus over 2.5G swap space used. This never happend again after it upgraded to Mavericks.

After the WIFI dropped I have to reconnect to the wifi point so I can access the network. As there isn't a proper solution to fix the issue and reconnect the wifi network will work the trick, why not automate it?

The easiest way to reconnect the wifi is run the command 

ipconfig set en1 DHCP

We can use the cron job to run this command automatically every minute, however, we only want to run it after the connection dropped. So we need some intelligent to do that


# replace 10.0.0.1 to your router ip address
count=`ping -c 2 10.0.0.1 | grep icmp | grep timeout | wc -l`; if [ $count != 0 ]
then
    ipconfig set en1 DHCP
 # it tells you when the network was reset
    osascript -e 'tell app "Finder" to display dialog "Reset Wifi Connection From cron Job."'
fi

You can either put the code into one script and configure the cron to execute it every minute or just compile the code to one single line and past it on the cron job. I chose the second option:


# temperary fix the wifi dropping issue on OSX Mavericks
# replace 10.0.0.1 to your router ip address
* * * * * count=`ping -c 2 10.0.0.1 | grep icmp | grep timeout | wc -l`; if [ $count != 0 ]; then ipconfig set en1 DHCP;osascript -e 'tell app "Finder" to display dialog "Reset Wifi Connection From cron Job."' ; fi

the osascript -e 'tell app "Finder" to display dialog "Reset Wifi Connection From cron Job."' will notify you the network was reset with a popup message on the Finder window so you will remember to delete the job from cron once that's fixed by Apple.

Thursday 23 May 2013

A Simpler PHP LDAP API

LDAP service and ActiveDirectory service are very commonly used services to hold employee information in large companies and organisations. I was a software engineer worked on a large oilfield service company which implemented the one of the best LDAP service to host over 80K employees records. This is one of the best LDAP services I ever seen.

As you can imaging I have to use the LDAP service to query employee records and authenticate user logins on different projects. Most of the time LAMP is my first choice of the development environment so I have to keep using the PHP ldap API (ldap_connect, ldap_bind etc) to do all sorts of LDAP queries and user authentication.

After several times of keep writing the same code again and again I came up with this simpler PHP LDAP API that you can complete ldap actions in 10 lines of code:

<?php
$portal_username='yufeiliu';
$portal_password='password';
$ldap_user = new LDAPUser();
$ldap_user->setLDAPHost("server", 389);
$ldap_user->setBaseDN('DC=domain,DC=company,DC=com');
$ldap_user->connectLDAPServer();
$ldap_user->setServiceAccount('CN=admin,ou=service,ou=accounts,dc=cs,dc=company,dc=com', 'password');
if($ldap_user->authorizeUser($portal_username, $portal_password)){
  echo "YES\n";
}else{
  echo "NO\n";
}
$ldap_user->disconnectLDAPServer();

?>

This API is not designed commonly to be used at anywhere so you may need to make some changes on the code so you can use it on your projects.

The php code can be downloaded from gist here