Month: October 2005

  • Oops. Server down?

    Here’s a good reason to never put passwords in source code. Apparently Yahoo’s php server was down today. On the other hand, some commenting would be better than what is shown here. Next post: The ethics of posting other peoples code.

    define('COOKIE_DOMAIN', 'www.yahoo.com');
    define('PIXEL_WIDTH', '145');

    $linkviews = array();

    function track_linkview ($link) {
    global $linkviews;
    array_push($linkviews, $link);
    }

    function log_linkviews () {
    global $linkviews;
    if (count($linkviews)) {
    yahoo_track_page_params(array('link' => join("\002", $linkviews)));
    }
    }

    function quote ($str) {
    return preg_replace('/([\\\"\'])/', '\\\$1', $str);
    }

    function js_start () {
    print "<script language=\"javascript\" type=\"text/javascript\">\n";
    print "d=document;\n";
    print "d.domain='yahoo.com';\n";
    print "p=parent.document;\n";
    print "lc=p.getElementById('lc');\n"; // weather content
    print "ca=p.getElementById('ca');\n"; // change location link
    print "cl=p.getElementById('cl');\n"; // change location
    print "wt=p.getElementById('wt');\n"; // module title
    print "wa=p.getElementById('wa');\n"; // alert
    print "wg=p.getElementById('wg');\n"; // weather message
    }

    function js_end () {
    print "</script>\n";
    }

    function js_set ($key, $value) {
    return "$key=\"" . quote($value) . "\";\n";
    }

    function weather_result ($label, $url, $cond) {
    $rd = $label == 'Today' ? 'r/w3' : 'r/w5';
    $lo = $cond["lo"];
    $hi = $cond["hi"];
    $sky = $cond["sky"];
    $fc = $cond["forecast"];
    $result = "<a href=\"$rd/*$url\"><b>$label</b></a>";
    $result .= "<img src=$sky alt=\"$fc\">";
    $result .= "$fc<br>";
    $result .= "hi <span class=hi>$hi°<span class=sc>F</span></span> - ";
    $result .= "lo <span class=lo>$lo°<span class=sc>F</span></span>";
    track_linkview($rd);
    return $result;
    }

    function show_results ($city_state, $weather) {
    $url = $weather->url;
    $today = weather_result("Today", $url, $weather->today);
    $tomorrow = weather_result("Tomorrow", $url, $weather->tomorrow);
    $xfc =
    "<span class=mr>" .
    "<a href=\"r/w7/*$url\"><b>»</b> Extended Weather Forecast</a>" .
    "</span>";

    print js_set("wt.innerHTML",
    htmlentities(fp_limit_location($city_state, PIXEL_WIDTH)));
    print js_set("wt.href", "r/wt/*$url");
    print js_set("ca.style.display", "inline");
    print js_set("ca.className", "");
    print js_set("lc.innerHTML",
    "<div class=b>$today</div>" .
    "<div class=b>$tomorrow</div>" .
    $xfc);
    //print "wt.focus();wt.blur();parent.clo=0;\n";
    print "parent.clo=0;\n";

    // U.S. location for local search, disabled
    if (0 && preg_match('/\b\w{2}$/', $city_state)) {
    print js_set("parent._wcs", $city_state);
    print "if (p.sf1.csz) " . js_set("p.sf1.csz.value", $city_state);
    }

    yahoo_track_page_params(array("wrs" => $weather->id));
    track_linkview("r/w7");
    }

    function show_error ($status) {
    $code = "error";
    if (!is_null($status)) {
    $code .= ":$status";
    }
    print js_set("wa.innerHTML",
    "<strong>Your search produced no matches.</strong><br>".
    "Please re-enter a City or U.S. Zip Code:");
    print js_set("wg.style.display", "none");
    print js_set("wa.style.display", "block");
    yahoo_track_page_params(array("wrs" => $code));
    }

    function show_picklist ($list) {
    $ccc_file = "/home/y/share/htdocs/includes/weather/ccc2full.cdb";
    $ccc_map = dba_open($ccc_file, "r-", "cdb");
    $choices = "";
    ## re-order USA first
    if (array_key_exists('USA', $list)) {
    $newlist = array();
    $newlist['USA'] = $list['USA'];
    foreach ($list as $ccc => $region) {
    $newlist[$ccc] = $region;
    }
    $list = $newlist;
    }
    foreach ($list as $ccc => $region) {
    $country = $ccc;
    if ($ccc_map !== FALSE &&
    ($full = dba_fetch($ccc, $ccc_map)) !== FALSE) {
    $country = $full;
    }
    $choices .= "<div>$country</div>";
    foreach ($region as $loc) {
    list($id, $cs) = $loc;
    $param = quote($id);
    $choices .= "<a href=\"javascript:parent.zp('$param');\">$cs</a>";
    }
    }
    if ($ccc_map !== FALSE) {
    dba_close($ccc_map);
    }
    print js_set("wa.innerHTML",
    "<span>" .
    "<strong>Your search matched multiple cities.</strong><br>" .
    "Please select the appropriate location below:" .
    "</span>" .
    "<span id=ls class=wil>" .
    $choices .
    "</span>");
    print js_set("wg.style.display", "block");
    print js_set("wa.style.display", "block");
    yahoo_track_page_params(array("wrs" => "picklist"));
    }

    function retry_validate_location ($lm, $csz, $limit) {
    $attempt = 0;

    do {
    if ($attempt) usleep(500000); // 0.5 seconds
    $attempt++;
    $return = $lm->validatelocation($csz, 1);
    } while ($return[0] == '-5' and $attempt < $limit);

    if ($return[0] != 1 and $return[0] != -1 and $return[0] != -2) {
    error_log("validatelocation($csz) failed: $return[0]");
    }

    return $return;
    }

    function find_location ($lm, $wtr, $csz) {
    $attempts = 3;
    $return = retry_validate_location($lm, $csz, $attempts);
    $results = array();

    if (($return[0] == -2 or $return[0] >= 0) &&
    array_key_exists('geolist', $return)) {
    foreach ($return['geolist'] as $location) {
    if ($wtr->load($location)) {
    array_push($results, $location);
    }
    else {
    error_log("no weather data for: " . fp_city_state($location));
    }
    }
    }

    return $results;
    }

    function set_weather_cookie ($value) {
    $expire = time() + 90 * 86400;
    setcookie(WEATHER_COOKIE, $value, $expire, "/", COOKIE_DOMAIN, 0);
    }

    function clear_weather_cookie () {
    setcookie(WEATHER_COOKIE, "", 0, "/", COOKIE_DOMAIN, 0);
    }

    ## main ()

    $v = $_GET;
    $location = new yahoo_location_manager();
    $weather = new YahooFrontpageWeather(array('pixel_width' => PIXEL_WIDTH));

    ## /yahoo/site/main/weather (non-frontpage traffic)
    yadl_spaceid('P#97167465');
    yahoo_track_page_params(array('PL' =>
    yahoo_full_cookie('PL') === FALSE ? 0 : 1));

    if (array_key_exists('test', $v)) {
    $version = 'v' . yahoo_get_data(YIV_GET, 'test');
    yahoo_track_page_params(array('test' => $version));
    }

    if (array_key_exists('wl', $v)) {
    $pixel = 'http://us.i1.yimg.com/us.yimg.com/i/space.gif';
    $wlocid = yahoo_get_data(YIV_GET, 'wl');

    if ($weather->load($wlocid)) {
    set_weather_cookie($wlocid);
    }

    header("Location: $pixel");
    }
    else if (array_key_exists('p', $v) and
    (($csz =
    yahoo_get_data(YIV_GET, 'p', YIV_FILTER_UNSAFE_RAW)) != '')) {
    $results = find_location($location, $weather, $csz);

    ## invalid location
    if (count($results) == 0) {
    if ($csz == 'delete') {
    // clear weather cookie
    if (yahoo_full_cookie(WEATHER_COOKIE) !== FALSE) {
    clear_weather_cookie();
    }
    // clear location manager cookie
    if (yahoo_full_cookie('PL') != FALSE) {
    setcookie('PL', '', 0, '/', ".yahoo.com");
    }
    }
    js_start();
    show_error('l');
    js_end();
    }
    ## single result
    else if (count($results) == 1) {
    $loc = $results[0];
    $cs = fp_city_state($loc);
    $id = $loc['uniqueId'];

    if ($weather->load($loc)) {
    if (array_key_exists('sv', $v) && $v['sv'] == 'on') {
    // clear weather cookie
    if (yahoo_full_cookie(WEATHER_COOKIE) !== FALSE) {
    clear_weather_cookie();
    }

    // clear PL older cookie scoped on www.yahoo.com
    if (yahoo_cookie_part('PL', 'V') == '1.0') {
    setcookie('PL', '', 0, '/', COOKIE_DOMAIN);
    }

    $return = $location->setLocation($id, "weather", 1);
    if ($return[0] != 1) {
    error_log("setLocation($id) failed: $return[0]");
    }

    yahoo_track_page_params(array('wsv' => 1));
    }

    if ($cs == '') {
    $cs = $weather->location;
    }

    js_start();
    show_results($cs, $weather);
    js_end();
    }
    else {
    js_start();
    show_error('w');
    js_end();
    }
    }
    ## pick list
    else {
    $list = array();

    // group by country
    foreach ($results as $loc) {
    $cs = fp_city_state($loc);
    $id = $loc['uniqueId'];
    $ccc = $loc['country'];
    $item = array($id, $cs);

    if (array_key_exists($ccc, $list)) {
    array_push($list[$ccc], $item);
    }
    else {
    $list[$ccc] = array($item);
    }
    }

    js_start();
    if (count($list) == 0) {
    show_error('pl');
    }
    else {
    show_picklist($list);
    }
    js_end();
    }
    }
    ## initial pageview
    else {
    $loc = fp_get_weather_location();

    if ($loc !== FALSE) {
    $cs = fp_city_state($loc);

    if ($weather->load($loc)) {
    if ($cs == '') {
    $cs = $weather->location;
    }
    js_start();
    show_results($cs, $weather);
    js_end();
    }
    }
    }

    log_linkviews();

    ?>

  • Streeettch

    Oh I want the luxury of exercise!

  • New Orleans Buses On The Move

    For those still following the New Orleans flooding, here is some interesting photographic evidence along with explanation of buses evacuating people.

  • Ipod Nano 200gb Upgrade – DIY

    For you Ipod enthusiasts that just want more space, instructions are now online to explain how to upgrade your Ipod Nano to 200gb for 150,000 minutes of music! If you don’t read all the instructions at least scroll to the very bottom for the results.

  • Customer service day. Client two happy

    Customer service day. Client two happy

  • Customer satisfaction day. Client meeting one done…

    Customer satisfaction day. Client meeting one done

  • Children Make Us Better Adults

    A simple request, "Dad, would you read me the book Granddaddy got me?" during a heated, high pressure deadline reminds us that sometimes a break makes us more productive. Taking a few minutes with children instead of replying, "not now. I’m busy." makes us feel good where as putting them off gives us guilt. Remember, a toddler and even older children do not understand the concept of "later" and particularly "I’m busy." They don’t care. They want you to be busy with them.

    Reading Amy’s story took less time than writing this post. She enjoyed the time and at the end of the story went on happily to other things. I love it!

    Studies are even showing that napping (taking a short break) during the day helps make us as much as 30% more productive.

    Liberty Wellness Tip: Well-rested employees create happier & more productive workplaces.

  • My Blades are gone!

    Blades is a concept SME Server (mitel e-smith) uses to allow easy additions of upgrades or software to the server. It is very much like Windows Update. I found this note on SME Server 5.6 release notes:

    Blades

    * The Blades web panel has been removed from the server manager as we have chosen to focus all blades-related development on our commercially supported products. Updates to this developer release will continue to be made available as downloadable RPMs as they were prior to the introduction of the blades interface. Commercial customers will continue to be able to download both updates and additional applications as software blades..

  • Got Woot?

    Good Woot today! Sold out in 39 minutes profitting Woot $23,992. Wouldn’t that be nice?!

    Today’s item quantity: 800
    Last Order time: 12:39 AM Central Time
    Woot Member to blame: jaykid007
    Order Pace: 0m 3.317s
    Woot Wage: $36,160.11 an hour

  • Linux Server Up!

    It took all stinkin’ day. Brought me bear the point of tears. But I got version 6.01 of e-smith server (now SME Server) installed and running. Normally this would take less than 2 hours but I was having hardware issues. What a pain!

    It set me unbelieveablly behind in my work but conceptually this greatly speed up my development efforts.

    Point of interest. The linux server which I do all my php development (the one with the harddrive that is finally dying) only has 40MB ram, a 1.6gb harddrive and is lightning fast! The new server, a 10gb harddrive and 64MB ram. I don’t know the processor on either offhand but they are vintage.

  • Accident in front of red cross office

    Accident in front of red cross office

  • Nothing in this town before 10 am!

    Nothing in this town before 10 am!

  • Thank you Comcast! Gimme more!

    332 KB/s! I thought we were supposed to be doing better than that but I’m not complaining. I recall the days of 4KB/s all too well.

    Today’s first task: build a new linux development server. Somehow work on two clients at once all day.

  • From the mouths of babes

    Amy (3): I’m ready for my noodles (lasagna) now and I promise not to throw them.

  • Juggling Skills Put To Test

    Finale

    Great visit with the folks. Much conversation and many good eats were had by all. The kids were on exceptional behavior! The dog was obnoxious.

    Dismantled a Dell Inspiron 700m and cleaned coffee from its innards. That’s a well built machine! Returned cleaned machine to client.

    Went to Bilo and was an embarassment to my wife.

    Time to cook dinner.