How to get MacOS version by the command line

NAME
     sw_vers -- print Mac OS X operating system version information

SYNOPSIS
     sw_vers
     sw_vers -productName
     sw_vers -productVersion
     sw_vers -buildVersion

DESCRIPTION
     sw_vers prints version information about the Mac OS X or Mac OS X Server operating system running on the local machine.

     When executed with no options sw_vers prints a short list of version properties:

EXAMPLE:

  $ sw_vers 
  ProductName: Mac OS X
  ProductVersion: 10.10.3
  BuildVersion: 14D136

How can I modify the size of column in a mysql table?

Use the following mysql command to increase the size of a column


mysql> alter table Table change column columnname columnname varchar(size);


Before:
mysql> describe Foo;
+--------------------------+--------------+------+-----+---------+-------+
| Field                    | Type         | Null | Key | Default | Extra |
+--------------------------+--------------+------+-----+---------+-------+
| name                     | varchar(255) | NO   | PRI | NULL    |       |
| comments                 | varchar(255) | YES  |     | NULL    |       |
+--------------------------+--------------+------+-----+---------+-------+

Run command:
mysql> alter table Foo change column comments comments varchar(1000); 

After:
mysql> describe Foo;
+--------------------------+--------------+------+-----+---------+-------+
| Field                    | Type         | Null | Key | Default | Extra |
+--------------------------+--------------+------+-----+---------+-------+
| name                     | varchar(255) | NO   | PRI | NULL    |       |
| comments                 | varchar(1000)| YES  |     | NULL    |       |
+--------------------------+--------------+------+-----+---------+-------+

Unix Shell Shortcuts

Here are a few shell shortcuts:

!! 
Repeats the most recent command.

!t 
Repeats the most recent command beginning with "t". Similarly for other letters, or strings of initial letters in a command. This is very handy when going through a compiling/running/editing cycle. For example, if you work on a latex document, after giving the full command names "latex file", "xdvi file", "dvips file", during the first cycle, you can then repeat the steps using the shortcuts "!l", "!x", "$d". (Be careful, though; if you type "!r" instead of "!t", you may inadvertently repeat the last delete command.)

dvips !$ 
This executes dvips with the last argument of the most recent command. For example, after doing "xdvi verylongfilename", the above command will run the file "verylongfilename" through dvips. Similarly, after editing a file with "vi verylongfilename", you can print out the file by saying "lpr verylongfilename".

history 
Gives a list of the most recent commands. Useful if you want to repeat a command, but don't remember the exact form you used. The number of commands saved in this way can be changed by adding a line such as "set history = 1000" in the .cshrc file.

history | grep 'perl' 
List all commands within the saved command history matching 'perl'.


!1729 
Repeat command number 1729 in the history listing.

Up/down arrows 
As an alternative to the exclamation mark commands, you can use the up/down arrows to move back and forth in the command history and repeat/edit a command.

How to show timestamps in your bash history?

Very useful when working on production management hosts and you want to know when  you ran a specific command.

Add the following to your to your ~/.bashrc.     

export HISTTIMEFORMAT="%F %T "

Example of Output:

$ history
  508  2016-06-22 19:26:09 history
  509  2016-06-22 19:26:15 vi .bashrc
  510  2016-06-22 19:26:21 ls
  511  2016-06-22 19:26:23 history

How to turn off Color Syntax Highlighting in vi or vim

Inside of VI:

Open a file:

    $ vi filename.txt

Set syntax off:

    :syntax off


You can edit ~/.vimrc file and add append vim command syntax on to it:

    $ cd 
    $ vi .vimrc
    syntax off

SyntaxError: '<' operator not allowed in environment markers

I'm getting an error installing python mock:

easy_install -U mock
Searching for mock
Reading https://pypi.python.org/simple/mock/
Best match: mock 2.0.0
Downloading https://pypi.python.org/packages/0c/53/014354fc93c591ccc4abff12c473ad565a2eb24dcd82490fae33dbf2539f/mock-2.0.0.tar.gz#md5=0febfafd14330c9dcaa40de2d82d40ad
Processing mock-2.0.0.tar.gz
Writing /var/folders/8t/_x8d0qg539z7ynrmr31xdpm00000gn/T/easy_install-mswJxc/mock-2.0.0/setup.cfg
Running mock-2.0.0/setup.py -q bdist_egg --dist-dir /var/folders/8t/_x8d0qg539z7ynrmr31xdpm00000gn/T/easy_install-mswJxc/mock-2.0.0/egg-dist-tmp-b2vJHn

