Scott Hanselman

Hanselminutes Podcast 85 - EarthClassMail.com - Moving from LAMP to .NET 3.5

October 20, 2007 Comment on this post [0] Posted in ASP.NET | Microsoft | Podcast | Programming
Sponsored By

logo My eighty-fifth podcast is up. In this one I talk to Matt Davis, an Architect at EarthClassMail.com about their switch from a LAMP stack (Linux, apache, mysql, php/perl/python) to .NET 3.x. What's working, what's not, and what kinds of issues are they are running into as their architect their solution.

Subscribe: Subscribe to Hanselminutes Subscribe to my Podcast in iTunes

If you have trouble downloading, or your download is slow, do try the torrent with µtorrent or another BitTorrent Downloader.

Do also remember the complete archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Telerik is our sponsor for this show.

Check out their UI Suite of controls for ASP.NET. It's very hardcore stuff. One of the things I appreciate about Telerik is their commitment to completeness. For example, they have a page about their Right-to-Left support while some vendors have zero support, or don't bother testing. They also are committed to XHTML compliance and publish their roadmap. It's nice when your controls vendor is very transparent.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

Enjoy. Who knows what'll happen in the next show?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Hanselminutes spotted in the wild

October 19, 2007 Comment on this post [17] Posted in Podcast
Sponsored By

This was just too cool not to mention, so forgive me this indulgence. I was over at Moe's Restaurant for lunch a few days ago and this fine gentleman said "Hi Scott" and was, at that moment, listening to Hanselminutes. Amazing coincidence!

hanselminutesphoto2

How cool is that? Are you listening? I think I'll start giving out prizes if this happens again! I should have bought him lunch.

The first time this happened it was in the Chicago Airport bathroom. That was slightly considerably more disturbing, as I was "in the process" at the time. Anyway, so cool that folks enjoy the show.

Keep sending me show ideas!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

The Weekly Source Code 8

October 19, 2007 Comment on this post [10] Posted in Source Code
Sponsored By

