I’VE DECIDED TO LOOK AT GARDENING

Standard

I’ve never had a particularly green thumb or even the inclination to play in the dirt. The idea of growing my own food however is appealing. At the high level you dig up some dirt, drop in some seeds, add water and bada-bing bada-boom food right? I always understood the premise but I have been skeptical about how much actual food you could produce from a normal sized garden. Some articles would have you believe that you can “Feed a family of 4” with a small backyard garden. I noticed that they never seem to say for how long though. A day? Week? Months?

2015-04-18 (1)


So being the prudent and responsible person that I am decided to jump right in with both feet! After all, easing in is for the uncommitted right? I’m fond of saying, “Everything’s simple, if you know how”, and this seems no different. Now that I had a goal I wanted to get started. I decided on a raised bed garden. Mostly so I could control the soil and partially because it means I get to make something. A couple of treated 2 x 12’s and some screws later and I’ve got me a genuine wooden rectangle.

The next step was to fill it with some dirt. We purchased various bags of organic garden soil and filled it up to about an inch or so from the top. Add in a dash of Perilite for soil compaction and good measure and we were ready to start planting.  If you’re wondering about the squares, they were created with jute twine.  What appears at first to be a geometry fetish is actually a system for laying out what you will plant.  Growing up, I had only seen gardens planted in rows.  My wife however advised me to get with the times and educated me on some alternatives.

All that’s left is for her to meticulously plan out which seeds go where while I sprinkle them around haphazardly to her dismay! (Kidding… mostly)

M44 Mosin Nagant Rubber Recoil Butt Pad

Standard

I have always enjoyed shooting the Mosin Nagant since that first time I shot one. Yes, the recoil packed a decent punch, but never in a way that I minded too much. I knew however that the recoil would probably put some people off, my wife included. One day by chance I happened to stumble upon the M44 Mosin Nagant Rubber Recoil Butt Pad.

M44 Mosin Nagant Rubber Recoil Butt Pad

Eventually I decided to take a chance on it, after all it was under $10.  The one downside to this is that it smells when you first get it.  I’m not sensitive to smells in general but the room I opened this in smelled like rubber for an hour or more, even after I had taken it to the garage.  The only remedy for it is time to air out.

20150129_220324

Installation was easy.  I actually installed mine at the range a few moments before shooting with just the flat head tool on my Leatherman.  The difference was immediately noticeable.  Even with heavier loads the recoil was tamed considerably.  My wife found the rifle enjoyable to shoot and our friend who also owns a Mosin was so impressed that he ordered one from his phone on the spot!  Everyone that tried it agreed that it really made the Mosin feel like a different gun.

I have read that some people will drill out the rubber circles in order to give the pad more flex.  I noted however that many people did this before trying it out unmodified first.  I would recommend at least trying it out to see if makes enough difference before you drill out the center.  If I could only pick one modification for the Mosin this would be it.  If you have one these rifles you are doing yourself a disservice by not attaching one of these beauties!

Drawing a heart using Path in WPF / WinRT

Standard

While writing a shape matching app for my daughter I’ve been generating several different shapes. While most were straightforward, creating a heart took a little bit of work and research that I thought I would share to possibly save someone time in the future.

<Canvas>
    <Path Stroke="Red" StrokeThickness="3" 
        Data="M 241,200 
              A 20,20 0 0 0 200,240
              C 210,250 240,270 240,270
              C 240,270 260,260 280,240
              A 20,20 0 0 0 239,200
              " />
</Canvas>

This is making use of 2 arcs and 2 Bezier curves.
M – moves start position to designated location (x, y)
A – specify line size & draw an arc from current to a new position
C – draw cubic Bezier to X, with control points at Y and Z

There are a few different mathematical equations for drawing a heart shape including the following:

x = 16sin^3(t)
y = 13cos(t) - 5cos(2t) - 2cos(3t) - cos(4t)

and 

((x^2 + y^2 - 1)^3) - (x^2 * y^3) = 0

Hopefully this saves you some time if you are trying to draw a heart!  Good coding!

WPF – Advanced Animation Effects

Standard

When designing an application there are many reasons to use an Animation Effect to an element in order to draw attention to it. My specific implementation was for monitoring application but the effects can be leveraged in many scenarios. Here are 5 common variations of requested animation effects.

GIF Example of Output

