Saturday, October 31, 2009

Javascript in Wordpress

httpdocs/wordpress/wp-content/themes/default/header.php >> MYJAVASCRIPTFILE.js

<?php
/**
 * @package WordPress
 * @subpackage Default_Theme
 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

<title><?php wp_title('«', true, 'right'); ?> <?php bloginfo('name'); ?></title>

<script type="text/javascript" src="/javascript/MYJAVASCRIPTFILE.js">
 </script>

<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />

<style type="text/css" media="screen">

<?php
// Checks to see whether it needs a sidebar or not
if ( empty($withcomments) && !is_single() ) {
?>
 #page { background: url("<?php bloginfo('stylesheet_directory'); ?>/images/kubrickbg-<?php bloginfo('text_direction'); ?>.jpg") repeat-y top; border: none; }
<?php } else { // No sidebar ?>
 #page { background: url("<?php bloginfo('stylesheet_directory'); ?>/images/kubrickbgwide.jpg") repeat-y top; border: none; }
<?php } ?>

</style>

<?php if ( is_singular() ) wp_enqueue_script( 'comment-reply' ); ?>

<?php wp_head(); ?>
</head>
<body <?php body_class(); ?>>
<div id="page">


<div id="header" role="banner">
 <div id="headerimg">
  <h1><a href="<?php echo get_option('home'); ?>/"><?php bloginfo('name'); ?></a></h1>
  <div class="description"><?php bloginfo('description'); ?></div>
 </div>
</div>
<hr />

Monday, October 19, 2009

helloworld.C

#include <iostream>

using namespace std;

int main()
{
  int thisisanumber;
  cout<<"\ncompiled with this command:\ng++ -g helloworld.C -o helloworld\n\n";
  cout<<"Please enter a number: ";
  cin>> thisisanumber;
  cin.ignore();
  cout<<"You entered: "<< thisisanumber <<"\n";
  cin.get();
}

Friday, October 16, 2009

PHP webform emails XML plain text

The PHP code that generates an email is so short due to using foreach($_POST as $key => $value). I was able to use the key names because, in the HTML form, I named the input fields with full, readable, descriptive names ( i.e. first_name rather than fname ).

The email is encoded as plain text. I originally set it up to send an ugly output from the form. Then the users requested XML. It was amazing how simple that was to add. I'd recommend XML as the structured output, oddly, for the readability alone.

SIMPLEST XML EXAMPLE
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
 <to>Tove</to>
 <from>Jani</from>
 <heading>Reminder</heading>
 <body>Don't forget me this weekend!</body>
</note>
<?php
$recipient = "this.is.lance.miller@gmail.com";
$message = "";
$ip = $_SERVER['REMOTE_ADDR'];
$email = "this.is.lance.miller@gmail.com";
if ($_POST['email']) { $email = $_POST['email'] ; }
if ($_POST['submit']) {
$message = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n<!-- html/php/xml code by this.is.lance.miller@gmail.com -->\n";
$message .= "<volunteer>\n";
foreach($_POST as $key => $value) {
 if ($key != "submit") { $message .= "\t<$key>\n\t$value\n\t</$key>\n";}
                                  }
$message .="\t<remote_address>\n\t${ip}\n\t</remote_address>\n";
$message .= "</volunteer>\n";
mail( $recipient , "Volunteer Form Submission $email $ip", $message, "From: $email" );
echo "Thank you. Your information has been sent.";
} else {

?>
<h1>Volunteer Application Form</h1>
<div style="padding:5px;background:#CCCCCC">
<form name="volunteer_form" method="POST" action="<?php echo $PHP_SELF;?>">
CONTACT INFORMATION:
<br />
First Name:<input type="text" name="first_name" size="25" />
Last Name:<input type="text" name="last_name" size="25" />
<br />
Address:<input type="text" name="address" size="80" />
<br />
Email:<input type="text" name="email" size="80" />
<br />
Home Phone:<input type="text" name="home_phone" size="16" />
Other Phone:<input type="text" name="other_phone" size="16" />
<br />
Emergency Contact:<input type="text" name="emergency_contact" size="25" />
Phone:<input type="text" name="emergency_contact_phone" size="16" />
</div>
<div style="padding:2px">
</div>
<div style="padding:5px;background:#CCCCCC">
AVAILABILITY:
<br />
<table><tr>
<td valign="top" align="left">
Weekdays <input type="radio" name="weekdays" value="Yes"> Yes <input type="radio" name="weekdays" value="No"> No 
<br />
Weekends <input type="radio" name="weekends" value="Yes"> Yes <input type="radio" name="weekends" value="No"> No 
<br />
Evenings <input type="radio" name="evenings" value="Yes"> Yes <input type="radio" name="evenings" value="No"> No 
<br />
</td><td valign="top" align="right">
<textarea cols="60" rows="4" name="details">
Details here if needed: 
</textarea>
</td></tr></table>
<br />
What events are you interested in volunteering for at the Abbotsford Entertainment and Sports Center?
<br />
<input type="radio" name="concerts" value="Yes"> Concerts
<input type="radio" name="hockey" value="Yes"> Hockey
<input type="radio" name="theatre" value="Yes"> Theatre
<br />
<input type="radio" name="trade_shows" value="Yes"> Trade Shows
<input type="radio" name="private_events" value="Yes"> Private Events
<br />
</div>
<div style="padding:2px">
</div>
<div style="padding:5px;background:#CCCCCC">
SKILLS AND EXPERIENCE:
<br />
Do you have a valid Drivers License?
<input type="radio" name="driverslicense" value="Yes"> Yes <input type="radio" name="driverslicense" value="No"> No 
<br />
Do you have a first aid certificate?
<input type="radio" name="first_aidc_ertificate" value="Yes"> Yes <input type="radio" name="first_aid_certificate" value="No"> No 
<br />
Do you have a food safe certificate?
<input type="radio" name="food_safe_certificate" value="Yes"> Yes <input type="radio" name="food_safe_certificate" value="No"> No 
<br />
</div>
<div style="padding:2px">
</div>
<div style="padding:5px;background:#CCCCCC">
SPECIAL SKILLS:
<br />
<input type="radio" name="av_support" value="Yes"> A/V Support
<input type="radio" name="artistic_skill" value="Yes"> Artistic Skill
<input type="radio" name="child_care" value="Yes"> Child Care
<br />
<input type="radio" name="coach_referee_official" value="Yes"> Coach/Referee/Official
<input type="radio" name="customer_service" value="Yes"> Customer Service
<input type="radio" name="first_aid_certificate" value="Yes"> First Aid Certificate
<br />
<input type="radio" name="public_speaking" value="Yes"> Public Speaking
<input type="radio" name="office_skills" value="Yes"> Office Skills
<input type="radio" name="photography" value="Yes"> Photography
<br />
<input type="radio" name="musical_skills" value="Yes"> Musical Skills
<input type="radio" name="sport_skills" value="Yes"> Sport Skills
<input type="radio" name="teaching_education" value="Yes"> Teaching/Education
<br />
<input type="radio" name="writing_editing" value="Yes"> Writing/Editing
<input type="radio" name="other_skill" value="Yes"> Other <input type="text" id="other_skill_detail" size="25" />
<br />
</div>
<div style="padding:2px">
</div>
<div style="padding:5px;background:#CCCCCC">
<input type="submit" name="submit" value=" SEND " />
</form>
</div>
<div style="padding:2px">
</div>
<div style="padding:5px;background:#CCCCCC">
<span style="font-style:monospace;font-size:75%">this.web.form by this.is.lance.miller@gmail.com</span>
</div>
<?php
}
?>

Wednesday, October 14, 2009

OS X CLI Open and Kill an App

#!/usr/bin/env bash

case ${1} in
      "open")
      open /Applications/Yahoo\!\ Messenger.app/;
      let "myentry = `ps -au lance | grep /Applications/Yahoo\!\ Messenger.app/ | grep -v grep | awk '{print $2}'`";
      echo "press enter to kill ${myentry}";
      read;
      kill $myentry; 
      clear;
      ps -au lance | grep /Applications/Yahoo\!\ Messenger.app/ | grep -v grep; 
       exit;;
   "") ls $0;cat $0;exit;;
esac


Monday, October 5, 2009

ipserver.py

#!/usr/bin/env python
#
# 
import os
import cgi


def main():
 print 'Content-Type: text/plain'
 print ''
        print os.environ['REMOTE_ADDR']
   

if __name__ == "__main__":
        
 main()