Installed /private/var/folders/8t/_x8d0qg539z7ynrmr31xdpm00000gn/T/easy_install-mswJxc/mock-2.0.0/.eggs/pbr-1.10.0-py2.7.egg
Marker evaluation failed, see the following error.  For more information see: http://docs.openstack.org/developer/pbr/compatibility.html#evaluate-marker
ERROR:root:Error parsing
Traceback (most recent call last):
  File "/private/var/folders/8t/_x8d0qg539z7ynrmr31xdpm00000gn/T/easy_install-mswJxc/mock-2.0.0/.eggs/pbr-1.10.0-py2.7.egg/pbr/core.py", line 111, in pbr
    attrs = util.cfg_to_args(path, dist.script_args)
  File "/private/var/folders/8t/_x8d0qg539z7ynrmr31xdpm00000gn/T/easy_install-mswJxc/mock-2.0.0/.eggs/pbr-1.10.0-py2.7.egg/pbr/util.py", line 248, in cfg_to_args
    kwargs = setup_cfg_to_setup_kwargs(config, script_args)
  File "/private/var/folders/8t/_x8d0qg539z7ynrmr31xdpm00000gn/T/easy_install-mswJxc/mock-2.0.0/.eggs/pbr-1.10.0-py2.7.egg/pbr/util.py", line 431, in setup_cfg_to_setup_kwargs
    if pkg_resources.evaluate_marker('(%s)' % env_marker):
  File "build/bdist.macosx-10.10-x86_64/egg/pkg_resources/__init__.py", line 1503, in evaluate_marker
    return cls.interpret(parser.expr(text).totuple(1)[1])
  File "build/bdist.macosx-10.10-x86_64/egg/pkg_resources/__init__.py", line 1537, in interpret
    return op(nodelist)
  File "build/bdist.macosx-10.10-x86_64/egg/pkg_resources/__init__.py", line 1451, in atom
    return cls.interpret(nodelist[2])
  File "build/bdist.macosx-10.10-x86_64/egg/pkg_resources/__init__.py", line 1537, in interpret
    return op(nodelist)
  File "build/bdist.macosx-10.10-x86_64/egg/pkg_resources/__init__.py", line 1472, in comparison
    raise SyntaxError(msg)
SyntaxError: '<' operator not allowed in environment markers

error: Setup script exited with error in setup command: Error parsing /private/var/folders/8t/_x8d0qg539z7ynrmr31xdpm00000gn/T/easy_install-mswJxc/mock-2.0.0/setup.cfg: SyntaxError: '<' operator not allowed in environment markers

The fix is to upgrade setuptools


Run the following before installing mock

# easy_install -U setuptools



Create mysql datbase table example

Here is an example on how to create a table using mysql:

mysql> use testdb;

mysql> create table mytable (
    myid integer not null,

    mynumber integer,
    mystring varchar(255),
    myboolean boolean,

    myblob blob,
    primary key (myid)
);



This table is used for some of the examples found at:
http://www.javacodex.com/JDBC

Getting the size of a BLOB in MySql

Here is an example on how to get size of a blob entry in a mysql table:

mysql> describe mytable;
+-----------+--------------+------+-----+---------+-------+
| Field     | Type         | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| mynumber  | int(11)      | NO   | PRI | NULL    |       |
| mystring  | varchar(255) | YES  |     | NULL    |       |
| myboolean | tinyint(1)   | YES  |     | NULL    |       |
| myblob    | blob         | YES  |     | NULL    |       |
+-----------+--------------+------+-----+---------+-------+
4 rows in set (0.00 sec)



mysql> select mynumber,sum(length(myblob)) from mytable;
+----------+---------------------+
| mynumber | sum(length(myblob)) |
+----------+---------------------+
|      101 |                5888 |
+----------+---------------------+
1 row in set (0.00 sec)

Using curl to access web pages using form based logins

Example on how to use curl to access a page that requires a login from a different page.


Look at the content of the login page to get the form action:

<form action="j_security_check" method="post">
  User Name:
  <input type="text" name="j_username" size="35">
  User Password:
  <input type="password" name="j_password" size="10">
  <input type="submit" value="login">
</form>


Create a cookie for storing sessions:
$ curl -b /tmp/cookies.txt -c /tmp/cookies.txt http://localhost:8080/myapp

