Scott Hanselman

How to attach MP3 sound effects to PowerPoint animation elements

February 29, '08 Comments [6] Posted in Musings | Tools
Sponsored By

imageI'm working on a presentation for the DE (Developer Evangelists) the day before Mix. Since so many MSFT folks are getting together in one place, we usually take advantage and do some side meetings, etc.

I'm doing this cool slide (at least I think so) and I added a small animation as picture comes in from off screen.

I wanted to add an MP3 to that effect so that it'd play as the animation happened. I wandered around the UI for a white, trying to figure this out.

It's a little counter-intuitive, but each Effect Element can have its own sound attached, so you have to Right Click on the Element in the Custom Animation Pane, as seen at right.

Click Effect Options and you'll see this dialog:

image

When you select Other Sound... you'll get a File Dialog prompting you for a WAV file. Here's where I got stuck for a moment. It ONLY allows WAV files and I wanted to play an MP3. Well, I could have converted the MP3 to a WAV, but not only would it have made the file a lot bigger, but I would have had to go looking for a converter.

It turns out that the WAV format can support MP3-compressed audio as long as the WAV header (wrapper) is correct. So, rather than "uncompressing" my MP3 into a fat WAV (using RAW PCM Audio), I can just run this little command line app "MP3 Decoder" and it will create a .WAV file with the MP3 inside.

Run the little app by Niklas Beisert and you're on your way. The file will be roughly the same size (still small!). Attach the "now WAV" to your animation and you've just successfully attached an MP3 to an animation in PowerPoint.

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Hanselminutes Podcast 102 - Mike Pizzo on the ADO.NET Entity Framework

February 29, '08 Comments [13] Posted in ASP.NET | Learning .NET | LINQ | Podcast | Tools
Sponsored By

figure1 My one-hundred-and-second podcast is up. In this episode, I sit down with Michael Pizzo, the Principal Architect of the ADO.NET Entity Framework. He gets technically down and dirty pretty fast and I get answers to all the hard questions like "Are LINQ to SQL and LINQ to Entities competing?" and "Which one should I use?" A very cool guy and a fun interview that finally set my head straight about the data stack.

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

The Weekly Source Code 17 - ASP.NET MVC Community Code Edition

February 27, '08 Comments [15] Posted in ASP.NET | ASP.NET MVC | Source Code
Sponsored By

I've been working on new Videos for ASP.NET MVC and the Mix conference, and I wanted to read some code that folks have created using the December CTP of ASP.NET MVC. There's a lot of good changes coming in the next Preview release and that feedback comes from active community members, so it's always good to read real source of real apps to see what folks are doing.

And so, Dear Reader, I present to you seventeenth in a infinite number of posts of "The Weekly Source Code." Here's some source I was reading this week.


CodeCampServer (source)

This application is a free open-source Code Camp management application, so if you're thinking of running a Code Camp, start here. As of this writing, it's build on the December drop of ASP.NET MVC and also uses StructureMap, IESI Collections, MVC Contrib, log4net, RhinoMocks, NUnit and NHibernate. Aaron Lerch and others have been working on this app for the Indy Code Camp, so if you're around Indianapolis check them out.

Better Things

One thing that's fun to see when reading code is when folks name classes something like "BetterMousetrap," where the class name advertises that it's superior to something specific. This project has "BetterMvcHandler:"

public class BetterMvcHandler : MvcHandler
{
	protected override void ProcessRequest(IHttpContext httpContext)
	{
		try
		{
			base.ProcessRequest(httpContext);
		}
		catch (Exception ex)
		{
			throw new Exception("Route used:" + RequestContext.RouteData.Route.Url, ex);
		}
	}
}

All they are doing is catching all exceptions, showing the current URL via the route, and pushing the original exception down a level. Smells a little iffy to me, but the valuable thing for the MVC Team to notice about this is that people need more insight into what is happening with Routes while debugging.

Here they use RhinoMocks so they can test their controllers without firing up ASP.NET/IIS. This will change some in the next drop, but this is totally the right idea. I've got a full 20 minute video coming showing just how to do this very thing:

namespace CodeCampServer.UnitTests
{
    public static class Extensions
    {
        public static IHttpContext DynamicIHttpContext(this MockRepository mocks, string url)
        {
            IHttpContext context = mocks.DynamicMock();
            IHttpRequest request = mocks.DynamicMock();
            IHttpResponse response = mocks.DynamicMock();

            SetupResult.For(context.Request).Return(request);
            SetupResult.For(context.Response).Return(response);
            SetupResult.For(request.AppRelativeCurrentExecutionFilePath).Return(url);
            SetupResult.For(request.PathInfo).Return(string.Empty);            

            return context;
        }
    }
}

Law of Demeter

When creating lots of Domain Objects, like in this application, on of the things that comes up a lot is the validity (or not) of the Law of Demeter. Basically this law is a design guideline that says your object should avoid reaching deeply into other objects.

For example, in this application, there's an Attendee object. It has a Contact object, which has things like FirstName, LastName, Email, etc. If you see something like this:

[Test]
public void ShouldGetProperName()
{
	Attendee attendee = new Attendee();
	attendee.Contact.FirstName = "Homey";
	attendee.Contact.LastName = "Simpsoy";
	Assert.That(attendee.GetName(), Is.EqualTo("Homey Simpsoy"));
}

You might want to ask yourself if reaching "two steps" in in order to get the FirstName and LastName is a good idea as now you're coupling the caller not only to Attendee, but also Contact, not to mention you're assuming that Contact isn't null. If you follow this rule religiously (and I'm not saying you should) the downside is that you end up with a bunch of wrapper methods like GetFirstName, etc. on your top level object. It's something to think about. Perhaps it's less valid in the context of a Domain Model where all these objects find themselves intertwined, but if you find yourself writing a.b().c().d.something, your sense of code smell really should kick in.

Helper Things

