Extracting First and Last name from a single field in a drupal content-type

It is possible to extract the first or last name from a single field in a drupal content-type using the computed_field module. Here were my steps, taken from the drupal structure guide :

  1. install computed_field and dependencies
  2. % drush dl computed_field
    Project computed_field (6.x-1.0-beta3) downloaded to      [success]
    /var/www/drupal6/sites/all/modules/computed_field.
    % drush en computed_field
    The following projects will be enabled: computed_field
    Do you really want to continue? (y/n): y
    computed_field was enabled successfully.                  [ok]
  3. edit your content type
  4. add a new ‘Computed’ field
  5. under Global settings, make certain the ‘Computed Field’ is in plain-text mode
  6. for last name
    • // compute last name
      preg_match('~([^\s]+)(?:,.*)?$~',$node->title, $match);
      $node_field[0]['value'] = $match[0];
    • for first name:
      // compute first name
      $node_field[0]['value'] = \
                      substr($node->title, 0, strrpos($node->title, " "));
  7. change data-type to “varchar”
  8. enable/check “Sortable”
  9. Save content-type
  10. Edit your view
  11. Add a ‘Sort Criteria’
  12. Use Content: Computed Last Name (field_computed_lastname)
  13. Click ‘Update’ and then save your view
  14. Navigate to the page where your listing is to see the new sorted version
Posted in drupal, web programming | Leave a comment

Expanding LVM Partition on Ubuntu 8.04 LTS with VMWare

  • power off VM
  • edit settings in vmware client to expand hard drive to desired size (i went from 15G to 40G)
  • power on VM
  • parition the expanded area (/dev/sda3 in my case)
fdisk /dev/sda
  • Create a physical volume for LVM:
# pvcreate /dev/sda3
Physical volume “/dev/sda3″ successfully created
  • Add the new physical volume to the volume group:
 #vgextend vg0 /dev/sda3
Volume group “vg0″ successfully extended
  • Extend the Logical Volume, you can find the amount of space with which you can expand by running the ‘vgdisplay’ command and use the value from “Free PE/Size”
# lvextend -L+24.99G /dev/vg0/lv0
  Rounding up size to full physical extent 24.99 GB
  Extending logical volume lv0 to 39.09 GB
  Logical volume lv0 successfully resized

Sourced some of the steps from http://www.swizzling.org/2008/04/01/expand-lvm-disk-on-linux-in-vmware/

Posted in sysadmin | Leave a comment

reset snow leopard firewall to defaults

originally from http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBIQFjAA&url=http%3A%2F%2Fforums.macrumors.com%2Fshowthread.php%3Ft%3D406592&ei=MNVWTNWbFYq8sQOh4aXaAg&usg=AFQjCNEedaVs_julrXp8dLwD0CWg31aMUA

“It sounds like a bad Application Firewall configuration (missing the exceptions that allow configd, mDNSresponder, and racoon). Restore from the defaults:”

sudo cp /usr/libexec/ApplicationFirewall/com.apple.alf.plist /Library/Preferences/com.apple.alf.plist

Posted in consulting | Tagged | Leave a comment

Flying at the Ruins

DS at the Ruins from randall on Vimeo.

Posted in hobbies | Leave a comment

No-Click Hover Links using Drupal & Nice Menus

I encountered a problem while viewing  a Drupal site with Nice Menus on an Android whereby you could not get to the submenu when clicking on the parent links. On an iPhone a single-tap is taken

1) set URL for parent links that you don’t want to take you anywhere to http://fake.link

2) add the following code to your template.php (at bottom is fine) – note prefix of function name is the template name ${template_name}_menu_item_link()

/* 2010-06-24 randall s. ehren <randall@isber.ucsb.edu>
 taken from http://drupal.org/node/143322#comment-1166563

 */

function zeropoint_menu_item_link($link) {
 if (empty($link['localized_options'])) {
 $link['localized_options'] = array();
 }

 if (!$link['page_callback'] && strpos( $link['href'], 'fake.link')) {
 return '<a href="#">'. $link['title'] .'</a>';
 }
 else {
 return l($link['title'], $link['href'], $link['localized_options']);
 }
}

3) check your navigation bar

Posted in Uncategorized | Leave a comment

Ways to disable emailed output or mail alert by crontab

Prevent the sending of errors and output by crontab

For a entry-by-entry method to prevent the sending of errors and output, add any one of the following at the end of the line for each cron job to redirect output to /dev/null:
>/dev/null 2>&1.
OR
&> /dev/null

