Posts tagged ‘programing’

November 11th, 2010

My guest chapter for Hacking Silverlight: Community Edition

Hacking Silverlight: Community Edition CoverI’ve been working hard to stay involved in the local user group community. My adventures put me in touch with a local Silverlight MVP, David J. Kelley. David has been working on a number of projects, one of which is a follow-up book to his first title Hacking Silverlight. This new edition is titled Hacking Silverlight: Community Edition. David asked me to write a chapter that highlights some of the great projects that are on My chapter is titled Codeplex Projects Everyone Should Know About and you can read it here.

In addition to the book there is a great Code Browser that you can install which will guide you through learning the XAML/C# techniques highlighted in the book. It was a great learning experience and I hope to be able to contribute more in the future.

April 28th, 2010

Simple PHP Twitter script

UPDATE: The new Twitter API v1.1 no longer supports this code. You will need to authenticate before using it. Here is a little tutorial on how to do that

I broke out this useful little PHP Twitter script from the WordPress theme jessica-fletcher-redux, which happens to be the theme I used as a template for this blog. There were a few issues I needed to overcome in order to make this work. I’m hosting this WordPress blog on Windows Server running IIS7. By default many PHP functions are disabled for security so you have to implement a work around.

The get_url_contents($url) function was added to overcome a security problem on IIS where file_get_contents() is not allowed. The other issues to is to make sure you grant write permission to PHP so it can write to your twittercache.xml file. These two changes make for a very clean twitter readout that can easily be styled using CSS.


function get_url_contents($url){
        $crl = curl_init();
        $timeout = 5;
        curl_setopt ($crl, CURLOPT_URL,$url);
        curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout);
        $ret = curl_exec($crl);
        return $ret;

