Michael Banzonhttps://michaelbanzon.com/Michael Banzon Blogabout-calendars-in-appshttps://michaelbanzon.com/blog/about-calendars-in-appsAbout Calendars in Apps<p>We all use calendars - but I fear we don't use them enough, and that we use them for the wrong things!</p> <p>I imagine that most of us use a calendar to guide our daily activitites. It might be a calendar on our computer/phone, on paper, or even in our mind.</p> <h1 id="what-is-a-calendar">What is a calendar?</h1> <p>In my opinion a calendar should be used to mark events that are <em>locked in time</em>. That means that if I have an event in my calendar on Saturday between 13:30 and 15:00 I am (somewhat) busy in the period of time, doing whatever that event is.</p> <p>That also means that events that are not locked in time should not go in my calendar.</p> <p>If I have to make a shopping list today, for picking up groceries tomorrow, it doesn't matter <em>when</em> I do it, as long as it is done <em>today</em>.</p> <p><strong>Error number one</strong>: <em>Put it in the calendar at a specific time</em>. <strong>Error numebr two</strong>: <em>Put it in the calendar, as an all-day event</em>.</p> <p>Both of these are <em>wrong</em>. In the first case you indicate <em>this needs to happen at this time</em>. and if that is not your intent, then don't. The second one indicates <em>this is something that is covering all of my day</em>, which (I hope!) is also wrong.</p> <p>Tasks like these belong on a <em>to do list</em> instead.</p> <h1 id="bring-in-the-apps">Bring in the apps</h1> <p>A lot of apps (for phones, mainly) now hold calendars.</p> <p>The app for communicating with the kids school. The app for the older kids lesson plan. The Formula 1 app, YouTube and other streaming services like Twitch etc.. The app for my gym classes. All of them have some kind of calendar or reminder function designed to let me know at a specific time, that <em>now I have to do this thing</em>.</p> <p>Funny enough, the reason for installing these apps in the first place - instead of simply using a website for booking etc. - is to have the notifications for events.</p> <h1 id="but-i-already-have-a-calendar">But I already have a calendar!</h1> <p>The problem with all apps and services having a calendar, is that now all the stuff I need to do at certain times ends up either <em>not</em> being in my main calendar, which is now useless OR it has to be duplicated in a manual process maintained by me.</p> <p>No matter how I look at this, it is bad!</p> <p>I could allow notifications from these apps, but that means it only works if a cary my phone around and actively look at it. Also, these notifications does not come alone - they bring a lot of other notifications with them from the very same apps.</p> <h1 id="the-solution-should-be-simple">The solution should be simple</h1> <p>Actually, my calendar can help solve this problem.</p> <p>The solution is built in!</p> <p>Import/export of events.</p> <p>If I sign up for a yoga class: Import into calendar!</p> <p>Easy! And for stuff that is more <em>ongoing</em> we have the option to have calendar invites. We all know them from <em>work</em>. They do what we need! You can even accept/decline to indicate if you are actually going to participate in that informative meeting at your kids school.</p> <h1 id="bonus-about-messages">Bonus, about messages</h1> <p>Many years ago GitHub nailed the issue-conversations!</p> <p>I get an email, I can reply to that email. Easy! The email is parsed and put into the issue thread.</p> <p>I wish we had that for all apps that include messaging.</p> 2025-02-03T06:18:36Ztesting-delayed-publishinghttps://michaelbanzon.com/blog/testing-delayed-publishingJust a test...<p>If all goes well this post will be live on (from) Feb. 2nd, 2025 at 18:00 (GMT?).</p> <p>This should also be the publishing time in the header of the post.</p> 2025-02-03T06:18:36Zgracefully-shutdown-go-serverhttps://michaelbanzon.com/blog/gracefully-shutdown-go-serverHow to gracefully shut down a Go server<p>When doing an HTTP server in Go the call to <code>http.ListenAndServe(...)</code> will block until the server stops. But it shouldn't stop. Ever.</p> <p>That leaves us with a problem - we might want to stop the server!</p> <p>There might be various reasons. Maybe we want to replace the binary with an updated version. Maybe we just want it to not run.</p> <p>Fortunately instead of using the default <code>.ListenAndServe(...)</code> we can create our own <code>http.Server</code> like this:</p> <pre><code class="language-Go">server := &amp;http.Server{ Addr: &quot;:8080&quot;, Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { time.Sleep(5 * time.Second) w.Write([]byte(&quot;Slept 5 seconds! Hello, World!&quot;)) }), } </code></pre> <p>This server, for the purpose of illustration, has only one simple handler that waits for five seconds and then returns the string.</p> <p>After creating a server like this, we can shut it down gracefully:</p> <pre><code class="language-Go">err := server.Shutdown(context.Background()) </code></pre> <p>Please notice that we pass a <code>context.Context</code> to the <code>.Shutdown(...)</code> function. That gives us the flexibility to control the shutdown process in greater details if needed (but for now we just use ).</p> <h1 id="handling-program-shutdown">Handling program shutdown</h1> <p>If we then setup a handler for signals (from the OS) to handle some events of interrest, for example <code>syscall.SIGINT</code> and <code>syscall.SIGTERM</code> we start a goroutine that will listen for any of these signals and that will then cal the <code>.Shutdown(...)</code> function on the server.</p> <p>Like this:</p> <pre><code class="language-Go">// setup signal handler to gracefully shutdown the program sig := make(chan os.Signal, 1) signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) go func() { &lt;-sig fmt.Println(&quot;Shutting down server...&quot;) err := server.Shutdown(context.Background()) if err != nil { // handle the error } }() </code></pre> <p>The signals from the OS will be sent to allow the program to gracefully shut down.</p> <h1 id="putting-it-all-together">Putting it all together</h1> <p>I have put everything here together with a lot of helper functions and signals to keep all the parts working.</p> <p>There is a channel <code>done</code> meant to signal that the program should exit. There is also a channel <code>errCh</code> that is used for sending errors.</p> <p>The full code is in <a href="https://github.com/mbanzon/stop-server-example">the repository on Github</a>.</p> 2025-02-03T06:18:36Zhello-worldhttps://michaelbanzon.com/blog/hello-worldHello world!<p>New blog, first post!</p> 2025-02-03T06:18:36Z