as in

0 1 5 10 * /path/to/script.sh >/dev/null 2>&1

or to enforce for all entries in the crontab, enter the following to the first line of your crontab:

MAILTO=""
Posted in Uncategorized | Leave a comment

The Chork :: Chopsticks & Fork

The Chork :: Chopsticks & Fork. See you later spork.

Posted in Uncategorized | Leave a comment

Zen Theme and Nice Menus – CSS Block Padding Issue

this fix was originally found here (http://www.1drupal.com/content/zen-theme-and-nice-menus-block-padding-issue) but i’m reposting in case that site goes away…

when using a customized Drupal Zen Theme, and Nice Menus instead of the standard Primary Navigation Menu extra padding can appear above or below the navigation bar. The Nice Menu is a block and inherits the default margin from Zen’s CSS.

.block /* Block wrapper */
{
margin-bottom: 1em;
}
you can change “1em” to “0″ or delete that statement and add:
#block-nice_menus-1 {
margin-bottom: 0;
}
“-1″ is for nice menu 1 (in this case, the primary menu).
Posted in drupal | Leave a comment

Graphing wind speed and direction using rrdtool and Wunderground.com XML Feeds

  • Create windspeed RRD data file:
rrdtool create sbwind.rrd \
 --start 1127253600 \
 DS:wind:GAUGE:600:U:U \
 DS:gust:GAUGE:600:U:U \
 RRA:MIN:0.5:1:600 \
 RRA:MIN:0.5:6:700 \
 RRA:MIN:0.5:24:775 \
 RRA:MIN:0.5:288:797 \
 RRA:AVERAGE:0.5:1:600 \
 RRA:AVERAGE:0.5:6:700 \
 RRA:AVERAGE:0.5:24:775 \
 RRA:AVERAGE:0.5:288:797 \
 RRA:MAX:0.5:1:600 \
 RRA:MAX:0.5:6:700 \
 RRA:MAX:0.5:24:775 \
 RRA:MAX:0.5:288:797
  • Create wind direction RRD data file:
rrdtool create sbwinddir.rrd \
 --start 1127253600 \
 DS:wind_direction:GAUGE:600:0:360 \
 RRA:AVERAGE:0.5:1:600

update_rrd_data.php

<?php
// 2010-02-22 - testing simplexml

/*
 - ellwood: http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MSBELL
 - bel air: http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=KCASANTA122
 - mesa   : http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MAS714
 - cumbre : http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MAS303
 - airport: http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MKSBA
 */

// setup variables

$debug = 1;

$a = array();
$a['ellwood']  = 'http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MSBELL';
$a['belair']   = 'http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=KCASANTA122';
$a['mesa']     = 'http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MAS714';
$a['lacumbre'] = 'http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MAS303';
$a['airport']  = 'http://api.wunderground.com/weatherstation/WXCurrentObXML.asp?ID=MKSBA';

$wdir = "/var/www/redigital.org/sbwindi/xml";