function generatetwitter($twittername){

	$username = $twittername; // Your twitter username.
	if ($username == ""){
		$username = "discorax";
	$limit = "15"; // Number of tweets to pull in.
	/* These prefixes and suffixes will display before and after the entire block of tweets. */
	$prefix = ""; // Prefix - some text you want displayed before all your tweets.
	$suffix = ""; // Suffix - some text you want displayed after all your tweets.
	$tweetprefix = "<li>"; // Tweet Prefix - some text you want displayed before each tweet.
	$tweetsuffix = "</li> \r"; // Tweet Suffix - some text you want displayed after each tweet.
	$feed_string = "" . $username . "&rpp=" . $limit;  

 function parse_feed($feed, $prefix, $tweetprefix, $tweetsuffix, $suffix, $username) {
		$feed = str_replace("<", "<", $feed);   		$feed = str_replace(">", ">", $feed);
		$clean = explode("<content type=\"html\">", $feed);
		$link = explode(",2005:", $feed);
		$amount = count($clean) - 1;
		echo $prefix;
			for ($i = 1; $i <= $amount; $i++) {   				$cleaner = explode("</content>", $clean[$i]);
				$linker = explode("</id>", $link[$i+1]);
				$this_tweets = str_replace("&apos;", "'", $cleaner[0]);
				$this_tweets = str_replace("&gt;", ">", $this_tweets);
				$this_tweets = preg_replace('!<a href.*?>!', '', $this_tweets);
				$this_tweets = preg_replace('!</a>!', '', $this_tweets);
				echo $tweetprefix.'<a href="'.$username.'/status/';
				echo $linker[0];
				echo '" target="_blank">'.$this_tweets.'</a>';
				echo $tweetsuffix;
		echo $suffix;

	$twitter_cache_file = 'twittercache.xml';

	$mtime= null;

	if($mtime== null ||(time()-$mtime)>(9*60)){// 9 minutes or older?

	if (!@file_get_contents($twitter_cache_file)){
		  echo __('Oops, something went wrong. Did you rename the cache folder? The cache file? You shouldn\'t have done that...', 'jfr_theme');
	}else {
		  $twitterFeed = file_get_contents($twitter_cache_file);

	parse_feed($twitterFeed, $prefix, $tweetprefix, $tweetsuffix, $suffix, $username);  


Setup is easy. You simply need to call the generatetwitter() function like so.

echo "<div>";
echo "<ul>";
echo "</ul></div>";

When you’re uploading the files to your server make sure to include a blank twittercache.xml file in the same directory as the script. You can change this location by changing the value of the $twitter_cache_file variable (line 48 above) to a path where you keep the twittercache.xml file (make sure you grant write permission to that folder).

That’s it. It’s a clean little code snippit for pulling a user’s twitter feed which you can easily extend using a simple form to select your twitter account. Happy coding.

March 5th, 2008

MIX08 Keynote online – Silverlight 2

I wasn’t able to attend MIX08 this year, but I was really interested in hearing the keynote especially about Silverlight 2. Lucky for me the MIX Online Blog team had a live stream that I could watch. Scott Guthrie came on and started talking just about the time I showed up. He announced the Silverlight 2 Beta 1 which will be available later today.

I caught the tail end of the Internet Explorer 8 talk. link should be live later today.

Scott Guthrie talked in his keynote a lot about business and monetization of RIAs. How can you create ads, add Ads to your content (video, audio etc).

OMG there is a VS2008 Banner ad Template plugin that they demoed. It created all the crap that I’ve been working on for a month now that is all packaged up. Hummm…being on a cutting edge can be tough. Now how do I get a copy of this thing so our deployment can be simplified.

HOW DO I DEPLOY THE AD…Video.Show deploying a Silverlight app. Lots of tracking, lots of useful metrics to tell the ad manager about how effective the campaign is. Overlay adverts, Preroll, and much more. Encoder 2 has some potential for rich advertising scenarios.

Using DoubleClick and Silverlight…Ari Poparo talking about supporting media publishing and Silverlight. Has some rich reporting metrics but also cool because a dev can use these events to enhance the experience.

So far, all these cool features aren’t available yet…blech. Site Showoff…Perkins Miller, Matthew Rex. 22,000 hours LIVE ONLINE VIDEO…holy crap! AND VOD (Video On Demand) That’s a lot of content. Interactive Video and Video Delivery of the highest quality. DVR capabilities with the live video, rewind live stream and alerts to quickly switch between viewing experiences. Sharing these videos with others, that’s pretty damn cool! Picture in Picture hahaha…this thing is completely over the top. Will this create a new standard? HAHAHA 3 different streams of the same event…see what other people are watching…and he just keeps going…gawd. I will have to check this out when it goes live. PLUS, how crazy good will this be for Silverlight deployment?!

Now Scott is going into RIAs. Cross-Browser, Cross-Platform .NET Framework.

  • Multi_Language Support
  • WPF UI Framework
  • Robust Networking
  • Integrated Data Support
  • High Performance
  • Small Download, Fast Install (Beta 1 – 4.6MB download)
  • Rich UI Controls

the “dev-igner” very rich control templateing skinning model Custom Animations, Custom State Changes as well as CSS style changes. Making it very easy to customize and skin these controls. New VS2008 Silverlight support…boy I’d love to have that right now. So you can BUILD the application but then hand off to a designer to re-skin without having to write or update any code. YEAH new beta 1 updates for VS2008 and Expression Studio shipping later today.

Showcasing a new Mail Client from AOL using Silverlight to speed up performance, add custom-ability, create an experience much like a desktop application.

Create experiences that don’t exist today…humm…lets see where this goes.


Line of Business – Application Cirque de Soleil using WPF.

HAHA Scott Guthrie circus talent was juggling two balls, and he even dropped um. Funny!

OK..Moving on to Mobile Devices. Silverlight for mobile, bringing Silverlight anywhere, same code, assets skills and tools, Next generation mobile experiences.
Mixer – Darren David, real time mobile based application. Where’s the party at…haha funny little app. Your cell phone telling you you’ve had too much to drink and then making you take a sobriety test…that’s funny. Nokia delivers Silverlight…not just for Mobile PCs. is the Silverlight application that will run native on Nokia phones, on the web, or on WPF on your desktop. Wow…dis on Flash Lite…they said it was too costly to build the weatherbug app. Wonder why that was?

Time to go get all the new updates to get started with Silverlight 2.