Another thing to look for when reading code that uses a framework you've worked on is methods or classes named "Helper." This is another clue that maybe your framework isn't meeting the downstream developer's needs, especially if they have a large number of helpers to get-around issues with your framework.

 public static class LinkHelpers
 {
     public static bool IsActive(this ViewPage thePage, string controller, string action)
     {
         return thePage.ViewContext.RouteData.Values["controller"].ToString() == controller &&
                thePage.ViewContext.RouteData.Values["action"].ToString() == action;            
     }
     
     public static bool IsActive(this ViewMasterPage thePage, string controller, string action)
     {
         return thePage.ViewContext.RouteData.Values["controller"].ToString() == controller &&
                thePage.ViewContext.RouteData.Values["action"].ToString() == action;            
     }
...

There are a number of extension methods in this project where the developers have spot-welded new methods onto ViewPage and ViewMasterPage as mix-ins or extension methods. Interestingly though, they never ended up using the Helpers! I usually create helpers after things really start to hurt and I've moved into the Refactoring stage. It's usually a good idea to get a holistic perspective on the project first, rather than creating a number of Helpers and associated overloads in anticipation of future pain.

Again, I'm not picking on this project, rather just using it as a jumping off point for discussion. It's certainly easy to read code and throw stones. As Linus likes to say, "talk is cheap, show me the code."


Kigg - Digg clone in ASP.NET MVC (Live Demo)

There's a good writeup on how Kazi Manzur Rashid and Sonu wrote this Digg Clone. They are doing a couple of interesting things in their application.

JSON and Ajax

They are using the new DataContractJsonSerializer that was added in .NET 3.5 and lives in System.Runtime.Serialization.Json and lets you serialize your objects to and from Javascript Object Notation (JSON). They created a json.aspx file that takes the current ViewData and serializes it to JSON:

    Response.Clear();
    Response.ContentType = "application/json";
    Response.Write(ViewData.ToJson());

Simple and it works. Whenever a controller wants to make JSON, they just ReviewView("Json", result). Personally, I would have made a JsonViewEngine and had the controller set its ViewEngine when neeeded, but suppose that would have rendered (ahem) the first parameter of RenderView moot.

They make good use of LINQ. Reading a nice clean LINQ query always makes me smile.

public TagItem[] GetTags(int top)
{
   return Tags.Select (
                  t => new TagItem {
                      ID = t.ID,
                      Name = t.Name,
                      Count = t.StoryTags.Count()
                  }
               )
               .OrderByDescending(t => t.Count)
               .ThenBy(t => t.Name)
               .Take(top)
               .ToArray();
}

Complex Views and ViewData

The main pages are fairly complex and include data from a number of different places, listing stories, tag clouds and categories. There's also multiple forms (remember the days when you could have multiple forms) on a page, like for the search box as an example. They've created a abstract BaseViewData class that others derive from, adding extra bits of data for their specific view.

For example, the Story Detail Page adds to the standard ViewData:

    public class StoryDetailData : BaseViewData
    {
        public StoryDetailItem Story
        {
            get;
            set;
        }
    }

And then the StoryController has this clever method that gets ViewData only if the type T is a BaseViewData and has a public parameterless constructor (that's the new() at the end):

private T GetViewData<T>() where T : BaseViewData, new()
{
    T viewData = new T();

    viewData.IsAuthenticated = IsUserAuthenticated;
    viewData.UserName = CurrentUserName;
    viewData.Categories = DataContext.GetCategories();
    viewData.Tags = DataContext.GetTags(_topTags);

    return viewData;
}

It populates the methods shared by the base class and returns the derived type. I wouldn't have come up with this on my own without some thought.

Each of these projects have different styles but each is a good place to start looking when writing a new ASP.NET MVC Application.


Related Posts and Links to Read

Technorati Tags: ,,

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Amazon Kindle

February 26, '08 Comments [40] Posted in Reviews
Sponsored By

DSC_0031UPDATE TWO MONTHS LATER: Now that I've had the Kindle for two months, I still think it's horribly ugly, but I use it EVERY DAY. I subscribe to the NYTimes, to Newsweek and a few blogs. I've purchased 12 books so far and converted/downloaded 20 free ones. The battery life is very good as long as you only turn on the Wireless when you need it. Additionally, I've started using the Kindle as my primary Audible audiobook device and love it. I just slapped a 2gig SD card in and I've got 50+ hours of audio. It's the only device I need for long plane rides.

A year ago I had a Sony Reader for a month and reveled in its awesome screen. It's true, in case you haven't heard, e-ink looks like paper. At least, as close to paper as anything that's not paper can look.

I finally broke down and got an Amazon Kindle for my birthday.

If you are already bored with this post and want to stop here, here's the conclusion. I love it.

Why?

The Good Stuff

This device exists for one reason and one brilliant reason only, for Amazon to more easily extract money from my wallet. It's an entire device built around the concept of "One Click" ordering. You do get a second chance if you accidentally order a book, but it's designed for the impulse buyer. If I hear about a book on NPR or The Daily Show, I can get it immediately. If I read a nice book cover at the Airport bookstore on a long layover, I can buy it.

Once you realize its purpose and accept it and are OK with it, you'll like this as well. I like the "any book in the world in one minute or less" (and Bezos is not kidding, the books show up FAST) that I'm disappointed when a book isn't available.

The screen interface is clean, if slow to redraw (because of the e-ink), with just a few obvious usability things that I'm sure they'll fix with regular updates.

DSC_0032I was also thrilled to see that it integrates with Audible, so I popped a two gig SD card in and grabbed a gig and a half of books (about 2 weeks of audio) from my Audible subscription. Why not use a MP3 player? I have had a love/hate relationship with my iPod and consequently have faded away from using it. I find myself listening to XM Radio more often, or using a Zune with the All You Can Listen To Zune Pass, so my iPod has kind of laid fallow. At this point, I just really like the idea of all my books, audio or otherwise, on this one device. It also has a surprisingly loud speaker so I can listen to books without headphones which surprised me.

DSC_0034The Kindle also has an experimental mobile web browser. I say Mobile, because you should consider the Kindle like a really slow Mobile Phone with a slow to redraw grayscale screen. My blog recognizes the Kindle as a mobile device and renders nicely, even with pictures.

This discovery was just an added benefit. I can also check email (painfully) with Gmail's mobile interface. This alone justified, to me, the Kindle's keyboard that I'd previously written off as silly. The Kindle has the potential to be quite the handheld computer if Amazon allows it. For now, I'll just bookmark my new Mobile Home Page http://cantoni.mobi and be happy.

It works great with PRC Mobile eBooks (a standard) and as such the whole Baen Free Library (and many other similar ones) are available to me.

The Kindle has its own email address so I can send myself PDFs for 10cents and they'll show up pretty nicely. No, I haven't done PDFs with big images or code, but I can tell you that technical books looked lousy and hard to read on the Sony Reader, and I have no reason to think that the Kindle would be better.

There's a collection of newspapers available, so I got a trial subscription to the NYTimes. I love it. It shows up every day and it's got pictures and everything. Reading the newspaper has naturally fit into my day much more cleanly now, and I'm not in front of a browser for 30 minutes reading. It's more linear in that respect and I prefer it.

It's also got blogs, but they cost a buck or two and I'm not in there so phooey on them. ;)

When you're in an EVDO coverage area, the wireless is surprisingly fast.

The "Meh" Stuff

The Next Page buttons run almost the length of both sides of the thing so I keep accidentally turning pages. Also, I've fallen asleep holding the buttons at least twice and found myself with a dead battery and on the last page.

It's ugly. From a design perspective, it's just not sexy. That said, the Sony Reader wasn't exactly clever either. If I were Amazon I would have gotten the iPod designers on board to help. I will say that it's design is more thoughtful than the Sony Reader's and after a few days I stopped caring. It just works.

The screen is paperback book sized, and I wish it were about 30% larger. There's just too much bezel framing it.

It's still $150 more than I'd like it to be, but I bought it anyway because I KNOW I'll use it. I use it every day to read the newspaper, which was also a surprise. (see above)

DSC_0034 DSC_0033 DSC_0032 DSC_0031

Do be warned, there isn't coast-to-coast coverage. If you live outside the US, or outside a decent-sized city, you won't have coverage. That said, I still live an hour outside of Portland and I have coverage and I likely will have coverage everywhere in the US that I'd visit on a business trip.Be sure to check the Kindle Coverage Tool.

Conclusion

I'm thrilled with the purchase, overall. The wireless ability is the key. I didn't want YET another device to dock to my machine. I am so sick of syncing things and looking for tiny USB cables. I even think I could get a device like this for an elder relative and they'd be able to use it without trouble. I suspect that the Kindle will have me reading more often (and I already read a lot). Recommended.

Related Posts

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

LINQ to Everything - LINQ to XSD adds more LINQiness

February 23, '08 Comments [11] Posted in LINQ | Programming | XML
Sponsored By

It's funny when you work at a company that has as many small projects as it has big ones. I hear one of two things:

"Is _______ dead? I haven't heard anything in a month from _____ team's blog! It must be dead.

or

"Can you just stop with the 99 different ways to do _______? There's more happening that I can handle."

I'll try to help with the latter in the coming months. Even though we hear about technologies like LINQ to SQL and LINQ to Entities or ASP.NET MVC and WCF and get confused about if they are complementary, there is (usually) a plan behind the whole stack, even if that plan isn't very well-communicated. I'll do a diagram or two to help soon.

But first, looking at the Is ____ dead? question. It'd be cool if someone just dropped a blog post as a "ping" every few weeks like "We're still here! Nope, not dead!" kind of like an Out of Office Response, but for blogs.

For example, LINQ to XSD was mentioned in June of 2007, looked rockin' sweet, and then went silent. However, small teams like this continue to move the ball forward, but we (the outside world) don't hear from them. I'll try to find those projects and ping for the people.

Just yesterday, LINQ to XSD surfaced (I actually had a video call with them on Weds) with a new release.

LINQ to XSD creates .NET classes with much better fidelity than what's created with (the aging) XSD.exe. Now, of course, XSD.exe makes classes for XmlSerialization, while LINQ to XSD makes classes that use an XDocument (not XmlDocument) as the backing store, so we are comparing Apples to Carburetors, but if your goal is to get Objects that come from an XML source, you should take a look at LINQ to XSD.

For example, if I take one of the goofiest schemas, OFX, a financial services schema (disclosure, I was the Vendor Committee Chair for OFX for a few years so I'm to blame a bit) and run it through LinqToXml.exe, here's some differences.

For example, in the XSD for OFX there's some types like "Amount" that have Restriction Facets. The type is a string, but it must match a certain regular expression, like:

<xsd:simpleType name="AmountType">
    <xsd:restriction base="xsd:string">
        <xsd:maxLength value="32"/>
        <xsd:minLength value="1"/>
        <xsd:whiteSpace value="collapse"/>
        <xsd:pattern value="[\+\-]?[0-9]*(([0-9][,\.]?)|([,\.][0-9]))[0-9]*"/>
    </xsd:restriction>
</xsd:simpleType>

However, when that's turned into generated code via XSD.exe and XmlSerialization, we get:

private string amountField
  
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string AMOUNT {   
get {        
return this.amountField;    
}    
set {        
this.amountField = value;    
} }

Which kind of sucks, from a fidelity point of view. We've lost information, the restriction is gone and the Type is gone.

Here's the same thing generated with LINQ to XSD:

public sealed class AmountType {     
[DebuggerBrowsable(DebuggerBrowsableState.Never)]    
public static Microsoft.Xml.Schema.Linq.SimpleTypeValidator TypeDefinition =
new Microsoft.Xml.Schema.Linq.AtomicSimpleTypeValidator(XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String),
new Microsoft.Xml.Schema.Linq.RestrictionFacets(((Microsoft.Xml.Schema.Linq.RestrictionFlags)(46)), null, 0, 0, null, null, 32, null, null, 1,
new string[] { "^(([\\+\\-]?[0-9]*(([0-9][,\\.]?)|([,\\.][0-9]))[0-9]*))$"}, 0, XmlSchemaWhiteSpace.Collapse));    
private AmountType() {} }

...and...then the accessor:

public string AMOUNT {     
get { XElement x = this.GetElement(XName.Get("AMOUNT", ""));        
return XTypedServices.ParseValue<string>(x, XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String).Datatype);     }
    set { this.SetElementWithValidation(XName.Get("AMOUNT", ""), value, "AMOUNT", global::ofx.net.types.Item2003.Item04.AmountType.TypeDefinition);     } }

