Planet PLUG

Planet PLUG is an aggregation of blogs written by members of the PLUG community. The opinions expressed are those of the original authors. Discussion of subject matter should be conducted on the author's blog, and not on the PLUG mailing list.


May 09, 2012

mikegrb

Migrating Post Tags from Wordpress to Octopress

I’ve migrated from Wordpress to Octopress and used the Jekyll wordpress migrator to move my posts over. Unfortunately, this doesn’t preserve post tags. The output looks like this:

1
2
3
4
5
6
7
8
---
layout: post
title: Devops w/ Perl @ Linode PPW Talk Slides
wordpress_id: 330
wordpress_url: http://michael.thegrebs.com/?p=330
date: 2011-10-27 14:46:31 -04:00
---
Earlier this month I gave a talk about...

Having the wordpress post id means extracting the post tags from the db should be quite easy. First we define our desired output:

1
2
3
4
5
6
7
8
9
---
layout: post
title: Devops w/ Perl @ Linode PPW Talk Slides
wordpress_id: 330
wordpress_url: http://michael.thegrebs.com/?p=330
date: 2011-10-27 14:46:31 -04:00
tags: geek perl slides
---
Earlier this month I gave a talk about ...

The tags field really can appear anywhere in this YAML fragment but I chose to throw it at the end. With 103 posts to loop over, run a query and insert a new line a short script makes sense. The real win for our script though is using the Tie::File module which presents each file as an array with an element for each line.

From there it’s simply a matter of reverse engineering the Wordpress schema to come up with a query that will return a space delimited list of tags for a given post id.

1
2
3
4
5
SELECT GROUP_CONCAT(t.`name` SEPARATOR " ") FROM `wp_term_relationships` r
INNER JOIN `wp_term_taxonomy` tax ON r.`term_taxonomy_id` = tax.`term_taxonomy_id`
INNER JOIN `wp_terms` t ON tax.`term_id` = t.`term_id`
WHERE r.`object_id` = ?
AND tax.`taxonomy` = "post_tag";

Throw that query in a script that iterates over the list of files and uses Tie::File to add a line to the post and we get:

(word2octo-tags.pl) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl 

use 5.010;
use strict;
use warnings;

use DBI;
use Tie::File;

my $path_to_posts = 'source/_posts';

my $dbh = DBI->connect('DBI:mysql:db_name:db_host','db_user','db_pass');

my $get_tags = $dbh->prepare(q{
    SELECT GROUP_CONCAT(t.`name` SEPARATOR " ") FROM `wp_term_relationships` r
    INNER JOIN `wp_term_taxonomy` tax ON r.`term_taxonomy_id` = tax.`term_taxonomy_id`
    INNER JOIN `wp_terms` t ON tax.`term_id` = t.`term_id`
    WHERE r.`object_id` = ?
    AND tax.`taxonomy` = "post_tag";
    });


for my $file (glob "$path_to_posts/*.markdown") {
    say $file;
    add_tags_to_file($file);
}

sub add_tags_to_file {
    my $filename = shift;
    tie my @file, 'Tie::File', $filename or die "No tie: $!";
    my $tags;
    while (my ($rec, $data) = each @file) {
        if ($data =~ m/^wordpress_id: (\d+)$/) {
            $tags = get_tag($1);
        }
        if( $data =~ /^date:/) {
            splice @file, $rec + 1, 0, $tags if $tags;
            return;
        }

    }
}

sub get_tag {
    my $post = shift;
    $get_tags->execute($post);
    my ($tags) = $get_tags->fetchrow_array();
    return "tags: " . $tags if $tags;
}

May 09, 2012 12:50 AM

April 21, 2012

Walt Mankowski

Finding Unicode Characters in LaTeX and BibTeX

Yesterday I discovered what I thought was an odd bug in BibTeX. For one of the journal articles in my bibliography, I had the BibTeX entry

journal = {Human–Computer Interaction},

but it was appearing in my bibliography as HumanComputer Interaction.

The error turned out to be that the innocent-looking hyphen between "Human" and "Computer" was actually a Unicode en-dash. I didn't intentionally insert it, but I guess I must have copied that bit of text from a Unicode-enabled website or email. LaTeX and BibTeX are happiest plain ASCII characters, and once I changed that character, it looked fine.

But that got me wondering if I had anymore Unicode characters in my dissertation project. They're nearly impossible to find by hand, so I wrote this little perl one-liner to find them for me:

perl -ne "print if /[^[:ascii:]]/" *.bib *.tex

I discovered 3 more bad dashes, and also a smartquote tossed in as well.

April 21, 2012 03:30 AM

April 18, 2012

Kam Salisbury

Dell C400 Linux Tips

