Running Summary August 17th – 23th 2014

This week I add a few extra runs with my family. The extra running was a slower pace because I was pushing a stroller with 2 kids in it but it was more mileage. Total mileage for the week was 38.5 miles. This week felt slow even though it wasn’t that slow. I need to work on pressing harder during 1 or 2 of my 6 mile runs and drop my average pace to the low or sub 8 min pace. Overall it was an ok week.

Sunday:

Description: This should have been my rest day but I ran pushing a stroller with my family.
Distance:  2 Miles
Total Time: 25:48 Min
Average Pace: 12:48 Min
Mile Splits: 12:46, 12:48

Monday:

Distance: 5 Miles
Total Time: 43:48 Min
Average Pace: 8:42 Min
Mile Splits: 8:49, 8:46, 8:23, 8:51, 8:37

Tuesday:

Distance: 6 Miles
Total Time: 52:41 Min
Average Pace: 8:47 Min
Mile Splits: 8:43, 8:28, 8:37, 9:12, 8:55, 8:43

Wednesday:

Description: Played around with creating RunKeeper workout (not as good as it should be). 5 min warm up, 9 x 30 sec fast, 5 min cool down. I added extra cool down to get my 6 miles in.
Distance: 6 Miles
Total Time: 51:39 Min
Average Pace: 8:36 Min
Mile Splits: 8:23, 7:33, 9:04, 9:16, 8:31, 8:45

Description: Double day I ran pushing a stroller with my family.
Distance:  2.26 Miles
Total Time: 29:55 Min
Average Pace: 13:15 Min
Mile Splits: 13:01, 13:22

Thursday:

Rest

Friday:

Distance: 6 Miles
Total Time: 51:26 Min
Average Pace: 8:32 Min
Mile Splits: 8:49, 8:24, 9:00, 8:25, 7:57, 8:39

Saturday:

Distance: 10 Miles
Total Time: 1:32:50 Min
Average Pace: 9:16 Min
Mile Splits: 9:07, 8:57, 8:49, 9:37, 9:59, 9:01, 9:16, 9:32, 9:04, 9:21

Description: Right after my 10 mile I ran to track and came back after my wife did 2 miles on the track.
Distance:  1.1 Miles
Total Time: 12:36 Min
Average Pace: 11:25 Min
Mile Splits: 11:22

Posted in Fitness, Running Tagged with:

Running Summary August 10th – 16th 2014

This week I continued to work on increasing my distance while trying to press for a faster pace. I ran a total of 34 miles and did a timed 1 mile on Tuesday. The timed mile was using RunKeeper running on a paved running trail. I think I could have pressed harder on a track. It’s really hard to push the last quarter when your not sure where the finish line is on a trail.  I did the mile in 6 minutes and 23 seconds. This new mile time seemed to flip something in my longer runs because I felt really good on my 6 and 11 mile runs later in the week. On my 11 mile run this week my average pace dropped almost 45 seconds a mile from my 10 mile run the week before. Overall it was a really good week.

Sunday:

Rest

Monday:

Distance: 6 Miles
Total Time: 55:35 Min
Average Pace: 9:14 Min
Mile Splits: 9:48, 9:07, 9:19, 9:29, 8:54, 8:45

Tuesday:

Distance: 5 Miles
Description: 1 mile warm up with 1 mile fast and 3 mile cool down.
Mile PR: 6:23 Min
Mile Splits: 8:57, 6:23, 11:11, 9:33, 9:28

Wednesday:

Distance: 6 Miles
Total Time: 52:49 Min
Average Pace: 8:47 Min
Mile Splits: 9:11, 8:36, 8:38, 8:52, 8:46, 8:31

Thursday:

Rest

Friday:

Distance: 6 Miles
Total Time: 48:18 Min
Average Pace: 8:02 Min
Mile Splits: 8:20, 8:00, 7:48, 8:06, 8:07, 7:51

Saturday:

Distance: 11 Miles
Total Time: 1:36:42 Min
Average Pace: 8:46 Min
Mile Splits: 9:24, 8:24, 8:38, 8:43, 8:30, 8:52, 8:40, 8:53, 8:50, 8:56, 8:32

Posted in Fitness, Running Tagged with:

Journey to a 15 minute 5k