Send user name and password to the form:
$ curl -b /tmp/cookies.txt -c /tmp/cookies.txt -d "j_username=user&j_password=password" $ http://localhost:8080/myapp/j_security_check


Get the content of the page using the session stored in the cookie: 

$ curl -b /tmp/cookies.txt -c /tmp/cookies.txt http://localhost:8080/myapp



How do I view cookies in Google Chrome?

The easiest way is to add the visit the following URL:

chrome://settings/cookies

How to Start & Stop MySQL Manually in OS X Yosemite

Start MySQL

sudo /usr/local/mysql/support-files/mysql.server start

Stop MySQL

sudo /usr/local/mysql/support-files/mysql.server stop

Restart MySQL

sudo /usr/local/mysql/support-files/mysql.server restart

Determining Your Current MySQL Version

Here is an example on how to get the version of MySQL that you are running:

mysql> SHOW VARIABLES LIKE "%version%";
+-------------------------+-------------------------+
| Variable_name           | Value                   |
+-------------------------+-------------------------+
| innodb_version          | 5.5.46                  |
| protocol_version        | 10                      |
| slave_type_conversions  |                         |
| version                 | 5.5.46-0ubuntu0.14.04.2 |
| version_comment         | (Ubuntu)                |
| version_compile_machine | i686                    |
| version_compile_os      | debian-linux-gnu        |
+-------------------------+-------------------------+
7 rows in set (0.93 sec)

zip all files in directory on linux

The directory that you want to zip up: 

$ ls -Rl ./src
src:
total 4
drwxrwxr-x 2 dennis dennis 4096 Feb 21 10:02 jdbc3040

src/jdbc3040:
total 20
-rw-rw-r-- 1 dennis dennis  827 Feb 21 09:50 DatabaseInfo.java
-rw-rw-r-- 1 dennis dennis  941 Feb 21 10:07 DriverReteieveDepartmentData.java
-rw-rw-r-- 1 dennis dennis  217 Feb 21 09:47 MyMain.java
-rw-rw-r-- 1 dennis dennis  462 Feb 21 09:24 MySQLConnection.java
-rw-rw-r-- 1 dennis dennis 1427 Feb 21 10:23 PreparedStatementExample.java

Zip the directory up into a single zip file:

$ zip -r /tmp/src.zip src
  adding: src/ (stored 0%)
  adding: src/jdbc3040/ (stored 0%)
  adding: src/jdbc3040/DriverReteieveDepartmentData.java (deflated 49%)
  adding: src/jdbc3040/DatabaseInfo.java (deflated 60%)
  adding: src/jdbc3040/MyMain.java (deflated 23%)
  adding: src/jdbc3040/MySQLConnection.java (deflated 49%)
  adding: src/jdbc3040/PreparedStatementExample.java (deflated 61%)


Show the contents of the zip file with out unzipping it:
 
$ unzip -l /tmp/src.zip
Archive:  src.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
        0  2016-02-21 09:19   src/
        0  2016-02-21 10:02   src/jdbc3040/
      941  2016-02-21 10:07   src/jdbc3040/DriverReteieveDepartmentData.java
      827  2016-02-21 09:50   src/jdbc3040/DatabaseInfo.java
      217  2016-02-21 09:47   src/jdbc3040/MyMain.java
      462  2016-02-21 09:24   src/jdbc3040/MySQLConnection.java
     1427  2016-02-21 10:23   src/jdbc3040/PreparedStatementExample.java
---------                     -------
     3874                     7 files

How To Create a New User and Grant Permissions in MySQL?

Create a database:
mysql> create database uml;

Create a user:
mysql> CREATE USER 'student'@'localhost' IDENTIFIED BY 'mysql';

Grant privileges:
mysql> GRANT ALL PRIVILEGES ON * . * TO 'student'@'localhost';

Log on:
$ mysql -u student -p
Enter password: mysql

Show users:
mysql> select host, user, password from mysql.user;
+-----------+------------------+-------------------------------------------+
| host      | user             | password                                  |
+-----------+------------------+-------------------------------------------+
| localhost | root             |                                           |
| ultra20   | root             |                                           |
| 127.0.0.1 | root             |                                           |
| ::1       | root             |                                           |
| localhost | student          | *E74858DB86EBA20BC33D0AECAE8A8108C56B17FA |
+-----------+------------------+-------------------------------------------+
9 rows in set (0.00 sec)

