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

Configure Static IP on CentOS

## Configure eth0
# vi /etc/sysconfig/network-scripts/ifcfg-eth0

NAME="System eth0"

## Configure Default Gateway
# vi /etc/sysconfig/network


## Restart Network Interface

/etc/init.d/network restart

## Configure DNS Server
# vi /etc/resolv.conf

nameserver      # Replace with your nameserver ip
nameserver # Replace with your nameserver ip

Debian – Change Hostname

Step 1: Edit /etc/hostname with the new name
Step 2: Edit /etc/hosts with the new name
Step 3: Reboot machine (shutdown -r now)

Find openssl and TLS protocol version

To get the version of OpenSSL installed on the OS:

$ openssl version
OpenSSL 1.0.1t  3 May 2016

To get the TLS/SSL protocol version, establish a secure connection to any of the servers on the web and the session information would have details of the Protocol.

$ openssl s_client -connect www.google.com:443
depth=3 C = US, O = Equifax, OU = Equifax Secure Certificate Authority
verify return:1
depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CA
verify return:1
depth=1 C = US, O = Google Inc, CN = Google Internet Authority G2
verify return:1
depth=0 C = US, ST = California, L = Mountain View, O = Google Inc, CN = www.google.com
verify return:1
Certificate chain
 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=www.google.com
   i:/C=US/O=Google Inc/CN=Google Internet Authority G2
 1 s:/C=US/O=Google Inc/CN=Google Internet Authority G2
   i:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
 2 s:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
   i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
Server certificate
subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=www.google.com
issuer=/C=US/O=Google Inc/CN=Google Internet Authority G2
No client certificate CA names sent
SSL handshake has read 3727 bytes and written 415 bytes
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-AES128-GCM-SHA256
    Session-ID: 519CA9ADE744B72A3E428105172579761A0E104E100CD11BA496497D4769E487
    Master-Key: BEE6BD732D3D48B68FD96C37BD0A072B3A31C78253CDBA0F623D9DB0FCE5D06F9DC13AD298EE48922B85D824FCE35C74
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    TLS session ticket lifetime hint: 100800 (seconds)
    TLS session ticket:
    0000 - fa 11 30 4d e2 45 8a a8-34 3b a5 b4 cd 1e c6 0a   ..0M.E..4;......
    0010 - ed 1e 03 d6 66 fb 83 c7-fb c5 ac e6 eb 69 2f c2   ....f........i/.
    0020 - 72 8f 38 a0 ba 1b 9b f5-34 70 63 6d 36 db 0a 0f   r.8.....4pcm6...
    0030 - 32 38 d9 03 df 10 78 2a-66 22 e5 eb c2 c4 c1 44   28....x*f".....D
    0040 - eb 36 ab d5 05 ed 54 20-37 8b b1 a8 2f 9a 2f ae   .6....T 7..././.
    0050 - 00 30 48 36 58 4c 80 1f-38 5c b9 da b3 85 8e f7   .0H6XL..8\......
    0060 - c8 dd 59 00 5c e8 ad 5e-7b 1d e7 1d e0 a2 ee 4b   ..Y.\..^{......K
    0070 - ec 5b d7 08 b0 24 1e a2-1a fd 47 74 b1 8b 1b b7   .[...$....Gt....
    0080 - 55 dd 01 c5 c7 29 fb f4-ec f3 88 27 d2 93 8c 32   U....).....'...2
    0090 - 7b e2 1b 54 b8 22 bf 90-f0 63 5c 46 14 9f a8 ad   {..T."...c\F....
    00a0 - 7b 5d 51 1d                                       {]Q.

    Start Time: 1473883627
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)

Grep without warnings

If I grep in a folder that has files and directories, I get warning and error messages like

grep: img: Is a directory

In case you’d like to skip the warnings and errors, use the option -s that will do the job for you.

grep -s "<?" *

-s, –no-messages
Suppress error messages about nonexistent or unreadable files. Portability note: unlike GNU grep, 7th Edition Unix grep did not conform to POSIX, because it lacked -q and its -s option behaved like GNU grep’s -q option. USG-style grep also lacked -q but its -s option behaved like GNU grep. Portable shell scripts should avoid both -q and -s and should redirect standard and error output to /dev/null instead. (-s is specified by POSIX.)

.htaccess – Force www redirect

I recently found that having domain.com and http://www.domain.com on your website would affect SEO (Search Engine Optimization). It’s recommended to use either. So I chose the latter. This can be easily done by having a .htaccess rule on your root directory.

# Force www redirect #
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301,NC]

301 is the HTTP status code for a Permanent Redirect which doesn’t affect the SEO ratings.