Linux: Opening .tar.gz Archive

gunzip filename.tar.gz

Followed by:

tar -xvf filename.tar

Generally you should untar things into a directory, or the present working directory will be the destination which can get messy quick.

Add Rules to IPTables

View and Delete IPTable Rules:

http://www.thegeekstuff.com/2010/07/list-and-flush-iptables-rules/

https://www.digitalocean.com/community/tutorials/how-to-list-and-delete-iptables-firewall-rules

Drop traffic from an IP

https://www.linode.com/docs/security/firewalls/control-network-traffic-with-iptables

("I" Insert rule shown below, see link for more rule types)

$ iptables -I INPUT -s 114.80.215.81 -j DROP

Decrypt Encrypted ColdFusion Datasource PW

In Terminal:
$ echo hRcZHqpT8Z9U/sjPqclyAw==|openssl des-ede3 -a -d -K 30794A21403124723870304C4072312436794A214031726A -iv 30794A2140312472; echo

(where the text in bold is your encrypted password)

NGINX: CORS Access

https://gist.github.com/algal/5480916

https://gist.github.com/alexjs/4165271

https://michielkalkman.com/snippets/nginx-cors-open-configuration.html

http://enable-cors.org/server_nginx.html

http://blog.ionic.io/handling-cors-issues-in-ionic/

https://github.com/lynndylanhurley/ng-token-auth/issues/157

SSH Agent

Check which keys are currently loaded.

$ ssh-add -l

Add a key file to your ssh list:

$ ssh-add #FULL_PATH#

Linux: Change Owner/Group of File

EXAMPLES

chown root /u
Change the owner of /u to "root".
chown root:staff /u
Likewise, but also change its group to "staff".
chown -hR root /u
Change the owner of /u and subfiles to "root".

NGINX: Kill process

sudo kill $(cat /opt/nginx/logs/nginx.pid)

Linux: Set VIM as default editor

  1. See the list of available editors.

    root@li1298-148:~# update-alternatives --list editor

  2. Update the default to your vim installation.

    root@li1298-148:~# update-alternatives --set editor /usr/bin/vim.basic

PostgreSQL: Backup and Restore DB

Backup:
$ pg_dump -U {user-name} {source_db} -f {dumpfilename.sql}

Restore:
$ psql -U {user-name} -d {desintation_db}-f {dumpfilename.sql}

PostgreSQL: List all users

SELECT usename FROM pg_user;

NGINX: Symlink sites-available

sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com

MySQL: Set user password

SET PASSWORD FOR 'bob'@'%.example.org' = PASSWORD('cleartext password');

Mongo DB Querying

Count number of records in array:
db.data_records.count( { dataset_id: { $in: [ 2509, 2224, 2128, 2145, 2472, 2249 ] } } )

Count number of records NOT in array:
db.data_records.count( { dataset_id: { $nin: [ 2509, 2224, 2128, 2145, 2472, 2249 ] } } )

Remove records NOT in array:
db.data_records.remove( { dataset_id: { $nin: [ 2509, 2224, 2128, 2145, 2472, 2249 ] } } )

TextMate CheatSheet

⌃ Control
⌥ Option
⌘ Command
⇧ Shift
⎋ Escape
⌅ Enter
↩ Return
⌦ Forward Delete
⌫ Backward Delete
﹖⃝ Help
↖ Home
↘ End
⇞ Page Up
⇟ Page Down
⇥ Tab
⇤ Back-tab

HTML BUNDLES

Insert Open/Close Tag (⌃<) — this command will take the word just typed and change it into placing the caret in the middle. It will recognize those tags where a close tag is not allowed (like hr) and instead insert placing the caret after the tag.

Wrap Selection in Open/Close Tag (⌃⇧W) — this will put

around the selection but allows you to o...

Linux: COPY TO LOCAL MACHINE USING SSH

COPY TO LOCAL MACHINE USING SSH
scp user@domain:remote_file_location local_file_location

Linux: Zip Folders Recursively

ZIP FOLDERS RECURSIVELY:

zip -9 -r

-9: optimize compression
-r: recursive

Active Record migration hack

ActiveRecord::Schema.define do
<>
end

Understanding CSS Vertical Alignment

vertical-align

vertical-align: middle

In Table Cells

In table cells (and in div with display: table-cell), this will work as expected. The content will be centered vertically.

In Inline Elements

It works like the old 'align' property. This means that it will KIND OF work the way you expect it.

For ALL Other Elements

Technically, it should not do ANYTHING on these elements.

MongoDB: List all collections by size

var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(stats[c]['ns'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize'] + ")"); }

nokogiri gem installation

This works on Mac OSX 10.9

gem install nokogiri -- --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/libxml2 --use-system-libraries

Git: Rename Local Branch

git branch -m <oldname> <newname>

If you want to rename the current branch, you can simply do:

git branch -m <newname>