Monday, November 25, 2013

Start/Stop PostgreSQL on Mac

Start PostgreSQL:-
sudo -u postgres /Library/PostgreSQL/9.3/bin/pg_ctl -D /Library/PostgreSQL/9.3/data start
Stop PostgreSQL:-
sudo -u postgres /Library/PostgreSQL/9.3/bin/pg_ctl -D /Library/PostgreSQL/9.3/data stop
Stop PostgreSQL from auto-starting on reboot:-
sudo launchctl unload -w /Library/LaunchDaemons/com.edb.launchd.postgresql-9.3.plist 
Make PostgreSQL auto-start on reboot:-
sudo launchctl load -w /Library/LaunchDaemons/com.edb.launchd.postgresql-9.3.plist 
Refs
http://www.xtuple.org/faq/xtuple-faq/postgresql/how-do-i-stop-postgresql-service-mac 
https://gist.github.com/abhishekdev/1960888

Saturday, August 17, 2013

Run Tomboy with Mono 3.2 on Mac

Compiling it from scratch based on http://xmemory.tompium.com/2012/06/running-tomboy-note-taking-app-on-mac.html doesn't work anymore. Here are the additional instructions:-
  • After getting the latest version of Tomboy (1.15.3),  replace "flush(true)" with "flush()" in Note.cs to fix a compile error. Not sure why the compiler complained about this line. Anyway, using just "flush()" fixes the problem but it may not write everything to disk straight away.
  • After building Tomboy, running it caused an exception:- 
Missing method System.Reflection.Assembly::op_Equality(Assembly,Assembly)
To fix it, modify a script file called Tomboy in Tomboy.app -> Contents/MacOS/Tomboy by changing the last line to
exec -a "Tomboy" "$MONO" --runtime=v4.0 --debug $ASSEMBLY $@
Refs
https://bugs.launchpad.net/ubuntu/+source/mono/+bug/882501

http://xmemory.tompium.com/2012/06/running-tomboy-note-taking-app-on-mac.html

Tuesday, August 13, 2013

Offline Maps on New Google Maps for iOS (v2) and Android (v7)

To download an area on the map, type 
ok maps
in the search box.

To clear the cached map, go to
Settings -> About, terms & privacy -> Terms & privacy 
and select
Clear application data
Refs
http://www.idownloadblog.com/2013/07/17/offline-maps-in-google-maps-2/

Sunday, August 11, 2013

System.Object is not defined or imported when building PCL project in Xamarin Studio 4.0.12

There're also a bunch of similar errors:-

