Getting dos2unix and unix2dos On Ubuntu

Since – unlike most other Linux distros – Ubuntu doesn’t come standard with either dos2unix or unix2dos, you have to install it yourself.  The package “tofrodos” in the repos is what you’ll want, and the simplest method to install it is, of course:

sudo apt-get install tofrodos

However, unless you want to retrain yourself to use their naming conventions (which I certainly don’t), you’ll want to add one final piece to the process:

vi ~/.bashrc

In there, add two new aliases:

alias dos2unix=’fromdos’;
alias unix2dos=’todos’;

Save and exit, and then simply type the following to update your session:

. ~/.bashrc

DO NOT, however, do that with your .bash_history file, as Philip Olson did a couple of years ago.  ;-P

Share

JavaScript In Smarty

Just before I gave up with Serendipity – which uses the Smarty templating engine – I was trying to add some Google Analytics code into the template.  Because GA creates an anonymous function in JavaScript, instead of simply including the remote JS source file (which does make sense, in reality), it includes curly braces — and Smarty hates that.  It prompted me with errors about unknown tags and stuff.  Hooray.

Well, thankfully, the fix was simple: wrap the JavaScript code in ‘literal’ tags.  Example:


{literal}
<script language="JavaScript">
alert('Smarty takes this literally.');
</script>
{/literal}

Share

Goodbye, s9y!

I’d finally had it.

Serendipity had a bunch of issues that were interruptive at best — destructive at worst.  I know plenty of other people have had success and been quite pleased with it, but it just wasn’t the right fit for me.  I’d known it for some time, but let’s face it: unless you’re a “blogger” by trade, you probably have more important things to do than update your personal hobby site.  I fell right into that camp myself.  I just couldn’t be bothered trying to convert it to something else.

Enter: WordPress.

Through one of my companies, PilotPig Web Hosting, we frequently get hosting orders for WordPress sites.  So the account is created, activated, and WordPress is installed for the customer.  I’ve done literally a few hundred installations and some basic customizations of the package, but I’ve never actually used it myself — until right now.  Seems decent.

Well, the one problem I thought I’d be facing was getting the posts from Serendipity imported into WordPress.  I was wrong.  All I needed to do was grab the full RSS 2.0 feed from s9y (/rss.php?version=2.0&all=1), save it to my Desktop, then run it through a quick conversion script that took all of two minutes to write:
<?php
if (!isset($argv[1])) {
echo 'Enter the RSS feed file to convert: ';
$argv[1] = trim(fread(STDIN,128));
}

$data = file_get_contents(dirname(__FILE__).DIRECTORY_SEPARATOR.$argv[1]);

file_put_contents(dirname(__FILE__).DIRECTORY_SEPARATOR.$argv[1].'-converted',
htmlspecialchars_decode($data,ENT_QUOTES));

Then just import it using the WordPress RSS importer tool, and – ta-da! – my work here was done, and I could go back to my day.  Neat.

Share

Merging Contacts on Android Phone

I don’t give a damn if it starts Jihad — my DROID could kick an iPhone’s ass with its keyboard locked shut and the screen powered off.

Still, at times, I want to shove it up the ass of a goat and send the goat off to the slaughter. The latest update to be deployed on Verizon Android devices is a great example of that, because it royally sucks. That and the camera — the DROID camera rots like a dead possum in the desert sun.

Today was another minor inconvenience that had me sternly telling my phone it was a pain in the ass: I was told that I could not edit Facebook contacts in my own phone’s contact list, and was given the options of “Done” and “Revert.” Revert what? You wouldn’t let me do anything in the first place!

Thankfully, after poking it with a stiff index finger and swiping at it like a cat playing with a ball of yarn (what the hell is with today’s animal theme with me?!?), I finally figured out how to resolve the problem.

Add a new contact by the same name as the one sync’ed from Facebook and save it. Then go in to edit that contact, and click the menu button to bring up additional options. Click “Join” and select the contact with whom you want to join the current record. Sometimes Android is able to intelligently match which contacts you would likely want to join (for example, Rodney DelaRosa with Rodney DelaRosa, which was what I first tried). Other times it could not (Anne Killins-Wahl with Boney Wailin). You can simply click “All Contacts” and scroll to the right one, though, which is fair enough. Then it will attempt to merge the contacts in a simple but logical fashion. You may need to edit a few fields sometimes, but I only had that problem once (oddly enough, with my wife’s contact info). Click “Done” and…. well, if you can’t guess what happens after that, maybe you can join the goat. Or possum. Or…. just go away.

