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

DEVICE="eth0"
NM_CONTROLLED="yes"
ONBOOT=yes
HWADDR=A4:BA:DB:37:F1:04
TYPE=Ethernet
BOOTPROTO=static
NAME="System eth0"
UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
IPADDR=192.168.1.44
NETMASK=255.255.255.0


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

NETWORKING=yes
HOSTNAME=centos6
GATEWAY=192.168.1.1


## Restart Network Interface
#

/etc/init.d/network restart

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

nameserver 8.8.8.8      # Replace with your nameserver ip
nameserver 192.168.1.1 # 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
CONNECTED(00000003)
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
-----BEGIN CERTIFICATE-----
MIIEgDCCA2igAwIBAgIIK6L1O7WFg3UwDQYJKoZIhvcNAQELBQAwSTELMAkGA1UE
BhMCVVMxEzARBgNVBAoTCkdvb2dsZSBJbmMxJTAjBgNVBAMTHEdvb2dsZSBJbnRl
cm5ldCBBdXRob3JpdHkgRzIwHhcNMTYwOTE0MDgyMDQwWhcNMTYxMjA3MDgxOTAw
WjBoMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwN
TW91bnRhaW4gVmlldzETMBEGA1UECgwKR29vZ2xlIEluYzEXMBUGA1UEAwwOd3d3
Lmdvb2dsZS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCAmQKH
oFWTZ2HK2CN21xj8iEDv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PcpIifFRyflDAY52c3DaLBlKnx6OBXaFoJwXa54ncQs4DXhJvzNDqf+X6BgTJ9x
jaMH7A==
-----END 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
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-AES128-GCM-SHA256
    Session-ID: 519CA9ADE744B72A3E428105172579761A0E104E100CD11BA496497D4769E487
    Session-ID-ctx: 
    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 "<?" *

Description:
-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.