rss and json format
- | Posted in
- json
- atlas
- asp.net
- aspnet
- rss
- asp.net ajax
- javascript
i was working on a little sample and wanted to make it a bit easier on myself to work with my rss data. my thought was to use the JSON format for the data and that way i could get at the data in super-cool-ajaxy-type ways. what was cool was what i found as i began searching.
ASP.NET Ajax provides a class library to javascript! in System.Web.Script.Serialization.JavascriptSerializer is where you will find your magic. the JavascriptSerializer can be used on anything that uses XmlSerialization. sweet.
so now all i had to do was take my RSS data (already in good xml format) and serialize that to xml. once the rss is in a strongly typed respresentation using XmlSerialization, then i can pass that object to the JavascriptSerializer and voila...json formatted representation.
so my rss:
<?xml version="1.0" encoding="UTF-8"?> <channel>
<title>Method ~ of ~ failed</title> <link>http://timheuer.com/blog/Default.aspx</link>
<description>ramblings from the digital underbelly</description>
<language>en-US</language> <copyright>timheuer</copyright>
<managingEditor>[email protected]</managingEditor>
<generator>Subtext Version 1.9.5.176</generator> ...
becomes:
{"Version":"2.0","Channel":{"Categories":[],"Cloud":null,
"Copyright":"timheuer","Description":"ramblings from the digital underbelly",
"Docs":null,"Generator":"Subtext Version 1.9.5.176", ... wicked. i put this in an asp.net handler file for me so now i can easily reference some rss data and immediately get back json data to work with, something like:
<script src="http://mysite/rss2json.ashx?u=http://feeds.feedburner.com/timheuer"></script>
you can get an rss serializer with this function built in over at piyush's blog. very cool, now i can move on to my next step...
setting expectations in user experience
- | Posted in
- user experience
i've finally found the ultimo mp3 integration for my auto. i don't have a new car, i don't have an aux jack, and i'm no longer in high school where i care about deep bass or wicked features, my factory stereo works fine thank you very much. fine, that is, except that i can't play my mass collection of audio (unless i do it 6 CDs at a time).
well, i've found it. unfortunately the actual store is in atlanta, ga, usa. a little too far for me to drive and get it installed...so i begin my research of installing it myself (yes, i know i'm about to venture on a bad idea). the company provided me with the installation manual so i can assess my pre-purchase jitters. while the end result of the installation looks incredibly wicked cool (the kind that will make the skool kidz say "d00d"), it isn't as easy to install (to the lay person who doesn't install car stereo equipment on a daily basis).
but the company has provided me with some complete expectations post-install. in a way they're providing me some pre-warnings on my user experience. here's a choice statement from their guide:
The <productname> module is a very complex piece of hardware that is responsible for very complicated communications between your <mp3 player> and your <car>. It will not just "work" once you plug it in. Much like a computer, it requires patience and an understanding of the hardware and its operation to use. You MUST be patient when operating the integration kit. The <productname> has a learning curve.
i was laughing. mother-in-law proof? um, no. the words complex, patient, and phrase 'not just work' are repeated...that's a goucher for sure not being mo-in-law proof. yes, they reall have the word work in quotes. it is beautiful.
but it makes me think if this is a good user experience or not. after all, if i acquire the product, the expectations are being set clear for me. does that make it a good ux? i think about these scenarios in software development as well, namely in the initial deployment stage. if companies writing software go out and say "okay, this is a great piece of software, but you have to ensure that your flux capacitor has been modified with the latest plugin and your alarm shields are down -- only after that will things work...be patient" would that enhance their product?
i think sometimes we are limited in scope what we can do in setting ux expectations (clearly this particular manufacturer hasn't ironed out the ideal kinks in their system, or perhaps they have and thus are delivering the best possible solution to us old car dweebs) and our users suffer. lowest. common. denominator. if you are developing your solution both technically and how your users will interact with it, you must take into account the turn on experience (or out-of-box experience). first impressions are said to be lasting ones. will yours be one?
silverlight on some free hosters
- | Posted in
- silverlight
- free hosting
well, in my previous examples, i was using a free linux hoster. i found another one that was much more reliable from a responsiveness standpoint, but found a snag and wanted to share.
you see on some free hosters, in order to be free they'll add banner adds to your pages. for my purposes, who cares. i signed up with this particular one and none of my samples were working. huh, weird i thought. until you look at the error message of 'unknown namespace' from silverlight. ahh...
you see what the free host was doing was injecting their banner ad code into *every* served request. so when the xaml page was requested, it was being injected into the root of the xaml, thus putting in stuff like <div>my banner ad</div> before the root <Canvas> node. the silverlight parser looked at that and said 'sorry man, homey don't play that.'
argh, off to find another...anyone know of a good free linux host (ad supported is okay as long as it doesn't do the above)?
silverlight and php
- | Posted in
- silverlight
- flickr
- php
- phpflickr
i saw a post over in russell myers' land seemingly acknowledging the confusion that might be out there of hosting silverlight. he noted my previous post about the topic. in his note though, russell mentions:
...it seems entirely possible to take a Silverlight application and integrate it on an existing Apache server to create a Silverlight experience within PHP or any other language that can embed the XAML content.
he's right on here, in fact, i'm not sure even samples will do it justice, but i tried anyway :-). take for example another quick swag sample using flickr. how can i use flickr services via php, get some images and display them in a silverlight application? simple.
first, let me stress again 2 things: i'm not a php developer (so be kind on my code) and i'm not saying this is the end-all-be-all of samples...just merely making a point.
in this example my goal is to have a form that accepts user input, which in turn does a tag search on flickr for some images using their REST api's via PHP. those images are then referenced in a silverlight control that creates a simple little control displaying the image and then for completely gratuitous reasons adds a web 2.0 reflection on the bottom of them :-).
here's what we are doing...first, the php application. now, in my sample here that i'll provide a link to (btw, i'm using a free host that appears to be having issues, so unless someone can point me to a free, reliable PHP host that is what i'm stuck with) we are using flickr's REST apis. i'm using a pre-packaged PHP library for flickr called phpFlickr oddly enough.
step one is creating the php interaction (did i already say i wasn't a php developer?). here's my basic code:
<?phprequire_once("phpFlickr/phpFlickr.php"); $flickr = new phpFlickr("YOUR API KEY HERE"); $i = 0; $tagName = $_POST["flickrTag"];if ($tagName == "") { $tagName = "silverlight"; } $photos = $flickr->photos_search(array("tags"=>$tagName, "tag_mode"=>"any", "per_page"=>"6", "page"=>"1")); ?><script type="text/javascript"> <?foreach($photos["photo"] as $photo) { $purl = $flickr->buildPhotoUrl($photo, "Square"); echo "photoArray.push(\"$purl\");"; } ?></script>
so we are essentially calling out to flickr and getting a search result back. now when you look at the foreach loop here's where you'll see the silverlight 'integration' part 1. in another javascript file i have declared a global javascript array called photoArray. in my loop here, i'm essentially building out the URL to the flickr photo and then jamming that into the array object.
once the content i need to manipulate for silverlight is in my javascript (or .NET code for v1.1) objects, they are on the client. read: no more server stuff... so really in this sample and others, PHP is simply providing some data, whether directly itself emitting XAML that will be consumed (as in this screencast), or providing data for the client to iterate through and create XAML elements on the fly in my sample here. in my example, with this new photoArray i'm instantiating a simple little control i had added (this is the ThumbnailImage.xaml file in the download) -- essentially a pre-build glob of XAML representing my end result.
i iterate through the array and create those elements:
for (var i=0; i < photoArray.length; i++) { var rimg = this.control.content.createFromXaml(xamlFrag, true); this.root.children.add(rimg); new PhpFlickr.Thumbnail(this.control, rimg, photoArray[i], left, top); left += 80; }
the PhpFlickr.Thumbnail object is a javascript prototype class that sets the canvas' inner elements to the image reference. you can learn about creating these little user controls for silverlight here (v1) and here (v1.1):
PhpFlickr.Thumbnail = function(control, target, imageSource, x, y) { this.target = target; this.thumb_image = target.findName("Thumbnail"); this.thumb_reflex = target.findName("ThumbnailReflect"); this.thumb_image.Source = imageSource; this.thumb_reflex.Source = imageSource; this.target["Canvas.Top"] = y; this.target["Canvas.Left"] = x; }
the end result of this sample looks something like this:

so as you can see, very little php code happening here...and that is kind of the point! yes, silverlight can be served up via any web server, and yes, silverlight can be used with any technology. again, my sample may not resonate to "get it" for you, but hopefully you will see the point that the interaction is on the client. so if you have php web services, great, silverlight can use them. if you want php to dynamically generate xaml and deliver it to the silverlight control, yes that can be done.
the sample is online here (again, shared/free host so don't hate me if it isn't up/working), and the sample code is below at the end of this post. i hope this helps clear some things up again, if not, please let me know.
Sample Code: SilverPhp.zip