: error CS0518: The predefined type `System.Object' is not defined or imported
: error CS0518: The predefined type `System.ValueType' is not defined or imported
: error CS0518: The predefined type `System.Attribute' is not defined or imported
: error CS0518: The predefined type `System.Int32' is not defined or imported
: error CS0518: The predefined type `System.UInt32' is not defined or imported
. . .


To fix this, go to References -> Edit References -> .Net Assembly then add mscorlib.dll from /Library/Frameworks/Mono.framework/Libraries/mono/4.5

Refs
https://bugzilla.xamarin.com/show_bug.cgi?id=12845

Friday, June 28, 2013

Enable Xdebug in MAMP

Uncomment the zend_extension line and modify the /Applications/MAMP/bin/php/php5.x/conf/php.ini file to look like this:-
[xdebug]
zend_extension="/Applications/MAMP/bin/php/php5.4.10/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_host=localhost
 
; On my machine, the default port 9000 has already been taken by something else.
xdebug.remote_port=9099
 
; Recommended when using Symfony
xdebug.max_nesting_level=250
Then restart the servers in MAMP.

Refs

Show print history on Mac

When I opened the web based CUPS admin interface to show print history:-
http://localhost:631/jobs?which_jobs=completed
I got the "Internal Server Error" message.

To fix it, I used the following commands
sudo cupsctl --debug-logging
sudo cupsctl --no-debug-logging
Refs

Wednesday, June 26, 2013

Custom php.ini on shared hosting

  • Find the default php.ini path. Mine is /usr/local/lib/php.ini
<?php phpinfo() ?>
  • Copy the default php.ini to the user's home folder and customise it.
<?php copy("/usr/local/lib/php.ini", "/home/username/php.ini") ?>
  • Create a .htaccess file in the user's home folder with the following content.
SetEnv PHPRC /home/username/php.ini
# The following lines are important if the php.ini file is put in the document root.
<Files php.ini>
order allow,deny
deny from all
</Files>
Refs

Monday, June 24, 2013

List processes and ports on Mac

  • Show listening ports
lsof -i -nP | grep LISTEN
or with all processes
sudo lsof -i -nP | grep LISTEN
  • Show ports with any state, e.g. ESTABLISHED, CLOSE_WAIT, CLOSED, LISTEN
sudo lsof -i -nP | grep TCP
or
sudo lsof -i -nP | grep UDP
Switches
-i select IPv[46] files
-n no host names
-P no port names

Refs
http://hints.macworld.com/article.php?story=20070425165628961

Friday, June 14, 2013

The system is running in low-graphics mode after upgrading the VirtualBox Guest additions to 4.2.12

I tried switching to use gdm instead of lightdm to see whether it could help but it didn't so I rolled back to v4.2.10 while waiting for v4.2.13 which was reported that this problem has been fixed.
  • Rebooted the machine in recovery mode in the Grub menu by, while booting:- 
    • Pressing ESC, or
    • Holding down the Shift key (this works better for me).
  • Uninstalled the VirtualBox Guest additions
cd /opt/VBoxGuestAdditions-4.2.12
./uninstall.sh
reboot 
  • After reboot, the screen was black. Here is what I did to fix this,
    • Pressed Cmd + F1 (or Alt + F1, don't know why Ctrl isn't needed on my machine) to switch to tty1.
    • Made LigthDM the default display manager
sudo dpkg-reconfigure lightdm
sudo reboot
  
        But it didn't work. It turned out that I also had to modify /etc/X11/default-display-manager to have the full path to lightdm like this.
/usr/sbin/lightdm
Then rebooted,
sudo reboot
After that, I could continue installing the VirtualBox Guest additions v4.2.10 and now everything is back to normal.

Refs

Saturday, June 1, 2013

Install httrack using brew on Mac

Typed
brew install httrack
Then I got:-
==> Downloading http://download.httrack.com/httrack-3.46.1.tar.gzAlready downloaded: /Library/Caches/Homebrew/httrack-3.46.1.tar.gz
Error: SHA1 mismatch
Expected: be6328d2ff3cbabd21426b7acc54edcf1ebb76e0
Actual: 237fca7a9c5c63b53c5d0134dac6e5714422384c
Archive: /Library/Caches/Homebrew/httrack-3.46.1.tar.gz
(To retry an incomplete download, remove the file above.)
So I did:-
brew update
Then I got:-
error: The following untracked working tree files would be overwritten by merge:     Library/Formula/libmusicbrainz.rbPlease move or remove them before you can merge.AbortingError: Failure while executing: git pull -q origin refs/heads/master:refs/remotes/origin/master
To fix it, I did:-
cd /usr/local
git fetch origin
git reset --hard origin/master
After that, I could run "brew update" and "brew install httrack" again with no problem. 

Refs
http://forum.httrack.com/readmsg/25812/25794/index.html
http://apple.stackexchange.com/questions/36862/install-homebrew-package-and-ignore-md5-hash
http://stackoverflow.com/questions/10762859/brew-update-the-following-untracked-working-tree-files-would-be-overwritten-by

Monday, May 27, 2013

Reduce memory usage in Chrome by suspending tabs

Google Chrome seems to use lots of memory especially when there are lots of tabs open at once. It quite often slows down my machine significantly to the point that I have to restart the browser (with all tabs still open after the restart) and then it gradually slows down again. I'm glad I came across The Great Suspender. This extension allows me to suspend any tab manually, or let it suspend idle tabs for me automatically.

Refs
http://lifehacker.com/5982490/the-great-suspender-suspends-memory+hungry-chrome-tabs-you-havent-used-lately
https://chrome.google.com/webstore/detail/the-great-suspender/klbibkeccnjlkjkiokjodocebajanakg?utm_source=chrome-ntp-icon

Friday, May 24, 2013

Convert an object array to a string array in Java


  • System.arraycopy(Object src, int srcPos, Object dest, int destPos, int length);
  • Arrays.asList(Object_Array).toArray(new String[Object_Array.length]);  
  • Java 1.6
        String[] stringArray = Arrays.copyOf(objectArray, objectArray.length, String[].class);

Refs

Friday, May 10, 2013

Find which process is using a file on Mac

Use this command
lsof | grep <filename>
or
lsof <filepath>
To ignore case, use
lsof | grep -i <filename>
Run it as root if the process is owned by root,
sudo lsof | grep -i <filename>
Refs

Getting the error "oasis-text.icns is in use" when installing LibreOffice on Mac


The full error message is

The operation can't be completed because the item "oasis-text.icns" is in use.

To fix it, just quit the SystemUIServer process in the Activity Monitor.

Wednesday, May 8, 2013

Install Force.com IDE on Eclipse 4.2 (Juno)

Cannot complete the install because one or more required items could not be found.
  Software being installed: Force.com IDE 27.0.0.201302151147 (com.salesforce.ide.feature.feature.group 27.0.0.201302151147)
  Missing requirement: Force.com IDE 27.0.0.201302151147 (com.salesforce.ide.feature.feature.group 27.0.0.201302151147) requires 'org.eclipse.update.ui 0.0.0' but it could not be found
Refs