These tips assisted me whenever I had a need to rebuild the Linux Operating System on my Dell C400 laptop back in 2007. Suggestions I have here may work for other Dell laptops or other Linux distributions, experiment and share please. clip_image001clip_image002 clip_image003The Dell C400 is a ultra mobile laptop platform sporting a Pentium III Processor, 1.2 GHz Mobile processor, touchpad/pointing stick and a 12.1 inch TFT Display. The C400 can be configured with up to two 512MB SDRAM DIMMs with a portion of that RAM supporting the Intel i830 series 1MB (shared) video. The C400 also has an internal 56k Modem, 10/100 Ethernet and sound card but all CD/DVD drives are externally connected via a special cable only. All hardware is detected by the Linux kernel (2.6.x) and modules with the internal modem requiring restricted drivers to be enabled. The latest BIOS revision does not support boot from USB devices, the single USB port being version 1.1 only. It is a great small format laptop with just a few quirks while running Linux. Problem = Install halts (freezes) and no amount of intervention or cursing will allow the install to continue. Cause = The install process fails to detect an appropriate setting for the frame buffer and the video display halts. Fix = As with previous version of Ubuntu and other Debian based distributions, you will enjoy a smoother install if you chose a text mode install type, press F6 and delete quiet from the command line then add vga=773 acpi=on. The install command argument vga=773 specifies an appropriate frame buffer setting so that the video display does not freeze when the hardware detection process probes for available video display resources. The install command argument acpi=on specifies that Linux should probe for and use the correctly identified applicable ACPI kernel modules for the C400's motherboard. Problem = The install delays significantly for no apparent reason (You assume that the laptop is taunting you). Cause = The hardware detection process will probe for a floppy disk drive (fd0) and will delay while waiting on the hardware query to time out. Fix = Be patient, unless you hear motherboard beeps and more than 5 minutes of delay elapses, the laptop is not purposely trying to aggravate you. (It only seems that way) Problem = X only sees 1MB of Video RAM. Cause = The default entry for the Video Chipset detected by Linux (Intel i830 series) during the install does not include a default RAM amount. Fix = Edit xorg.conf to add video RAM amount. 1. Use the terminal shell to sudo nano /etc/X11/xorg.conf 2. Locate the following section of settings, add the lines shown in bold if not already present... Section "Device" Identifier "Intel Corporation 82830 CGC [Chipset Graphics Controller" Driver "intel" BusID "PCI:0:2:0" VideoRam 16384 Option "DRI" "True" Option "VBERestore" "True" EndSection *The VideoRam entry value must be a multiple of 1024. The Options DRI and VBERestore support the sleep and hibernate video functions. 3. Save your file edits (For nano it will be by pressing keys CTRL and X then answering Y for yes to save the file. 4. Reboot (Use normal shut down and restart options) to test. Problem = Linux operating system start up and shut down display is absent or otherwise not viewable. Cause = The default frame buffer video settings are not configured in grub for the type of LCD display on the laptop. Fix = Edit Linux kernel grub boot parameters so that video (The splash screen during startup/shutdown) is shown. 1. Use the terminal shell to sudo nano /boot/grub/menu.lst 2. Move the cursor position to the end of the line that starts with # kopt= add vga=773 acpi=on to the end of the line. Ensure there is a space separating the new entry from the text already present. 3. Save your file edits (For nano it will be by pressing keys CTRL and X then answering Y for yes to save the file). 4. Use the terminal shell to sudo update-grub 5. Reboot (Use normal shutdown and restart options) to test. Problem = Linux does not suspend properly, sometimes runs the CPU full out instead of 1/2 speed to save battery. Cause = APM instead of ACPI is installed by default, the tools to scale the CPU speed are not installed either. Fix = Install the required tools and configure them. *Warning! Test your changes. Make sure that no additional configuration changes are necessary to suspend to RAM when you close the laptop lid if that is your power saving intention. I'm not kidding, you could lose data because a setting change was missed here and all was assumed to be right as rain. 1. Use the terminal shell to sudo apt-get update *Errors in later process steps about not found packages means you did not enable various distribution repositories from the Synaptic sources configuration interface. 2. Then, use the terminal shell to sudo apt-get upgrade (Installing out of date packages is a waste of time and can actually cause conflicts requiring additional time to troubleshoot and fix later. Spend the time to have an up to date system now versus whishing you had done so... later.) 3. Then, use the terminal shell to sudo apt-get install acpid cpudyn i8kutils 4. Reboot (Use normal shutdown and restart options) to test. Problem = The Linux OS seems to spend a lot of time reading from the hard disk, even when launching often used or small applications. Cause = Prelinking is not installed or configured by default. Fix = Install and configure the prelink package, prelink does not actually boost performance of the entire OS, just loading of applications only. 1. Use the terminal shell to sudo apt-get install prelink 2. Then, use the terminal shell to sudo nano /etc/default/prelink and change PRELINKING= to yes 3. Save your file edits (For nano it will be by pressing keys CTRL and X then answering Y for yes to save the file). 4. You can start the initial prelink now by running from the Terminal shell.sudo /etc/cron.daily/prelink(The process will run for 30+ minutes in some cases) or just let cron do its job during the next reboot cycle. Problem = There is 512MB of RAM installed and the Linux OS insists on heavy use of the swap file, slowing disk access considerably. Cause = The default kernel setting for swap file use is not aggressive enough for high RAM installs. Fix = Configure a more appropriate kernel swap directive. 1. Use the terminal shell to sudo nano /etc/sysctl.conf add vm.swappiness=3 to the end of the file. 2. Save your file edits (For nano it will be by pressing keys CTRL and X then answering Y for yes to save the file). 3. Reboot (Use normal shutdown and restart options) to test.
This work is licensed under a Creative Commons license.

by Kam Salisbury (kamreefsalisbury@gmail.com) at April 18, 2012 02:20 AM