Share

SSH Client On Ubuntu Desktop Timing Out

It would happen again and again and again…. I’d walk away from the computer (yeah, on rare occasions that happens), or I’d flip to another terminal and get sidetracked there:

Write failed: Broken pipe

Son of a bitch! And why the hell don’t I remember to vi in screen until moments like this?!?

Well, unless I keep ‘top’ open or run a while [ 1 ]; do echo -n '';sleep 30; done, it continues to drop out without fail. And an interesting (to me) fact that I’ve actually recorded: I spend more than 60% of my day on the command line.

Logically, the first things I tried were to add /etc/ssh/ssh_config parameters for both KeepAlive and TCPKeepAlive, but that still had no positive effect. Then I started to dig deeper into the issue to see what other options I had. There were no network problems or abnormally-high numbers of dropped packets or shards, it would happen regardless of whether it was WiFi, 3G, or LAN cabled, and all other network services and applications were working just fine — including things like telephony, which was perfectly clear. I knew that it had to be a timeout issue, and since it wasn’t restricted to just a single server (or even to just thirty or forty servers, for that matter), nor was it an issue until I [finally] switched from Mandriva to Ubuntu, it had to be a local problem.

I dug and dug and dug, almost all the way to Virtual China, and finally found my Holy Grail:

ServerAliveInterval

Right now, I’m using ServerAliveInterval 120 and, for the first time since the issue reared its ugly head, I’ve been able to keep SSH sessions open and idle overnight. Hoorayings for Internets funs again and stuffs! Now maybe I can stop losing time on this and go back to only dealing with the issue of my mouse getting stuck between screens with Xinerama

Share

ImageMagick `convert` 100% CPU Usage

Plain and simple: upgrade to the latest, if necessary, and compile with the flag:

–disable-openmp

Flashy and complicated: if you’re on CentOS5, specifically, you can do what I needed to do. I needed to write a patch for a client’s network of systems. You don’t need to do that, though, unless you need OpenMP on there (which you probably don’t). Wish I’d realized that was the issue before I went hog-wild.

So if you’re running into an issue where the ‘convert’ command is using 100% of your CPU (we had it running 800% — 100% x 8 cores), try the above. Most likely, that’ll fix ‘er.

Share

Binding Windows Key to KDE Menu In KDE4

Seems to be a lot of confusion in KDE4 as to how to bind the Windows key on a standard keyboard to the KDE menu. Well, let’s make the solution brief:

1.) Drop to a command prompt (such as konsole).
2.) Type: xev
3.) Press the Windows key (either side, or both sides individually) and notice the number assigned to the ‘keycode’ identifier.
4.) Create (or edit) your .Xmodmap profile file. Example: vi ~/.Xmodmap
In your .Xmodmap profile, add the following, where ### is your keycode from above, and save the file:
keycode ###=F13
5.) Back at the command line, activate the above by typing: xmodmap -e ‘keycode ###=F13’
6.) Right-click the KDE menu and click “Application Launcher Menu Settings” from the menu that appears.
7.) Click “Keyboard Shortcut”.
8.) Click the button with the picture of the wrench on the “Keyboard Shortcut” screen and press the Windows key. You should see F13 appear in the box.
9.) Move your mouse out of the box and click the “OK” button to close the dialog and activate the key.
10.) Press the Windows key and see the menu pop up as expected. NOTE: You can’t tap it again to close the window. Instead, you’ll need to press the ESC key or click elsewhere.

NOTE: The above is done for brevity. A good lesson to learn from this is that ‘xev’ is a useful tool, and ‘xmodmap’ is your friend. Oh, and that the KDE folks still haven’t gotten their crap entirely straight with KDE4 as of version 4.2.4 (the version in which this was tested).

There are also other ways. In fact, I did the following for my Mandriva 2009.1 + KDE 4.2:

