Shared posts

19 Sep 07:07

gs-collections 4.0 Released

by mdavey

Goldman Sachs moves forwards with gs-collections 4.0.  Code Kata offers training and excercises on gs-collections.  A rather old slide deck offers an intro here. Inspired by Smalltalk Collection protocol :)   Wonder if the Deutsche Bank Lodestone had anything to do with GS’s Open Sourcing? I notice as well that the Lodestone WordPress blog is now marked as private


07 Jul 07:25

One of Microsoft's Best-Kept Secrets - Python Tools for Visual Studio (PTVS)

by Scott Hanselman
Terryspitz

Niiice.

Python Tools for VS
 

I've talked some about the sweet support for node and PHP in Azure. You can also File | New | Node.js express application in WebMatrix, or run WordPress and get intellisense as well.

"I installed windows just so i can use PTVS" - Comment on Hacker News

But I'm consistently shocked that folks forget about Python at Microsoft. I am a C# person, myself, but the Developer Division at Microsoft loves their languages. C++, VB, C#, F#, etc and they aren't messing about when they get serious about a language.

One of the least-known and most-kick-butt free products we have is PTVS - Python Tools for Visual Studio. Whether you're just interested in learning Python or you're a hardcore PhD who wants mixed-language Python and C++ debugging or somewhere in between, you gotta check this out. (Seriously, the mixed-mode debugging thing can't be overstressed...)

The Misconceptions

  • Microsoft? Python?  Oh, it must be all about IronPython, that's dead, right?
    • IronPython is a community-run project and just put an 2.7.4 alpha out last month.  PTVS fully supports IronPython, but the most advanced support is for standard CPython!
  • PTVS needs VisualStudio? I don't have any money.
    • PTVS, combined with the Integrated/isolated VS Shell is completely and perpetually free.  And with the advent of VS2013, they've combined them into a single installer: https://pytools.codeplex.com/releases (at bottom of page).

This is Real

Here's my VS2013 after installing PyTools (PTVS). I've got IronPython which is Python running under the .NET CLR, but I've also got Django apps as well as a regular CPython or making a new project from existing code.

Python inside VS

You can see that PTVS knows what Python engines I have installed, and I can easily switch between them. Here you can see that VS is refreshing the auto-completion (intellisense) databases for each version.

A list of Python Interpreters

There's also a complete REPL inside Visual Studio for each:

Python REPL inside VS

Developing Django Apps in Visual Studio

Maybe you're a Django (one of Python's Web Frameworks) web developer, you can use VS to develop your app.

Go File New | Django App, then make a new Python Virtual Environment from the Solution Explorer, and watch Visual Studio freaking installed pip for you (the Python package manager). It's very seamless.

Adding a Virtual Python Environment

Which gives me this:

Python in my VS and I'm FREAKING OUT

Then I right click on "dev" and just like NuGet (except this is Python, so pip) I install django:

Installing Django

Django is massive, so this took a while, but still! And.....I've accomplished Hello World in Django. Well, Hello Django, at least, launched from Visual Studio.

Hello Django

You should feel free to go and run through the whole Django Tutorial if you like and even deploy your app to Azure! You can host Django on a regular Azure Web Site, or a Virtual Machine if you want more control.

You can even interactively debug Python running in Azure on Linux from your Visual Studio instance! Check out Steve do just that at PyCon in this YouTube video.

There's a bunch of great educational and quick start Tutorials on the Python Tools YouTube Channel, they are a great resource to bookmark.

You can attach to remote Python processes over SSL and debug if you like.

Setting up Python Debugging

It's Really Integrated

Let's get real here for a second. Lots of projects plug stuff into Visual Studio. You may have made it this far into the post and be saying "oh, wah wah, this thing sets up some batch files and some syntax highlighting and calls itself a full-featured Python IDE."

Um, no. This is the best of VS and the best of Python and I'm blown away. Check this out. PTVS knows that I'm doing unit testing here and they've integrated Python Unit Testing with the VS Unit Testing UI.

Unit Testing in Python and VS? My heart can't take it!

This is debugging, remote debugging, cross language debugging, tool tips, watches, locals, call stacks, unit testing, full REPL with inline graphics, profiling, cloud publish, best of class CPython support, and so much more.

Nailed it

If you're into Python or knows someone who is, for reals, drink it in and get on board at https://pytools.codeplex.com. Check out their samples. They've got Python talking to Kinect, Python talking to Excel and more. Their PTVS Documentation is really good as well.

Just getting started? Well, go Learn Python The Hard Way.

Installing PTVS

