<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Chui&#039;s Counterpoint</title>
	<atom:link href="http://www.redmountainsw.com/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.redmountainsw.com/wordpress</link>
	<description>Just another Red Mountain Software Sites site</description>
	<lastBuildDate>Sun, 17 Mar 2013 00:32:05 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>How to call a XML Service without adding Service Reference</title>
		<link>http://www.redmountainsw.com/wordpress/2013/03/08/how-to-call-a-xml-service-without-adding-service-reference/</link>
		<comments>http://www.redmountainsw.com/wordpress/2013/03/08/how-to-call-a-xml-service-without-adding-service-reference/#comments</comments>
		<pubDate>Fri, 08 Mar 2013 13:32:06 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1666</guid>
		<description><![CDATA[string url = &#34;http://etcetcetc&#34;; HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create(new Uri(url)); HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); XmlDocument doc = new XmlDocument(); doc.Load(resp.GetResponseStream()); var totals = doc.SelectSingleNode(&#34;/root/eventFundraisingTotals_collection/eventFundraisingTotals&#34;); var verifiedGoal = totals.SelectSingleNode(&#34;eventVerifiedFundraisingGoal/text()&#34;).Value; var unverifiedGoal = totals.SelectSingleNode(&#34;eventUnVerifiedFundraisingGoal/text()&#34;).Value; var statusMessage = totals.SelectSingleNode(&#34;statusMessage/text()&#34;).Value;]]></description>
				<content:encoded><![CDATA[<pre class="brush: c#">
string url = &quot;http://etcetcetc&quot;;
HttpWebRequest req = (HttpWebRequest) HttpWebRequest.Create(new Uri(url));
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();

XmlDocument doc = new XmlDocument();
doc.Load(resp.GetResponseStream());
var totals = doc.SelectSingleNode(&quot;/root/eventFundraisingTotals_collection/eventFundraisingTotals&quot;);
var verifiedGoal = totals.SelectSingleNode(&quot;eventVerifiedFundraisingGoal/text()&quot;).Value;
var unverifiedGoal = totals.SelectSingleNode(&quot;eventUnVerifiedFundraisingGoal/text()&quot;).Value;
var statusMessage = totals.SelectSingleNode(&quot;statusMessage/text()&quot;).Value;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2013/03/08/how-to-call-a-xml-service-without-adding-service-reference/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight Links</title>
		<link>http://www.redmountainsw.com/wordpress/2013/03/04/silverlight-links/</link>
		<comments>http://www.redmountainsw.com/wordpress/2013/03/04/silverlight-links/#comments</comments>
		<pubDate>Mon, 04 Mar 2013 21:34:20 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1665</guid>
		<description><![CDATA[Subscribing to Change Notifications without Memory Leaks]]></description>
				<content:encoded><![CDATA[<ul><a href="http://blog.catenalogic.com/post/2013/03/01/Subscribing-to-change-notifications-without-memory-leaks.aspx">Subscribing to Change Notifications without Memory Leaks</a>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2013/03/04/silverlight-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaFX and RxJava</title>
		<link>http://www.redmountainsw.com/wordpress/2013/02/28/javafx-and-rxjava/</link>
		<comments>http://www.redmountainsw.com/wordpress/2013/02/28/javafx-and-rxjava/#comments</comments>
		<pubDate>Thu, 28 Feb 2013 14:07:45 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[javafx]]></category>
		<category><![CDATA[rx]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1659</guid>
		<description><![CDATA[Netflix has released a Java port of .NET&#8217;s Reactive Extensions called RxJava. I&#8217;m new to RxJava although I&#8217;ve played around a little with its .NET counterpart. In a nutshell, reactive programming is a not unlike the traditional days of unix shell scripting where you&#8217;d pipe streams of text from simple primitives to one another. Here [...]]]></description>
				<content:encoded><![CDATA[<p>Netflix has released a Java port of .NET&#8217;s Reactive Extensions called <a href="https://github.com/Netflix/RxJava">RxJava</a>. I&#8217;m new to RxJava although I&#8217;ve played around a little with its .NET counterpart. </p>
<p>In a nutshell, reactive programming is a not unlike the traditional days of unix shell scripting where you&#8217;d pipe streams of text from simple primitives to one another. Here are a couple of examples from the <a href="http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-4.html">Bash Manual</a>.</p>
<pre class="brush: sh">
ls -l | grep &quot;\.txt$&quot;
ls -l | sed -e &quot;s/[aeio]/u/g&quot; 
</pre>
<p>You can also combine two streams into one and then do processing on them.</p>
<pre class="brush: sh">
# Look for ERROR string in both stdout and stderr.
foo 2&gt;&amp;1 | grep ERROR
</pre>
<p>Similarly, if you were doing GUI programming for select objects on a screen, you might wish to implement CTRL+Click as a way to add items to a selection. Doing this using event handlers can lead to a tangle of logic very quickly, especially if CTRL key is also used for other functionality.</p>
<p>Using Reactive programming, you&#8217;d essentially express your logic this way: listen to key down event and filter for CTRL key, then launch a listener for the click event, and after that launch listener for KeyUpEvent. This can be all done in one method, so that the logic stays together.</p>
<pre class="brush: sh">
     cat keyDownEvents | grep -l CTRL | xargs &#039;cat clickEvent&#039; | xargs &#039;cat keyUpEvents | grep -l CTRL&#039;
</pre>
<p>More examples would be forthcoming, but in the meantime, I&#8217;d like to introduce a way to transform an event handler into an observable stream.</p>
<pre class="brush: java">
/* the following defines an observable stream of click events on a button btn  */
/* the button&#039;s event handler is not hooked up until this observable stream is */
/* subscribed by an Observer. (We pass in a routine to hook up the event       */
/* handler just-in-time.                                                       */
Observable&lt;ActionEvent&gt; clickEvents = OperationToObservableEvent.toObservable(new Action1&lt;EventHandler&lt;ActionEvent&gt;&gt;() {
  @Override
  public void call(EventHandler&lt;ActionEvent&gt; eventHandler) {
    btn.setOnAction(eventHandler);
  }
});
</pre>
<p>The syntax is rather ugly without type inference, but I&#8217;d expect Java 8&#8242;s lambdas to improve the readability significantly.</p>
<pre class="brush: java">
/* We subscribe to the stream here. Make sure you call subscription.close()  */
/* when you are done, or the event handler will cause a memory leak.         */
Subscription subscription = clickEvents.subscribe(new Action1&lt;ActionEvent&gt;() {
        @Override
        public void call(ActionEvent t1) {
          System.out.println(&quot;Event Handled&quot; + t1);
        }
      });
</pre>
<p>And here&#8217;s the supporting code:</p>
<pre class="brush: java">
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rx.operators;

import javafx.event.Event;
import javafx.event.EventHandler;
import rx.Observable;
import rx.Observer;
import rx.Subscription;
import rx.util.functions.Action1;
import rx.util.functions.Func1;

/**
 *
 * @author Chui
 */
public class OperationToObservableEvent {

  private static class ToObservableEvent&lt;T extends Event&gt;
          implements Func1&lt;Observer&lt;T&gt;, Subscription&gt;,
          Subscription,
          EventHandler&lt;T&gt; {

    private final Action1&lt;EventHandler&lt;T&gt;&gt; addListener;
    private final Action1&lt;EventHandler&lt;T&gt;&gt; removeListener;
    private Observer&lt;T&gt; observer;

    public ToObservableEvent(
            Action1&lt;EventHandler&lt;T&gt;&gt; addListener,
            Action1&lt;EventHandler&lt;T&gt;&gt; removeListener) {
      this.addListener = addListener;
      this.removeListener = removeListener;
    }

    @Override
    public Subscription call(final Observer&lt;T&gt; observer) {
      this.observer = observer;
      this.addListener.call(this);
      return this;
    }

    @Override
    public void handle(T event) {
      observer.onNext(event);
    }

    @Override
    public void unsubscribe() {
      if (this.removeListener == null)
      {
        // there is no removeEventListener function,
        // so we assume this is a setEventListener,
        // and set it to null
        this.addListener.call(null);
      }
      else
      {
        this.removeListener.call(this);
      }
    }
  }
  
  /**
   * Returns an observable stream of events. 
   * @param &lt;T&gt; the type of events in the stream
   * @param setListener a callback to hook up an event handler when an Observer subscribes to the stream.
   * @return an Observable stream of events of type T
   */
  public static &lt;T extends Event&gt; Observable&lt;T&gt; toObservable(
          Action1&lt;EventHandler&lt;T&gt;&gt; setListener)
  {
    return Observable.create(toObservableEvent(setListener, null));
  }
  
  /**
   * 
   * @param &lt;T&gt; the type of events in the stream
   * @param addListener a callback to hook up event handler when an Observer subscribes to the stream
   * @param removeListener a callback to unhook the event handler when the subscription is done
   * @return an Observable stream of events of type T
   */
  public static &lt;T extends Event&gt; Observable&lt;T&gt; toObservable(
          Action1&lt;EventHandler&lt;T&gt;&gt; addListener,
          Action1&lt;EventHandler&lt;T&gt;&gt; removeListener)
  {
    return Observable.create(toObservableEvent(addListener, removeListener));
  }
  
  /**
   * This is an internal routine.
   * @param &lt;T&gt;
   * @param addListener
   * @param removeListener
   * @return 
   */
  public static &lt;T extends Event&gt; Func1&lt;Observer&lt;T&gt;, Subscription&gt; toObservableEvent(
          Action1&lt;EventHandler&lt;T&gt;&gt; addListener,
          Action1&lt;EventHandler&lt;T&gt;&gt; removeListener)
  {
    return new ToObservableEvent(addListener, removeListener);
  }
}
</pre>
<pre class="brush: java">
/*
 * CompositeDisposable is a port of the .NET equivalent
 * Add any subscriptions to a CompositeDisposable, and when 
 * the unsubscribe() is called, all the subscriptions will
 * be unsubscribed at the same time.
 */
package rx.disposables;

import java.util.ArrayList;
import rx.Subscription;

public class CompositeDisposable extends ArrayList&lt;Subscription&gt; 
  implements Subscription, AutoCloseable
{

  @Override
  public void unsubscribe() {
    for(Subscription item: this)
    {
      item.unsubscribe();
    }
  }

  @Override
  public void close() {
    this.unsubscribe();
  }
  
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2013/02/28/javafx-and-rxjava/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding Global Behaviors to Silverlight Controls</title>
		<link>http://www.redmountainsw.com/wordpress/2013/02/26/adding-global-behaviors-to-silverlight-controls/</link>
		<comments>http://www.redmountainsw.com/wordpress/2013/02/26/adding-global-behaviors-to-silverlight-controls/#comments</comments>
		<pubDate>Tue, 26 Feb 2013 13:20:11 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1638</guid>
		<description><![CDATA[Take a look at the two buttons below, and hover your mouse over them. You&#8217;ll notice that the buttons hide themselves. However, when you take a look at the XAML, it is not obvious how this is implemented. &#60;UserControl x:Class=&#34;GlobalBehavior.MainPage&#34; xmlns=&#34;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#34; xmlns:x=&#34;http://schemas.microsoft.com/winfx/2006/xaml&#34; xmlns:d=&#34;http://schemas.microsoft.com/expression/blend/2008&#34; xmlns:mc=&#34;http://schemas.openxmlformats.org/markup-compatibility/2006&#34; xmlns:i=&#34;http://schemas.microsoft.com/expression/2010/interactivity&#34; xmlns:local=&#34;clr-namespace:GlobalBehavior&#34; mc:Ignorable=&#34;d&#34; d:DesignHeight=&#34;300&#34; d:DesignWidth=&#34;400&#34;&#62; &#60;Grid x:Name=&#34;LayoutRoot&#34; Background=&#34;White&#34;&#62; &#60;Button Content=&#34;Click Me&#34; [...]]]></description>
				<content:encoded><![CDATA[<p>Take a look at the two buttons below, and hover your mouse over them. You&#8217;ll notice that the buttons hide themselves.</p>
<p><script type="text/javascript" src="/wordpress/files/2013/02/Silverlight.js"></script></p>
<div id="silverlightControlHost" style="width:400px; height:160px">
        <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"><param name="source" value="/wordpress/files/2013/02/GlobalBehavior.xap"/><param name="onError" value="onSilverlightError" /><param name="background" value="white" /><param name="minRuntimeVersion" value="5.0.61118.0" /><param name="autoUpgrade" value="true" /><a href="http://go.microsoft.com/fwlink/?LinkID=149156&#038;v=5.0.61118.0" style="text-decoration:none"><br />
 			  <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="Get Microsoft Silverlight" style="border-style:none"/><br />
		  </a><br />
	    </object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
<p>However, when you take a look at the XAML, it is not obvious how this is implemented.</p>
<pre class="brush: xml">
&lt;UserControl x:Class=&quot;GlobalBehavior.MainPage&quot;
    xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
    xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
    xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
    xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
    xmlns:i=&quot;http://schemas.microsoft.com/expression/2010/interactivity&quot;
    xmlns:local=&quot;clr-namespace:GlobalBehavior&quot;
    mc:Ignorable=&quot;d&quot;             
    d:DesignHeight=&quot;300&quot; d:DesignWidth=&quot;400&quot;&gt;

    &lt;Grid x:Name=&quot;LayoutRoot&quot; Background=&quot;White&quot;&gt;
        
        &lt;Button Content=&quot;Click Me&quot; Margin=&quot;36,28,0,0&quot; HorizontalAlignment=&quot;Left&quot; Width=&quot;112&quot; Height=&quot;47&quot; VerticalAlignment=&quot;Top&quot; /&gt;
        &lt;Button Content=&quot;Click Me&quot; Margin=&quot;133,104,0,0&quot; HorizontalAlignment=&quot;Left&quot; Width=&quot;112&quot; Height=&quot;47&quot; VerticalAlignment=&quot;Top&quot; /&gt;

    &lt;/Grid&gt;
&lt;/UserControl&gt;
</pre>
<p>This is done by attaching a behavior to the default Button style. There is a little wrinkle to the trick. The style setters by default is not able to set complex attached dependency properties. However, it can handle simple dependency properties. So, we&#8217;d write a simple depedency property that can be attached like this:</p>
<pre class="brush: xml">

        &lt;Style TargetType=&quot;Button&quot;&gt;
            &lt;Setter Property=&quot;local:HideButtonBehavior.ButtonBehaviors&quot; Value=&quot;True&quot; /&gt;
        &lt;/Style&gt;

</pre>
<p>and the ButtonBehaviors dependency property sets the actual Behaviors on the button.</p>
<pre class="brush: c#">
namespace GlobalBehavior
{
    using System;
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Interactivity;
    using System.Windows.Media;
    using System.Windows.Media.Animation;

    public partial class HideButtonBehavior : Behavior&lt;FrameworkElement&gt;
    {        
        #region HideButtonBehavior.ButtonBehaviors depedency property

        public static bool GetButtonBehaviors(DependencyObject obj)
        {
            return (bool)obj.GetValue(ButtonBehaviorsProperty);
        }

        public static void SetButtonBehaviors(DependencyObject obj, bool value)
        {
            obj.SetValue(ButtonBehaviorsProperty, value);
        }

        // Using a DependencyProperty as the backing store for ButtonBehaviors. 
        public static readonly DependencyProperty ButtonBehaviorsProperty =
            DependencyProperty.RegisterAttached(&quot;ButtonBehaviors&quot;,
            typeof(bool), typeof(Button), new PropertyMetadata(false, ButtonBehaviorsChanged));

        private static void ButtonBehaviorsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var behaviors = Interaction.GetBehaviors(d);
            var existingBehavior = behaviors.FirstOrDefault(b =&gt; b.GetType() ==
              typeof(HideButtonBehavior)) as HideButtonBehavior;
            if ((bool)e.NewValue == false &amp;amp;&amp;amp; existingBehavior != null)
            {
                behaviors.Remove(existingBehavior);
            }
            else if ((bool)e.NewValue == true &amp;amp;&amp;amp; existingBehavior == null)
            {
                /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
                /* !!! THE REST ARE ALL BOILERPLATE. THE REAL GOODNESS IS HERE !!! */
                behaviors.Add(new HideButtonBehavior());
                /* !!!                                                         !!! */
                /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! */
            }
        }

        #endregion

    }
}
</pre>
<p>and for completeness, here&#8217;s the code for the silly Button behavior.</p>
<pre class="brush: c#">
namespace GlobalBehavior
{
    using System;
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Input;
    using System.Windows.Interactivity;
    using System.Windows.Media;
    using System.Windows.Media.Animation;

    public partial class HideButtonBehavior : Behavior&lt;FrameworkElement&gt;
    {
        #region Custom Button Behavior

        protected override void OnAttached()
        {
            base.OnAttached();
            Button button = this.AssociatedObject as Button;
            button.RenderTransform = new ScaleTransform();
            button.MouseMove += button_MouseMove;
        }

        protected override void OnDetaching()
        {
            Button button = this.AssociatedObject as Button;
            button.MouseMove -= button_MouseMove;
            base.OnDetaching();
        }

        void button_MouseMove(object sender, MouseEventArgs e)
        {
            DoubleAnimationUsingKeyFrames anim = new DoubleAnimationUsingKeyFrames();
            anim.KeyFrames.Add(new LinearDoubleKeyFrame() { Value = 0.0, KeyTime = TimeSpan.FromMilliseconds(150) });
            anim.KeyFrames.Add(new LinearDoubleKeyFrame() { Value = 0.0, KeyTime = TimeSpan.FromMilliseconds(2000) });
            anim.KeyFrames.Add(new LinearDoubleKeyFrame() { Value = 1.0, KeyTime = TimeSpan.FromMilliseconds(2150) });

            Storyboard.SetTarget(anim, this.AssociatedObject);
            Storyboard.SetTargetProperty(anim, new PropertyPath(&quot;(UIElement.RenderTransform).(ScaleTransform.ScaleY)&quot;));

            Storyboard sb = new Storyboard();
            sb.Children.Add(anim);
            sb.Begin();
        }
        #endregion

    }
}
</pre>
<h2>Acknowledgements</h2>
<p>This technique is first discovered by <a href="http://julmar.com/blog/mark/?p=20">julmar</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2013/02/26/adding-global-behaviors-to-silverlight-controls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reactive Extensions Pop Up Toaster</title>
		<link>http://www.redmountainsw.com/wordpress/2013/02/24/reactive-extensions-pop-up-toaster/</link>
		<comments>http://www.redmountainsw.com/wordpress/2013/02/24/reactive-extensions-pop-up-toaster/#comments</comments>
		<pubDate>Sun, 24 Feb 2013 04:50:44 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Engineering notes]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[reactive]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1630</guid>
		<description><![CDATA[I&#8217;m experimenting with RX, and this is an early attempt at expressing the following logic. Start to slide the toaster into view, then fade it out, and remove the toaster from visual tree If a mouse enters the toaster, then pause the sliding, and pause the fading out, and fade it in. Also, wait for [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;m experimenting with RX, and this is an early attempt at expressing the following logic.</p>
<ul>
<li>Start to slide the toaster into view,  then fade it out, and remove the toaster from visual tree</li>
<li>If a mouse enters the toaster, then pause the sliding, and pause the fading out, and fade it in. Also, wait for mouse to leave</li>
<li>When mouse leaves, resume sliding toaster, and fade out the toaster.</li>
</ul>
<pre class="brush: c#">
        private void rxPop()
        {
            Rectangle toaster = (Rectangle)this.FindName(&quot;toaster1&quot;);
            Thickness newToasterPosition = new Thickness(
                 toaster.Margin.Left, toaster.Margin.Top,
                 toaster.Margin.Right, toaster.Margin.Bottom + toaster.Height);

            /* Animations */
            Storyboard slideInAnimation = slideTo(toaster,
                newToasterPosition,
                TimeSpan.FromMilliseconds(450));

            Storyboard fadeInAnimation = animateOpacity(toaster, 1.0, TimeSpan.FromMilliseconds(150));

            Storyboard fadeOutAnimation = animateOpacity(toaster, 0.0, TimeSpan.FromSeconds(3));
            
            /* Events */
            var mouseEnter = Observable.FromEventPattern&lt;MouseEventHandler, MouseEventArgs&gt;
                (h =&gt; toaster.MouseEnter += h,
                 h =&gt; toaster.MouseEnter -= h);

            var mouseOut = Observable.FromEventPattern&lt;MouseEventHandler, MouseEventArgs&gt;
                (h =&gt; toaster.MouseLeave += h,
                 h =&gt; toaster.MouseLeave -= h);            

            /* Business logic: mouseEnter/mouseLeave should pause/restart animations */
            var mouseEnterSubscription = mouseEnter
                .ObserveOnDispatcher()
                .Do(mouseEnterEventArgs =&gt;
                {
                    fadeOutAnimation.Pause();
                    fadeInAnimation.Begin();
                    slideInAnimation.Pause();
                })
                .Select(e =&gt; mouseOut)
                .Switch()
                .Do(mouseLeaveEventArgs =&gt;
                {
                    fadeOutAnimation.Begin();
                    fadeInAnimation.Stop();
                    slideInAnimation.Resume();
                })
                .Subscribe();

            /* Business logic: slideIn then fadeOut then remove from visual tree */
            slideInAnimation
                .BeginUntilDone()
                .Select(slideInCompletedEvent =&gt;
                    fadeOutAnimation.BeginUntilDone())
                .Switch()
                .Subscribe(fadeOutAnimationCompletedEvent =&gt;
                {
                    mouseEnterSubscription.Dispose();

                    // remove from visual tree
                    (toaster.Parent as Panel).Children.Remove(toaster);
                });

        }

        private Storyboard slideTo(FrameworkElement toaster, Thickness newMargin, TimeSpan duration)
        {
            DoubleAnimation slide = new DoubleAnimation()
            {
                From = newMargin.Bottom - toaster.Margin.Bottom,
                To = 0.0,
                Duration = duration,
            };
            toaster.Margin = newMargin;
            Storyboard.SetTarget(slide, toaster);
            Storyboard.SetTargetProperty(slide,
                new PropertyPath(&quot;(UIElement.RenderTransform).(TranslateTransform.Y)&quot;));
            Storyboard slideboard = new Storyboard();
            slideboard.Children.Add(slide);
            return slideboard;
        }

        private Storyboard animateOpacity(FrameworkElement toaster, double target, TimeSpan duration)
        {
            DoubleAnimation fade = new DoubleAnimation()
            {
                To = target,
                Duration = duration,
            };

            Storyboard.SetTarget(fade, toaster);
            Storyboard.SetTargetProperty(fade,
                new PropertyPath(&quot;Opacity&quot;));
            Storyboard slideboard = new Storyboard();
            slideboard.Children.Add(fade);
            return slideboard;
        }

    public static class RxExtensions
    {
        public static IObservable&lt;EventPattern&lt;EventArgs&gt;&gt; BeginUntilDone(this Storyboard sb)
        {
            var tmp = Observable.FromEventPattern(
                h =&gt; sb.Completed += h,
                h =&gt; sb.Completed -= h);
            sb.Begin();
            return tmp;
        }
    }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2013/02/24/reactive-extensions-pop-up-toaster/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Silverlight &#8211; faster compilation by reducing xap file size</title>
		<link>http://www.redmountainsw.com/wordpress/2013/02/23/silverlight-faster-compilation-by-reducing-xap-file-size/</link>
		<comments>http://www.redmountainsw.com/wordpress/2013/02/23/silverlight-faster-compilation-by-reducing-xap-file-size/#comments</comments>
		<pubDate>Sat, 23 Feb 2013 09:06:08 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[silverlight]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1631</guid>
		<description><![CDATA[Suppose we have a Silverlight Solution that has tens of projects. A lot of time is spent building the .xap file. Every time a DLL is touched, the entire solution is re-xapped. To avoid this, we can use Assembly Library Caching. However, this is not always ideal. Each of the projects might be only a [...]]]></description>
				<content:encoded><![CDATA[<p>Suppose we have a Silverlight Solution that has tens of projects. A lot of time is spent building the .xap file. Every time a DLL is touched, the entire solution is re-xapped. </p>
<p>To avoid this, we can use Assembly Library Caching. However, this is not always ideal. Each of the projects might be only a tiny DLL, and it is a lot of work. Each change in version number will require the .extmap.xml be updated. Furthermore, if we don&#8217;t change the version number, we might end up with Silverlight loading an older version, and we end up with &#8220;Symbol not loaded&#8221; in the debugger.</p>
<p>There is an alternative.</p>
<ol>
<li>Since we typically work on one assembly at a time, set all the assemblies we don&#8217;t care about to CopyLocal=False</li>
<li>Then, (optional) in the Configuration Manager, uncheck the &#8220;Build&#8221; option for these DLLs as well. </li>
<li>Next, zip up these DLLs, let&#8217;s call it library.zip. It should not have any directory structure at all e.g.<br />
<code><br />
  mylibrary01.dll<br />
  mylibrary02.dll<br />
</code></li>
<li>Then in the Properties/AppManifest.xml of the main project, add the following entry
<pre class="brush: xml">
&lt;Deployment xmlns=&quot;http://schemas.microsoft.com/client/2007/deployment&quot;
        xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;&gt;
    &lt;Deployment.Parts&gt;
    &lt;/Deployment.Parts&gt;
  &lt;Deployment.ExternalParts&gt;
    &lt;ExtensionPart Source=&quot;library.zip&quot;/&gt;
  &lt;/Deployment.ExternalParts&gt;  
&lt;/Deployment&gt;
</pre>
</li>
<li>You are done.</li>
</ol>
<p>When you start up this project, you&#8217;ll notice that compiling can be very fast, as xapping will skip all the files that have CopyLocal=false.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2013/02/23/silverlight-faster-compilation-by-reducing-xap-file-size/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>In Memory of Aaron Swartz</title>
		<link>http://www.redmountainsw.com/wordpress/2013/01/16/in-memory-of-aaron-swartz/</link>
		<comments>http://www.redmountainsw.com/wordpress/2013/01/16/in-memory-of-aaron-swartz/#comments</comments>
		<pubDate>Wed, 16 Jan 2013 00:28:23 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[General]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1623</guid>
		<description><![CDATA[Russian prosecutors sought 3 years of jail term for this act of political defiance by Pussyriot. Aaron Swartz was threatened with 35.]]></description>
				<content:encoded><![CDATA[<p><iframe width="420" height="315" src="http://www.youtube.com/embed/grEBLskpDWQ" frameborder="0" allowfullscreen></iframe></p>
<p>Russian prosecutors sought 3 years of jail term for this act of political defiance by Pussyriot. Aaron Swartz was threatened with 35.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2013/01/16/in-memory-of-aaron-swartz/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Turning leiningen script into an executable</title>
		<link>http://www.redmountainsw.com/wordpress/2013/01/09/turning-leiningen-script-into-an-executable/</link>
		<comments>http://www.redmountainsw.com/wordpress/2013/01/09/turning-leiningen-script-into-an-executable/#comments</comments>
		<pubDate>Wed, 09 Jan 2013 13:23:04 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[lisp]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1609</guid>
		<description><![CDATA[I used the venerable launch4j to wrap leiningen-standalone jar into an executable. You can get the Windows clojure binaries here. There were a few problems along the way. Clojure reports MethodNotFound Leiningen already contains Clojure 1.2.1. If we intend to run Clojure 1.4, it has to appear on the classpath first. However, when Launch4j wraps [...]]]></description>
				<content:encoded><![CDATA[<p>I used the venerable <a href="http://launch4j.sourceforge.net">launch4j</a> to wrap leiningen-standalone jar into an executable. You can get the <a href="https://dl.dropbox.com/u/8424800/Clojure/index.html">Windows clojure binaries here</a>.</p>
<p>There were a few problems along the way.</p>
<h1>Clojure reports MethodNotFound</h1>
<p>Leiningen already contains Clojure 1.2.1. If we intend to run Clojure 1.4, it has to appear on the classpath first. However, when Launch4j wraps a leiningen-standalone.jar, it is the first file that appears on the classpath. The solution is to specify clojure-1.4.0.jar as the main jar.</p>
<h1>Launch4j couldn&#8217;t find clojure.jar</h1>
<p>The documentation was incorrect. The location of the jar files were <em>incorrectly</em> stated to be relative to the exe file. In practice, the executable directory must be explicitly included. e.g. %EXEDIR%\clojure-1.4.0.jar</p>
<h1>Other tricks</h1>
<p>I was able to wrap clojure.jar into clojure.exe, which performs double-duty as a .jar file. I was able to include clojure.exe into the classpath to save disk space.</p>
<p><a href="http://www.redmountainsw.com/wordpress/2013/01/09/turning-leiningen-script-into-an-executable/launch4j-clojure/" rel="attachment wp-att-1615">Download launch4j-clojure.zip</a></p>
<pre class="brush: xml">
&lt;launch4jConfig&gt;
  &lt;dontWrapJar&gt;true&lt;/dontWrapJar&gt;
  &lt;headerType&gt;console&lt;/headerType&gt;
  &lt;jar&gt;%EXEDIR%\clojure.exe&lt;/jar&gt;
  &lt;outfile&gt;lein.exe&lt;/outfile&gt;
  &lt;errTitle&gt;&lt;/errTitle&gt;
  &lt;cmdLine&gt;clojure.main -e &quot;(use &amp;apos;leiningen.core)(-main)&quot; %@&lt;/cmdLine&gt;
  &lt;chdir&gt;&lt;/chdir&gt;
  &lt;priority&gt;normal&lt;/priority&gt;
  &lt;downloadUrl&gt;http://java.com/download&lt;/downloadUrl&gt;
  &lt;supportUrl&gt;&lt;/supportUrl&gt;
  &lt;customProcName&gt;false&lt;/customProcName&gt;
  &lt;stayAlive&gt;false&lt;/stayAlive&gt;
  &lt;manifest&gt;&lt;/manifest&gt;
  &lt;icon&gt;&lt;/icon&gt;
  &lt;classPath&gt;
    &lt;mainClass&gt;jline.ConsoleRunner&lt;/mainClass&gt;
    &lt;cp&gt;%EXEDIR%\leiningen-1.7.0-standalone.jar&lt;/cp&gt;
  &lt;/classPath&gt;
  &lt;jre&gt;
    &lt;path&gt;&lt;/path&gt;
    &lt;minVersion&gt;1.5.0&lt;/minVersion&gt;
    &lt;maxVersion&gt;&lt;/maxVersion&gt;
    &lt;jdkPreference&gt;preferJre&lt;/jdkPreference&gt;
    &lt;opt&gt;-client &lt;/opt&gt;
    &lt;opt&gt;-XX:+TieredCompilation&lt;/opt&gt;
  &lt;/jre&gt;
&lt;/launch4jConfig&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2013/01/09/turning-leiningen-script-into-an-executable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why can&#8217;t I build python extensions with a different version of Visual Studio?</title>
		<link>http://www.redmountainsw.com/wordpress/2013/01/08/why-cant-i-build-python-extensions-with-a-different-version-of-visual-studio/</link>
		<comments>http://www.redmountainsw.com/wordpress/2013/01/08/why-cant-i-build-python-extensions-with-a-different-version-of-visual-studio/#comments</comments>
		<pubDate>Tue, 08 Jan 2013 06:22:02 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1603</guid>
		<description><![CDATA[The short answer: you probably can if you are careful enough to limit your use of Python API calls. For example, you cannot use PyFile_AsFile, the reason is that C runtime objects like FILE* created in one runtime e.g. msvcrt.dll cannot be used in another, e.g. msvcrt70.dll In addition, malloc() allocated memory from one runtime [...]]]></description>
				<content:encoded><![CDATA[<p><strong>The short answer</strong>: you <em>probably</em> can if you are careful enough to limit your use of Python API calls.</p>
<p>For example, you cannot use <a href="http://docs.python.org/2/c-api/file.html#PyFile_AsFile">PyFile_AsFile</a>, the reason is that C runtime objects like FILE* created in one runtime e.g. msvcrt.dll cannot be used in another, e.g. msvcrt70.dll</p>
<p>In addition, malloc() allocated memory from one runtime cannot be freed from another runtime.</p>
<p>Here&#8217;s a rundown:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ms235460(v=vs.90).aspx">Potential Errors Passing CRT Objects Across DLL Boundaries</a></li>
<li>Also read <a href="http://www.python.org/dev/peps/pep-0384/">PEP 384 &#8211; maintaining a stable ABI</a>, where it mentions<br />
<blockquote><p>In addition, functions expecting FILE* are not part of the ABI, to avoid depending on a specific version of the Microsoft C runtime DLL on Windows.</p></blockquote>
</li>
</ul>
<p>Interestingly, there are techniques called forwarder DLLs that redirect DLL calls to another version. </p>
<ul>
<li>See <a href="http://blogs.msdn.com/b/oldnewthing/archive/2006/07/19/671238.aspx">Exported functions that are really forwarders</a>.</li>
<li><a href="http://stackoverflow.com/questions/4060143/forwarding-data-in-a-dll">DLL forwarding in Python</a> (StackOverflow).</li>
</ul>
<p>More interestingly though is the possibility of using Visual Studio to link against the older runtime directly</p>
<ul>
<li><a href="http://developer.berlios.de/devlog/akruis/2012/06/03/msvcrtdll-and-visual-studio/">linking against the old MSVCRT with newer versions of visual studio</a>, also </li>
<li><a href="http://kobyk.wordpress.com/2007/07/20/dynamically-linking-with-msvcrtdll-using-visual-c-2005/">Dynamically linking with MSVCRT.DLL using Visual C++ 2005</a>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2013/01/08/why-cant-i-build-python-extensions-with-a-different-version-of-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaFX Experiments</title>
		<link>http://www.redmountainsw.com/wordpress/2013/01/07/javafx-experiments/</link>
		<comments>http://www.redmountainsw.com/wordpress/2013/01/07/javafx-experiments/#comments</comments>
		<pubDate>Mon, 07 Jan 2013 16:44:20 +0000</pubDate>
		<dc:creator>Chui</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[javafx]]></category>

		<guid isPermaLink="false">http://www.redmountainsw.com/wordpress/?p=1602</guid>
		<description><![CDATA[Note: Upload to public_html/wp-content/blogs.dir/4/files/javafx #1 Cheat sheets FXML ((Scene)FXMLLoader.load(getClass().getResource(&#34;fxml_tableview.fxml&#34;)) // to get controller FXMLLoader loader = new FXMLLoader(getClass().getResource(&#34;fxml_tableview.fxml&#34;)); (Scene) loader.load(); (MyController) loader.getController(); Stylesheets JavaFX Stylesheets have to be set programmatically, not declaratively. scene.getStylesheets().add(&#34;/resources/shell.css&#34;); ItemsSource binding ListView has an ObservableList itemsProperty whereupon invalidated() calls if (getSkin() instanceof ListViewSkin) { ListViewSkin&#60;?&#62; skin = (ListViewSkin&#60;?&#62;) getSkin(); skin.updateListViewItems(); }]]></description>
				<content:encoded><![CDATA[<p>Note: Upload to public_html/wp-content/blogs.dir/4/files/javafx</p>
<p><a href="http://www.redmountainsw.com/wordpress/files/javafx/JavaFXApplication1.html">#1</a></p>
<h1>Cheat sheets</h1>
<h2>FXML</h2>
<pre class="brush: java">
((Scene)FXMLLoader.load(getClass().getResource(&quot;fxml_tableview.fxml&quot;))

// to get controller
FXMLLoader loader = new FXMLLoader(getClass().getResource(&quot;fxml_tableview.fxml&quot;));
(Scene) loader.load();
(MyController) loader.getController();
</pre>
<h2>Stylesheets</h2>
<p>JavaFX Stylesheets have to be set programmatically, not declaratively. </p>
<pre class="brush: java">
scene.getStylesheets().add(&quot;/resources/shell.css&quot;);
</pre>
<h2>ItemsSource binding</h2>
<p>ListView has an <code>ObservableList<T> itemsProperty</code> whereupon <code>invalidated()</code> calls</p>
<pre class="brush: java">
if (getSkin() instanceof ListViewSkin) {
  ListViewSkin&lt;?&gt; skin = (ListViewSkin&lt;?&gt;) getSkin();
  skin.updateListViewItems();
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.redmountainsw.com/wordpress/2013/01/07/javafx-experiments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
