Executing psql from command prompt on Mac OSX after installing PostgreSQL

I installed PostgreSQL but wasn’t able to execute psql on the command prompt to execute queries. I had to add the PostgreSQL path to the PATH variable in order to do that. It’s best to append the path in the bash_profile so it’s ready and available every time the shell loads. Add the following lines (depending on the location of your PostgreSQL version)

# Modify PATH
export PATH=$PATH:/Library/PostgreSQL/9.5/bin

Mac – Update openssl

I had a hard time updating openssl on my Mac OSX. Here’s what I did to update the libraries:

Install and upate brew

brew update
brew install openssl
brew link --force openssl

openssl version

If one of the bad versions come up (1.0.1a-f), you can figure out which version of openssl you’re using, this way:

which openssl

Often this is from /usr/bin. To make sure you get the updated version, drop a symlink into /usr/local/bin to point to the updated openssl, like this:

ln -s /usr/local/Cellar/openssl/1.0.1g/bin/openssl /usr/local/bin/openssl

Note: You may have to exit and start the Terminal session to see the new changes.

As an alternative to that final step, some people replace the openssl in /usr/bin with a symlink to /usr/local/Cellar/openssl/1.0.1g/bin/openssl (or whatever your version is):

mv /usr/bin/openssl /usr/bin/openssl_OLD
ln -s /usr/local/Cellar/openssl/1.0.1g/bin/openssl /usr/bin/openssl

But this is known to cause problems with some more recent versions of OSX. Better to just insert a new symlink into /usr/local/bin, which should take precedence on your path over /usr/bin.

Original article: http://apple.stackexchange.com/questions/126830/how-to-upgrade-openssl-in-os-x

Copy/Move top 100 files to a directory

I have a large number of files that I need to separate in parts and put in a different directory. I used to copy the files individually and paste them over in a directory. Then I found this cool trick to get the top 100 files from the current directory and copy/move them over to a different one. You can substitute mv/cp based on what you need.

find . -name "*.jpg" -maxdepth 1 -type f | head -100 |  xargs -I{} mv {} Color-Part1/

Keep repeating this command by replacing the name of the directory at the end. Trust me, saves a lot of time.

Install PHP mcrypt library on a Mac

Another crazy installation item. Just why I love debian so much now. But anyways, here are the steps to install the mcrypt library on a Mac. For reference, follow this link

1. Install xcode update in terminal

xcode-select --install

2. Create a temp directory for your libraries

cd ~ ; mkdir mcrypt ; cd mcrypt

3. Get the libmcrypt library from this link. The version I got was 2.5.8. Extract the tar files.

4. Check your php code by executing “php -version”. Get the php code from this link closest to your own version. In my case, it was 5.5.20. Extract the tar files.

5. Configuring libmcrypt

cd libmcrypt-2.5.8
sudo make install

With the libmcrypt configured and libraries now installed, time for to make the mcrypt extension.

6. Install Autoconf

cd ~/mcrypt
curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
tar xvfz autoconf-latest.tar.gz
cd autoconf-2.69/
sudo make install

7. Compile mcrypt php Extension
Move to the directory where the php code was extracted.

cd ../php-5.5.9/ext/mcrypt/

Output should be similar to:
Configuring for:
PHP Api Version: 20121113
Zend Module Api No: 20121212
Zend Extension Api No: 220121212

sudo make install

The result of this should be similar to:
Installing shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20121212/

8. Enabling mcrypt.so php Extension
Create a new file /etc/php.ini and add the following lines:

extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20121212/"

9. Restart Apache

sudo apachectl restart

10. To verify installation, execute “php –info” and look for mcrypt support. Or simply,

php --info | grep mcrypt

You should see this output mcrypt support => enabled to ensure that the library is installed successfully.