Google
 

Wednesday, April 29, 2009

Poem: If I Could

0 comments
I'm feeling emo today.




When my brain turns about, there's the back of my eyes:
A darkness built up out of secrets and lies,
Growing each time I am what I despise,
And I'd be blind to it if I could.

Behind my ears rings out the high wailing voice
Which will screech at my glee but at pain rejoice.
Lending doubt to my actions, it laughs at each choice
And I'd deafen myself if I could.

The base of my tongue tastes the tang of despair:
The brimstone of hell and life's pain both lie there.
A flavor that ebbs and then suddenly flares,
And I'd lose all my taste if I could.

Deep down in my nose is the scent of defeat,
Of each battle lost, of each task I can't meet.
The fumes burn my nostrils and make my veins bleed,
And I would smell naught if I could.

At the ends of my fingers, a warmth emanates
That wards off the chill from the cowardly Fates.
An aching that cleanses, a hunger that sates,
And I will reach out while I can.

By my hand,
~Michael Akerman

Monday, April 27, 2009

Tutorial: Separating Notes from Google Reader Shared Items Posts in SweetCron

0 comments
Jump to the solution
Jump to the short version
Download the modified files

I set up a LifeStream recently (http://www.michaelakerman.com. It's ugly as sin currently, but coming along) using SweetCron. My initial CSS-customizing fervor was dampened when I ran into a problem with my Google Reader feed items.

Here's the deal: when you share an item on Google Reader with a note, it enters your RSS feed looking like this:


Shared by Michael

Here's a note on this item!

And here's the item!



The note and the line "Shared by Michael" (or whatever your name happens to be. Use your imagination) are contained within a <blockquote> tag.

The problem is, every item's content is fed through a function that removes HTML formatting, other than line breaks, so all that is left is:

Shared by Michael

Here's a note on this item!And here's the item!



Since the <blockquote> provided the line break between the note and the actual content, there's no reliable way in the processed item to find the end of the note. The "Shared by" line can still be stripped fairly easily using string matching, but that leaves the content sounding like a Tourette's patient.

The solution, then, is to get at it before the HTML formatting is stripped off, which will take more than just a plugin. Here's how I did it:



Solution

(As a disclaimer, I don't know PHP formally. A lot of the language I use to describe the code is borrowed from Java or made up)

The first thing we must do is get the note split off before the HTML tags are removed. The cleaning happens in sweetcron.php, which is located, by default, in /system/application/libraries. At about line 70 is a column of function calls to define various array elements and instance variables. It looks like this:


$new->item_data = array();
$new->item_data['title'] = $item->get_title();
$new->item_data['permalink'] = $item->get_permalink();
$new->item_data['content'] = $item->get_content();
$new->item_data['enclosures'] = $item->get_enclosures();
$new->item_data['categories'] = $item->get_categories();
$new->item_data['tags'] = $this->get_tags($new->item_data);
$new->item_data['image'] = $this->get_image($item->get_content());


We're going to add the note to the array by calling a new function (we haven't written it yet). Add the following line at the end of the above list:

$new->item_data['note'] = $this->CI->input->xss_clean(trim(strip_tags($this->get_note($item->get_content()))));


This line defines a new array element 'note' in the item_data array attached to the object $new (which is later built into an $item object). The actual value given to the 'note' element is the result of running $item->get_content() through:

  • get_note()
  • strip_tags()
  • trim() and
  • xss_clean()
These might look confusing now, but they're pretty logical. The get_content() call gets the content of the item (see?). get_note() parses out the note from the content, which then has the HTML tags stripped off (strip_tags()) and the whitespace trimmed off the ends (trim()). The result is then sanitized with xss_clean(), which is a function designed to prevent various scripting attacks.

Anyway, onward! Everything we need is already built into SweetCron except for get_note(). We can put this anywhere in sweetcron.php that is not inside another function. I put mine right after function get_image($html) (line 185, now) if you want to emulate me!

The get_note function should look something like this:

function get_note($html) {
    if (stripos($html, '<blockquote>Shared by') !== false) {
      $pieces = explode("</blockquote>", $html, 2);
      unset($html);
      if(is_array($pieces) && !empty($pieces)) {
        return $pieces[0];
      } else {
        return false;
      }
    } else {
      return false;
    }
}


If you copy-paste this, you might need to replace all of the less-than and greater-than signs, since I used the HTML non-functional versions.

The function gives the name $html to the item_content. Then, stripos() is used to test $html for the string "<blockquote>Shared by". It's case insensitive, and will return a value if it finds the string or false if it does not. If it does find it, we enter the loop.

The variable $pieces is created, and the results of explode() are poured into it. This will split $html into two pieces at the </blockquote>. $html is cleared so we don't forget to get rid of it. If $pieces actually does contain two parts, the method returns to first part, which is the note. Yay!

Save sweetcron.php and put it back where it belongs. We're done with it.

The next issue is to get the note out of the remaining content. We can do that in a plugin. Navigate to /system/application/plugins and open google_com.php. If that doesn't exist, go ahead and open your favorite text editor and save the blank page as google_com.php. We'll work from there.

Here is the complete code of my plugin:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Google_com {

    function pre_db($item, $original)
    {
    $original_publisher = $original->get_permalink();
      if(!empty($item->item_data['note'])){
        $lookin = $item->item_content;
        $find = $item->item_data['note'];
        $pos = strpos($lookin, $find);

        if ($pos !== false){
          $item->item_content = str_replace($find, '', $lookin);
        }
        //Set length of "Shared by Name" thing + 1 as the final value in the next line.
        $item->item_data['note'] = substr($item->item_data['note'],18);
      }
      return $item;
    }

    function pre_display($item)
    {
      return $item;
    }


}
?>



Again, watch the less-than and greater-than signs.

I'm going to skip the beginning, because it's boilerplate plugin stuff.

If the item_data['note'] value is not empty, the content is searched for the note. If the note is found, the note in the content is removed by str_replace().

The "Shared by" line is then removed from the note. This is something you'll have to edit.



Important!

Write or type out the phrase Shared by Name, where Name is what Google displays when you share something, e.g. Shared by Michael for me. Count the number of characters, including spaces (17 for my phrase). Add one to this value.

Replace the number 18 in the substr() arguments with the value you just calculated. This will tell substr() how many characters to strip out. For some reason there are two phantom characters in the "Shared by" line that I can't identify. Adding 1 to the number of characters will take care of that.


Save the file, and put it in the /system/application/plugins directory. The note is removed and separated!

Manipulating the note can be done in the _activity_feed of your theme in the same way that the item_content or item_title can. Just use <?php echo $item->item_data['note']?> to summon the note object.



Step-by-step Recap
  1. Add the note element to the list of array elements in /system/application/libraries/sweetcron.php.
  2. Add the get_note() function to sweetcron.php.
  3. Save sweetcron.php.
  4. In /system/application/plugins, create or edit google_com.php to include this stuff.
  5. Edit google_com.php as per this important note.
  6. Save google_com.php.
  7. Call your note in the _activity_feed.php file for your theme using <?php echo $item->item_data['note']?> in google.com items.


If you're having trouble, you can try simply downloading the modified files from my LifeStream. You'll still have to edit google_com.php to reflect the length of your name.

By my hand,
~Michael Akerman

Sunday, April 19, 2009

Arboretum

0 comments
Yesterday I visited the JC Raulston Arboretum with Madison (of Madison's Flowers) and Scott. It's a beautiful place, nestled off Hillsborough in one of those large chunks of land that NCSU owns due to the grace of fortuitous foundation.

Aside: NCSU is remarkably lucky, as far as land ownership goes. Founded in 1889 between Raleigh and Durham, NCSU basically took what UNC considered theirs when it opened, getting Land Grant money because of some skilled lobbyists:

Then there was only one hurdle left to cross; how to get the Land Grant funds that were presumably going to UNC-Chapel Hill. Governor Alfred Scales, along with the Swift Creek Farmer’s Club of Wake County, Polk and the Watauga Club, pressured the legislature to allocate Land Grant funds to the new college. A wealthy real estate developer named R. Stanhope Pullen donated 60 acres west of Raleigh to serve as the college’s location.


The location west of Raleigh was farmland at the time: undeveloped, relatively uninhabited. So, NCSU was in the unique position among UNC schools of being able to buy massive tracts of land for low, low prices. Useful, because now the school owns approximately 107,000 acres of land, much of it in the thick of Raleigh.

The arboretum is larger than I expected. It was a beautiful spring day, sunny and warm, and lots of stuff was in bloom. Madison brought her cockatiel, Icarus, who rode on my shoulder for a while. He was very popular with the other visitors.

I've posted a bunch of photos on Facebook (probably Flickr too, later), and feel free to check out Scott's photostream and Madison's photostream!

By my hand,
~Michael Akerman

Tuesday, April 14, 2009

Notebookery

2 comments
I've started carrying around a little black notebook. It's a discard from my father, who bought it because the office supply store didn't have the notebook he normally uses. It was inferior (though it was the same brand).

It's acceptable for me, though.

Inspiration strikes at odd times. I have the type of mind that spawns rhyming couplets in the shower without forewarning. Already I've written a significant poem (the Scribbled Poem from yesterday was part of a larger poem) and a private rant in it. I'm also practicing drawing.

For years I thought I couldn't draw. It never made much sense to me: I can visualize with uncanny clarity, and I can hold images in my mind well, but something in the mechanism from my brain to the paper always failed. I've been reading a lot of webcomics recently, though, and the degree of improvement over only a few years is remarkable. Early Penny Arcades are practically incomparable to the modern incarnation. Questionable Content went through a similar transformation. Even Achewood has improved over the years (it's a very sparse comic). So, I figure it's just a matter of practice.

I'm better than I thought I was already. I drew a pair of stylized eyes that came out recognizably eyeish, which I count as a victory!

By my hand,
~Michael Akerman

Monday, April 13, 2009

Scribbled Poem

0 comments
While the dreamer lives his dream
With his muse behind a wall,
He listens at the chink
And shudders at her call.

By my hand,
~Michael Akerman

Sunday, April 12, 2009

Easter

2 comments
Happy Easter, internet!

I was thinking the other day about Jesus. The standard dogma holds that he died for our sins. The historical record confirms that he lived approximately two millenia ago. Since Christian theology also holds that one does not get eternal life without believing in Jesus, even under a Creationist timescale this would mean that for 10000 years, mankind was completely out in the cold with no possibility of salvation.

If we're to also assume that God is inherently good, this doesn't make sense. So, I don't believe Jesus died for our sins, but died to tell us that God forgives us. That is, God was always a forgiving God, and man simply didn't understand that until God sent down his son to tell us directly.

What, then, of other religions? The above sentiment effectively discounts the necessity of Christianity for salvation, causing Jesus to be a messenger (though still the Messiah). If it is true that God is good, then people must have the opportunity to find salvation regardless of their cultural resources. If one were raised in a strongly Hindu society, for instance, it is quite possible that one would never encounter the idea of Christianity. I cannot conceive of a being of infinite good persecuting someone for their upbringing. So there must be some other requirement than simply owning a Bible.

It is a basic tenant of the beliefs of every major religion and of most thinking men that one ought to be "good": love your neighbor, be charitable, be kind, etc. I think the "goodness" (a word, I think, that means more in quotation marks than out) of a man, not his religious beliefs, is the true litmus test. If there is an afterlife, it is not an exclusive club for Westerners, but a reward for a life well lived.

By my hand,
~Michael Akerman

Saturday, April 11, 2009

Bombadil

0 comments
I went to the Bombadil show at the Lincoln Theater last night with Madison. Excellent show!

We skipped the first opening act (Madison had free tickets, so it's not like we had a reason to see bands we weren't interested in). The second was Benji Hughes, which was... alternative blues (?) or something, fronted by the Dude (Lebowski) after he hadn't shaved for a few months. Intriguing music, but I'll have to download it to say anything of substance about it. Could not hear the vocals at all. A cursory listen at MySpace leads me to believe I like them better live.

Bombadil itself was excellent. I met Daniel via Madison before the show: he, and the other members, seem pleasantly nerdy. The music is sort of a traditionally-inspired rock, with almost Irish overtones. I'd highly recommend them!

Tangent: I discovered Bombadil only a week or so ago via Last.fm. It was one of those moments when you hear the beginning of one song and know you'll like everything the band makes. Malcolm Gladwell discusses this type of thing in Blink. I'm a tremendous believer in the power of intuition.

I do rather wish I had learned of Bombadil earlier, though, because I didn't know most of the songs by heart yet at the concert. Ah, well.

By my hand,
~Michael Akerman

Friday, April 10, 2009

Madison's Flowers

0 comments
While I'm on the subject of Twitter, I want to throw some of my meager Google-juice behind my friend's site.

Metricula is a Raleigh-area horticulturalist who blogs about the folklore surrounding Southern plants at Madison's Flowers. Go give it a read! Learn something!

By my hand,
~Michael Akerman

Twitter

0 comments
I've been using Twitter a lot recently. Something about the 140-character limit on each post is refreshing. When I blog on CoK or IVIC, I tend to be exceedingly long-winded, primarily because I want to be clear. I think, though, that it's probably relatively unlikely for people to read posts topping out at around five single-spaced pages. Twitter, then, is a good exercise for me.

Actually, it's more than that, I think. It's a good exercise for anyone who takes the practice of writing seriously. The downfall of many an author, many a blogger and many an anecdote is a lack of brevity. It's easy to get caught up in one's own words. Microblogging teaches the control of one's typographical sphincter (to prevent verbal diarrhea, naturally).

There's still some to be desired, of course: one cannot espouse a deep philosophical treatise in 140 characters. I have CoK and IVIC for that, though, where I can, and now I know to keep it short and understandable. The short of this post, then, is to convince myself to blog again, and to remind myself to split long ideas up so that people can actually digest them. What good is a treatise no one reads?

By my hand,
~Michael Akerman