Working Ninja
2017-03-15T07:38:50
dd if=<path to input file> | pv -s <size e.g. 1377M> | dd of=<path to target device>

Source: https://superuser.com/questions/351814/how-to-copy-an-iso-image-onto-usb-with-dd#351815

2017-02-04T16:02:28

To swap control and command, add the following to your ~/.Xmodmap file:

remove control = Control_L
remove mod4 = Super_L Super_R

keysym Control_L = Super_L
keysym Super_L = Control_L
keysym Super_R = Control_L

add control = Control_L Control_R
add mod4 = Super_L Super_R

The above current works for both an Apple laptop and an Apple keyboard.

Also, to use Command+Tab to cycle windows, make sure to update keyboard shortcuts to use Ctrl+Tab instead of Alt+Tab (for Xfce, Window Manager -> Keyboard). All other keyboard shortcuts should come through (from the Control to Command swap perspective).

Source: https://stackoverflow.com/questions/7099602/cmd-control-keys-swap-in-ubuntu

2016-11-21T23:35:33

The Old Way

import os

os.system('find /home/user/documents -type f -iname "*.doc"')

The New, Recommended Way

import subprocess

subprocess.check_call([
    'find',
    '/home/user/documents',
    '-type', 'f',
    '-iname', '*.doc'
])

Bonus Tidbit

At this point, we can incorporate some nice exception handling:

import subprocess

try:
    subprocess.check_call([
        'find',
        '/home/user/documents',
        '-type', 'f',
        '-iname', '*.doc'
    ])
except subprocess.CallProcessError as e:
    print e.returncode
    print e.cmd
    print e.output

See the official Python Documentation for more usage and recommendations on the subprocess module.

2016-11-02T20:35:49

Server
Install NFS server components:

# apt-get install nfs-kernel-server portmap

Add the "root" of all shares (if this is your only share, this should be all you need):

# echo "/home 192.168.1.0/24(ro,fsid=0)" >> /etc/exports

Add additional shares:

# echo "/home/joe 192.168.1.0/24(rw,sync,no_subtree_check)" >> /etc/exports

Update NFS exports table:

# exportfs -avr

Restart NFS server:

# service nfs-kernel-server restart

Don't forget to allow NFS through iptables.

Client

# apt-get install nfs-common
# mount server:/share /share

Prosit!

Notes

Slow initial directory listing is caused by aliases (specifically color output). Explanation here: http://www.novell.com/support/kb/doc.php?id=7005969. Use \ls -la instead of ll as a workaround.

Sources:
https://wiki.debian.org/NFS
https://help.ubuntu.com/community/SettingUpNFSHowTo
https://www.centos.org/docs/5/html/Deployment_Guide-en-US/s1-nfs-server-config-exports.html
http://www.tldp.org/HOWTO/NFS-HOWTO/intro.html
http://nfs.sourceforge.net/nfs-howto/ar01s07.html

2016-11-01T16:55:19

Before adding a script to cron and finding that it doesn't work because of a PATH issue, here's a handy command to test:

env -i ./script

This will run your script in the same environment that cron will.

2016-03-31T22:34:52

I must have it saved somewhere but it was nowhere to be found. The password was lost. My root account was forever secure--or was it?

# service mariadb stop
# mysqld_safe --skip-grant-tables &
# mysql -u root
> USE mysql
> UPDATE user SET password=PASSWORD("mynewpassword") WHERE User='root';
> FLUSH PRIVILEGES
> QUIT

This didn't stop the mysqld_safe process, so I killed the parent mysql process (/usr/libexec/mysqld) via its process ID ($pid).

# kill $pid

Start MySQL back up.

# service mariadb start

Finally, for security purposes, remove the UPDATE user ... SQL statement from ~/.mysql_history.

Profit! And don't forget to securely store your password.

2016-03-26T10:26:48

GitLab was throwing me a 500 server error this morning after an upgrade via yum. To troubleshoot, I ran the self diagnose command from terminal:

# gitlab-rake gitlab:check

Which gave me the following error to fix:

All migrations up? ... no
  Try fixing it:
  sudo -u git -H bundle exec rake db:migrate RAILS_ENV=production
  Please fix the error above and rerun the checks.

Since I installed GitLab via a yum package, I ran a slightly different command to run the GitLab migrations:

# gitlab-rake db:migrate RAILS_ENV=production

Now I was presented with the source of the issue, relating to PostgreSQL. I needed to enable the pg_trgm extension:

== 20160226114608 AddTrigramIndexesForSearching: migrating ====================
-- execute("SELECT true AS enabled FROM pg_available_extensions WHERE name = 'pg_trgm' AND installed_version IS NOT NULL;")
   -> 0.0066s
rake aborted!
StandardError: An error has occurred, all later migrations canceled:

You must enable the pg_trgm extension. You can do so by running "CREATE EXTENSION pg_trgm;" as a PostgreSQL super user, this must be done for every GitLab database.

And sure enough, others were having the same issue. These are the steps they (and I) executed to fix the issue:

# yum install postgresql-contrib
# su - postgres
$ psql -d gitlabhq_production -c "CREATE EXTENSION pg_trgm;"
$ exit
# gitlab-rake db:migrate RAILS_ENV=production
# gitlab-ctl reconfigure
# gitlab-ctl restart

Profit!

Source: https://gitlab.com/gitlab-org/gitlab-ce/issues/14526

2016-03-10T17:26:15
$ VBoxManage modifyhd YOUR_HARD_DISK.vdi --resize SIZE_IN_MB

Source: http://askubuntu.com/questions/88647/how-do-i-increase-the-hard-disk-size-of-the-virtual-machine

2016-02-04T07:37:49

I went to update my Ubuntu machine today and found out there wasn't enough space on /boot to perform the update. You can remove older kernels to free up space:

// Check which kernel you're using
$ uname -r

// List all installed kernels
# dpkg --list 'linux-image*'

// Remove the kernel (I recommend the oldest [kernel with the smallest number])
# apt-get remove linux-image-VERSION

Source: https://askubuntu.com/questions/345588/what-is-the-safest-way-to-clean-up-boot-partition

2016-01-21T22:03:11

Unable to boot after kernel (3.19) upgrade on Ubuntu. Here's the fix:

  1. Add copy_modules_dir kernel/ubuntu/i915 to /usr/share/initramfs-tools/hooks/framebuffer.
  2. Then run update-initramfs -k all -u.
  3. Profit.

Fix found here: https://bugs.launchpad.net/ubuntu/+source/cryptsetup/+bug/1500751