RSS
 

Archive for the ‘Computers’ Category

Howto: Enable PCNTL in Ubuntu PHP installations

30 Jul

PCNTL in PHP allows for some handy advanced “trickery” using the OS process functions inherent in Linux (*nix?).  I believe some features are available in Windows, but I know for certain that pcntl_fork() is not.

Anyway, it is not enabled by default, so if you want to take advantage of the functions on your Ubuntu LAMP server, you might spend hours searching the web for that magic aptitude command.  But, as far as I can tell, it doesn’t exist.

Luckily, I stumbled across this article on the Ubuntu forums, so I’m dedicating a post here with the hopes that other will find it more easily.

Please note that you’ll probably need build-essentials and a few other source compilation basics, but as long as you have that, the following code will get you what you want.

First, in your home directory:

mkdir php
cd php
apt-get source php5
cd php5-(WHATEVER_RELEASE)/ext/pcntl
phpize
./configure
make

Then:

cp modules/pcntl.so /usr/lib/php5/WHEVER_YOUR_SO_FILES_ARE/
echo "extension=pcntl.so" > /etc/php5/conf.d/pcntl.ini

FYI: “make install” does not appear to put the files in the correct place.

Btw, please direct any thanks/praise to skout23 on the Ubuntu forums.

 
 

WordPress 3.0, multi-sites, and migrating only some of your posts

13 Jul

I started my original blog a little over a year ago now simply as a way to have a place to post thoughts online. As it progressed and I started to flesh out my music site, I realized that I actually have at least 3 distinct types of thoughts I want to post: music-related, general commentary on my life, hobbies, and interests, and philosophical topics.

WordPress is extremely powerful, and I quickly began using its RSS functionality to feed my music related posts to my music website, but, as it turns out, this is kind of bad from a search engine perspective. I ended up using cross-domain canonical URLs to make Google happy. Additionally, it was kind of confusing. While I don’t really have much traffic to any of my sites, I like to pretend that I do, and it just wasn’t adding up.

Then comes WordPress 3.0 which allows you to host multiple blogs (even, unofficially, on multiple domains), so it gave me the opportunity to allocate content correctly to my domains.

There are drawbacks, of course.  It’s not like you get to just make posts and decide which domain you want it on.  You still have separate sites with separate management profiles, etc., it’s just that anytime you upgrade core components (such as themes, plugins, and even WordPress itself) you don’t have to do it for every blog.

Plus, all your content is in a centralized, easily accessible place.  Perhaps in the future more fine-tuned enhancements will evolve, but for the time being all I had to do was some MySQL footwork (in moving the right posts to the right blogs, which was simple enough as I already had “Music” and “Philosphy” categories).

I have had crimulus.com reserved for some time as my “personal” site — projects I’m working on, hobby showcases, etc., but I never really fleshed it out.  My music site, jeremytharp.com, is about 5 years old now, but it relayed podcast data, music news, etc. for anyone visiting that site, but, for a search engine, it treated it as if it were hosted on my actual blog which is at coffeecuphalfmoons.com.

To summarize, I just wanted to express how pleased I am with the feature as well as inform any readers (if you exist) of the changes.

Finally, for the technological grit, if anyone else intends to do this, I had to make a modification to my coffeecuphalfmoons.com theme.

I had plenty of indexed content, so now most of those are on crimulus.com or blog.jeremytharp.com, so links from search engines would generate a 404.  I simply modified my theme’s index.php send a GET request for the $_SERVER['REQUEST_URI'] on each of the domains (crimulus.com and blog.jeremytharp.com) in the event that have_posts() returned false.  If either of those requests returns a header code other than 404, I send a 301 redirect for that.

So, a search engine refers a user to http://www.coffeecuphalfmoons.com/a/post/that/i/moved/

I check (using cURL) to see if http://www.crimulus.com/a/post/that/i/moved/ or http://blog.jeremytharp.com/a/post/that/i/moved/ returns a 200, 301, etc.  If so, then it’s probably the post that was originally referred to.