It’s been a little over 2 years since my last post. A lot has happened in 2 years. We had our second child, new jobs for both my wife and I. I’m sure we’ve had many more changes. I plan to start blogging again. This go around I’m planning to focus more on my fitness and running. So lets start…

The last several years I put on weight, a lot of weight. I began to get annoyed and didn’t want to buy fatter fat clothes. My weight peaked around 230 pounds in December 2013. I started eating better and working out January 2014. You could call it a New Year’s resolutions, but I think it’s more of a life style change.

I’ve always enjoyed running so the majority of my workouts are running with some added weight training. Early on running was hard because I couldn’t go as far or fast as I thought I should be able to. After a few months I had issues with shin and calf pain that caused me to shift to the stationary bike for a few weeks. As the months have gone by I’ve dropped weight and improved my endurance and speed. This morning my weight 188 pounds. A much healthier weight and I still have to lose more before I will be back in running shape.

In January I was only able to run 1.5 miles 2 or 3 times week at about a 10 minute pace. Which was extremely frustrating because I remember my running from 13 years ago. 8 months in I’m running a little over 30 miles a week and even on my easy long runs at a sub 9 minute pace. I’ve been focused on building up my miles for a strong base. To date my longest run as been a 10.3 miles. I’m feeling good about my milage and I’m planning to start doing speed work in a few weeks to improve my speed.

Here are some of my self timed results all done in the last 2 week:
100 meter – 13.17
200 meter – 32.14
400 meter – 68.45
1 mile – 6:23 (on the trail using RunKeeper)

I’m happy with my current results but I’m ready to push for more. I plan to post at least weekly to sum up the weeks training. As this posts title suggests long term goal is to run a 15 minute 5k. This blog will document either my success or my failure. Which do you think it will be?

Posted in Fitness, General, Running Tagged with: ,

Stripe Bundle for Laravel

I’ve been learning the ins and outs of Laravel for a little over a week. Last night I decided I should create a quick bundle. I created a simple API bundle for Stripe because I will need it for a future project and Stripe is amazing. The bundle was super easy to create maybe two lines of code. But beauty is in Laravel’s bundle manager. It makes bundles very easy to install in your project.

Check out the Laravel Bundle page here or go right to the source on GitHub here.

Posted in PHP, Programming Tagged with: ,

Regex Flickr Parser

Today’s Regex is used to parse a string for Flickr links and extract the Photo_ID. Once we have the Photo_ID we’re able to create a standard embed code from nearly any Flickr URL.

Supported Links:

The following Regex supports these Flickr links and embed code snippets.

Normal URL : http://www.flickr.com/photos/gambort/6501997531/
Short URL :  http://flic.kr/p/aUyrkH
Embed :      >a href="http://www.flickr.com/photos/gambort/6501997531/" 
             title="Skyrim black dragon by gambort, on Flickr"><img 
	     src="http://farm8.staticflickr.com/7004/6501997531_80aa9da91a.jpg" 
             width="500" height="334" alt="Skyrim black dragon"></a>
	
****Short Code id needs to be decoded and replaced with the full photo ID****