Installing python-swiftclient on Mac Yosemite

Installing python-swiftclient on OS X Yosemite is exceedingly difficult compared to earlier versions of OS X. Yosemite ships with Python 2.7.6. Runningsudo easy_install pip will install pip 1.5.6.
Those versions should work with python-swiftclient, but after installing the package with pip install python-swiftclient and running the swiftcommand, the following error is thrown:
Traceback (most recent call last):
  File "/usr/local/bin/swift", line 7, in <module>
    from swiftclient.shell import main
  File "/Library/Python/2.7/site-packages/swiftclient/shell.py", line 31, in <module>
    from swiftclient.multithreading import OutputManager
  File "/Library/Python/2.7/site-packages/swiftclient/multithreading.py", line 22, in <module>
    from six.moves.queue import PriorityQueue
ImportError: No module named queue
Google does not turn up anything useful. I would expect this error if Yosemite was using Python 3 because the queue module has been renamed. I can only assume the problem is due to Apple making their own modifications to the system installed Python, easy_install, and pip.
A colleague suggested installing Python, easy_install, and pip from Homebrew. This ended up being the solution.
Before installing Python, easy_install, and pip from Homebrew, clean up what was installed with the system installed pip by running the following commands (the Python dependencies for python-swiftclient can be foud here):
sudo pip uninstall futures
sudo pip uninstall requests
sudo pip uninstall simplejson
sudo pip uninstall six
sudo pip uninstall python-swiftclient
Next, if you haven’t already, install Homebrew by following the instructions on their website.
Then, install Python (this will setup a new easy_install and pip for you):
brew install python
Finally, install python-swiftclient:
pip install python-swiftclient
Now the swift command should work without issue.

How to do a Gradle build with out running any of the Junit tests?

How to do a Gradle build with out running any of the Junit tests?

Run:

 $ gradle build -x test

GIT: How do I show the changes which have been staged?

GIT - how to show the contents of files that have been changed.

Using the git cli to find what has been changed.

Run the following:
$ git diff --cached

or

Specify a file:
git diff --cached filename


Find what package a file belongs

Which rpm package does a file belong to?

run "rpm -qf file"

Here is an example on how to find out what rpm (redhat package) a file belongs to:

# rpm -qf /bin/ls
coreutils-8.4-37.0.2.el6.x86_64

# rpm -qf /etc/passwd
setup-2.8.14-20.el6_4.1.noarch


Getting RPM to list packages by install date

Here is an example on how to get a list of the redhat packages (rpm) sorted by install date:

# rpm -qa --queryformat '%{installtime} (%{installtime:date}) %{name}\n' | sort -n
1446148673 (Thu 29 Oct 2015 12:57:53 PM PDT) culmus-fonts-common
1446148673 (Thu 29 Oct 2015 12:57:53 PM PDT) fontpackages-filesystem
1446148673 (Thu 29 Oct 2015 12:57:53 PM PDT) kacst-fonts-common
1446148673 (Thu 29 Oct 2015 12:57:53 PM PDT) khmeros-fonts-common
1446148673 (Thu 29 Oct 2015 12:57:53 PM PDT) m17n-db
1446148673 (Thu 29 Oct 2015 12:57:53 PM PDT) smc-fonts-common
1446148673 (Thu 29 Oct 2015 12:57:53 PM PDT) thai-scalable-fonts-common
1446148674 (Thu 29 Oct 2015 12:57:54 PM PDT) filesystem
1446148674 (Thu 29 Oct 2015 12:57:54 PM PDT) un-core-fonts-common
1446148675 (Thu 29 Oct 2015 12:57:55 PM PDT) iso-codes
1446148675 (Thu 29 Oct 2015 12:57:55 PM PDT) samyak-fonts-common
1446148676 (Thu 29 Oct 2015 12:57:56 PM PDT) jakarta-commons-collections
.......


How to Enable Local SMTP Server (Postfix) on OS-X

How to Enable Local SMTP Server (Postfix) on OS-X Leopard

Edit org.postfix.master.plist:

$ sudo vi /System/Library/LaunchDaemons/org.postfix.master.plist

add:
    <key>RunAtLoad</key> 
    <true/> 
    <key>KeepAlive</key> 
    <true/>

Start postfix:

$ sudo launchctl start org.postfix.master

Check that SMPT is running:

    $ telnet localhost 25