This is how you help keep pagerank value and link-juice when you’re migrating only a few posts from a blog on one domain to a blog on another.  At least, that’s how I did it.

 

FedEx Shipping XML API Idiosyncrasies — the saga continues (PHP & Soap envelopes)

24 May

I am doing a fairly large implementation using the exposed APIs of all 4 major shippers.  I’ve posted a few notes on USPS, and I’ve been using UPS for so long it almost seems to make perfect sense.

So, while I have to applaud FedEx for the granularity and versatility of the API they have exposed, it has caused me severe headaches due to the PHP SimpleXML issues it brings up with SOAP envelopes — particularly nested soap envelopes.

Long story short, the jist of this post is to help others deal with the responses they receive from the FedEx servers (if, like me, their pre-packaged methods do not implement tidily into your application structure).

Here is a sample response of a rate request (NOTE: this is a “Warning” response, only here for demo purposes):


   <?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Header xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
    <env:Body xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <v8:RateReply xmlns:v8="http://fedex.com/ws/rate/v8">
            <v8:HighestSeverity>WARNING</v8:HighestSeverity>
            <v8:Notifications>
                <v8:Severity>WARNING</v8:Severity>
                <v8:Source>crs</v8:Source>
                <v8:Code>556</v8:Code>
                <v8:Message>There are no valid services available. </v8:Message>
                <v8:LocalizedMessage>There are no valid services available. </v8:LocalizedMessage>
            </v8:Notifications>
            <v8:TransactionDetail xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
                <v8:CustomerTransactionId>TC05_Rate_Package_Groups_POS</v8:CustomerTransactionId>
            </v8:TransactionDetail>
            <v8:Version xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
                <v8:ServiceId>crs</v8:ServiceId>
                <v8:Major>8</v8:Major>
                <v8:Intermediate>0</v8:Intermediate>
                <v8:Minor>0</v8:Minor>
            </v8:Version>
        </v8:RateReply>
    </env:Body>
</soapenv:Envelope>
    

There are lots of ways you might envision accessing that precious “RateReply” tag, but to keep it simple and avoid inferences, you get to it like this:

