Archive for Dev Notes’ Category


Comments Off

Manage Apache on OSX (Updated or Yosemite)

Here is a little tip for customizing apache on OSX.

The first thing you have to do is turn on Web Sharing in your System Preferences. This will start the local Apache server and you can access it by going to http://localhost. From here, you can start modifying it to your will. Apache customization is a big topic and you can find all you need on the Apache website.

Here are a few tips:

  • Apache is installed at: /etc/apache2
  • Apache config is at: /etc/apach2/httpd.conf
  • Apache user config is at: /etc/apach2/users/<username>.conf
  • Apache extra config is at: /etc/apach2/extra/*.conf
  • You can customize your own virtual server by modifying: /etc/apach2/users/<username>.conf
  • You can start/stop Apache by:
    • Enabling/disabling Web Sharing in System Preferences
    • running the following in terminal:
      sudo apachectl <start|stop|restart>

In order for you to get going and have a user directory, you will need to make sure the following is done.

  • Create folder to host your files (e.g. /Users/<my_username>/Sites/)
  • Create an index file in the above folder with a message so you know when it is working.
  • In /etc/apach2/httpd.conf, make sure:
    • userdir_module is loaded (i.e. not commented out).

      LoadModule userdir_module libexec/apache2/
    • httpd-userdir.conf is included.

      Include /etc/apache2/extra/httpd-userdir.conf
  • In /etc/apache2/extra/httpd-userdir.conf, make sure that user configuration files are included.

    Include /private/etc/apache2/users/*.conf
  • In /etc/apache2/users, make sure to create a user file for yourself (note: you will have to use sudo to make sure permissions on the file are set to 644 and owned by root:wheel).



    <Directory "/Users/<my_username>/Sites/">
      Options Indexes MultiViews
      AllowOverride All
      Require all granted
      DirectoryIndex index.html

At this point you can should be able to start (or restart) Apache and test your setup.


read more



Getting Fancy with Terminal

One of my recent adventures into NodeJS has led me down the path of MEAN and reading various articles on that, I came across various Terminal alternatives and enhancements. I know, I know, I am late to the party, but when I saw FishShell, I was sold. Then I saw Powerline and liked that too, so here is how to set these up.

First thing is to make sure you have Homebrew installed. Then you can install fish simply by running the following command:

[korey@localhost ~]$ brew install fish

Now that fish is installed, you will have a few options in making it your default shell. Homebrew provides instructions already, but I just wanted it on my account for Terminal, so I changed the shell command in Terminal’s preferences.

Great, now you can use fish anytime you open terminal, but what about getting Powerline setup? The instructions are here, but I will include what I did here for completeness.

[korey@localhost ~]$ brew install python
[korey@localhost ~]$ pip install powerline-status

The next step is to install the patched fonts so your prompt will not have strange characters on it. For this part, you need to download the patched fonts zip from github, and then run the script included there. The last step here is equally important; you should change the font used by your selected terminal profile to one of the fonts for Powerline.
Now that Powerline is installed, you will need to update your Fish config to load it.

[korey@localhost ~]$ vi ~/.config/fish/
# source autojump
[ -f /usr/local/share/autojump/ ]; and . /usr/local/share/autojump/
#source powerline
set fish_function_path $fish_function_path "/usr/local/lib/python2.7/site-packages/powerline/bindings/fish"

My last step was to install auto jump, which is another great tool and you can see that it has also been included in the above listing in my Fish config.

[korey@localhost ~]$ brew install autojump

You should now end up with a autocomplete terminal similar to this:

read more


Comments Off

Installing MongoDB on OSX (Yosemite)

Installing MongoDB on OS X is an easy task. However, if you want the service to start each time your computer is restarted, some additional effort is required.

The easiest way to get MongoDB installers is to use Homebrew.

[korey@localhost ~]$ brew install mongodb

At this point MongoDB is installed. To start it manually, first create the location where the DB will be stored (default is /data/db):

[korey@localhost ~]$ mkdir /data/db
[korey@localhost ~]$ mongd

Note that the user running mongod needs to have write access to the DB folder. The downside here is that the DB needs to be started manually each time and it will run as your userid.

In order to automatically start the service, it is necessary to create a LaunchDaemon which will allow the service to start as soon as the computer starts.

    1. The first step is to create a service account so the service does not run as root.
    2. Next, is to create a proper location for the log and database location:

    [korey@localhost ~]$ sudo mkdir -p /var/lib/mongodb
    [korey@localhost ~]$ sudo mkdir -p /var/log/mongo
    [korey@localhost ~]$ sudo chown -R _mongo:_mongo /var/lib/mongodb
    [korey@localhost ~]$ sudo chown -R _mongo:_mongo /var/log/mongo

    3. Now that we have an account and location, it is time to create the daemon plist file:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN >
    <plist version="1.0">

    Store this file at: /Library/LaunchDaemons and name it: org.mongo.mongod.plist.

Now you can start and stop the service without having to restart your computer by using the following commands:

[korey@localhost ~]$ sudo launchctl load /Library/LaunchDaemons/org.mongo.mongod.plist
[korey@localhost ~]$ sudo launchctl unload /Library/LaunchDaemons/org.mongo.mongod.plist
read more


Comments Off

Creating a service account on OS X (Yosemite)

Creating service users on OS X is not as straight forward as doing so on Linux system.  For starters, the useradd command is not available.

So in order to perform the same action on OS X, open a terminal window and run the following commands. For this example, I will create a group and user in order to run MongoDB.

[korey@localhost ~]$ sudo dscl . -list /Users UniqueID
_amavisd                83
_appleevents            55
_appowner               87
_appserver              79
_ard                    67
_assetcache             235
_astris                 245
_atsserver              97
_avbdeviced             229
_calendar               93
_ces                    32
_clamav                 82
_coreaudiod             202
_coremediaiod           236
_cvmsroot               212

The above command lists all the current users along with their UID. This is necessary so that we can pick an unused ID below 500 (UIDs above 500 are for normal users). You can run the same command with /Groups instead of /Users to get a list of groups.

First, lets create a group for the users with the same name:

[korey@localhost ~]$ sudo dscl . -create /Groups/_mongo gid 300
[korey@localhost ~]$ sudo dscl . -create /Groups/_mongo RealName "Mongo DB Server Group"
[korey@localhost ~]$ sudo dscl . -create /Groups/_mongo passwd "*"

As you can see the group ID is set to 300, and the password is set to “*”. This is a special password not to allow logins as that group of user. I am not certain if this is necessary, but looking at other similar groups on OS X, it seems to be the right way to do this.

Now, lets create the user and make sure that it will not show up as a user on the login screen:

[korey@localhost ~]$ sudo dscl . -create /Users/_mongo
[korey@localhost ~]$ sudo dscl . -create /Users/_mongo uid 300
[korey@localhost ~]$ sudo dscl . -create /Users/_mongo gid 300
[korey@localhost ~]$ sudo dscl . -create /Users/_mongo NFSHomeDirectory /var/empty
[korey@localhost ~]$ sudo dscl . -create /Users/_mongo UserShell /usr/bin/false
[korey@localhost ~]$ sudo dscl . -create /Users/_mongo RealName "Mongo DB Server"
[korey@localhost ~]$ sudo dscl . -create /Users/_mongo passwd "*"

At this point, the service account is created, and its primary group set to the one we just created. Setting the shell and home folders are necessary to make sure that the account does not show up on the login screen and to ensure that even if someone does login as that user, they will not have access to anything. Once again, the account password here is set to “*” in order to not allow logins.

If you look at /etc/passwd on your OS X machine, you’ll notice that most service accounts are listed in there, but the above account is not. I am not sure if this will be problematic over the long term, but for all intents and purposes, the service account works as expected.

Naturally, I searched a good while before I came up with the above command set and here are some links that helped me:

read more


Comments Off

Automating Android Builds

In order to have a fully regression tested application, it is necessary to have an automated build process to ensure all checkins are validated nightly ( or whatever your schedule is). This is a simple task for most Java projects, however you may run into some issues with Android that I point out here.

  • If you started your project from Eclipse, you may not have the Ant build file and supporting properties file in your project
  • If you want to sign your application with a key, the default build keeps prompting you for the keystore password

Both of these are relatively easy to over come and here is a great article on StackOverflow. My only goal here is capture it all in one place.

Environment Setup

The first thing to do, is to make sure that your android SDK folder is on your path. In order to do that, just update your local .bash_profile in your home folder to include the following paths:

export PATH=$PATH:$HOME:$HOME/Documents/Development/android-sdk-macosx/tools:\
export ANDROID_HOME=/Users/Kouroche/Documents/Development/android-sdk-macosx

Note the \ in the first export command. It is there to split the command over two lines, but you don’t need that in there. This will not only add the Android SDK to your path, but also define ANDROID_HOME which is used by the build file (more on that later).

At this point, you will either have to logout and login again, or source .bash_profile to make sure the changes took effect. To verify, run the following command from your home folder:

$ android list targets

Build files

In order to add the build files to your project, you can either create a new project from the command line and copy those build files to your project, or you could update you project from the command line to add in the build files.

Creating a new project

In order to create a new project from the command line, run the following command:

$ android create project --target <target-id> --name MyFirstApp \
--path <path to dev folder>/MyApp --activity MainActivity \
--package com.acme.myapp

The app name nor the package matter. The only thing you may want to match to your current application is the <target-id>.

Once the project is created, copy over the following files to the root of your own project and then delete this app folder.

  • – This is where you store your project specific properties for Ant
  • build.xml – This is the generic build file provided by the Android SDK and will most likely not need changing
  • – This file contains the path to your SDK, but I prefer not to copy it over since it may get checked in by mistake.
  • progaurd-project.txt – This file contains ProGaurd rules if you choose to obfuscate your code, and more can be found here about that.
  • – This file contains the target for your project and is most likely already part of your project.

Updating your existing project

This is probably your best bet since it is less of a hack and should add the same set of files to your project.

$ android update project --name <project_name> --target <target-id> \
--path <path_to_your_project>

Once again, make sure to use the same <target-id>

Customizing the build

Now that you can use Ant to build your project, you may want to customize the build process to meet your needs. For example, I always include a build ID somewhere in the application so users can report which build they are on when reporting issues, or you may want your release build to point to a different backend server than your debug build. In any case, the Android SDK makes this also very easy.

Looking at the build file, it optionally imports a custom_rules.xml file that you can create in your project root folder to hook into the build process. The build file even lists out the targets for your to include. Here is a sample one I created:

<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules" default="-pre-compile">
    <target name="-pre-compile">
        <!--  get build ID to automate inserting it -->
		<format property="buildId" pattern="yyyyMMddHHmm" locale="en,US"/>
	<replaceregexp byline="true" file="${source.absolute.dir}/com/acme/app/">
        	<regexp pattern='String\s*_VER\s*=\s*"\d*"'/>
        	<substitution expression='String _VER = "${buildId}"'/>
        <!-- Depending wheather this is release or not, update the host file to match -->
        <if condition="${}">
                <property name="" value="" />
                <property name="" value="${}" />
        <replaceregexp byline="true" 
        	<regexp pattern='String\s*HOST\s*=\s*".*"'/>
        	<substitution expression='String HOST = "${}"'/>

What this does, is to update the build ID in my constants class, and also update the backend server my app talks to depending on whether it is a release build or not.

Signing the app

One of the issues I mentioned early on, for the need to have build automation, was having to provide a password each time the app needed to be signed. Well, the key to solving this problem is the file which includes your project specific properties.

Unfortunately, i have not found a way around having to include your password in plaintext in some form or fashion so that it can be used, but if your an individual or have a designated build person or machine, you can lock the file down pretty good.

So, to get back to the issue at hand, include the following four lines in your file and you are good to go:<path to your keystore file><your keystore password>
 key.alias=<your keystore alias>
 key.alias.password=<your alias password>

If you have been building with Eclipse for while and don’t recall your keystore alias, an easy way is to go through the export process in Eclipse to release the app and see what the keystore alias is.

The build command

OK, so now that it is all set, the easy part is building the application. You can run either of the following commands to build the app for debug or release respectively.

$ ant debug
$ ant release

Good luck.

read more


Comments Off

How to find the key an Android app was signed with

I found this on stack overflow, so I am just recapturing here since i found it so useful.

First, unzip the APK and extract the file /META-INF/ANDROID_.RSA (this file may also be CERT.RSA, but there should only be one .RSA file).

Then issue this command:

     keytool -printcert -file ANDROID_.RSA

You will get certificate fingerprints like this:

     MD5:  B3:4F:BE:07:AA:78:24:DC:CA:92:36:FF:AE:8C:17:DB
     SHA1: 16:59:E7:E3:0C:AA:7A:0D:F2:0D:05:20:12:A8:85:0B:32:C5:4F:68
     Signature algorithm name: SHA1withRSA

Then use the keytool again to print out all the aliases of your signing keystore:

     keytool -list -keystore my-signing-key.keystore

You will get a list of aliases and their certificate fingerprint:

     android_key, Jan 23, 2010, PrivateKeyEntry,
     Certificate fingerprint (MD5): B3:4F:BE:07:AA:78:24:DC:CA:92:36:FF:AE:8C:17:DB

Voila! we can now determined the apk has been signed with this keystore, and with the alias ‘android_key’.

Keytool is part of Java, so make sure your PATH has Java installation dir in it.

read more


Comments Off

Get Firefox Boot-2-Gecko up and running

There are two more players that are trying to enter the mobile OS space: Firefox, and Ubuntu. While the latter is making the move for more native applications to run faster on phones, the former is trying to take page out of WebOS’ playbook by going the pure HTML5 route.

I had a chance to install the Firefox OS recently on a Nexus S and it fairs well but still has a long way to go before it is ready for prime time. Here are some links to get you started if you want to try them.

  1. Take a backup of your phone.  Since i had a Google Phone, I was not worried too much since Google provides the factory images here (so long as you know your model).
  2. Go to the Firefox link here and get started.

Firefox’s instructions are pretty straight forward and everything has been automated to the point that I just fast paced through the commands and ran those (on a Mac).  the process does take sometime, specially if you do not have a fast PC, and it downloads the Android SDK and tools to boot.  My only issue was finding the google page to restore my phone since the Firefox OS is still not on par with iOS or even Android, and I needed my phone.

Ubuntu on the other has is making more calculated decisions and only providing installers for mutli-core devices. As they say, “You only get one chance to make a first impression,” so it better be good.  Here are some instructions to install it on the Nexus 7.

read more


Comments Off

Configure Witopia VPN on DD-WRT

I like using a VPN service for a more secure browsing experience and I have used Witopia for the past little while with great success. The only issue was that I had to install it on all the PCs that I wanted to use it with and then remember to turn it on, etc which I did not like very much. So after a decent amount of googling, I decided to get a second router that supports DD-WRT and set that up to always be connected via VPN. This way, it is just a matter of switching my wireless connection from any device.

After some research I settled on Buffalo AirStation WHR-HP-G300N (bought from Newegg) which is a tiny little router that comes with DD-WRT installed. The only downside, I later found, is that since it’s got smaller memory on-board it does not support OpenVPN.

Witopia itself does provide a Cloakbox Pro device itself which is a higher end Buffalo router pre-configured to VPN, but I wanted to do it my way. So keep in mind as you read the instructions below that my setup is using a VPN router that is behind my main router.

Setup Instructions

  1. Add Google’s public DNS servers as static DNS servers for the DHCP server. Note that since my main router is using 192.168.1.x, I put this router on 192.168.11.x to make sure there is no complications.
  2. Configure the wireless access point on the router so that it does not conflict with your main wirless connection (i.e. give it a different name and use a different channel to be extra safe).
  3. Enable and configure the PPTP client on the router to connect to your favorite VPN location. You can get a list of the VPN location for Witopia here. For the Server IP or DNS Name I put in the IP address of the vpn server I wanted to connect to (e.g.
  4. Add a startup script to the router to configure it to use the VPN connection properly.

    The script below will wait until VPN is connected and then update the router’s routing appropriately. Note that is the internal IP of my main router, not the VPN router which is

    echo "echo \"Startup Config started\" >> /tmp/mylog.txt" > /tmp/
    echo PPTPSERVER=$(/usr/sbin/nvram get pptpd_client_srvip) >> /tmp/
    echo PPTPGWY= >> /tmp/
    echo "/sbin/route add -host \$PPTPSERVER gw \$PPTPGWY" >> /tmp/
    echo "#/sbin/route del default" >> /tmp/
    echo "/sbin/route add default gw \$PPTPGWY metric 100" >> /tmp/
    echo "/sbin/route add default dev ppp0" >> /tmp/
    echo "/sbin/route del default" >> /tmp/
    echo "/sbin/route del default" >> /tmp/
    echo iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE >> /tmp/
    echo "ifconfig ppp0 > /dev/null" > /tmp/
    echo "RC=\$?" >> /tmp/
    echo "echo \"Checking ppp0: \$RC\" >> /tmp/mylog.txt" >> /tmp/
    echo "while [ \$RC -ne 0 ]; do" >> /tmp/
    echo "  sleep 5" >> /tmp/
    echo "  ifconfig ppp0 > /dev/null" >> /tmp/
    echo "  RC=\$?" >> /tmp/
    echo "  echo \"Checking ppp0: \$RC\" >> /tmp/mylog.txt" >> /tmp/
    echo "done" >> /tmp/
    echo "echo \"Running\" >> /tmp/mylog.txt" >> /tmp/
    echo "ifconfig ppp0 >> /tmp/mylog.txt" >> /tmp/
    echo "sh /tmp/" >> /tmp/
    sh /tmp/ &

Once all this is setup, connect to the wireless for the VPN router, and go to IP Location Finder and make sure that it reports your location correctly. If it is still reporting your current location, then VPN is not working and you have to get your hands dirty and login to the router itself and poke around. That is beyond what I wanted to get into here, but I am sure you can find your solution on the internets.

read more


Comments Off

Calculate the Broadcast IP for your network

There is a good article on how to calculate the broadcast IP based on your IP address and net mask on eHow. What I have here is a quick utility to facilitate things.

provide IP and netmask:



Broadcast IP:

read more


Comments Off

Installing MySQL on CentOS

First thing you need to do is make sure the binaries are installed using yum. Note that this will only install MySQL and that you may need to run it as root depending on your systems permissions.

[korey@localhost ~]$ yum install mysql-server mysql

The next thing is start MySQL:

[korey@localhost ~]$ service mysqld start

Once you start the service, it will give you some instructions for having it start automatically on reboot, and how to secure it.
Finally, secure MySQL, by setting a password for the root user and removing the anonymous user. Just make sure you use the same password for the first two statements below, otherwise you’ll end up scratching your head as to why you cannot login sometimes.

[korey@localhost ~]$ mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('****');
mysql> SET PASSWORD FOR 'root'@'localhost.localdomain' = PASSWORD('****');
mysql> DROP USER ''@'localhost.localdomain';
mysql> DROP USER ''@'localhost';
read more

Page 1 of 212