<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kenneth Stewart on Medium]]></title>
        <description><![CDATA[Stories by Kenneth Stewart on Medium]]></description>
        <link>https://medium.com/@kennethastewart?source=rss-b49d4d20f2fa------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*JcNIwYzLl-r70Eqx2C933g.png</url>
            <title>Stories by Kenneth Stewart on Medium</title>
            <link>https://medium.com/@kennethastewart?source=rss-b49d4d20f2fa------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 07:41:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kennethastewart/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Animated Button Groups in Xamarin Forms]]></title>
            <link>https://kennethastewart.medium.com/animated-button-groups-in-xamarin-forms-8aa75fcec58e?source=rss-b49d4d20f2fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/8aa75fcec58e</guid>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[animated]]></category>
            <category><![CDATA[button]]></category>
            <category><![CDATA[xamarin-forms]]></category>
            <category><![CDATA[xamarin]]></category>
            <dc:creator><![CDATA[Kenneth Stewart]]></dc:creator>
            <pubDate>Tue, 11 May 2021 18:36:00 GMT</pubDate>
            <atom:updated>2021-05-11T18:36:00.246Z</atom:updated>
            <content:encoded><![CDATA[<p>This article is first of a series of how-to-guides on creating animated buttons groups. In this one we will use simple view extension animations to create a retractable Nav-bar.</p><h3>Reveal and Hide Buttons</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*nN_WgQYjs8PrPZ_y3WaN_g.gif" /></figure><h4>Layout</h4><p>Moving Buttons (Or any item with a gesture detector) from its original position breaks the gesture detection, so we must first position the buttons to where we want them at the end of the animation.</p><p>We will be using the Opacity property to hide buttons rather than IsVisible, as this will allow us to fade the buttons in slowly rather than having them suddenly appear. Android does not render image buttons with a transparent background by default, so we will also need to set this to avoid buttons having the grey background shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/644/1*VE-yHee6ozw5nICmEMGEzA.png" /></figure><pre>&lt;StackLayout<br>    Orientation=&quot;Horizontal&quot;<br>    BackgroundColor=&quot;Wheat&quot;&gt;<br>            &lt;ImageButton<br>                x:Name=&quot;ExpandButton&quot;<br>                BackgroundColor=&quot;Transparent&quot;<br>                HorizontalOptions=&quot;FillAndExpand&quot;<br>                Clicked=&quot;RevealButton_Clicked&quot;<br>                /&gt;<br>            &lt;ImageButton<br>                x:Name=&quot;ExploreButton&quot;<br>                Opacity=&quot;0&quot;<br>                HorizontalOptions=&quot;FillAndExpand&quot;<br>                Scale=&quot;0.8&quot;<br>                BackgroundColor=&quot;Transparent&quot;<br>                /&gt;<br>            &lt;ImageButton<br>                x:Name=&quot;HomeButton&quot;<br>                HorizontalOptions=&quot;FillAndExpand&quot;<br>                Opacity=&quot;0&quot;<br>                Scale=&quot;0.8&quot;<br>                BackgroundColor=&quot;Transparent&quot;<br>                /&gt;<br>            &lt;ImageButton<br>                x:Name=&quot;SettingsButton&quot;<br>                Opacity=&quot;0&quot;<br>                BackgroundColor=&quot;Transparent&quot;<br>                HorizontalOptions=&quot;FillAndExpand&quot;<br>                Scale=&quot;0.8&quot;<br>                /&gt;<br>            &lt;ImageButton<br>                x:Name=&quot;HideButton&quot;<br>                Opacity=&quot;0&quot;<br>                BackgroundColor=&quot;Transparent&quot;<br>                HorizontalOptions=&quot;FillAndExpand&quot;<br>                Clicked=&quot;HideButton_Clicked&quot;<br>                /&gt;<br>&lt;/StackLayout&gt;</pre><p>Animations</p><p>Xamarin Forms provides two options to trigger animations. <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/animation/simple">Simple Animations </a>which can be triggered as extensions methods on most views and <a href="https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/animation/custom">Custom Animations</a>, which allow for more control over the way in which animations are executed. In this example we will be using simple view extension animations.</p><pre>MyButton.TranslateTo(x, y, time , Easing Function);</pre><p>In the above example, setting x to 100 will move the button 100 pixels to the right, setting it to -100 would move it 100 pixels the the left.</p><p>For Y a positive number would move it up and a negative down.</p><p>Time can be set in milliseconds, so setting it to 2000 would mean the animation would take 2 seconds to complete.</p><p>Easing types can be accessed through the Easing class and define how an item is animated. Easing.SpringOut for example will overshoot the set value and then return to it, the way a stalled car jolts forward before it stops.</p><p>The first thing we will be animating is the ‘reveal arrow’, which will shoot out of view. And then the ‘hide arrow’, whcih we will fade into view. To trigger this we will be using a click event - this needs to be async as we need to await the animations. We also want to ensure the arrow button is aways moved off screen so we will need to get the device width.</p><pre>double deviceWidth;<br>public TroopOutButtonGroupPage()<br>{<br>    InitializeComponent();<br>    deviceWidth = Application.Current.MainPage.Width;<br>}</pre><pre>async void RevealBtn_Clicked(System.Object s, System.EventArgs e)<br>{<br>     await ExpandButton<br>               .TranslateTo(deviceWidth + 10,<br>                            0, <br>                            1000, <br>                            Easing.CubicOut);<br>}</pre><p>I have added 10 pixels to device width to ensure none of the arrow button appears on screen. Easing has been set to CubicOut, which starts slow and then speed up near the end.</p><p>Next we need to reveal the hide button. As we are <em>awaiting</em> animations, the hide button will not be shown until the expand button’s animation has finished.</p><pre>await HideButton.FadeTo(100, 500, Easing.Linear);</pre><p>Finally we need to move the expand button back to it’s original position. We are doing this to allow the reveal and hide animations to run in a loop. Before we move it, we first need to hide it, which can be done by setting its opacity to 0.</p><pre>ExpandButton.Opacity = 0;<br>await ExpandButton.TranslateTo(0, 0, 0);</pre><p>We can now set up a click event for the hide button. This click event will look very similar to the method we just wrote but with animations which mirror those. The final result should look like this:</p><pre>double deviceWidth;<br>public TroopOutButtonGroupPage()<br>{<br>    InitializeComponent();<br>    deviceWidth = Application.Current.MainPage.Width;<br>}</pre><pre>async void RevealBtn_Clicked(System.Object s, System.EventArgs e)<br>{<br>     await ExpandButton<br>               .TranslateTo(deviceWidth + 10,<br>                            0, <br>                            1000, <br>                            Easing.CubicOut);<br>     await HideButton.FadeTo(100, 500, Easing.Linear);<br>     ExpandButton.Opacity = 0;<br>     await ExpandButton.TranslateTo(0, 0, 0);<br>}</pre><pre>async void HideBtn_Clicked(System.Object s, System.EventArgs e)<br>{<br>     await HideButton<br>             .TranslateTo(-deviceWidth - 10,<br>                          0, <br>                          1000, <br>                          Easing.SpringOut);<br>     await ExpandButton.FadeTo(100, 500, Easing.Linear);<br>     HideButton.Opacity = 0;<br>     await HideButton.TranslateTo(0, 0, 0);<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*dTS5-1VBoNYnmDVkoNDDYw.gif" /></figure><p>Now all that’s left to deal with are the Nav-bar buttons we are actually hiding and revealing. These will all use the same fade-in animations.</p><pre>await ExploreButton.FadeTo(100, 1000, Easing.CubicIn);<br>await HomeButton.FadeTo(100, 1000, Easing.CubicIn);<br>await SettingsButton.FadeTo(100, 1000, Easing.CubicIn);</pre><p>Here we encounter the biggest problem with extension animations, which is that we must await one before the next one can begin. We could shorten the duration of the fade in animation but doing so will almost negate the fade-in effect entirely and even if we do shorten them, there is still a slight pause between one animation ending and another beginning, so it will still appear painfully slow for the user.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*7LzUDZL_t4f1IQwGgMnyPQ.gif" /></figure><p>To get around this we use Task.WhenAll() which run all 3 animation simutaneously.</p><pre>await Task.WhenAll(<br>               ExploreButton.FadeTo(100, 1000, Easing.CubicIn),<br>               HomeButton.FadeTo(100, 1000, Easing.CubicIn),<br>               SettingsButton.FadeTo(100, 1000, Easing.CubicIn)<br>               );</pre><p>To fade out the buttons when the ‘hide arrow button’ is clicked you can use the same animation but set opacity to 0 rather than 100. I chose to await each animation and shorten the time.This looks a lot better fading out than it did fading in. Once you’ve done that you should be left with something like this:</p><pre>async void RevealBtn_Clicked(System.Object s, System.EventArgs e)<br>{<br>            await ExpandButton<br>                  .TranslateTo(<br>                      deviceWidth + 10, <br>                      0, <br>                      1000, <br>                      Easing.SpringOut<br>                   );<br>            await Task.WhenAll(<br>                    ExploreButton.FadeTo(100, 1000, Easing.CubicIn),<br>                    HomeButton.FadeTo(100, 1000, Easing.CubicIn),<br>                    SettingsButton.FadeTo(100, 1000, Easing.CubicIn)<br>                    );<br>            await HideButton.FadeTo(100, 500, Easing.Linear);<br>            ExpandButton.Opacity = 0;<br>            await ExpandButton.TranslateTo(0, 0, 0);<br>}</pre><pre>async void HideBtn_Clicked(System.Object sender, System.EventArgs e)<br>        {<br>            await SettingsButton.FadeTo(0, 200, Easing.Linear);<br>            await HomeButton.FadeTo(0, 200, Easing.Linear);<br>            await ExploreButton.FadeTo(0, 200, Easing.Linear);<br>            await HideButton.TranslateTo(<br>                             -deviceWidth - 10, <br>                             0, <br>                             1000, <br>                             Easing.SpringOut<br>                            );<br>            await ExpandButton.FadeTo(100, 500, Easing.Linear);<br>            HideButton.Opacity = 0;<br>            await HideButton.TranslateTo(0, 0, 0);<br>        }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*nN_WgQYjs8PrPZ_y3WaN_g.gif" /></figure><p>Thanks for reading! The code can all be found <a href="https://github.com/yossaj/XamButtonGroupAnimations/blob/master/AnimatedButtons/Views/TroopOutButtonGroupPage.xaml.cs">here</a> on the <a href="https://github.com/yossaj/XamButtonGroupAnimations/blob/master/AnimatedButtons/Views/TroopOutButtonGroupPage.xaml.cs">Github Repo.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8aa75fcec58e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Fridge Cam That Greed Shames You]]></title>
            <link>https://kennethastewart.medium.com/a-fridge-cam-that-greed-shames-you-7bab713d5f4?source=rss-b49d4d20f2fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/7bab713d5f4</guid>
            <category><![CDATA[pi]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[greed]]></category>
            <category><![CDATA[lockdown]]></category>
            <category><![CDATA[raspberry-pi]]></category>
            <dc:creator><![CDATA[Kenneth Stewart]]></dc:creator>
            <pubDate>Sat, 06 Feb 2021 17:36:54 GMT</pubDate>
            <atom:updated>2021-02-06T19:30:59.847Z</atom:updated>
            <content:encoded><![CDATA[<p>Raspberry Pi controlled Webcam that shames you on Instagram.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hQ2TjeiToP4BLbYD" /><figcaption>Photo by <a href="https://unsplash.com/@nicotitto?utm_source=medium&amp;utm_medium=referral">nrd</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Lockdown and my general lack of will power has meant an uptick in my noctural raids on the fridge, so I built a fridge cam that shames me into stopping.</p><p>This is the setup:</p><ol><li>A Raspberry Pi</li><li><a href="https://thepihut.com/products/magnetic-contact-switch-door-sensor">A Magnetic Contact Switch</a></li><li>A Webcam or a pi-cam</li><li>A powerbank.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*DwTjr5Cyow6ulX3DMxs3mg.png" /></figure><p>The hardware setup is very simple. Just hook up the magnetic contact switch to the raspberry pi’s GPIO pins. Then plug in a power bank and a webcam. Shove it all in a box. Stick the magnetic switch to the inside of the fridge. And you’re done.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xn45RexLjnAWjUps_2P4Pw.jpeg" /></figure><p>Now let’s look at the code.</p><p>First you need to make sure your magnetic switch works. The code below listens to see if the fridge door has been opened. (The circuit completes when the two magnets seperate, i.e. when the fridge door opens. )</p><pre>import RPi.GPIO as GPIO<br>import time</pre><pre>def listenForGreedyDoorOpen():<br>    while True:<br>        if GPIO.input(18):<br>            print(&quot;Fatboy opened the fridge!!&quot;)<br><br>        else:<br>            print(&quot;Door closed!&quot;)<br>time.sleep(0.5)</pre><p>Next we need a way to take a photo once the door has opened. The easiest way I found to do this was by using the fantasic cv2 library provided by <a href="https://opencv.org/">Open CV </a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cba4249150a9b2beef04316e9e14138a/href">https://medium.com/media/cba4249150a9b2beef04316e9e14138a/href</a></iframe><p>We can now trigger this method when the fridge door opens, like so:</p><pre>def listenForGreedyDoorOpen():<br>    while True:<br>        if GPIO.input(18):<br>            print(&quot;Fatboy opened the fridge!!&quot;)<br>            <strong>webcam_capture.run_webcam_capture(1)</strong><br>        else:<br>            print(&quot;Door closed!&quot;)</pre><p>Now come this really ugly part. At the time of writing Instagram do not have a service within their api which allows users to post an image. So the only option I could think of was to make a bot with selenium. This bot can open a browser, login to my instagram acocunt and post an image for me. The obvious problem with this is whenever Instagram makes a change to their user flow this code will break (If you know a better way please please please let me know). The bot needs to run using a mobile webdriver profile as mac/pc browsers don’t show the ‘Add a new image’ button. The code for the Instagram Bot can be found <a href="https://github.com/yossaj/FridgeShameCam/blob/master/InstagramPostAutomated.py">here</a>.</p><p>Finally you can add the bot to run in our main method after a photo has been taken. Like so:</p><pre>def listenForGreedyDoorOpen():<br>    while True:<br>        if GPIO.input(18):<br>            print(&quot;Fatboy opened the fridge!!&quot;)<br>            webcam_capture.run_webcam_capture(1)<br>     <strong>       instaBot = Bot.init(config.username, config.password)<br>            instaBot.login()            <br>            instaBot.postImage()</strong><br>        else:<br>            print(&quot;Door closed!&quot;)</pre><p>There are two outstanding problems with this shaming device. First, It shames me all day simply for eating, rather than just for over eating in the evening. Second, it is far too dangerous to use in its current state as it shames everyone who opens the fridge (which includes my wife).</p><p>The first problem is easily solved by adding some time conditions. To solve the second problem I will try to add some face recognition. I’ll try and get an update out soon so keep your eyes peeled.</p><p>While working on this project I found this article by <a href="https://simonprickett.medium.com/?source=post_page-----ab89ad499964--------------------------------">Simon Prickett</a> very useful. <a href="https://medium.com/conectric-networks/playing-with-raspberry-pi-door-sensor-fun-ab89ad499964">Playing with Raspberry Pi: Door Sensor Fun</a></p><p>Github repo : <a href="https://github.com/yossaj/FridgeShameCam">https://github.com/yossaj/FridgeShameCam</a></p><p>Video of the Fridge Cam in action can be found <a href="https://www.instagram.com/p/CH_Nh6FJb57/?utm_source=ig_web_copy_link">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7bab713d5f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Get your Ruby-Sinatra App on Heroku]]></title>
            <link>https://medium.com/swlh/get-your-ruby-sinatra-app-on-heroku-47f1436cbf52?source=rss-b49d4d20f2fa------2</link>
            <guid isPermaLink="false">https://medium.com/p/47f1436cbf52</guid>
            <category><![CDATA[heroku]]></category>
            <dc:creator><![CDATA[Kenneth Stewart]]></dc:creator>
            <pubDate>Tue, 11 Jun 2019 15:37:51 GMT</pubDate>
            <atom:updated>2019-06-19T17:10:20.188Z</atom:updated>
            <content:encoded><![CDATA[<p>I couldn’t find any clear guides to launching Ruby-Sinatra apps on Heroku so I decided to write one.</p><p>The first step you’ll need to take is create a Heroku account. That’s fairly straight-forward so I wont get into it.</p><p>Once you’ve done that you will want to go into command line and install a bundler and heroku. First the bundler:</p><p>gem install bundler.</p><p>Then install heroku:</p><pre>brew install heroku/brew/heroku</pre><p>You will then be prompted to log into Heroku by the command-line. Once you’ve done that you should create a new Heroku repository.</p><pre>heroku create</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/886/1*j_1yGQIZn48v_TaF13WnIQ.png" /></figure><p>Your Heroku Project will the be given a random name — Adj + Geographical-Feature. You should also be able to see it if you go to &gt;&gt; <a href="https://dashboard.heroku.com/apps">https://dashboard.heroku.com/apps</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/1*bXSravKKTybmcx0wDgZiyg.png" /></figure><p>Now that you have that set-up you will need to add a couple files to your project to tell Heroku how to run it. You will need to touch 3 new files in the command line: config.ru | Procfile | Gemfile</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*kPJvV34GK1c6tPkMS8dnRw.png" /></figure><p>The only gems I am using in my Gemfile are ‘pg’ and ‘sinatra’, so my gemfile looks like this.</p><pre>source ‘https://rubygems.org&#39;<br>gem ‘sinatra’</pre><pre>gem ‘pg’, ‘~&gt; 0.18’</pre><p>The congfig.ru file is also very simple. It looks like this:</p><pre>run Sinatra::Application</pre><p>Next is Procfile. This gives Heroku the commands it will need to run your app. This should include the command you type into your command line to run your app locally.</p><pre>web: bundle exec ruby app.rb -p $PORT</pre><p>‘app.rb’ is my main controller file, if yours isn’t named ‘app.rb’ you will need to change it.</p><p>Only a few more steps to go. Back in command line you will need to do a bundle install to setup a Gemfile.lock.</p><pre>bundle install</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*DvFafp1xA2PNEGZZwVHQOQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/271/1*MUsQ7REEhV7-pF4ZXEJdcg.png" /></figure><p>You should now have a Gemfile.lock in your folder. It should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/1*ypYg9w5pqrDNnTqrNoZihQ.png" /></figure><p>You can now launch to Heroku! First add, commit and push all your files to github and then push to Heroku with the following command:</p><pre>git push heroku master</pre><p>Now, your app probably won’t be working at this point. You still need to set up your database. Go to your Heroku Dashboard ::&gt; click on Resources ::&gt; click on Heroku Postgres.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*3sJm6hfe1pqCtRGNcGy4aQ.png" /></figure><p>Once you are in the postgres database dashboard go to setting and then click on ‘View Credentials…’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2gCrYW4cb029DZt4V0udhQ.png" /></figure><p>Here you will get all the data you need to access your database. Copy and paste them into your sql runner, it should look something like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*wDChyfnOVFk6Nc0RJPu69g.png" /></figure><p>Once you have done that you will need to create some tables before you seed your database. You can do this by running your .sql folder in on Heroku’s database. To do this you can go back to credentials and copy the Heroku CLI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/652/1*_-6Ifs8srXeNnGx4kZh-0Q.png" /></figure><p>Run your sql file like this.</p><pre>&lt;Your Heroku CLI&gt; &lt; db/&lt;your_sql&gt;.sql</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*bghXDNNcIeyh63IeHRNiHw.png" /></figure><p>You can then seed your database:</p><pre>Ruby db/seeds.rb</pre><p>And that’s you done! … Hopefully.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47f1436cbf52" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/get-your-ruby-sinatra-app-on-heroku-47f1436cbf52">Get your Ruby-Sinatra App on Heroku</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>