cat << EOT >> ~/.kde4/Autostart/bindWindowsKey.sh
xmodmap ‘keycode 133=F13’;
xmodmap ‘keycode 134=F14’;
xmodmap ‘keycode 135=F15’;
EOT

Now to figure out why Plasma keeps interfering and disabling the damn thing when I restart X or relaunch the session…. maybe I’ll post back here later.

Share

Windows 7 DWM (dwm.exe) High CPU Performance Issues

On this system, I’m blessed with a triple-headed setup: I have three nice LCD monitors on my desktop which create a panoramic view of my terminal screens. I’m also cursed with Windows 7 and it’s [many] flaws. Lately, I’ve been having an issue with Windows 7’s Desktop Window Manager (DWM, shown as dwm.exe in Task Manager) consuming large amounts of CPU and RAM resources. After a bit of snooping around, I found a simple fix:

1.) Click the START button.
2.) Type “powershell” into the “Search programs and files” box.
2a.) If you see a menu item for PowerShell, open it.
2b.) If you do not see a menu item for PowerShell, this won’t work for you.
3.) Type “net stop uxsms”
3a.) Try this if you want a stripped-down version of your ALT+TAB and fewer bits of eye candy. It’s just like WinXP, and runs quicker. If your ALT+TAB was slow, it should now zip along quite nicely.
3b.) If you want your effects and nicer ALT+TAB screens back, type “net start uxsms” and you should be good to go.

Share

The BASIC Equivalent of Hell

10 PRINT “This is the song that doesn’t end.”
20 GOSUB 50
30 PRINT “Some people started singing it, not knowing what it was.”
40 PRINT “And they’ll continue singing it forever, just because….”
45 GOTO 10
50 PRINT “Yes, it goes on and on, my friend.”
60 RETURN

Share

Add New Domains to Apache On Command Line

I had a need to add several domains to Apache for a client about an hour ago, and instead of copying, pasting, changing, and repeating, I opted to script it. It’s very simple (read: not secure for multiple users in production), but served my needs today beautifully. Feel free to clean it up and use it, change it, whatever.

The primary reason this is added is to show how CLI scripts can be made to wait for and accept user input. Note the use of STDOUT and STDIN in the script. This is something that I’ve found to be quite unfortunately overlooked in a lot of CLI scripts. Using this, you can make a PHP CLI script interactive, instead of requiring arguments to be passed on the command line.

Also, note that this particular script wasn’t needed for user creation, DNS, or anything of the like. Strictly for adding an Apache directive for the domain.

(The code itself is indented, but I’m learning more and more why Philip Olsen scoffed at me for installing Serendipity last year. Eventually my error in judgment shall be rectified.)


#!/usr/bin/php
<?php

if(trim(`whoami`) != 'root') die("You must be root to run this command.\n");

fwrite(STDOUT,"Domain to be added: ");
$domain = trim(fgets(STDIN));

fwrite(STDOUT,"Username to use for this domain: ");
$user = trim(fgets(STDIN));

fwrite(STDOUT,"Group to use for this domain: ");
$group = trim(fgets(STDIN));

fwrite(STDOUT,"Path to use for the web root of this domain: ");
$path = trim(fgets(STDIN));

fwrite(STDOUT,"Server administrator's email address to use: ");
$email = trim(fgets(STDIN));

echo "Writing.... ";

$newHost =<<<TXT

NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin $email
DocumentRoot $path
ServerName $domain
ServerAlias www.$domain
ErrorLog logs/$domain-error_log
CustomLog logs/$domain-access_log combined
<IfModule mod_suphp.c>
suPHP_Engine On
suPHP_ConfigPath "/etc/"
suPHP_AddHandler x-httpd-php
suPHP_AddHandler php5-script .php
suPHP_UserGroup $user $group
</IfModule>
</VirtualHost>
TXT;

file_put_contents('/etc/httpd/conf/httpd.conf',$newHost,FILE_APPEND);

echo "Done.\n";

fwrite(STDOUT,"Should I restart Apache now for the changes to take effect? (y/N) ");
if(preg_match('/^ye?s?$/i',trim(fgets(STDIN)))) {
exec('service httpd restart');
echo "Apache restarted.\n";
}

?>

Share