Here's the complete install instrucitons. You need VS, the PTVS, and some Python.

    PTVS is free

    Finally, explore the Resources and Docs for Python Tools for Visual Studio, including, but not limited to Editing, Refactoring, Unit Tests, Django, IPython notebook and Azure cloud computing, Kinect for Python and Pyvot - an Excel to Python bridge.



    © 2013 Scott Hanselman. All rights reserved.
         
    29 Mar 22:48

    Fallback HTML5 audio tags for a simple MP3 podcast are harder than you'd think

    by Scott Hanselman

    I've been spending the evenings and weekends lately redesigning the blog and the Hanselminutes podcast site. I hadn't realized how cheesy looking the podcast site was all these years. I'd like to get the show expanded to a wider audience as I feel that listenership has kind of flattened lately. I am in the process of adding faces for ALL 360+ shows going back 6 years.

    A big thanks to Lynsey Smith from Portland Girl Geek Dinners, by the way, for her hard work in finding pics for me!

    I also wanted a nicer in-browser audio experience so I assumed I'd just drop in the audio tag and be done, right?

    The HTML5 Audio tag is wonderful, right? Just works. This is the dream:

    <audio id="audioplayer" preload="metadata" type="audio/mp3" >
    
    <source src="http://s3.amazonaws.com/hanselminutes/hanselminutes_0363.mp3" type="audio/mp3"/>
    Your browser doesn't support the HTML audio tag. Be sad.
    </audio>

    You can try that live at http://jsfiddle.net/CdxbX/ if you like.

    Except it's not nearly that easy.

    Here's what you'll see on IE9+:

    image

    Here's Chrome:

    image

    Here's Firefox, version 19:

    Ya, Firefox currently doesn't support MP3 audio so it just flashes once then disappears. Firefox will support MP3s in audio soon though by using the underlying operating system to play the stream rather than its own embedded code.

    In Firefox 20 (the beta channel) on Windows 7 and above, you can test MP3 Audio support by turning on the preference media.windows-media-foundation.enabled in about:config.

    The part I was disappointed in was more of an HTML5 specification issue. Notice that while I have fallback text present, I don't see it in Firefox. That's because fallback elements are only used if your browser doesn't support the audio tag at all.

    It doesn't do what I would expect at all. What I want is "Can you support any of these audio sources? No? Fallback." This seems intuitive to me.

    I talked to Chris Double via Christian Heilmann at Mozilla and he said "You'd need to raise the issue with WHATWG/W3C. It's been debated before in the past. " Indeed it has. From Oct 2009, more people saying that it's not intuitive to fall back in this way:

    I expected (incorrectly, in this case) that if I only produced one source element (an MP4), Firefox would drop down to use the fallback content, as it does if I include an object element for a format not supported (for example, if I include a QuickTime object and QT is not installed, the user sees fallback content). As far as I can see, the only option in this situation is to rely on Javascript and the video element's canPlayType() function. - Kit Grose

    This lack of an intuitive fallback means that I can't make an audio player that works everywhere using just HTML. I have to use JavaScript, which is a bummer for such a fundamental scenario.

    Getting HTML5 audio to fall back correctly in all browsers

    Instead you have to make an audio tag dynamically, then interrogate the tag. This applies to both audio and video tags. I ended up using some code from my friend Matt Coneybeare.

    <audio id="audioplayer" preload controls loop>
    
    <source src="audio.mp3">
    </audio>
    <script type="text/javascript">
    var audioTag = document.createElement('audio');
    if (!(!!(audioTag.canPlayType) && ("no" != audioTag.canPlayType("audio/mpeg")) && ("" != audioTag.canPlayType("audio/mpeg")))) {
    AudioPlayer.embed("audioplayer", {soundFile: "audio.mp3"});
    }
    </script>

    The AudioPlayer.embed at the end there is the WordPress AudioPlayer in standalone form. This way on Firefox I get the flash player since it answered false to canPlayType.

    Flash audio player in Firefox

    A Responsive and Touch-Friendly Audio Player in HTML5

    However, the default audio player made by the <audio> tag is kind of lame, and I'd like it to better support touch, look great on tablets, etc. For this, I'll turn to Osvaldas Valutis's AudioPlayer. It's a nice little jQuery plugin that replaces the <audio> element with a lovely chunk of HTML. Since you can't actually style the HTML5 <audio> element, people just hide it, recreate it, then broker calls over to the hidden-but-still-working audio element.

    This plugin, along with a little CSS styling of its default colors gives me a nice audio player that looks the same and works everywhere. Except Firefox 19/20 until the next version Firefox answers true to "canPlayType" and then it should just start working! Until then, it's the Flash fallback player, which works nicely as well.

    image

    The other problem is the QuickTime plugin that most Firefox users have installed. When styling with the Osvaldas' AudioPlayer, the JavaScript interrogation would cause Firefox will prompt folks to install it in some cases if it's not there, and it still doesn't work if it is installed.

    I ended up modifying Matt's detection a little to work with this Osvaldas' styling. I realize the code could be more dynamic with less elements, but this was easier for me to read.

    • First, try the audio tag. Works? Great, style it with audioPlayer();
    • Can't do MP3 audio? Dynamically make a Flash player with that P. Hide the audio player (likely not needed.)

    Unfortunately for readability, there's the ".audioPlayer" jQuery plugin that styles the HTML and there's the "AudioPlayer" flash embed. They are different but named the same. I didn't change them. ;)

    <audio id="audioplayer" preload="auto" controls style="width:100%;" >
    
    <source src="your.mp3" type="audio/mp3">
    Your browser doesn't support the HTML audio tag. You can still download the show, though!
    </audio>
    <p id="audioplayer_1"></p>
    <script type="text/javascript">
    var audioTag = document.createElement('audio');
    /* Do we not support MP3 audio? If not, dynamically made a Flash SWF player. */
    if (!(!!(audioTag.canPlayType) && ("no" != audioTag.canPlayType("audio/mpeg")) && ("" != audioTag.canPlayType("audio/mpeg")))) {
    AudioPlayer.embed("audioplayer_1", {soundFile: "your.mp3", transparentpagebg: "yes"});
    $( '#audioplayer').hide();
    }
    else /* Ok, we do support MP3 audio, style the audio tag into a touch-friendly player */
    {
    /* If we didn't do the "if mp3 supported" check above, this call would prompt Firefox install quicktime! */
    $( '#audioplayer' ).audioPlayer();
    }
    </script>

    All in all, it works pretty well so far.

    ODD BUG: Chrome does seem to have some kind of hang where this audio player is getting blocked while the comments load on my site. Any JavaScript experts want to weight in? If you load a page - like this one - and hit play before the page is loaded, the audio doesn't play. This only happens in Chrome. Thoughts?

    While you're here, check out the new http://hanselminutes.com and consider subscribing! It's "Fresh Air for Developers."



    © 2013 Scott Hanselman. All rights reserved.