In my new ongoing quest to read source code to be a better developer, I now present the eighth an infinite number of a weekly series called "The Weekly Source Code." Here's some source I'm reading this week that I enjoyed.

  • The Vista Battery Saver is a fun and simple little application that shuts off Aero and the Sidebar when you're running on batteries. The source is up at CodePlex. He registered his application with Windows for Power Notifications. Windows will send his application a Window Message when the system's power state changes.
  •     //In the main WinForm, he overrides the WndProc
        protected override void WndProc(ref Message m)
        {
             base.WndProc(ref m);
             if (m.Msg == PowerMngr.WM_POWERBROADCAST)
             {
                 PowerMngr.GetManager().PowerSettingChange(m);
             }
        }
    
            //Earlier he selects the messages he's interested in.
            internal void RegisterForPowerNotifications(IntPtr hwnd)
            {
                hPowerSrc = RegisterPowerSettingNotification(hwnd,
                ref GUID_ACDC_POWER_SOURCE,
                DEVICE_NOTIFY_WINDOW_HANDLE);
    
                hBattCapacity = RegisterPowerSettingNotification(hwnd,
                ref GUID_BATTERY_PERCENTAGE_REMAINING,
                DEVICE_NOTIFY_WINDOW_HANDLE);
    
                hMonitorOn = RegisterPowerSettingNotification(hwnd,
                ref GUID_MONITOR_POWER_ON,
                DEVICE_NOTIFY_WINDOW_HANDLE);
    
                hPowerScheme = RegisterPowerSettingNotification(hwnd,
                ref GUID_POWERSCHEME_PERSONALITY,
                DEVICE_NOTIFY_WINDOW_HANDLE);
            }
    
            [DllImport(@"User32", SetLastError = true, EntryPoint = "RegisterPowerSettingNotification", CallingConvention = CallingConvention.StdCall)]
            private static extern IntPtr RegisterPowerSettingNotification(
                IntPtr hRecipient,
                ref Guid PowerSettingGuid,
                Int32 Flags);
  • Patrick Smacchia released a Strongly Typed Path Library today. You know Patrick, he's NDepend-guy and he rocks. He includes a Class Diagram as well:
    PathClassDiagram
    I'll let you go check it out, because you should. I think a class this smart would be a nice addition to the BCL. Here's some of his tests showing the usage of the library. Make careful note of the !'s inside the Asserts. They weren't totally obvious to me. I usually use == false. I find it easier to read.
  •       //
          // Path string validation
          //
          string reason;
          Debug.Assert(PathHelper.IsValidAbsolutePath(@"C:\Dir2\Dir1", out reason));
          Debug.Assert(!PathHelper.IsValidAbsolutePath(@"C:\..\Dir1", out reason));
          Debug.Assert(!PathHelper.IsValidAbsolutePath(@".\Dir1", out reason));
          Debug.Assert(!PathHelper.IsValidAbsolutePath(@"1:\Dir1", out reason));
          Debug.Assert(PathHelper.IsValidRelativePath(@".\Dir1\Dir2", out reason));
          Debug.Assert(PathHelper.IsValidRelativePath(@"..\Dir1\Dir2", out reason));
          Debug.Assert(PathHelper.IsValidRelativePath(@".\Dir1\..\Dir2", out reason));
          Debug.Assert(!PathHelper.IsValidRelativePath(@".\Dir1\..\..\Dir2", out reason));
          Debug.Assert(!PathHelper.IsValidRelativePath(@"C:\Dir1\Dir2", out reason));
  • I was talking to John Lam this week and he said: "BTW I’m having a ton of fun with C# 3.0 – it really is a beautiful language. Here’s an app that I wrote today that dumps all of our implemented Ruby methods to a YAML file." It'll be up on RubyForge later this week, but here's a snippet. It's about 100 lines and it takes a while to sink in. It's simple and it's a nice way to use LINQ against Reflection and the extension methods that use generics is nice and clean. Start at the Main() at the bottom and work your way around. Sure it could be shorter and hackier, but he appears to be balancing functionality with his own sense of aesthetic.
  • using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Reflection;
    using System.Text;
    using Ruby;
    using Ruby.Extensions;
    using Microsoft.Scripting.Utils;
    using Ruby.Runtime;
    
    namespace IronRuby.Library.Scanner {
        static class ExtensionMethods {
            public static IEnumerable<T> SelectCustomAttributes<T>(this Type type) where T : Attribute {
                return type.GetCustomAttributes(typeof(T), false).Cast<T>();
            }
    
            public static IEnumerable<T> SelectCustomAttributes<T>(this MethodInfo method) where T : Attribute {
                return method.GetCustomAttributes(typeof(T), false).Cast<T>();
            }
        }
    
        class RubyClassInfo {
            public Type ClrType { get; set; }
    
            public delegate void Block(IEnumerable<RubyMethodAttribute> methods);
    
            public string Name {
                get { return ClrType.SelectCustomAttributes<RubyClassAttribute>().First().Name ?? ClrType.Name; }
            }
    
            private Type LookupExtensionModuleType(IncludesAttribute attr) {
                Type includedType;
                Program.ExtensionModules.TryGetValue(attr.Type, out includedType);
                return includedType ?? attr.Type;
            }
    
            private void GetMethodNames(Type t, Block accumulate) {
                var methods = (from m in t.GetMethods()
                               where m.IsDefined(typeof(RubyMethodAttribute), false)
                               select m.SelectCustomAttributes<RubyMethodAttribute>().First());
    
                accumulate(methods);
    
                foreach (IncludesAttribute attr in t.SelectCustomAttributes<IncludesAttribute>()) 
                    GetMethodNames(LookupExtensionModuleType(attr), accumulate);
            }
    
            private IEnumerable<string> GetMethodNames(RubyMethodAttributes methodType) {
                var result = new List<string>();
                GetMethodNames(ClrType, methods => 
                    result.AddRange((from m in methods
                                     where m.MethodAttributes == methodType 
                                     select m.Name).Distinct()));
                result.Sort();
                return result;
            }
    
            public IEnumerable<string> InstanceMethods {
                get { return GetMethodNames(RubyMethodAttributes.PublicInstance); }
            }
    
            public IEnumerable<string> SingletonMethods {
                get { return GetMethodNames(RubyMethodAttributes.PublicSingleton); }
            }
        }
    
        class Program {
            static IEnumerable<RubyClassInfo> GetRubyTypes(Assembly a) {
                return from rci in
                            (from t in a.GetTypes()
                             where t.IsDefined(typeof(RubyClassAttribute), false) 
                                   && !t.IsDefined(typeof(RubyExtensionModuleAttribute), false) 
                             select new RubyClassInfo { ClrType = t })
                       orderby rci.Name
                       select rci;
            }
    
            static Dictionary<Type, Type> GetExtensionModules(Assembly a) {
                var modules = from t in a.GetTypes()
                              where t.IsDefined(typeof(RubyExtensionModuleAttribute), false)
                              select new { Type = t, Attribute = t.SelectCustomAttributes<RubyExtensionModuleAttribute>().First() };
                
    
                var result = new Dictionary<Type, Type>();
                foreach(var m in modules)
                    result[m.Attribute.Extends] = m.Type;
                return result;
            }
    
            const string RubyAssembly = @"Ruby, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";
            internal static Dictionary<Type, Type> ExtensionModules;
    
            static void DumpMethods(IEnumerable<RubyClassInfo> types, Func<RubyClassInfo, IEnumerable<string>> getMethods) {
                foreach (RubyClassInfo rci in types) {
                    Console.WriteLine("{0}:", rci.Name);
                    foreach (string methodName in getMethods(rci))
                        Console.WriteLine("  - {0}", methodName);
                }
            }
    
            static void Main(string[] args) {
                var name = new AssemblyName(RubyAssembly);
                var a = Assembly.Load(name);
    
                ExtensionModules = GetExtensionModules(a);
                var types = GetRubyTypes(a);
    
                DumpMethods(types, t => t.InstanceMethods);
                DumpMethods(types, t => t.SingletonMethods);
            }
        }
    }