$xml = simplexml_load_string ($xml_from_above);
$xml->children(‘http://schemas.xmlsoap.org/soap/envelope/’)->Body->children(‘http://fedex.com/ws/rate/v8′)->RateReply;

I do suppose this is obvious enough, but believe me, the nuances that can throw it off can still cause you to inadvertently lose ridiculous amounts of time on it.

Furthermore, if you prefer to do direct PHP cURL XML calls (which you probably do given that you’re reading this), you’ll find that FedEx is not terribly interested in your type of programmer. To find a simple sample XML call, you’ll have a tough time (although I managed to find it in the WSDL downloadable ZIP). However, this is a very basic call. To add additional data (such as the exotic field that apparently no one would ever think to use — “InsuredValue”) — this field has the form (EXACTLY, stuff in brackets is what can be changed) “<InsuredValue><Currency>[currencytype]</Currency><Amount>[float]</Amount></InsuredValue>”

The “InsuredValue” node/field must go immediately before the “Weight” node in the “RequestedPackageLineItems” node. (This of course reference FedEx API v8 — things may be different in future releases.)

 

USPS Shipping XML API Testing Idiosyncrasies

20 May

If you’re a web developer and happen to develop software for use in e-commerce, chances are, somewhere along the lines you’ll need or want to integrate with the big 4 shippers’ (UPS, USPS, FedEx, DHL) APIs.  You’ll find right off the bat that they all offer rather robust APIs, so your options are sufficient.

Then you’ll get to programming and realize that the documentation is pretty crappy, but specifically I want to address the idiosyncrasies of the USPS “test” environment.  Effectively, what USPS means when they say “test” is not a test of robustness of your application, but simply whether or not your application can build a sample request (an EXACT sample request), and send it to their server.  Yeah — it’s like asking a math teacher to write the numbers 1 to 30 on a sheet of paper (in order) before he/she can get hired.

The problem is, the USPS docs don’t tell you this, nor do they show you the sample request.  So, for others who are about to embark on a few hour journey finding these details on Google (or worse, emailing USPS directly …eeek) I’m going to sum up a few facts here.

The most laborious for me so far is the one I already mentioned above.  For a rate request, the docs show you a RateV3Request, but in testing you can only use a RateV2 request (which does not support package dimensions).  Also, you must use the zip codes 10022 and 20008 for origination and zip, as well as 10 lbs. 5 oz. for the weight, and “LARGE” for the size.  Everything else (LAUGH) you have leeway with.

If you don’t use these exact values, you’ll get responses like “Please enter a valid zip code for the sender” (which of course makes you think you wrote the XML incorrectly) or “The package size must be ‘Regular’, ‘Large’, or ‘Oversize.’” (even though you have “regular” quite clearly in the request.

The advice is to get to production as soon as possible, though why USPS would design things this way is beyond me, but them’s the cards, you gotta play ‘em.

I will add more here as I find them obstaclicious enough (yeah I just made up that word).

Amendment 1:  I should add that the issues about the documentation not mentioning the “canned” requests is only applicable to the PDF documentation.  It is stated quite clearly in the HTML versions.  Go figure …

 

Google AdSense rejection and cross-domain duplicate content experience

08 Mar

Since the rejection replies you get from Google regarding applications to their AdSense program can be quite vague and even cryptic, I thought I would share my experience. First things first, you are not going to get to talk to Google directly — you have to use the forums. (Here is my thread.)

My rejection was simply:

Hello Jeremy,

Thank you for your interest in Google AdSense. Unfortunately, after
reviewing your application, we’re unable to accept you into Google AdSense
at this time.

We did not approve your application for the reasons listed below.

Issues:

- Unacceptable site content

Looking around their restrictions, I really could not find a solution, as I couldn’t find any rule that I explicitly violated.  I posted a request for insight on the forums, and a very insightful user (wasaweb) pointed out my extensive duplicate content on http://jeremytharp.com/ and http://www.coffeecuphalfmoons.com/.  And it’s true — I use my blog’s rss to feed much of the content on my music site.

Since I want to keep the sites separate, I saw no reasonable solution, but then I discovered that recently Google began allowing cross-domain canonical URLs.  Eureka!  I simply set the canonical URLs on the pages on jeremytharp.com that fed from coffeecuphalfmoons.com to the appropriate page that fed the same content on coffeecuphalfmoons.com.  When I resubmitted the AdSense application, it was approved!

Keep in mind that there are a LOT of reasons you might get rejected from AdSense, but given that this was very simply successful, I thought I would share.

I also noticed an immediate reorganization of my site:jeremytharp.com results on Google (for the better).  I’m hoping it has some positive effects on PR on both pages as well.

 
 

WORDPRESS HOW-TO: Ignore/Hide A Category On Your Home Page

28 Feb

Sometimes you don’t want a particular category to appear on your WordPress home page.  For me, I create weekly Twitter digests, and I’d rather they not be part of the page welcome.

The process of hiding them actually took me a little bit to figure out, so I thought I’d share.  It’s rather simple, so don’t blink!  :)

Simply edit “index.php” in the wp-content/themes/<your_theme_here>/ directory.

Between the lines:

<?php if (have_posts()) : ?>

and

<?php while (have_posts()) : the post(); ?>

Insert the line:

<?php if (is_home()) { query_posts("cat=-XXX"); } ?>

Be sure to replace “XXX” with the unique numeric ID of the category you want to ignore.  To find the ID, log into your admin, navigate to your categories, and select the one you want to ignore.  The number will then appear in the URL.

NOTE: Make sure you don’t delete the “-” before the “XXX” or else you will ONLY show entries from the category.

If you update your theme, you will probably have to repeat this procedure.

If you want to hide multiple categories simply append the other categories to the string with a comma: (Example: “cat=-12,-82,-4″)

It also follows, then, that this technique can also be used to hide tags, posts, etc.

 

Verizon Wireless USB760 USB Modem Ubuntu Howto

13 Feb

This is a repost of information located at: Verizon Wireless USB760 on the Ubuntu Forums.

I am putting it here because I found it very useful, and wanted people to be able to find it.  If you anyone takes issue with my publishing it here, please contact me.

At any rate, the Verizon USB760 does not work right away, so you have to modify two files.  This solution was posted by Databit. I added a few notes for clarification purposes and enclosed them in brackets.

File 1: /etc/udev/rules.d/70-persistent-cd.rules

Find the line that contains "Novatel_Mass_Storage" and append the following to it:

RUN+="/usr/bin/eject %k"

[You will probably need to use a comma before this part]

File 2: /usr/share/hal/fdi/information/10freedesktop/10-modem.fdi [Will require superuser privileges]

Add this in the USB section:

      <!-- Verizon USB760-->
      <match key="@info.parent:usb.vendor_id" int="0x1410">
        <match key="@info.parent:usb.product_id" int="0x6000">
          <match key="@info.parent:usb.interface.number" int="0">
            <append key="info.capabilities" type="strlist">modem</append>
            <append key="modem.command_sets" type="strlist">IS-707-A</append>
          </match>
        </match>
      </match>

I have tested this and it worked without issue in Jaunty Jackalope 9.04.

 
 

Linux BASH Script: Convert mp3 to avi with static image (command line)

21 Jan

This is a script I made to take advantage of the ffmpeg package in linux to quickly convert an mp3 to avi using a static image. I personally use this technique for uploading my songs to YouTube. I originally found the conversion command here.

All you need is a linux distro with ffmpeg installed, a jpeg or png image, and an mp3. Note: It is highly likely other image formats, audio formats, and output video formats will work, but I have only used jpeg/png+mp3+avi and so cannot attest to results otherwise.

Usage: bash mp32avi.sh <image_file> <mp3_file> <output_file.avi>

Code (mp32avi.sh):

#!/bin/bash
FFMPEG=`which ffmpeg`
if [ "$FFMPEG" = "" ] ; then
	echo "Please install ffmpeg.";
	exit 0;
fi
if [ $# != 3 ] ; then
	echo "Usage: $0 <image_file> <mp3_file> <output_file.avi>";
	exit 0;
fi
if [ ! -f $1 ] ; then
	echo "Source image '$1' not found.";
	exit 0;
fi
if [ ! -f $2 ] ; then
	echo "Source mp3 '$2' not found.";
	exit 0;
fi
if [ -f $3 ] ; then
	echo "Output file '$3' exists.  Overwrite? (y/n)";
	read CONFIRM
	if [ "$CONFIRM" == "y" ] ; then
		echo "Overwriting '$3'"
	else
		if [ "$CONFIRM" == "Y" ] ; then
			echo "Overwriting '$3'"
		else
			echo "Operation canceled.";
			exit 0;
		fi
	fi
fi
TIME=`$FFMPEG -i $2 |& grep 'Duration' | awk '{ print $2; }' | sed -e 's/,//g'`
$FFMPEG -loop_input -i $1 -i $2 -acodec copy -y -t $TIME $3
 

IE6 is not yet dead, although it should be … though I wonder

09 Nov

There’s not much contention that IE6 is an outdated browser and is not suited for the modern web.  If you don’t buy that just on sheer merit, there’s no point to read the rest of this article.

Most informed articles addressing the issue have boiled “the reason why” down to the fact that those users can’t upgrade (restricted by work, slow computer, etc.)

However, I wonder how it would be to build an HTML/JavaScript browser (which is effectively what Firefox currently is) that embeds directly into IE6 by visiting a webpage.

A user loads IE6, sets his/her home page to “awesome-js-browser.com” and then navigates from within that page.

I would venture that this would more of a nuisance and a resource hog than anything, else I think Mozilla would have tried it …

or have they? …

 
1 Comment

Posted in Computers

 

Coffee Cup Half Moons now has an official URL Shortener!

27 Oct

http://cchm.us/

Based on the same engine as http://abv8.me/ and http://ihrt.it/ (developed by my web company, geeXmedia).

I plan soon to launch URL shorteners on http://tharp.me/ and http://tharp.us/