// loop through the locations and update the graphs
foreach ($a as $location => $value) {

 $xml_url = $value;

 $wind_data = simplexml_load_file($xml_url);

 //$wind_data = $xml;

 $wind_mph      = $wind_data->wind_mph;
 $wind_gust_mph = $wind_data->wind_gust_mph;
 if ($wind_gust_mph == "0")
 $wind_gust_mph = $wind_mph;
 $wind_direction      = $wind_data->wind_direction;
 $wind_degrees  = $wind_data->wind_degrees;
 $wind_string   = $wind_data->wind_string;

 //$update_rrd_data_cmd = "/usr/bin/rrdtool update ${wdir}/${location}.rrd \"N:${wind_mph}:${wind_gust_mph}\"";
 //$update_rrd_data = `$update_rrd_data_cmd`;

 $update_dir_data_cmd = "/usr/bin/rrdtool update ${wdir}/${location}_dir.rrd \"N:${wind_degrees}\"";
 $update_dir_data = `$update_dir_data_cmd`;

 $update_graph_cmd = "/usr/bin/rrdtool graph ${wdir}/${location}_d.png \
 -M -v mph -t ${location}-'${wind_string}' -w 320 --height=120 --alt-autoscale-max --lower-limit=0 -s 09:00 -e 20:00 \
DEF:a=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE  \
DEF:b=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE \
DEF:c=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE  \
DEF:d=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE \
DEF:e=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE \
DEF:f=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE \
DEF:g=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE \
DEF:h=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE \
DEF:i=${wdir}/${location}_dir.rrd:wind_direction:AVERAGE  \
DEF:j=${wdir}/${location}.rrd:wind:AVERAGE \
DEF:ba=${wdir}/${location}.rrd:gust:AVERAGE \
DEF:bb=${wdir}/${location}.rrd:wind:AVERAGE \
CDEF:cdefa=i,0,GE,i,22.5,GE,UNKN,INF,IF,UNKN,IF  \
CDEF:cdefb=i,22.6,GE,i,67.5,GE,UNKN,INF,IF,UNKN,IF  \
CDEF:cdefc=i,67.6,GE,i,112.5,GE,UNKN,INF,IF,UNKN,IF \
CDEF:cdefd=i,112.6,GE,i,157.5,GE,UNKN,INF,IF,UNKN,IF \
CDEF:cdefe=i,157.6,GE,i,202.5,GE,UNKN,INF,IF,UNKN,IF \
CDEF:cdeff=i,202.6,GE,i,247.5,GE,UNKN,INF,IF,UNKN,IF \
CDEF:cdefg=i,247.6,GE,i,292.5,GE,UNKN,INF,IF,UNKN,IF  \
CDEF:cdefh=i,292.6,GE,i,337.5,GE,UNKN,INF,IF,UNKN,IF  \
CDEF:cdefi=i,337.6,GT,i,360.99,GT,UNKN,INF,IF,UNKN,IF \
AREA:cdefa#8D85F3:\"North\" \
AREA:cdefb#9FA4EE:\"North East\"  \
AREA:cdefc#F9FD5F:\"East\" \
AREA:cdefd#EACC00:\"South East\\n\"  \
AREA:cdefe#EAAF00:\"South\"  \
AREA:cdeff#EA8F00:\"South West\"  \
AREA:cdefg#00CF00:\"West\" \
AREA:cdefh#6557D0:\"North West\\n\" \
AREA:cdefi#8D85F3:\"\" \
GPRINT:i:LAST:\"Current Direction in Degrees\:%8.2lf %s\\n\" \
AREA:bb#C0C0C0:\"\" \
LINE2:ba#562B29:\"\" \
LINE1:bb#000000:\"\"
";

 $update_graph = `$update_graph_cmd`;

 if ( $debug ) {
 echo "<p>\n";
 echo "<h2> location = ${location}</h2>\n";
 echo "<h3> url = ${value}</h3>\n";
 echo "<img src=${location}_d.png><br>\n";
 echo "<pre>\n";
 print_r($wind_data);
 echo $update_dir_data_cmd . "<br>";
 echo $update_graph_cmd . "<br>";
 echo "</pre></p><hr>\n";
 }
}
?>

index.php

<?php

#20100524 - randall s. ehren <randall@redigital.org>

$base_path = "/sbwindi/";
?>
<html>
<head>
<!-- render the page for iphones well -->
<meta name="viewport" content="width=device-width,minimum-scale=1.0, initial-scale=1" />
<title>iphone bel air knolls wind graph</title>
<style>
@media screen and (max-device-width: 480px){
/*--- iPhone only CSS here ---*/
body{
 -webkit-text-size-adjust:none;
 /* font-family:Helvetica, Arial, Verdana, sans-serif; */
 margin:0;
 padding:0;
}

}
#menubar ul {
 list-style: none;
 padding: 0;
 margin: 0;
}
#menubar li {
 float: left;
 margin: 0 0em;
}

#menubar li a {
 background: url(css-nav.gif) #fff bottom left repeat-x;
 height: 2em;
 line-height: 2em;
 float: left;
 width: 3.9em;
 display: block;
 border: 0.1em solid #dcdce9;
 color: #0d2474;
 text-decoration: none;
 text-align: center;
}

#content {

}
</style>
</head>
<body>
<div id="header">
 <div id="menubar">
 <ul>
 <li><a href="<?=$_SERVER[PHP_SELF]?>?l=airport">airport</a></li>
 <li><a href="<?=$_SERVER[PHP_SELF]?>?l=ellwood">ellwood</a></li>
 <li><a href="<?=$_SERVER[PHP_SELF]?>?l=belair">belair</a></li>
 <li><a href="<?=$_SERVER[PHP_SELF]?>?l=lacumbre">lacumbre</a></li>
 <li><a href="<?=$_SERVER[PHP_SELF]?>?l=mesa">mesa</a></li>
 </ul>
 </div>
</div>
<p>
<div id="content" align="left">
<?php