Feel free to send me any links to cool source you find.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

HTTP Error 404.17 - PHP on IIS7 under 64bit Vista

October 17, 2007 Comment on this post [5] Posted in IIS | Vista | PHP
Sponsored By

IIS 7.0 Detailed Error - 404.17 - Not Found - Windows Internet Explorer If you're getting...

"HTTP Error 404.17 - Not Found - The requested content appears to be script and will not be served by the static file handler."

...on Vista while trying to get PHP working under IIS7 with the standard ISAPI "php5isapi.dll" ask yourself, are you running 64-bit? That ISAPI DLL is a 32-bit DLL, so you'll have to either change your default Application Pool to enable 32-bit, or preferably create a separate 32-bit AppPool for your PHP Application.

Right click on the Application Pool and select "Advanced Settings" then "Enable 32-bit Applications."

Advanced Settings

At this point, you're all set with the standard ISAPI PHP stuff. 

phpinfo() - Windows Internet Explorer

Even better, consider using the FastCGI for IIS component. I'll do a screencast on that soon.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

The Five Second Rule - Does it Apply Internationally?

October 16, 2007 Comment on this post [141] Posted in Musings
Sponsored By

SkittlesFiveSecondRule There's a good article in the Washington Post from July that was on a repeat on the Radio this morning about the Five Second Rule. There's even some research on it and a WikiWorld comic.

"The five-second rule. If you've never heard of it, ask any sixth-grader. "It means that if you drop something on the ground, you can still eat it if you pick it up in five seconds," says Kiara Hopkins, 11."

I'm not sure when this started, but I've always known this. I think my two-year-old knows this, although it may be the five-day-rule for him. 

"It's not just for children: In a 2003 survey conducted at the University of Illinois, 70 percent of women and 56 percent of men had knowledge of the rule."

I'm shocked it's not 100%. There's also the interesting "Line of Sight Corollary to the Five Second Rule" which allows you to extend the Five Second Rule as long as you held the dropped object in your line of sight the entire time. "Who knows what could have happened while I wasn't looking?"

Additionally, things like M&Ms and Skittles candies have a hard-shell or 'armor' that allow for an more liberal interpretation of the Rule. Wet things, on the other hand, like cake or fruit, might only be allowed two seconds, or none at all.

Because I have a fairly international (non-US) bunch of readers here, I'd like to ask you:

  • Dear International Reader, is the Five Second Rule a global (read: all humans) phenomenon? Does it cross cultures?
  • More interestingly, what do you call it in your native language?

Discuss.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.