Archive for September, 2011

Redirect non-www to www (and vice-versa) via htaccess

This is probably old news for a lot of folks, but it’s handy nonetheless and I often have to look up these .htaccess strings. Note that Apache mod_rewrite is required for any of this to work.

This (and it’s comments) are based on the Drupal default .htaccess file [License as of 9/30/11: GPL], because the Drupal .htaccess file explains it very well. Mind that lines starting with # are comments. Uncomment them to make them take effect.

Also, this should NOT be used with a WordPress install (it will result in a redirect loop). Instead, make the change in Dashboard > Settings > General.

RewriteEngine On
# If your site can be accessed both with and without the 'www.' prefix, you
# can use one of the following settings to redirect users to your preferred
# URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
#
# To redirect all users to access the site WITH the 'www.' prefix,
# (http://example.com/... will be redirected to http://www.example.com/...)
# uncomment the following:
# RewriteCond %{HTTP_HOST} !^www. [NC]
# RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#
# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment the following:
# RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
# RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]

Questions, comments, or feedback? Please leave a comment below. Thank you!

, , ,

Leave a comment

Easy Ubuntu data usage monitor

If you’re lucky enough to have a broadband card that works under Linux, your plan probably includes an “allowance” or data usage quota per month. You might be thinking how nice it would be to have a utility that tracks your data usage for the month (or other period) and gives you an easy-to-read report. You might also want said monitoring utility to have pre-built packages for Ubuntu / Debian.

NTM (Network Traffic Monitor) is what you want. As of this post the latest version is NTM 1.2.4.

Start by going to the NTM download site and downloading ntm-1.2.4.deb. Then double-click on it to install it using Ubuntu Software Center.

Once installed, you will find NTM at Applications > Internet.

Upon starting, it minimizes to the tray (next to the clock). You can open the interface by left-clicking the icon, and open the menu to access preferences by right-clicking the icon.

By default NTM monitors ppp0, which is the most likely interface that your broadband card will use. If you want to monitor a different interface, change that under the General tab. If you’re not sure what interface to use, run the following command:

ifconfig -a

This lists all interfaces and will help you locate your desired connection by IP / MAC and other info.

Also by default, NTM is configured with some other settings, such as auto-disconnecting after a data threshold has been reached (98MB by default), and disconnecting after a certain number of usage hours (30). These are likely too low for most mobile broadband users. Be sure to change these settings, under the Traffic, Time Slot, and Time tabs, to prevent unexpected disconnections.

Questions, comments, or other feedback? Please comment below. Thanks!

, ,

Leave a comment

Windows CHKDSK at boot cancelled by phantom keypress

When you run the Windows checkdisk (chkdsk) utility, it may report the disk being in use and recommend that you schedule chkdsk to run the next time the computer restarts, like the following screenshot shows:

chkdsk_schedule2

Windows can’t check the disk while it’s in use. Do you want to check for hard disk errors the next  time you start your computer?

However, doing that ran me into a very curious issue on Michele’s laptop: I would restart the computer, and get a message telling me to press any key within a few seconds to abort the scan if I so desired. Sorry, but I don’t have the exact message in front of me at the moment. Curiously it would abort itself after a second or two, stating that I pressed a key (which I did not). I’m fairly certain this is caused by this issue here: kernel atkbd.c: Unknown key released messages on Linux.

In order to make the chkdsk run without aborting due to that phantom keystroke, you have to set the delay to zero. To do this, boot back up into Windows, open an administrative-level command prompt, and run the following:

chkntfs /t:0

That will set the delay to zero seconds, effectively making it unable to be interrupted. Schedule the disk check again and reboot. It should run without issue.

Questions, comment, or any issues with the above are welcome in the comments section. Thank you!

, ,

Leave a comment

How to tell if your CPU supports virtualization under Ubuntu Linux

If you’re thinking of running a virtual machine, you should check first to see if your processor supports the VT extension. To do so, run the following command in a terminal.

cat /proc/cpuinfo | egrep '(vmx|svm)'

Having the VT extension allows improved virtual machine performance, as well as the ability to run 64-bit virtual machines. Note that some manufacturers have an option to enable/disable VT in the BIOS (which is usually set to disabled), so if you have VT extensions, you may want to check to make sure it’s enabled.

Further Reading: Linux Tip: How to Tell if Your Processor Supports VT

Sorry for the brief post, but it’s late and I’m just making a quick note of this. Note that this works in just about any Linux distro, not just Ubuntu.

,

Leave a comment

Enable or disable individual browser plugins in Chrome or Chromium

I needed this tonight when doing failover testing on a page I’m putting together. You can enable/disable browser plugins in Chrome / Chromium by typing the following into the browser’s address bar:

about:plugins