Note that this is generated, so don't judge it on aesthetics, it's about the experience as a consumer of the API. This is cool because we don't lose anything, the mapping between CLR type and XSD type is clean enough, you get a real type, but you can still access it as a string. If you set a value it's validated on the fly.

Remember again, this is an interesting, if biased, comparison as LINQ to XSD uses an XDocument as the backing store and its properties access the DOM, while XSD.exe/XmlSerializer makes copies using dynamically generated temporary helpers and XmlReaders/XmlWriters to make Objects out of your Angle Brackets.

Another good example of a quiet team that still has cool stuff coming is LINQ to SQL as they update for SQL 2008.

Dear Reader, what's the best way for a team to tell you they are not dead?

Related Posts

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Hanselminutes Podcast 101 - Dr. Michio Kaku on the Physics of the Impossible

February 22, '08 Comments [26] Posted in Podcast
Sponsored By

Physics of the Impossible: A Scientific Exploration into the World of Phasers, Force Fields, Teleportation, and Time TravelMy one-hundred-and-first podcast is up. Last week I was at an internal Microsoft conference and Dr. Kaku was speaking. I reached out to him personally and was able to interview him at 6 in the morning between his keynote rehearsal and his actual talk, just before he flew back to New York. Needless to say, he's a busy guy and I really appreciated his willingness to chat with me.

Dr. Michio Kaku is a theoretical physicist, best-selling author, and popularizer of science. He's the co-founder of string field theory (a branch of string theory), and continues Einstein's search to unite the four fundamental forces of nature into one unified theory. His book tour starts March 18th and the new book ships March 11th.

michio_collage

In this show, Scott talks with theoretical physicist and futurist Dr. Michio Kaku about making what was once considered impossible technology into reality. This is the topic of his new book, Physics of the Impossible: A Scientific Exploration into the World of Phasers, Force Fields, Teleportation, and Time Travel.

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

The Weekly Source Code 16 - Duct Tape Edition

February 21, '08 Comments [18] Posted in Source Code
Sponsored By

duct-tape-roll A few weeks ago I interviewed Steven Frank (blog), co-owner of Panic and a Mac Developer (who I went to college with). After that interview I stumbled upon the very recently release NSDuctTape project. First, how can you not like a project named after Duct Tape. Second, whenever I hear that some code will bridge to completely incongruent and unbridgeable things, I gotta check it out. What can I say, if there's a freak somewhere that promises to tape two things together, I want to see it! ;) (And I mean freak in the most positive way!)