The XAML

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" x:Class="MainWindow"
    Title="MainWindow" Height="450" Width="250">
    <Window.Resources>

        <!-- Marching Ants -->
        <Storyboard x:Key="MarchingAnts">
                <DoubleAnimation BeginTime="00:00:00"
                                Storyboard.TargetName="AlertBox"
                                Storyboard.TargetProperty="StrokeThickness"
                                To="4"
                                Duration="0:0:0.25" />
                           <!-- If you want to run counter-clockwise, just swap the 'From' and 'To' values. -->
                <DoubleAnimation BeginTime="00:00:00" RepeatBehavior="Forever" Storyboard.TargetName="AlertBox" Storyboard.TargetProperty="StrokeDashOffset" 
                                Duration="0:3:0" From="1000" To="0"/>
        </Storyboard>

        <!-- Pulse -->
        <Storyboard x:Key="Pulse" RepeatBehavior="Forever">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="PulseBox">
                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1.15"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="PulseBox">
                <EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="1.15"/>
                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

        <!-- Flipper -->
        <Storyboard x:Key="Flipper" RepeatBehavior="Forever">
            <PointAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)" Storyboard.TargetName="FlipperBox">
                <EasingPointKeyFrame KeyTime="0:0:1" Value="0.5,0.5"/>
                <EasingPointKeyFrame KeyTime="0:0:2" Value="0.5,0.5"/>
            </PointAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="FlipperBox">
                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="-1"/>
                <EasingDoubleKeyFrame KeyTime="0:0:2" Value="1"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>


        <!-- Elasic Lines -->
        <Storyboard x:Key="ElasticLines" RepeatBehavior="Forever" AutoReverse="True">
            <PointAnimationUsingKeyFrames Storyboard.TargetProperty="(Shape.Fill).(LinearGradientBrush.EndPoint)" Storyboard.TargetName="ElasticBox">
                <EasingPointKeyFrame KeyTime="0:0:4" Value="12,8"/>
            </PointAnimationUsingKeyFrames>
        </Storyboard>

        <!-- Knight Rider -->
        <Storyboard x:Key="KnightRider" RepeatBehavior="Forever" AutoReverse="True">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="KRBox">
                <EasingDoubleKeyFrame KeyTime="0:0:1" Value="-50"/>
                <EasingDoubleKeyFrame KeyTime="0:0:2" Value="50"/>
                <EasingDoubleKeyFrame KeyTime="0:0:3" Value="0"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>

    </Window.Resources>
    <Window.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard Storyboard="{StaticResource Pulse}"/>
            <BeginStoryboard Storyboard="{StaticResource MarchingAnts}"/>
            <BeginStoryboard Storyboard="{StaticResource Flipper}"/>
            <BeginStoryboard Storyboard="{StaticResource ElasticLines}"/>
            <BeginStoryboard Storyboard="{StaticResource KnightRider}"/>
        </EventTrigger>
    </Window.Triggers>

    <Grid HorizontalAlignment="Center" VerticalAlignment="Center">
        <Grid.Resources>
            <Style TargetType="{x:Type TextBlock}">
                <Setter Property="Foreground" Value="White"/>
                <Setter Property="FontWeight" Value="Bold"/>
                <Setter Property="FontSize" Value="35"/>
                <Setter Property="HorizontalAlignment" Value="Center"/>
                <Setter Property="VerticalAlignment" Value="Center"/>
                <Setter Property="Text" Value="ALERT"/>
            </Style>
            <Style TargetType="{x:Type Grid}">
                <Setter Property="Margin" Value="0,10"/>                
            </Style>
            <Style TargetType="{x:Type Rectangle}">
                <Setter Property="Height" Value="50"/>
                <Setter Property="Width" Value="150"/>
            </Style>
        </Grid.Resources>

        <StackPanel>

        <!-- Marching Ants -->
        <Grid>

            <Rectangle x:Name="AlertBox"
                      Stroke="Red" 
                       StrokeDashOffset="2" StrokeDashArray="5" Margin="5">
                <Rectangle.Fill>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="6,4" MappingMode="Absolute" SpreadMethod="Repeat">
                        <GradientStop Color="Red" Offset="0.25"/>
                        <GradientStop Color="#00000000" Offset="0.15"/>
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>

            <TextBlock/>

        </Grid>
        <!-- End Marching Ants -->


        <!-- Pulse : Will not skew other elements location like width/height animations would. -->
        <Grid>
            <Border x:Name="PulseBox"
                        Background="Red" RenderTransformOrigin="0.5,0.5">
                <Border.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform/>
                        <TranslateTransform/>
                    </TransformGroup>
                </Border.RenderTransform>

                <TextBlock/>

            </Border>
        </Grid>
        <!-- End Pulse -->


        <!-- Flipper -->
        <Grid>
            <Border x:Name="FlipperBox"
                        Background="Red">
                <Border.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform/>
                        <TranslateTransform/>
                    </TransformGroup>
                </Border.RenderTransform>

                <TextBlock/>

            </Border>
        </Grid>
        <!-- End Flipper -->


        <!-- Elastic Lines -->
        <Grid>
            <Rectangle x:Name="ElasticBox"
                      Stroke="Red" StrokeThickness="5" Margin="5">
                <Rectangle.Fill>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="6,4" MappingMode="Absolute" SpreadMethod="Repeat">
                        <GradientStop Color="Red" Offset="0.25"/>
                        <GradientStop Color="#00000000" Offset="0.15"/>
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>

            <TextBlock/>

        </Grid>
        <!-- End Elastic Box -->


        <!-- Knight Rider -->
        <Grid>
            <Rectangle Fill="Red"/>
            <Rectangle x:Name="KRBox" Width="50" Fill="White" RenderTransformOrigin="0.5,0.5">
                <Rectangle.RenderTransform>
                    <TransformGroup>
                        <ScaleTransform/>
                        <SkewTransform/>
                        <RotateTransform/>
                        <TranslateTransform/>
                    </TransformGroup>
                </Rectangle.RenderTransform>
            </Rectangle>

            <TextBlock Foreground="Red"/>

        </Grid>
        <!-- End Knight Rider -->

        </StackPanel>

    </Grid>
