Friday Links 0.0.21 - Bezier Curves, Scientist, and a Webforms Tip

This is based on an email I send my .NET team at work

Happy Friday,

It’s been a while. I got lazy over the holidays. Few quick things this week.

Bezier Curves from the Ground Up

http://jamie-wong.com/post/bezier-curves/

If you’ve done any photoshop, or vector graphics work, or even messed with CSS animation timings you’re probably familiar with Bezier curves. Usually those tools have a line with some simple grab points you can drag around to change how quick a line curves.

I always wondered in the back of my mind how the math worked: how does the algorithm know exactly what pixels to draw? A straight line is easy y = mx + b from algebra, but a curve seemed like magic.

I never cared enough to look it up, I feared it would be math well above what I can remember from school.

Anyway, this article came around a few weeks ago and I thought it was an eye opening explanation. It goes through the math and has a bunch of really helpful animations.

Refactoring Production Code With Experiments and Scientist.NET

http://dontcodetired.com/blog/post/Refactoring-Production-Code-With-Experiments-and-ScientistNET

In Ruby, the GitHub team released a gem (think NuGet package) called Scientist for help testing refactorings. The premise is that you run both the new version of the code and the old version and compare the results. The result of the old code actually gets used until you are sure your refactoring is safe.

You can read about it in depth on their engineering blog

Anyway, its since been ported to everything, including PHP, Node and of course .NET

Check out this brief article for a sample of how it works.

Webforms Without a Code-Behind

So I needed a debugging tool in Sitecore to fire an event and kick off a long process that rebuilds the sitemap.xml. An easy way to do that is to drop an ASPX page into the sitecore/admin folder on the webserver. But what about the code behind? I didn’t want to bother having to deploy and compile two files just for this temporary debugging page.

I figured you could write the entire webform codebehind code right in the ASPX but it took a bit of Googling to recall how.

Now obviously you wouldn’t generally do this for production work, but I think its a useful trick for things like debugging pages. It has the advantage that you can just change the file and reload: no compile & deploy step.

sitecore/admin/refresh-sitemaps.aspx
<%@ Page Language="C#" AutoEventWireup="true" %> <script runat="server" language="C#"> void MyButton_OnClick(Object sender, EventArgs e) { string siteName = site.Text; Sitecore.Events.Event.RaiseEvent("refreshSitemap", siteName); Output.Text = siteName + " is being refreshed."; } </script> <!DOCTYPE html> <html> <head runat="server"> <title>Event Reset</title> <link rel="shortcut icon" href="/sitecore/images/favicon.ico" /> </head> <body> <form id="form1" runat="server"> <asp:Textbox id="site" runat="server" /> <asp:Button id="c_reset" runat="server" OnClick="MyButton_OnClick" Text="Reset" /> <asp:Literal id="Output" runat="server"></asp:Literal> </form> </body> </html>

The trick is that goofy <script runat="server" language="C#"> block. Just put your handlers in their and they’ll get compiled into a backing class for the page.