Again, I’ve broken it up the Regex and commented each line.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$regexstr = '~
# Match Flickr link and embed code
(?:<a [^>]*href=")?		# If a tag match up to first quote of src
(?:				# Group Flickr url
	https?:\/\/		# Either http or https
	(?:[\w]+\.)*		# Optional subdomains
	(?:               		# Group host alternatives.
		flic\.kr     	# Either flic.kr
	        	| flickr\.com	# or flickr.com 
	)			# End Host Group
	(?:\/photos)?		# Optional video sub directory
	\/[^\/]+\/		# Slash and stuff before Id
	([0-9a-zA-Z]+)	# $1: PHOTO_ID is numeric
	[^\s]*			# Not a space
)				# End group
"?				# Match end quote if part of src
(?:.*></a>)?			# Match the end of the a tag
~ix';

Usage Example:

This example is more involved than the previous posts because we need to make an API call to get the image URL after we get the Flickr Photo_ID. I’ve also included a Base58 decode function incase the url is the short flic.kr style link.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function ParseForFlickr($string){
	$regexstr = <<REGEX FROM ABOVE>>;
 
	require_once('phpFlickr.php');
	$f = new phpFlickr("<<Flickr API Key>>");
 
	preg_match_all($regexstr, $string, $matches, PREG_SET_ORDER);
 
	//Loop results		
	foreach ($matches as $val) {	
		//If short code decode it     
		if (strpos($val[0], "flic.kr") !== false) {
			$val[1] = $this->flickrDecode($val[1]);
		} 
 
		//make flickr api call with photo id
		$pinfo = $f->photos_getSizes($val[1]);
		//Array 3 is the medium 500 size
		$imgstr = ' <p><img class="upostimg" src="'.$pinfo[3]['source'].'" /></p> ';
		$string = str_replace($val[0],$imgstr,$string);
	}
	return $string;
}
 
function flickrDecode($num){
	$alphabet = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
 
	$decoded = 0;
	$multi = 1;
	while (strlen($num) > 0) {
		$digit = $num[strlen($num)-1];
		$decoded += $multi * strpos($alphabet, $digit);
		$multi = $multi * strlen($alphabet);
		$num = substr($num, 0, -1);
	}
 
	return $decoded;
}

For more Regex see Regex YouTube Parser or Regex Vimeo Parser

Posted in Computers, PHP, Programming, Regex Tagged with: , ,

Regex Vimeo Parser

Today’s Regex is used to parse a string for Vimeo links and extract the Video_ID. Once we have the Video_ID we’re able to create a standard embed code from Vimeo links.

Supported Links:

The following Regex supports these Vimeo links and embed code snippets.

Normal URL: http://vimeo.com/9669721
Group URL:   http://vimeo.com/groups/tvc/videos/32626014
New Embed:   <iframe src="http://player.vimeo.com/video/9669721?title=0
             &byline=0&portrait=0&color=ffffff" width="400" 
             height="225" frameborder="0" webkitAllowFullScreen 
             mozallowfullscreen allowFullScreen > </iframe >

**** Doesn't handle Vimeo's old embed code ****

Again, I’ve broken it up the Regex and commented each line.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$regexstr = '~
 # Match Vimeo link and embed code
(?:<iframe [^>]*src=")? 	# If iframe match up to first quote of src
(?:				# Group vimeo url
	https?:\/\/		# Either http or https
	(?:[\w]+\.)*		# Optional subdomains
	vimeo\.com		# Match vimeo.com
	(?:[\/\w]*\/videos?)?	# Optional video sub directory this handles groups links also
	\/			# Slash before Id
	([0-9]+)		# $1: VIDEO_ID is numeric
	[^\s]*			# Not a space
)				# End group
"?				# Match end quote if part of src
(?:[^>]*></iframe>)?		# Match the end of the iframe
(?:<p>.*</p>)?		        # Match any title information stuff
~ix';

Usage Example:

This example function takes an input string and uses the above Regex to parse off the Vimeo Video_ID ($1) and add it to $iframestr to create a standard embed code.

1
2
3
4
5
6
function ParsePostVimeo($string){
	$regexstr = <<REGEX FROM ABOVE>>;
	$iframestr = ' <p><iframe src="http://player.vimeo.com/video/$1?title=0&amp;byline=0&amp;portrait=0" width="500" height="284" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></iframe></p> ';
 
	return preg_replace($regexstr, $iframestr, $string);
}

For more Regex see Regex YouTube Parser

Posted in Computers, PHP, Programming, Regex Tagged with: , ,

Regex YouTube Parser

Over the next several days I’m going to post a series of Regex strings. These Regex strings can be used to parse input for different links. I’m using PHP in my examples (you may need to tweak the Regex to work in another language).

Today’s Regex is used to parse a string for YouTube links and extract the Video_ID. Once I have the Video_ID I’m able to create a standard embed code from nearly any YouTube URL.

Supported Links:

The following Regex supports these YouTube links and embed code snippets.

Short URL : http://youtu.be/OxWMsxa5uVk
Normal URL: http://www.youtube.com/watch?v=OxWMsxa5uVk&t=28s
HTTPS URL : https://www.youtube.com/watch?v=OxWMsxa5uVk&feature=g-logo
New Embed : <iframe width="560" height="315" src="http://www.youtube.com/
            embed/OxWMsxa5uVk" frameborder="0"
            allowfullscreen></iframe>
Old Embed : <object width="1280" height="720"><param name="movie" 
            value="http://www.youtube.com/v/OxWMsxa5uVk?    
            version=3&hl=en_US&rel=0"></param>
            <param name="allowFullScreen" value="true"></param>
            <param name="allowscriptaccess" 
            value="always"></param><embed 
            src="http://www.youtube.com/v/OxWMsxa5uVk?version=3&
            hl=en_US&rel=0" type="application/x-shockwave-flash" 
            width="1280" height="720" allowscriptaccess="always" 
            allowfullscreen="true"> </embed></object>

I won’t spend a lot of time explaining the Regex because I’ve broken it up Regex and commented each line.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
$regexstr = '~
# Match Youtube link and embed code
(?:				 # Group to match embed codes
   (?:<iframe [^>]*src=")?	 # If iframe match up to first quote of src
   |(?:				 # Group to match if older embed
      (?:<object .*>)?		 # Match opening Object tag
      (?:<param .*</param>)*     # Match all param tags
      (?:<embed [^>]*src=")?     # Match embed tag to the first quote of src
   )?				 # End older embed code group
)?				 # End embed code groups
(?:				 # Group youtube url
   https?:\/\/		         # Either http or https
   (?:[\w]+\.)*		         # Optional subdomains
   (?:               	         # Group host alternatives.
       youtu\.be/      	         # Either youtu.be,
       | youtube\.com		 # or youtube.com 
       | youtube-nocookie\.com	 # or youtube-nocookie.com
   )				 # End Host Group
   (?:\S*[^\w\-\s])?       	 # Extra stuff up to VIDEO_ID
   ([\w\-]{11})		         # $1: VIDEO_ID is numeric
   [^\s]*			 # Not a space
)				 # End group
"?				 # Match end quote if part of src
(?:[^>]*>)?			 # Match any extra stuff up to close brace
(?:				 # Group to match last embed code
   </iframe>		         # Match the end of the iframe	
   |</embed></object>	         # or Match the end of the older embed
)?				 # End Group of last bit of embed code
~ix';

Usage Example:

This example function takes an input string and uses the above Regex to parse off the Video_ID ($1) and add it to $iframestr to create a standard embed code.

1
2
3
4
5
6
function ParsePostYouTube($string){
  $regexstr = <<REGEX FROM ABOVE>>;
  $iframestr = ' <p><iframe width="500" height="284" src="http://www.youtube.com/embed/$1?wmode=transparent" frameborder="0" allowfullscreen></iframe></p> ';
 
  return preg_replace($regexstr, $iframestr, $string);
}
Posted in Computers, PHP, Programming, Regex Tagged with: , ,

JQuery DataTable Birthday Sort

I’m working on a project that uses DataTables a JQuery plug-in that turns ordinary table into dynamic tables. One of the columns includes a list of birthdays. We didn’t want the standard date sorting. We wanted the birthdays to sort primarily by month. Below you will see the custom sort algorithm I came up with to sort our birthdays.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function sortdatatable(a,b){
	//a is blank return 1 to sort after b
	if(a == '') return 1;
	//b is blank return 0 no change
	if(b == '') return 0;
 
	//Split dates on / 
	//format expected is mm/dd/yyyy
	//array 0 is month
	//array 1 is day
	//array 1 is year
	var x = a.split('/'), y = b.split('/');
 
	//Parse month strings to int for comparison
	var xInt = parseInt(x[0]), yInt = parseInt(y[0]);
 
	//If months are the same check days.
	if(xInt == yInt){
		//Parse day strings to int for comparison
		var x1Int =parseInt(x[1]), y1Int = parseInt(y[1]);
 
		//if days are the same check years
		if(x1Int == y1Int){
			//Parse day strings to int for comparison
			var x2Int = parseInt(x[2]), y2Int = parseInt(y[2]);
 
			//if years are the same return 0.
			//if xInt is smaller than yInt return 1 to sort after y else return -1 
			return x2Int == y2Int ? 0 : x2Int < y2Int ? 1 : -1;
		} else {
			//if xInt is smaller than yInt return 1 to sort after y else return -1 
			return x1Int < y1Int ? 1 : -1;
		}
	} else {
		//if xInt is smaller than yInt return 1 to sort after y else return -1 
		return xInt < yInt ? 1 : -1;
	}
}
 
jQuery.fn.dataTableExt.oSort['birthday-asc'] = function(a, b) {
	return -(sortdatatable(a,b));
};
 
jQuery.fn.dataTableExt.oSort['birthday-desc'] = function(a, b) {
	return sortdatatable(a,b);
};

The meat of the sorting is the sortdatatable function. The algorithm sorts according to descending order. We compare the months first. If the months are the same we compare days and if the days are the same we compare years. If months, days, and years are all the same we return 0 to leave those two items in the same order.

The ascending and descending algorithms are the inverse of each other. So to save space in the JavaScript file we use the same function and return the -(sortdatatable(a,b)) for the ascending sort.

Posted in JavaScript, JQuery, Programming Tagged with: , ,

Silverlight Binding Linear Order

I stumbled across this Silverlight “feature” today. Silverlight’s binding works in a linear order.

1
<ComboBox SelectedValue="{Binding SelectedHour, Mode=TwoWay}" ItemsSource="{Binding Hours}" />

In the above code, selected value isn’t being set on page load. When I change the ComboBox my SelectedHour ViewModel property was being updated with a new value. This let me know that my binding is working. In further debugging I noticed SelectedHour property was being accessed before the Hours property. The binding was trying to set the selected value but the ComboBox was ignoring it because it didn’t have any values. For fun I tired moving ItemSource binding in front of the SelectedValue binding.

1
<ComboBox ItemsSource="{Binding Hours}" SelectedValue="{Binding SelectedHour, Mode=TwoWay}" />

Everything started working perfectly. Now I know to watch the order of my XAML properties in Silverlight.

Posted in Programming, Silverlight Tagged with: , ,

PHP Date in Human Readable Format

I’m working on a PHP project that requires human readable, relative date formatting. Below is the PHP function I’m using. The function handles past and future dates.

Sample Future Output :

  • 30 seconds to go
  • 1 minute to go
  • 5 hours to go
  • Tomorrow at 2:25pm
  • June 30, 2022 5:34pm

Sample Past Output :

  • 0 seconds ago
  • 32 minutes ago
  • 20 hours ago
  • Yesterday at 5:26pm
  • Monday at 10:28am
  • June 25 at 5:23am
  • March 30, 2010 at 5:34pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
public function FormatTime($timestamp)
{
	// Get time difference and setup arrays
	$difference = time() - $timestamp;
	$periods = array("second", "minute", "hour", "day", "week", "month", "years");
	$lengths = array("60","60","24","7","4.35","12");
 
	// Past or present
	if ($difference >= 0) 
	{
		$ending = "ago";
	}
	else
	{
		$difference = -$difference;
		$ending = "to go";
	}
 
	// Figure out difference by looping while less than array length
	// and difference is larger than lengths.
	$arr_len = count($lengths);
	for($j = 0; $j < $arr_len && $difference >= $lengths[$j]; $j++)
	{
		$difference /= $lengths[$j];
	}
 
	// Round up		
	$difference = round($difference);
 
	// Make plural if needed
	if($difference != 1) 
	{
		$periods[$j].= "s";
	}
 
	// Default format
	$text = "$difference $periods[$j] $ending";
 
	// over 24 hours
	if($j > 2)
	{
		// future date over a day formate with year
		if($ending == "to go")
		{
			if($j == 3 && $difference == 1)
			{
				$text = "Tomorrow at ". date("g:i a", $timestamp);
			}
			else
			{
				$text = date("F j, Y \a\\t g:i a", $timestamp);
			}
			return $text;
		}
 
		if($j == 3 && $difference == 1) // Yesterday
		{
			$text = "Yesterday at ". date("g:i a", $timestamp);
		}
		else if($j == 3) // Less than a week display -- Monday at 5:28pm
		{
			$text = date("l \a\\t g:i a", $timestamp);
		}
		else if($j < 6 && !($j == 5 && $difference == 12)) // Less than a year display -- June 25 at 5:23am
		{
			$text = date("F j \a\\t g:i a", $timestamp);
		}
		else // if over a year or the same month one year ago -- June 30, 2010 at 5:34pm
		{
			$text = date("F j, Y \a\\t g:i a", $timestamp);
		}
	}
 
	return $text;
}
Posted in Computers, Programming Tagged with: ,