</Window>

Hopefully this helps you with your animation needs!

ANOTHER REASON AMAZON IS AWESOME!

Standard

While browsing Amazon about a week ago I noticed a spotlight ad for Amazon’s newest device Echo.  After running through the marketing material I was pretty impressed and ready to give one a try.  That’s when I saw it.  “Sign up to request and invite and If selected, you will receive an e-mail with an invitation to purchase in the coming weeks.”  Needless to say the marketing worked, now I really wanted one!  Fast forward to today where I again find myself pining over the Echo and looking for a way to coerce an invite.

Being in a playful mood I crafted the following email and sent it to Echo Customer Service Team.

“Greetings follower of the Amazon,I have been enraptured by the whisperings of the blessing of Echo.  What
sacrifice dost thou demand that I might receive an invite to partake of
such bounty?  I have virgins ready to push into volcanoes, forsake me not!Your loyal follower,Joshua of the clan Terry”

Must to my surprise a few hours later I received one of the best responses to one of my emails to date.  Just in case you needed one more reason that Amazon is awesome I submit the following reply.

“Warmest greetings Joshua of the clan Terry,I am Katie McCloud of the Clan McCloud.Echo surely is a blessing, as we require no sacrifice for thou to request an invitation to experience its wondrous bounty. I beg of thee to follow the link below to request thine invitation to join our throng of loyal Echo followers. https://www.amazon.com/echo I do preach patience, my son! We expect to begin sending invitations in the weeks to come. Alas, I have no information on how the mighty few that will be bestowed the honor of receiving an Echo will be chosen.Thanks be to thee for thy never ending fealty.”

Katie, where ever your at thanks for making my day!

IEditableObject and Restoring Text After Cancelling Changes

Standard

It’s a common scenario, the user starts to edit something and then changes their mind. What happens in an application with Two-Way binding? As soon as the user began to type you began persisting the data, in effect there is no going back.

Cue IEditableObject to the rescue!

The answer is to implement the IEditableObject interface on your class. The interface defines 3 void methods: BeginEdit(), CancelEdit(), & EndEdit().

In the BeginEdit() we set the editing mode to true and make a copy of the original value. If you were dealing with more than one field, I recommend getting a copy of your object using MemberwiseClone, unless your class includes reference types in which case you will want to make a deep copy instead.

public void BeginEdit()
{
     IsEditing = true;
     // Save a copy of the original value
     originalmessage = this.Messages;
}

public void CancelEdit()
{
      // Put the original value back
      this.Messages = originalmessage;
      IsEditing = false;
}

public void EndEdit()
{
      IsEditing = false;
      // Save the current value of the field
      repository.SaveMessages(this.Messages); 
}