How to Move MySQL's Data Directory

Sometimes it becomes necessary to move the location where MySQL stores databases. Either you have run out of room or something else has happened and you need to modify MySQL’s data directory. Here’s how to do it. First, I would stop MySQL’s daemon if you aren’t running production databases currently (which I would suggest reading this entire guide and thinking of a different way of doing this if you are):

Create a Windows 8 Bootable USB Drive with Mac OS

Mac OS X 10.8 (Mountain Lion) makes it relatively easy to create a bootable USB drive for installing Windows 8. You don’t have to be installing Windows 8 to the Mac, it will work on any computer that can boot from USB. I used Mac OS to prepare a bootable USB to install Windows 8 on a regular PC laptop. You will need the following: USB drive that is at least 4 GB Windows 8 ISO To create the drive, open Bootcamp Assistant from the applications in Mac OS.

Adding a user to sudoers file

“username is not in the sudoers file. This incident will be reported.” Aw. Well if you have root access, here’s how to add your user to the sudoers file. This will allow you to simply use sudo instead of su and logging in as root. su echo 'username ALL=(ALL) ALL' >> /etc/sudoers The first command will ask you for the root password. The second command adds username to the sudoers file.

Redirecting with JavaScript

Sometimes you want to redirect visitors to a different page, but don’t have access to the server-side language on the server where your page resides. Here’s how to redirect with JavaScript: <script type="text/javascript"> window.location = "http://example.com/redirect/"; </script> That will redirect any visitors to the page specified, if they have JavaScript enabled. I also leave a note for those that have no JavaScript capabilities or in case something goes wrong:

Title case a string in Python

While writing a python program, I came upon the need to convert a string to title case, or to capitalize the initial character of each word. Although PHP has ucwords(), Python does not partake in the “two methods for everything anyone has ever thought about”. Here’s a small function to give you title cased strings: def title_case(line): return ' '.join([s[0].upper() + s[1:] for s in line.split(' ')]) This will turn a string like “my fancy string” into “My Fancy String”.

Moving from Ubuntu to Debian

With the recent changes and events around Ubuntu, I have decided to start using Debian for my personal desktop and server OS. I thought I would detail the reasons behind my decision and my experience while making the switch. What’s wrong with Ubuntu? Here are a few of the reasons why I decided to start using Debian after using Ubuntu for 5 years: Unity Sending desktop search queries to external servers Mark Shuttleworth’s recent comments Unity: some love, some hate it.

Using dmenu with Openbox

I’ve already talked about using less RAM with Ubuntu and how openbox is an awesome lightweight window manager – capable of replacing heavy desktop environments like KDE and GNOME. Here’s another way to save some RAM while using openbox. I previously used a program called Kupfer to quickly open other programs that I use often. A quick ctrl+space would open Kupfer’s entry window and simply typing a program’s name would get Kupfer to suggest matches and open one.

Using Regular Expressions in Vim's Replace

That’s right, I’m using Vim again. I talk myself into going back to Sublime Text 2 from time to time, but then realize I miss Vim. One thing I felt Sublime was stronger at was find and replace and using regular expressions while you’re at it. It turns out that it was just my lack of knowledge of Vim’s find and replace functionality, including regular expressions support. It’s actually very easy to use regular expressions when finding and replacing with Vim: :%s/[0-9][0-9]/XX/g

Suspend Ubuntu without Sudo

I like to have a keyboard shorcut for things I do often in Ubuntu. I use openbox, which, aside from being awesome, makes it very easy to create keyboard shortcuts and keep them across installs (just back up your .config/openbox directory). Here’s a command I have assigned to a key combination that will put suspend an Ubuntu machine, without needing root permission: dbus-send –print-reply –system –dest=org.freedesktop.UPower /org/freedesktop/UPower org.freedesktop.UPower.Suspend This makes it easy to suspend a computer that doesn’t have a “sleep” function key.

Roll Your Own Site Checker with Python

There are tons of services out there that will monitor the status of a website for you. Pingdom, Uptime Robot, etc all will watch a site and inform you if it is down. Since it’s trivial to check a site’s status, I wrote my own equivalent using Python. Here it is: Site Checker with Python This checks a website (argument #1) and will send me an email if the site is down twice in 30 seconds.