NSDuctTape is niche, to be clear, but if you want to write .NET code using Mono on the Mac and you want access to the Objective C Cocoa libraries, this is your one-stop shop. (NOTE: If you do download his source, you'll likely have to pull the files out one at a time because there's Mac files in the zip with the same names as folders and Windows doesn't like it.)

And so, Dear Reader, I present to you sixteenth in a infinite number of posts of "The Weekly Source Code." Here's some source I was reading this week.

Dave, the author, hasn't check on Mono's support for Linq, but he uses C# 3.0 features to create his own LINQ-lite helper methods. I found this to be a clever "punt."

	
internal static class Enumerable
{
	public static IEnumerable Select(IEnumerable list, Converter convert)
	{
		foreach (TInput value in list)
			yield return convert(value);
	}

	public static IEnumerable SelectMany(IEnumerable list, Converter> convert)
	{
		foreach (TInput value in list)
			foreach (TOutput converted in convert(value))
				yield return converted;
	}

	public static IEnumerable Where(IEnumerable list, Predicate predicate)
	{
		foreach (T value in list)
			if (predicate(value))
				yield return value;
	}

	public static List ToList(IEnumerable list)
	{
		List result = list as List;
		return result ?? new List(list);
	}

	public static T[] ToArray(IEnumerable list)
	{
		return ToList(list).ToArray();
	}
}

Because he's "thunking" (not the technically accurate word, but I like saying it) down into unmanaged code that needs to have handles allocated and deallocated, he creates an HGlobal wrapper class using my most favorite .NET BCL pattern, IDisposable. Classic stuff, simple and works great.

...snip...

public void Dispose()
{
	if (_hGlobal != IntPtr.Zero)
		Marshal.FreeHGlobal(_hGlobal);
	_hGlobal = IntPtr.Zero;
}

private DisposableHGlobal(IntPtr hGlobal)
{
	_hGlobal = hGlobal;
}

public static DisposableHGlobal StructureToHGlobal(T value)
	where T : struct
{
	DisposableHGlobal result = new DisposableHGlobal(Marshal.SizeOf(value));
	Marshal.StructureToPtr(value, result.ToIntPtr(), false);
	return result;
}
...snip...

Finally, in his application managed "wrapper" he spins through his chosen System.Types and registers each of them with ObjectiveC. This interop is one way, meaning that he's choosing to expose his .NET types as Objective C classes.

public static void Run(string nibFile, IEnumerable exposedTypes)
{
	ObjectiveCClass nsAutoReleasePoolClass = ObjectiveCClass.GetClass("NSAutoreleasePool");
	IntPtr autoReleasePool = nsAutoReleasePoolClass.Instantiate();
	ObjectiveCMethods.SendMessage(autoReleasePool, ObjectiveCMethods.SelectorFromString("init"));
	try
	{
		IntPtr process = IntPtr.Zero;
		GetCurrentProcess(ref process);
		TransformProcessType(ref process, ProcessType.ForegroundApplication);
		SetFrontProcess(ref process);

		Registrar.Initialize();

		foreach (Type type in exposedTypes)
		{
			ObjectiveCNameAttribute attribute = MemberInfoUtility.GetCustomAttribute(type);
			Registrar.RegisterClass(attribute != null ? attribute.Name : type.Name, type);
		}

		ObjectiveCClass nsBundleClass = ObjectiveCClass.GetClass("NSBundle");
		IntPtr name = NativeString.StringToNativeString(nibFile);
		ObjectiveCClass nsDictionaryClass = ObjectiveCClass.GetClass("NSDictionary");
		IntPtr key = NativeString.StringToNativeString("NSOwner");
		ObjectiveCClass nsApplicationClass = ObjectiveCClass.GetClass("NSApplication");
		IntPtr sharedApplication = ObjectiveCMethods.SendMessage(nsApplicationClass.ToIntPtr(), ObjectiveCMethods.SelectorFromString("sharedApplication"));
		IntPtr nsDictionary = ObjectiveCMethods.SendMessage(nsDictionaryClass.ToIntPtr(), ObjectiveCMethods.SelectorFromString("dictionaryWithObject:forKey:"), sharedApplication, key);
		IntPtr zone = ObjectiveCMethods.SendMessage(sharedApplication, ObjectiveCMethods.SelectorFromString("zone"));
		ObjectiveCMethods.SendMessage(nsBundleClass.ToIntPtr(), ObjectiveCMethods.SelectorFromString("loadNibFile:externalNameTable:withZone:"), name, nsDictionary, zone);

		ObjectiveCMethods.SendMessage(sharedApplication, ObjectiveCMethods.SelectorFromString("run"));
	}
	finally
	{
		ObjectiveCMethods.SendMessage(autoReleasePool, ObjectiveCMethods.SelectorFromString("release"));
		autoReleasePool = IntPtr.Zero;
	}
}

It's inside the RegisterClass where he creates Objective C classes for each .NET class, lazily making class definitions, and poking values into them. He's using "reflection" on both sides...reflecting over the .NET types, methods, etc and dynamically creating the same types, methods, etc on the ObjectiveC side.

Freaky and fun!

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Learning Languages Fast - Can you Flush the Toilet in Zulu?

February 20, '08 Comments [80] Posted in Musings
Sponsored By

Tim Ferriss has a penchant for languages. His post How to Learn (But Not Master) Any Language in 1 Hour got me thinking because he gives eight sentences that you can use to get a really good understanding of how a particular language is constructed.

The apple is red.
It is John’s apple.
I give John the apple.
We give him the apple.
He gives it to John.
She gives it to him.
I must give it to him.
I want to give it to her.

Tim uses these sentences because they show how verbs are conjugated between speaker and subject, they show gender, number, direct and indirect objects, negations and tense. Fantastic.

Interestingly, if you ask two speakers of the same language, you might get different answers.

Here's my wife's answers for the first 6 sentences in isiNdebele:

I ephuli libomvu.
Li ephuli likaJoni.
Nginika uJoni i ephuli.
Simnika i ephuli.
Ulinika uJoni.
Ulinika yena.

And here is the same from her sister.

I apple leli libomvu
Ngelika Johane.
Ngipha uJohane i apple.
Siyamupha i apple.
Uyalipha uJohn.
Uyalipha yena.

There's a few things interesting about this, other than two sisters will never agree on anything. Deconstructing isiNdebele (isiZulu), we see:

  • Nouns start with a vowel as in iapple or iephuli or uJohn. (There are many noun classes, not every one starts with i.)
  • The prefix si- indicates we and ya- is present tense, so siyamupha is we (are giving) give
  • Mo uses ukunika to say "to give" and her sister says ukulipha meaning "to hand over" but they really both mean to give. (From http://isizulu.net/) Then her sister goes an uses ukulipha in her 3rd example, so get good examples!
  • There's no gender in the last two, so uyalipha can mean both he gives and she gives.
  • I can see how some verbs are conjugated as in ngipha (I give) and uyalipha (he/she gives)

If there are borrowed words in the language that resonate with me (meaning, I can easily remember them) like imota (car) or ifoni (phone) I can now put together sentences like Imota kaScott (It is Scott's car) or if I learn a few basic infinitive verbs like ukufuna (to want), ukufunda (to learn) or ukucela (to request) I can assemble sentences like:

  • ngicela imali - I want (request) money
  • ngifuna ukufunda isiZulu - I want to learn Zulu

What do you think of Tim's sentences? While you'll not become fluent, it seems to me that this a fun an effective way to learn more than just memorized phrases. You'll certainly build a nice base to build on if your brain works this way.

I know I have a very international readership, and I love travel, so I'd love it if you'd all add in the comments the native translations of these eight sentences in the format:

The apple is red. - PHONETIC PRONOUCIATION - NATIVE ALPHABET
etc...

As an aside, Richard Sprague once said that if you really want to know if someone who says they know a language is really fluent in that language, you should ask them how to say "Flush the toilet." Why that phrase? Because most folks who've cobbled together an understanding of a language from High School or phrase books might be able to assemble an awkward sentence that sounds like "push the button to make the water come" rather than the colloquial or commonly used phrase. For example, in French, "tirer la chasse" translates to the English "pull the chain." Only a person who has lived in a country and gained some fluency knows these kinds of colloquialisms. So the next time your office mate says he knows six languages...find out in how many he can say flush the toilet.

Related Posts

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Knowing when to ask for help - Microsoft SharedView

February 17, '08 Comments [30] Posted in Reviews | Tools
Sponsored By

5231481f-1120-47c9-8279-f005c7c74ee0I've been a mess all weekend. Truly. I've been as stressed as I've been in my life, trying to learn a new technology deeply enough to teach it. It's one thing to learn a tech enough to be capable, but in my new role at Microsoft I'm feeling more of a sense of responsibility than I did when I was just Joe Public Who Talks Loud.

I mean, if you speak with authority, you ought to know something about the topic, right? ;)

Anyway, I finally realized that I wasn't reaching out enough to my network of friends/peers/colleagues. This is probably because I'm still getting used to working from home. It's lonely sometimes, and I can't just drop over to a friend's cubicle. This solitary feeling has made me "buckle down" and try to figure things out more that I used to, since I can't just pop into an adjacent office.

Well, my personal lesson for today is knowing when to ask for help.

I've become REALLY good at remote tools since I've been doing this remote thing (even before). I've used NetMeeting, Remote Assistance, GoToMeeting, VNC, CoPilot.com, LiveMeeting, Hamachi and a dozen things in-between.

Nothing has come close to the ease of Microsoft SharedView. It isn't heavyweight like LiveMeeting or fuzzy like VNC, plus it lets you show your screen to up to 15 other people.

One of the coolest things is that everyone gets their own "personal mouse pointer" with their name hanging off it, so you can see what someone is referring to when they are talking!

Today when I was at life's lowest ebb, I called Rob and Phil and said "guys, I need a code review." I did a Vonage conference call and they logged into the Shared Session using just my email address. Bam. No pausing, no firewall futzing, it's the greatest thing since FolderShare.

I hope it stays free and wonderful, because it saved my bacon this evening. Whew. Now I can sleep.

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

This Week on Channel 9: Feb 15

February 17, '08 Comments [11] Posted in ASP.NET | Microsoft | Podcast
Sponsored By

While I was up in Redmond for the week, I stopped by the "This Week on Channel 9" show with Dan Fernandez and Brian Keller.

It's a weekly show and this is the 3rd episode. I had a great time and I'm hoping they ask me back, maybe once a month.

Someone asked me on Twitter "you're becoming a media person, do you write code anymore?"...and I cried. Yes, I write code every day, phooey on you. ;) I'm just having fun visiting my buddies, but I'll try to show you some more code.

I kind of messed up their show because we were screwing around and they kept laughing. You can see some out-takes (bloopers) if you watch until the very end, after the credits at about 25:00.

I hope you enjoy it.

NOTE: If you want a FullScreen WMV you can get it, as well as a downloadable version or view it on the Channel 9 site.

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 twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Geek Developer Cribs on10

February 15, '08 Comments [39] Posted in ASP.NET | Channel9 | Microsoft | Personal | Podcast | Programming | Remote Work
Sponsored By

Rory and Chris came over to the new house recently and this is what came of that visit. The video is up on10.

"In this edition of Show Us Your Home, Scott Hanselman - a guy who works out of his home office - shows us his Geek Developer Crib with Rory Blyth on the glass and Chris Sells on the open mic.
Scott takes us on a tour of his OCD wiring, Windows Home Server, Xboxen, and personal effects. Special thanks to Rory for producing."

Related Posts You Might Enjoy

  • Wiring the house for a Home Network
  • Part 2 - Design Q&A
  • Part 3 - ISP Hookup
  • Part 4 - Thank You Cat 6 Gigabit Ethernet
  • Part 5 - Gigabit Throughput and Vista
  • Part 6 - Identifying Performance Factors of Home Gigabit Networks
  • How To: Use Google Earth or Virtual Earth to Visualize a New House Lot - Part 1
  • How To: Use Google Earth and SketchItUp to Visualize a New House Lot - Part 2
  • Podcast - Planning, Placing and Building a House with Google Earth and SketchUp
  • 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 twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    Hanselminutes Podcast 100 - Building Community with Norm Judah - CTO of Microsoft Services

    February 15, '08 Comments [3] Posted in ASP.NET | Microsoft | Podcast | Programming
    Sponsored By

    ph_norm_judah

    My one-hundredth podcast is up. Madness. This week I talk to Norm Judah, the CTO of Microsoft Services. We talk about running a world-wide multi-cultural organization of 16,000 consultants, building online community, and writing green software.

    We spoke at Microsoft TechReady6, an internal Microsoft version of TechEd just for the field. Norm conceived and organized this massive conference in order to get the field up to date on the all the cool stuff coming out of development centers. Whip smart, yet still accessible, Norm was very cool to take time from his insane schedule and talk to me. I hope you enjoy it.

    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 twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    MS-Ajax Client Javascript integrated within the Aptana IDE

    February 12, '08 Comments [8] Posted in ASP.NET | Javascript | Microsoft | Musings | Programming
    Sponsored By

    Aptana has a cool Eclipse-based IDE for writing AJAX-y websites. It's got built-in support, via plugins, for most of the major Javascript Libraries. At the core of ASP.NET's AJAX support is the Microsoft AJAX Library 3.5 (direct download), a collection of Javascript classes that you can use in any application, whether it uses ASP.NET or not. The library is licensed under the Ms-PL, the least restrictive Microsoft license. It's the "do what makes you happy" license.

    Anyway, I wanted it integrated into Aptana's Studio, so I took the client libraries and bundled them into a JAR file as an Aptana (Eclipse) plugin. You just download this one JAR and save it in the Aptana\Plugins folder and when you make a new Web Project, Microsoft Ajax 3.5 will appear in the list.

    clip_image002

    When you select (it's a checkbox, so you can add multiple libraries to one project) you'll get the Javascript and "intellisense" for the libraries, as well as a Hello World Sample...

    clip_image002[6]

    ...as well as integrated with the online Ajax Documentation

    clip_image002[8]

    I think that JS components like MS-Ajax should be easily accessible in other IDEs that aren't Visual Studio, like Aptana.

    The one big feature that I didn't have time to do was full Intellisense (Aptana calls it "Code Assist") as it'll require a custom ScriptDoc XML file to describe each method within the libraries. This means that you'll not get the extra documentation tooltip, but I'm working in it.

    Bertrand has a post explaining what our format for JS metadata looks like. The Open Ajax Alliance has an IDE Charter that describes an interoperable way for IDEs to interact with libraries, publish metadata,etc. Microsoft joined the Alliance last year and passed the Open Ajax Interop Test last September. Bertrand has a whole category dedicated to Open Ajax. When these specs gets better figured out, we'll make sure this gets supported. I may write a tool in the short term to convert between our format into Aptana's if folks ask. Eventually, however, everyone will use the standard (after it comes out, you know how standard take time).

    I've  been talking with Aptana to get this support built in and possibly auto-downloadable, but for now, if you're running Aptana and you'd like MS-Ajax support, save this JAR (com.ajax.ms.3.5.21022.8.jar) into Aptana's plugin directory and restart the IDE.

    Later, I'll show you how to do the inverse with Visual Studio, integrating Prototype and JQuery.

    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 twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    ooVoo - Multi-person Video Chat comes to Windows

    February 9, '08 Comments [19] Posted in Remote Work | Reviews | Tools
    Sponsored By

    iChat As a remote worker going to meetings sucks. It sucks big time. Huge. Nothing is worse (from a work perspective) than listening to six faint voices over a speakerphone get work done while you struggle to remain relevant.

    Sometimes I can convince someone to bring a laptop to a meeting but inevitably they haven't got the right software working. If we can actually get a video going, I have to explain to them how to get it going full screen.

    If we actually do get it working using either Office Communicator, Live Messenger or Skype, we can only have one to one video. (Yes, I know about iChat, but not everyone has a Mac).

    I'm not sure of the relationship between ooVoo and the others, but I can tell you that ooVoo is like Skype PLUS multi-person chat. Wow. It's fantastic. It'll do 6 people. I tested it with four as you can see above. The video is better than the audio, but we had folks in 4 states (1 in Hawaii) so I'm not sure everyone had the best connection.

    It also has a beautiful "You Don't Know Jack" juicy style animated interface. It's very responsive and you can minimize and maximize whatever individual or individuals are talking at the time.

    Color me impressed. It doesn't have any of the office features like Office Communicator, so that'll still be my primary chat for work, but this'll be great for the couple of meetings I have a week with remote folks in many locations. If you sign up my ooVoo name is "shanselman."

    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 twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    ASP.NET Wiki Beta

    February 8, '08 Comments [17] Posted in ASP.NET | Learning .NET | Microsoft
    Sponsored By

    imageOne of my first projects when I started working here is an ASP.NET Wiki. ScottGu had the idea and my team had to make it happen. The Beta (finally!) launched today. A lot of work went into the development and seeding of this project.

    The idea is that folks spend a lot of time trolling the blogs, googling live-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.

    Search is great, but for targeted answers you can't beat the one-two punch of search plus human  editing. I spent a long time looking for content and seeding the wiki, but there's still piles to do. Hopefully it won't be just me editing it.

    What's the point:

    • To provide a targeted, categorized, human-hand-edited, and living Wiki for finding answers to ASP.NET questions.

    You can leave comments on the content, there's RSS feeds, and you add your own updates and make it better. You'll also get recognition points if you're a member of the http://www.asp.net community.

    image

    You can get there from http://wiki.asp.net/ and it's also been added to main tab menu of http://www.asp.net. Folks are already starting to discover the site and make changes. I hope you find it helpful!

    Thanks above all to my friend Ward for inventing the Wiki in the first place!

    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 twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    Using an IDE to write PowerShell Scripts

    February 8, '08 Comments [10] Posted in PowerShell
    Sponsored By

    imageI was writing a PowerShell Script for the 2008 Window Scripting Games (are you in the games?) and I found writing a long complex script using only a text edit to be really tiring.

    I blogged about a PowerShell IDE two years ago, but for whatever reason it didn't stick. I didn't start using it regularly and fell back to the command-line and notepad.

    However, while I was writing scripts for the Games I got fed up with just the command-line. I went back to http://www.powershell.com and starting coding in the PowerShellPlus Editor. You can get it free. Schweet.

    This IDE has come so far and it's a joy to use. It's got a debugger and intellisense and syntax highlighting. It's like SQL Analyzer, but for PowerShell. It's a great way to not only learn PowerShell but it's very powerful for advanced users. Seriously, go get it.

    UPDATE with $50 off COUPON: From the comments: "So we have a special deal for loyal hanselman fans..For the next 2 weeks we will give $50 off our price of $129, giving you our PowerShell Suite for only $79.  However we've only set up the coupon code with google checkout, so you'll have to checkout through there. So basically add the item to your cart, and check out with Google checkout and use the coupon code: hanselman and you'll be on your way."

    Related Posts

    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 twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    Hanselminutes Podcast 99 - Mac Development with Panic's Steven Frank

    February 8, '08 Comments [15] Posted in Podcast
    Sponsored By

    stevesunchips My ninety-ninth podcast is up. Seriously, 99. That's INSANE. We've got a special guest for the 100th show next week, but this show is equally awesome.

    In this episode, I sit down with Steven Frank, co-founder of the Award-Winning Mac Development shop Panic. Panic develops software like Transmit (THE Apple FTP client), Unison (The Apple NNTP client) and most recently Coda, a "one window" web development IDE.

    Oddly enough, they are also the only licensed provider of Katamari swag in North America, and their shopping cart interface is bangin'.

    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 twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    Visual Studio Programmer Themes Gallery

    February 7, '08 Comments [50] Posted in ASP.NET | Microsoft | Programming | Silverlight | Tools | Windows Client
    Sponsored By

    UPDATE: http://studiostyles.info/ for a great growing community of Visual Studio Styles and Themes. You can create, import and export themes in your browser!

    Import and Export Settings Wizard More and more I find myself "skinning and themeing" my Visual Studio development environment in order to stay frosty. It's surprising how changing your theme (fonts, colors, etc.) can re-energize me when I'm having trouble with some problem or motivation.

    Here's a gallery of some nice Visual Studio Themes to refresh your look.

    Remember to always back up your settings so you can get back to the way things were and have no fear when you're changing your settings. Note also that some of these settings files you'll find out in the wild may (mistakenly) have Keyboard Bindings included. You'll want to selectively import just the fonts and colors that you want and avoid importing over your own custom keyboard settings.

    I switched to a darker scheme a while back, as have many others. I also spent a while looking for the perfect font as have others. When you stumble on a 2005 theme that you want ot use in 2008, Tomas has an XSLT to make the transition smoother.


    Oren Ellenbogen's Dark Scheme

    A lot of the darker schemes like Oren's don't use a True Black, but an "off  black." His theme is very low contrast and uses muted, relaxing colors.

    ide_colors_regular


    Mike "Blowmage" Moore's Ruby Blue

    This is a low-contrast calm schema, but operators and numbers have a little "pop" to them.

    image 


    Vibrant Borland by Mawi

    This one bring backs good memories of writing Borland C++ with OWL and Turbovision, with a little Norton Commander thrown in for fun.

    image


    CodingHorror

    One of the few light-colored themes, Jeff's also uses a custom font to make 0 and O stand out. Note that the white background is more of a paper-colored off-white.

    image


    Dave Reed's Jedi Scheme

    Dave's schema uses a complete black, and a neon blue. A little intense, but much higher contrast.

    image


    Damien Guard's Humane

    This earthy theme includes little details like smart fonts and italics.

     image


    Tomas Restrepo's Themes

    Tomas has done a huge amount of work in this space. You can get seven of his themes here. He's even got a tool to port color schemes from Visual Studio to SQL Management Studio.

    Desert Nights

    This theme uses the greatest range of colors outside of the Vibrant Ink them, and approaches, but doesn't reach, a number of primary colors.

    image

    Garden of Eden

    Green, Kermit-green, sea-green, they are all here in this blue-green theme.

    image

    Ragnarok

    Initially similar to many dark themes, this one uses complementary colors to provide contrast between identifiers and keywords, string literals and comments.

    image

    Nightingale

    A more cheerful dark theme that includes italics for string literals and brighter neons for keywords.

    image

    Moria Alternate

    This uses Deja Vu Sans Mono as it's font and uses a lot more neutrals and grays outside of the keyword space.

    image


    Brad Wilson Dark Visual Studio

    A muted, low-contrast theme with blues and purples. Even the yellow is relaxed.

     image


    Martin Plante (slimCODE)

    Martin likes small text, no ClearType to take advantage of crisp LCD screens. Rather than committing to blue or black he goes for a navy-gray-blue background.

    image


    John Lam's Vibrant Ink Port

    John's trying for a straight port of Textmate's famous Vibrant Ink. This is a sharp, bright, neo-classic theme. Note his use of Monaco.

    image


    Rob Conery - Textmate

    This is Rob's take on Vibrant Ink, added Consolas as the font, some bolding, and lowers the contrast a smidge.

    image


    Post links your themes in the comments!

    Related Posts

    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 twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    The Weekly Source Code 15 - Tiny Managed Operating System Edition

    February 4, '08 Comments [15] Posted in Learning .NET | Microsoft | Musings | Programming | Source Code
    Sponsored By

    Thanks to Thijs Kroesbergen for the pointer to this week's source. He turned me on to a tiny Operating System written in C# called "Cosmos (C# Open Source Managed Operating System)". As the project says, why? Because it's fun! I wrote a Tiny Virtual OS in C# for an Operating Systems class I took while I was going to school at night.

    And so, Dear Reader, I present to you fifteenth in a infinite number of posts of "The Weekly Source Code." Here's some source I was reading this week.

    First, I went back and looked at some of my source code from the Tiny OS project. It was written, largely at night, in .NET 1.1. It was for a 10 week (one term) project, and I wrote it all in a weekend so as to have the rest of the term free.

    It's pretty horrific to read old source. I would propose that if you can look at old code you wrote and feel good about it that you're either insane, deranged or a really good programmer. One of those three.

    Do remember that this project was a tiny Virtual OS. We were given an Instruction Set for our little processor and a format for programs and the goal was to write an OS to run them.

    Here's the constructor for my MemoryManager. I'm sure doing a lot of work in the constructor! One of the fun little things I did for this Tiny OS was to swap memory pages as XML Files. It was a little joke because XML was such overkill and overhead for something so nuanced as a memory manager. I figured since I was simulating an OS's behavior using something as high-level as .NET, then why shouldn't I swap fake memory to disk as XML?

    I wanted the source for this Tiny Virtual OS to ready like all the psuedo-code we'd been looking at in the Operating Systems books.

    Looking back, I think it'd have been cool if I'd made a WinForms host and did a graphical view of memory that would allow folks to see things like memory fragmentation. Maybe I'll do one in WPF or as an XBAP, it'd be a cool learning tool for some of the students I talk to.

    public MemoryManager(uint virtualMemSizeIn)
    {
    	// Find a size for addressableMemory that is on a page boundary
    	virtualMemSize = CPU.UtilRoundToBoundary(virtualMemSizeIn, CPU.pageSize);
    
    	// Size of memory must be a factor of CPU.pageSize
    	// This was asserted when the CPU initialized memory
    	uint physicalpages = (uint)(CPU.physicalMemory.Length/CPU.pageSize);
    	uint addressablepages = (uint)(virtualMemSize/CPU.pageSize);
    	
    	_pageTable = new ArrayList((int)addressablepages);
    
    	// Delete all our Swap Files
    	foreach (string f in Directory.GetFiles(".","*.xml"))
    		File.Delete(f);
    
    	// For all off addressable memory...
    	// Make the pages in physical and the pages that aren't in physical
    	for (uint i = 0;i < virtualMemSize; i+=CPU.pageSize)
    	{
    		// Mark the Pages that are in physical memory as "false" or "not free"
    		MemoryPage p;
    		if (i < CPU.physicalMemory.Length) 
    		{
    			p = new MemoryPage(i, true);
    			freePhysicalPages[(int)(i/CPU.pageSize)] = false;
    		}
    		else p = new MemoryPage(i, false);
    
    		_pageTable.Add(p);
    	}
    }

    Now my OS a trinket, to be clear. Cosmos, on the other hands, is darned interesting. How could you create a REAL OS (meaning an actual bootable OS off of hardware, be it virtual or physical, using IL? You translate the IL to ASM, of course. Very cool and darned clever.

    Cosmos includes a compiler (IL2CPU, which is part of Cosmos) that reads the input file (usually the shell) and Cosmos libraries and compiles the resulting IL to x86 code. IL2CPU has a layer for cross platform and we plan to support other processors and platforms, including x64. IL2CPU also supports certain extension methods which allow C# code to interact directly with the CPU, registers, and ports in the kernel. IL2CPU contains some inline assembler, but there are no ASM files that need to be linked in.

    Currently IL2CPU first outputs raw asm files (with IL comments) and then processes them through nasm (a free assembler). Later we plan to emit directly to binary.

    The scenarios that Cosmos could be used in are very interesting. Because it's easy to write to and easy to build, you could create little mini-OSes with just the features you want. You could make an OS that just does DNS, or just does some REST service. Who knows. (Yes, I know you could also do a stripped down Linux). There is also talk about getting Cosmos to work on the Wii.

    The example below is from Indy.IL2CPU.Assembler.X86.Native. As you can see, IL2CPU writes out ASM.

    protected override void EmitDataSectionHeader(string aGroup, StreamWriter aOutputWriter) {
        base.EmitDataSectionHeader(aGroup, aOutputWriter);
        if (aGroup == MainGroup) {
              aOutputWriter.WriteLine("section .data");
              aOutputWriter.WriteLine("_start:  ");
              aOutputWriter.WriteLine("; multiboot header ");
              aOutputWriter.WriteLine("MBFLAGS equ 0x03 ; 4KB aligned modules etc., full memory info,  ");
              aOutputWriter.WriteLine("                        ; use special header (see below) ");
              aOutputWriter.WriteLine("dd 0x1BADB002           ; multiboot signature ");
              aOutputWriter.WriteLine("dd MBFLAGS              ; 4kb page aligment for modules, supply memory info ");
              aOutputWriter.WriteLine("dd -0x1BADB002-MBFLAGS  ; checksum=-(FLAGS+0x1BADB002) ");
              aOutputWriter.WriteLine("; other data - that is the additional (optional) header which helps to load  ");
              aOutputWriter.WriteLine("; the kernel. ");
              aOutputWriter.WriteLine("; end of header ");
              aOutputWriter.WriteLine("MultiBootInfo_Memory_High dd 0");
              aOutputWriter.WriteLine("MultiBootInfo_Memory_Low dd 0");
     }

    There's lots of methods like this that do the hard work. The orchestration, however, is up in Engine.cs, where assemblies are taken appear via reflection, and their methods are taken apart using the obvious (my psuedo-code):

    foreach Type in Assembly
       foreach Method in Type
          ProcessMethod into ASM (via ProcessAllMethods)

    Using an interesting ILReader, a useful class in and of itself. Here's a trimmed chunk from ProcessAllMethods that uses the ILReader.

    At this point, we've loaded an assembly, got a type, and we're sitting on xCurrentMethod. They take the method, check for some exception handling (I've trimmed that, it's tedious) and they get an OpCode, and then using the current Assembler, they assemble that operation. Lather, rinse, repeat as necessary.

    ILReader xReader = new ILReader(xCurrentMethod);
        while (xReader.Read()) {
        if (mInstructionsToSkip > 0) {
            mInstructionsToSkip--;
            continue;
        }
        ExceptionHandlingClause xCurrentHandler = null;
        ...snip...        
        xMethodInfo.CurrentHandler = xCurrentHandler;
        xOp = GetOpFromType(mMap.GetOpForOpCode(xReader.OpCode), xReader, xMethodInfo);
        if ((!xOp.SupportsMetalMode) && mAssembler.InMetalMode) {
          throw new Exception("OpCode '" + xReader.OpCode + "' not supported in Metal mode!");
        }
        xOp.Assembler = mAssembler;
        new Comment("StackItems = " + 
          mAssembler.StackContents.Count + ", 
          Top item = " + 
           (mAssembler.StackContents.Count > 0 ? mAssembler.StackContents.Peek().ToString() : "(empty)"));
           xOp.Assemble();
        }

    There's not a lot of comments in the Cosmos Project, but once you get your head around what they are doing, it's a pretty amazing piece of work, and I can see why they are having so much fun.

    From their site at http://www.gocosmos.org:

    If you just want to play with Cosmos:

    1. Install the user kit.
    2. Join the discussion list

    Other resources:

    1. Read the FAQ.
    2. Subscribe to the Cosmos Blog
    3. Documentation - Most developer documentation right now.
    If you are interested in kernel development:
    1. Get source from CodePlex
    2. Read the full requirements. They are pretty basic though, and everything you need except for Windows (For development) is free.
    3. Read Getting Started

    Enjoy!

    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 twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    MS Deploy - New IIS Web Deployment Tool

    February 2, '08 Comments [12] Posted in ASP.NET | IIS | Tools
    Sponsored By

    Microsoft Web Deployment Agent Service Properties (Local Computer)Months ago, even before I started at Microsoft, I got to talk to some very nice people about a project they were calling AdminX. After I told them that that was very possibly the worst name they could possibly give it (and they took part that very well) we got to dig into what the tool was going to do. As with all great tools it did stuff that we had already written at my last company. It's always nice to throw home-grown tools away if found tools will do the job better.

    Anyway, there's a Tech Preview of MS Deploy out for both x86 and x64. It installs a Windows Service, but it doesn't need to be running except when it's doing work so don't panic.

    It's got a metric ton (a good thing) of options. For example, if I want to archive/backup a Site, I go:

    msdeploy.exe" -verb:sync -source:appHostConfig="Default Web Site" -dest:archivedir=c:\mybackup

    You can restore just by reversing source and dest. All the settings are maintained and stored in XML.

    There's other "verbs" to use. For example, you can getDependencies (currently only on IIS6, IIS7 to come) and get details on exactly what your app needs in terms of authentication, filters, modules, etc.

    You can transfer or 'sync' websites or web servers between each other like this:

    msdeploy -verb:sync -source:webserver,targetName=http://computername/MSDEPLOY/ -dest:webserver > msdeploysync.log

    Also, because there's a Windows Service involved, you can do remote deploys - that's the part we've all been waiting for. MS Deploy also supports the -whatif flag, showing you what will happen without doing anything. 

    There is also a plan to have a PowerShell cmdlet interface for MS Deploy when it releases, so things are looking up in the IIS space.

    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 twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

    Firefox, WPF and XBAP

    February 2, '08 Comments [27] Posted in Microsoft | Programming | Windows Client
    Sponsored By

    WoodGrove Finance Explorer - Mozilla FirefoxI finally got around to trying a .NET 3.5 XBAP (XAML Browser App or "WPF Browser Apps") in Firefox, and it works just as advertised. I put together an incredibly useful and powerful application consisting of a picture of me and a button. I think everyone will want to run it. ;)

    Seriously though, it's very easy to deploy apps like this. This reminds me of the year I spent working for Aurum (then a division of Baan) creating a large application using VBPs - ActiveX Documents.

    These were the same basic idea. Your application would run - then IE4, methinks - using the Browser as it's Window Frame, much the way Word or Acrobat can open up a document inside the Browser. This is all still very old-school ISite COM stuff.

    Anyway, XBAPs aren't Silverlight, they are the Full .NET Framework in your browser. With .NET 3.5 that means IE or Firefox. Think of XBAPs as ClickOnce applications that never jump out of the browser.

    Keep in mind that mine is a silly example, and yes, this one could be done with DHTML, however the Woodgrove Finance Application (a .NET 3.0 WPF Application, seen above in Firefox) would be more challenging, hence the idea behind WPF Browser Apps.

    I fire up VS2008 and hit File | New Project | WPF Browser Application.

    image

    Then, I drag an image on the Page and a Button. I use Split Screen View so I can see the XAML being written a the same time. I double-click on the surface, then go back and double-click on the button. That adds the Loaded= and Click= event handlers you see below. I could have typed this manually also.

    <Page x:Class="WpfBrowserApplication1.Page1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Page1" Loaded="Page_Loaded">
        <Grid>
            <Button Height="57" Margin="70,0,70,24" Name="button1" 
    VerticalAlignment="Bottom" Click="button1_Click">What a great App!</Button> <Image Name="image1" Margin="50,18,48,96" > <Image.RenderTransform> <RotateTransform Angle="0" CenterX="100" CenterY="100" /> </Image.RenderTransform> </Image> </Grid> </Page>

    I'm going to do two things. One, I'll load a picture from an Embedded Resource. I could have loaded it from a location like my web server, but this is harder and educational for me. Then, two, I'll make the picture turn when I push the button. I could add an Animation declaratively but again, this is a little harder and more interesting.

    First, getting the embedded graphical resource. This might look familiar if you've done it with WinForms.

    System.IO.Stream stream = this.GetType().Assembly.
    GetManifestResourceStream("WpfBrowserApplication1.MyFile.jpg"); JpegBitmapDecoder bitmapDecoder =
    new JpegBitmapDecoder(stream,
    BitmapCreateOptions.PreservePixelFormat,
    BitmapCacheOption.Default); ImageSource imageSource = bitmapDecoder.Frames[0]; image1.Source = imageSource;

    I've made it more lines than is needed, but basically, get the stream, decode the graphic (Gif, Jpeg, PNG) and grab the Frame. If it were a Gif, it might be animated, hence Frames[0].

    Ok, easy. Now to make it spin. And not just turn in a chunky way, but smoothly turn 60 degrees with each button press. I make an animation, set a From and To value as a double and tell it to last a half second. Then I grab the RotateTransform off the image and begin the animation.

    private int angle = 0;
    private void button1_Click(object sender, RoutedEventArgs e)
    {
      DoubleAnimation ani = new DoubleAnimation();
      ani.From = angle;
      angle += 60;
      ani.To = angle;
      if (angle >= 360) angle = 0;
      ani.Duration = new Duration(new TimeSpan(0, 0, 0, 0, 500));
    
      RotateTransform tran = (RotateTransform)image1.RenderTransform;
      tran.BeginAnimation(RotateTransform.AngleProperty, ani);
    }

    There's a pile of good articles and books out there on WPF. What strikes me is how many high level it is. It's nice to think of constructs like angle and RotateTransform rather than doing the math.

    The silly result of this code is at http://www.hanselman.com/clickonce/takethree/WpfBrowserApplication1.xbap and it works in both Firefox and IE if you have .NET 3.5 installed.

    Related Posts

    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 twitter subscribe
    About   Newsletter
    Sponsored By
    Hosting By
    Dedicated Windows Server Hosting by SherWeb

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