Uncomplicated Firewall (UFW)

RackSpace's flavor of Ubuntu has installed the Uncomplicated Firewall and enables it by default (my experience).  Nice utility to manage the iptables for a local software based firewall.  

Enable UFW

To turn UFW on with the default set of rules:

sudo ufw enable

To check the status of UFW:

sudo ufw status verbose

Allow

sudo ufw allow <port>/<optional: protocol>

example: Allow incoming tcp and udp packet for MySQL

sudo ufw allow 3306  #open port for MySQL

example: To allow incoming tcp and udp packet on port 53

sudo ufw allow 53

example: To allow incoming tcp packets on port 53

sudo ufw allow 53/tcp

example: To allow incoming udp packets on port 53

sudo ufw allow 53/udp

Deny

sudo ufw deny <port>/<optional: protocol>

example: To deny tcp and udp packets on port 53

sudo ufw deny 53

example: To deny incoming tcp packets on port 53

sudo ufw deny 53/tcp

example: To deny incoming udp packets on port 53

sudo ufw deny 53/udp

Remove First Part of a Column Value

Let's say you have some values in your MySQL database that look like this:

a_180.0/v1355635866/r0y0ajbjiqry42tqscof.jpg

You want to to remove the first bit in a bulk process (the a_180.0/) and you don't want to have to write a 10 line Python script.  Well then, do it in good 'ol SQL.

Table: event_photo, Column: original_image_id

 UPDATE event_photo SET original_image_id = TRIM(LEADING 'a_180.0/' FROM original_image_id);

If you want to remove the .jpg part of the column value you can do this:

UPDATE event_photo SET original_image_id = TRIM(TRAILING '.jpg' FROM original_image_id);

If you have spaces in the front or back of the value and you want to remove those just do this:

UPDATE event_photo SET original_image_id = TRIM(original_image_id);

Drop a Foreign Key in MySQL

Fiddling with the removal of a foreign key in MySQL can drive an engineer mad.  In order to remove the key you must use the name of the constraint in the drop statement - not the name of the index.

The show command lists out the DDL for the table, including the created foreign keys:

mysql> show create table t1;

...
  CONSTRAINT `MY_TABLE_FK05` FOREIGN KEY (`FLIGHT_ID`,
`USER_ID`) REFERENCES `MY_OTHER_TABLE` (`FLIGHT_ID`,
`USER_ID`)

You can then issue the drop command with the name of the constraint (yeah, not really intuitive)

mysql> alter table t1 drop foreign key MY_TABLE_FK05;
Query OK, 0 rows affected (0.03 sec)
Records: 0  Duplicates: 0  Warnings: 0