March 1st, 2010
Between miles 18 and 19, I overhear two people standing off to the side of the road talking about marathons. One of them mentions that he hiked 26 miles in the mountains once but it took awhile to do.
I ended up finishing Tampa’s Gasparilla marathon in 4 hours 29 minutes 2 seconds (middle of the pack finishing time), and my fastest time to do one so far. The first 23 miles entailed running for 7 minutes and walking for 1 minute. That strategy works well for me as attempting to run them straight through rapidly decays into forced walking shortly after 16 miles, leading to finish times of over 5 hours. After routinely banging my head against the wall for my first three marathons, I discovered that run/walking greatly helps. Run/walking them shortens the finish time to under 5 hours.
Of course, weather plays an important role. Cool and dry enables you; warm and humid slowly wears you down. Yesterday’s marathon fell into the cool and dry category, making it seem easier.
Posted in Etc.
No Comments
February 27th, 2010
Update 1 – Project ditched.
After not having much luck using a screen recorder for the Macintosh and a free recorder for the PC, I’m evaluating one of PC commercial programs. My situation is a bit odd since I’m doing these recordings of a guest operating system running in a virtual machine. After stumbling last Summer and Fall, I managed to wrestle out a video once every couple of weeks; the commercial product, Camtasia Studio, allows me to crank them out at 4-5 times per week.
The videos consume roughly 2 MB/minute of storage space. The majority of the recordings are done on a computer desktop with a solid background color. Introducing a spreadsheet into the background, causes the data consumption to increase to 2.7 MB/min. An idle screen with just voice causes it to drop to 0.9 MB/min. This is over a duration of two and a half hours of recording. The following video format is produced:
- Format: MP4
- Dimensions: 1280×720
- Frames per second: 15
- Key frame every: 10 seconds
- Video quality: 85%
- Audio bitrate: 96 kb/s
From a self-hosted content delivery standpoint, some WordPress (blogging software) plugins use an Adobe flash player (free for non-commercial use), JW Player, to display media content from a variety of media formats. Last year I used the Shadowbox JS plugin to show videos. This year, there is a new plugin contender on the block, called Stream Video.
Alternatively, I could post my content on free delivery services such as Youtube, Vimeo and blip.tv. I know Youtube has a time limitation of approximately 10 minutes per video. The other two options are unexplored. One advantage to the self-hosting videos is that there are no oddball community rules or guidelines to follow. One drawback is there will be an unforeseen glass ceiling of realized storage and bandwidth limitations. I am aware of the actual limits (these vary per web hosting provider), but there might be a realized limit (“glass ceiling”) before the actual limit is reached. At this point, I do not know what it is or if this limit can be reached.
Posted in Screencasts
No Comments
January 2nd, 2010
Even though I built a new PC, I did not want to purchase a LCD monitor, preferring to squeeze more life out of my aging 21” Viewsonic G220f CRT monitor. (Edit 1/16 – Okay, I did buy one.) I always set the monitor resolution to 1280×1024 @ 100Hz. Windows XP has a 100Hz screen refresh rate option available but this option is missing for Windows 7.
Windows 7 looks for a special signal coming from monitors that list their supported screen resolutions and refresh rates known as EDID. LCD monitors send EDID information whereas my CRT monitor does not, causing Windows 7 to default to a generic monitor with a limited set of refresh rates.
This walk-though enables the 100Hz refresh rate option and assumes you use the following:
- Windows 7, 64-bit
- A 21” ViewSonic G220f CRT monitor
- A video card based with a Nvidia chipset.
The following steps will set the resolution to 1280 x 1024 @ 100 Hz. If you desire something different, then use your preferred settings. Be sure that these are valid for you monitor.
Read the rest of this entry »
Posted in Hardware
12 Comments
December 3rd, 2009
A sequence of characters compose a string. PHP comes equipped with an arsenal of string related functions. This posting will cover three string functions: strlen, strpos and strrpos.
Strings are enclosed in a pair of either single or double quotation marks. Characters are taken at face value when enclosed in single doubles. Additional processing occurs when characters are enclosed in double quotation marks; variable substitutions are made and escaped characters (e.g. \n) are translated into character codes.
In the example below, $firstSaying and $secondSaying have matching string values. The variable $person is automatically evaluated to ‘day’ because the value of $firstString is enclosed in double quotes.
<?php
$duration = 'day';
$firstSaying = "An apple a $duration";
$secondSaying = 'An apple a day';
?>
Internally, the value of $secondSaying is:
| Character |
A |
n |
|
a |
p |
p |
l |
e |
|
a |
|
d |
a |
y |
| Position |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
The table above the shows the position of each character within the string. Some programming languages use a starting position of one (Visual Basic) while the majority use a starting position of zero.
To retrieve a single character from a string, place the character position enclosed in brackets [ ] immediately after the string variable. For example, the following retrieves and displays 13th character in $secondString.
<?php
$secondSaying = 'An apple a day';
echo($secondSaying[13]);
?>
This program outputs the character y.
PHP is lenient when attempting at get characters that falls outside boundaries of a string (e.g. retrieving characters using a negative position or beyond the length of the string. It always returns an empty string “”. Bear in mind that trying this in programming languages may get you into trouble.
String Length
The function strlen accepts one argument, a string, and returns the length of that string. Since the first character begins at position zero, the string length is one greater than last character position in the string.
<?php
$secondSaying = 'An apple a day';
//Retrieve the length of the string
$secondSayingLength = strlen($secondSaying);
echo("The length of string '$secondSaying' is $secondSayingLength.\n");
?>
Output: The length of string 'An apple a day' is 14.
Calling strlen on a null value returns a length of zero.
Searching within Strings
To locate the starting position of text with a string, use the function strpos. Standard calls to strpos accept two arguments, the first parameter being the string to search (the subject or the haystack) and second the text to find (the needle). The text can be a single character or a string consisting of multiple characters. The function will begin at the left hand side of the string and search right for the string. If the search text cannot be located, a boolean value false is returned.
Note: Be careful when checking if the search text is found. The starting position of 0 has the same value as the boolean false. Use the identical === binary operator or the not identical operator !== to make this differentiation.
<?php
$secondSaying = 'An apple a day';
$searchText = 'a';
//Find the position of 'a'
$positionOfA = strpos($secondSaying, $searchText);
if ($positionOfA !== false) {
echo("The first occurrence of '$searchText' is at position $positionOfA.\n");
}
else {
echo("Could not locate $searchText\n");
}
?>
The source code above retrieves the first occurrence of a lowercase ‘a’.
| Character |
A |
n |
|
a |
p |
p |
l |
e |
|
a |
|
d |
a |
y |
| Position |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
Output: The first occurrence of 'a' is at position 3.
But the first occurrence of the letter a is at position zero.
Well, strpos is case sensitive. It locates the first lowercase ‘a’; an uppercase ‘A’ isn’t a lowercase one. To locate the first occurrence of of ‘a’ regardless of its case use stripos. In the example above it returns the integer zero.
Case insensitive string functions ignore the case of characters when performing operations. These functions begin with stri where their case sensitive counterparts begin with str. For example, stricmp is case insensitive and strcmp is case sensitive.
The function strpos accepts an optional parameter, the position within the string (offset) to conduct a search. To find the second ‘a’ within the string, I will begin searching one character after the first ‘a’ at $positionOfA + 1.
| Character |
A |
n |
|
a |
p |
p |
l |
e |
|
a |
|
d |
a |
y |
| Position |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
I cannot assume that there will always be text following the first ‘a’ to search on. PHP doesn’t care if you search outside the boundary of the string, but in this example, I will keep my search within the string by using strlen.
<?php
$secondSaying = 'An apple a day';
$secondSayingLength = strlen($secondSaying);
$searchText = 'a';
//Find the position of 'a'
$positionOfA = strpos($secondSaying, $searchText);
$positionOfSecondA = false;
if ($positionOfA !== false) {
// Find the position of the second 'a'
if ($secondSayingLength > ($positionOfA + 1)) {
$positionOfSecondA = strpos($secondSaying, $searchText, $positionOfA + 1);
}
}
if ($positionOfSecondA !== false) {
echo("The second occurrence of '$searchText' is at position $positionOfSecondA.\n");
}
else {
echo("Could not locate second occurrence of '$searchText'.\n");
}
?>
Output: The second occurrence of 'a' is at position 9.
To find the last occurrence ‘a’, use the function strrpos. This searches for a string in reverse, hence the extra ‘r’ in the function name. It accepts the same arguments as the forward version of the search.
For those living in the dark ages of PHP 4 (waves hand), strrpos only searches on single characters. If I wanted to find the last occurrence of the word apple and pass the string ‘apple’ as an argument, strrpos would search for the last occurrence of the letter ‘a’. This will not give us the correct result in PHP 4.
Here’s an example of finding the last occurrence of the letter ‘a’ in PHP 5.
<?php
$secondSaying = 'An apple a day';
$searchText = 'a';
//Find the last position of 'a'
$positionOfA = strrpos($secondSaying, $searchText);
if ($positionOfA !== false) {
echo("The last occurrence of '$searchText' is at position $positionOfA.\n");
}
else {
echo("Could not locate the last occurrence of '$searchText'.\n");
}
?>
Output: The last occurrence of 'a' is at position 12.
Posted in PHP, Programming
No Comments