The page that opens will allow easy enabling / disabling of plugins.

Leave a comment

WARNING: erroneous pipeline: no element “lamemp3enc”

I was using gst-launch to create and handle an audio stream, but when I went to run it on a second Ubuntu box I could not figure out why I was getting an error.

Here was a section of my command:

gst-launch-0.10 pulsesrc device=alsa_output.pci-0000_02_02.0.analog-stereo.monitor ! audioconvert ! audio/x-raw-int,channels=2,rate=32000 ! lamemp3enc ! ...

I got this error:

WARNING: erroneous pipeline: no element "lamemp3enc"

Looking through Synaptic, I could not find out how to get this lamemp3enc installed, try as I might. I checked the GStreamer Reference, which says it’s part of the “ugly” plugins set. But after installing gstreamer0.10-plugins-ugly I was getting the same error. It turns out I needed to enable the multiverse repository and install gstreamer0.10-plugins-ugly-multiverse. Install via Synaptic or use the following command:

sudo apt-get install gstreamer0.10-plugins-ugly-multiverse

Hopefully this helps anyone trying to figure out the same issue.

,

Leave a comment

How to import Android phone contacts to Gmail contacts

If you set up your Google account using your Android phone, or you added contacts to your phone but didn’t set them as Google account contacts, you will find they’re not synced to your Google account. This means that they’re not available as contacts when composing messages, and worse, you’re not using your Google account as a backup in case your phone is lost or damaged, or you swap phones.

You can easily fix this by doing the following steps from your Android phone:

  • Open Contacts
  • Hit menu > Import/Export
  • Export to SD card, then hit OK to confirm.

After a few moments, your data will be exported.

Next, we delete all contacts, to prevent confusion

  • In Contacts, hit menu > delete > Select All > delete

If you don’t have this option, try Delete All Contacts from Android Market.

(If you’re concerned about deleting your contacts before re-importing them, you can always import them, then resolve the duplicates manually, but you will have stale contacts in your phone. Deleting your contacts then re-importing them a second time will take care of that.)

Lastly, re-import all the contacts to your Google account

  • Hit Import/Export again
  • Select Import from SD Card
  • Select Save contact to… (your Google account) NOT phone

After a few moments, your data will be re-imported, and synced with your Google account online. Note that it may take up to a few minutes for the contacts to start appearing in your Google account.

If you mistakenly import multiple times, you may end up with duplicates in your online Google account. To fix this, simply open more > Find and Merge duplicates from your Contact manager as shown below:

Yes, I really do have 329 contacts.

Note: It is not possible to preserve group information during an export/import. It’s not supported by Google.

Questions and comments are welcome below, thank you!

, ,

Leave a comment

Determine if current user is an admin in WordPress using PHP

You can determine if the current logged-in WordPress user is an admin and take a certain action in WordPress using PHP. If you’re using a PHP widget plugin, you can use this code in a PHP widget to show or do something if the current user is an admin. You can also use this to limit the display of a block you might be working on to only admin users while you’re working on it.


This method is ideal because only admins have the manage_options capability.

Comments are welcome below. Thank you.

,

Leave a comment

Batch converting audio files to MP3

If you’re converting a single file, http://media.io/ is a great online tool. However, for batch conversion, you’ll want to look at one or more of the following tools:

Windows:

dbPowerAmp is a great conversion utility http://www.dbpoweramp.com/dmc.htm

Ubuntu:

While dbPowerAmp says Linux is supported through Wine, I’ve found that soundconverter works wonderfully. To install it:

sudo apt-get install soundconverter

Next, just run it. You can select your input files and directories in the GUI. By default, soundconverter produces .ogg output. If you want mp3, simply select it in Edit > Preferences

, , ,

Leave a comment

Reverting localized Adobe CS5 interface to English

If you’re a Adobe CS5 user and you have a localized language installation but you want to revert to English as the interface language, either temporarily or permanently, follow this tip:

First, completely exit your Adobe product, then follow the instructions for your OS below.

Windows:

In explorer, open C:Program Files (or Program Files (x86))

then AdobeAdobe Photoshop CS5Locales

You should have one (or more) locale folders, such as en_GB or es_MX. Open it, then Support Files within it.

You should see a tw10248.dat file (either with or without the extension, depending on your settings.) Either rename or delete this file, depending on if you want to revert to your localized language installation again in the future, and restart your Adobe product.

Mac:

In Finder’s search box, type tw10428. The file tw10428.dat should appear (either with or without the extension, depending on your settings.). Either rename or delete this file, depending on if you want to revert to your localized language installation again in the future, and restart your Adobe product. (To rename, select File > Get Info)

The interface language should now appear in English.

Questions or comments on this are welcome in the comments section below. Thank you!

,

Leave a comment