function display_wind_graphs($location)
{
 echo "<br><br>\n";
 echo "<img src=\"/sbwindi/xml/${location}_d.png\" width=\"320\" alt=\"${location}\">";
 echo "<br>\n";
 echo "<img src=\"/sbwindi/xml/${location}_h.png\" width=\"320\" alt=\"${location}\">";
}

 $location = $_GET["l"];
 switch ($location) {
 case "airport":
 $loc_name = "Airport";
 //echo '<a href="http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=MKSBA"><img src="http://banners.wunderground.com/cgi-bin/banner/ban/wxBanner?bannertype=pws250&weatherstationcount=MKSBA" width="250" height="150" border="0" alt="Weather Underground PWS MKSBA" /></a>';
 display_wind_graphs($location);
 break;
 case "mesa":
 $loc_name = "Mesa";
 //echo '<a href="http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=MAS714"><img src="http://banners.wunderground.com/cgi-bin/banner/ban/wxBanner?bannertype=pws250&weatherstationcount=MAS714" width="250" height="150" border="0" alt="Weather Underground PWS MAS714" /></a>';
 display_wind_graphs($location);
 break;
 case "ellwood":
 $loc_name = "Mesa";
 //echo '<a href="http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=MSBELL"><img src="http://banners.wunderground.com/cgi-bin/banner/ban/wxBanner?bannertype=pws250&weatherstationcount=MSBELL" width="250" height="150" border="0" alt="Weather Underground PWS MSBELL" /></a>';
 display_wind_graphs($location);
 break;
 case "lacumbre":
 //echo '<a href="http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=MAS303"><img src="http://banners.wunderground.com/cgi-bin/banner/ban/wxBanner?bannertype=pws250&weatherstationcount=MAS303" width="250" height="150" border="0" alt="Weather Underground PWS MAS303" /></a>';
 display_wind_graphs($location);
 break;
 case "belair":
 //echo '<a href="http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=KCASANTA122"><img src="http://banners.wunderground.com/cgi-bin/banner/ban/wxBanner?bannertype=pws250&weatherstationcount=KCASANTA122" width="250" height="150" border="0" alt="Weather Underground PWS KCASANTA122" /></a>';
 display_wind_graphs($location);
 break;
 }

?>
</div>
</body>
</html>
Posted in Uncategorized, sysadmin, web programming | Leave a comment

Cannot complete WindowsXP repair/install in Safe Mode, Setup continually retarts from black Safe Mode screen

if you receive the message “Cannot complete WindowsXP repair/install in Safe Mode, Setup continually retarts from black Safe Mode screen.” while trying to repair a broken Windows XP installation here are the steps to resolving the problem, as found at http://www.geekstogo.com/forum/Cannot-complete-WindowsXP-repair-install-Safe-Mode-t92558.html :

  1. Configure the computer to start from the CD-ROM or DVD-ROM drive. For information about how to do this, see your computer documentation, or contact your computer manufacturer.
  2. Insert the Windows XP CD-ROM into your CD-ROM or DVD-ROM drive, and then restart your computer
  3. When you receive the “Press any key to boot from CD” message, press a key to start your computer from the Windows XP CD-ROM.
  4. When you receive the “Welcome to Setup” message, press R to start the Recovery Console.
  5. If you have a dual-boot or multiple-boot computer, select the installation that you have to use from the Recovery Console.
  6. When you are prompted, type the administrator password, and then press ENTER.
  7. At the command prompt, type bootcfg /list, and then press ENTER. The entries in your current Boot.ini file appear on the screen.
  8. At the command prompt, type bootcfg /rebuild, and then press ENTER. This command scans the hard disks of the computer for Windows XP, Microsoft Windows 2000, or Microsoft Windows NT installations, and then displays the results. Follow the instructions that appear on the screen to add the Windows installations to the Boot.ini file. For example, follow these steps to add a Windows XP installation to the Boot.ini file:
  • When you receive a message that is similar to the following message, press Y:
Total Identified Windows Installs: 1

[1] C:\Windows
Add installation to boot list? (Yes/No/All)

  • You receive a message that is similar to the following message:
Enter Load Identifier

This is the name of the operating system. When you receive this message, type the name of your operating system, and then press ENTER. This is either Microsoft Windows XP Professional or Microsoft Windows XP Home Edition.

  • You receive a message that is similar to the following:
Enter OS Load options

When you receive this message, type /fastdetect, and then press ENTER.

Note The instructions that appear on your screen may be different, depending on the configuration of your computer.

Posted in Uncategorized | Leave a comment