Skip to main content


Showing posts from 2010

Parsing Delicious Export File

With all the brew ha ha going on about how Delicious is going to be dumped I made a backup of my Delicious bookmarks. While I was at it I created a quick utility to parse the export file so I could play with the links and tags. Key to parsing the file was the HTML Agility Pack . The Bookmark class: [csharp] public class Bookmark { public string Title { get; set; } public string Href { get; set; } public DateTime AddDate { get; set; } public string AddDateEpoch { get; set; } public List<string> Tags { get; set; } public bool IsPrivate { get; set; } public Bookmark() { Tags = new List<string>(); } public static Bookmark New(HtmlNode node) { if (node == null) throw new ArgumentNullException("node"); var bookmark = new Bookmark { Title = node.InnerText ?? string.Empty, Href = node.Attributes["href"].Value ?? string.Empty, AddDate = FromUnixTime(Convert.ToDouble(node.Attributes["ADD_DATE"].V

ObservableCollection AddRange

Damon Payne has a post AddRange for ObservableCollection in Silverlight 3 . It is pretty short and sweet way to improve performance when batch adding data to an ObservableCollection. He created a SmartCollection: [csharp] public class SmartCollection<T> : ObservableCollection<T> { public SmartCollection() { _suspendCollectionChangeNotification = false; } bool _suspendCollectionChangeNotification; protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e) { if (!_suspendCollectionChangeNotification) { base.OnCollectionChanged(e); } } public void SuspendCollectionChangeNotification() { _suspendCollectionChangeNotification = true; } public void ResumeCollectionChangeNotification() { _suspendCollectionChangeNotification = false; } public void AddRange

RE:Why is Microsoft suddenly so hot for HTML5? | Betanews

Last week, Gartner predicted that mobile would be a trillion-dollar industry by 2014. It\'s a market Microsoft doesn\'t want to be shut out of. via Why is Microsoft suddenly so hot for HTML5? | Betanews . This and my earlier post reinforce my belief that it is time to break the chains of Microsoft.  Meaning it is time for me to stop being a Mort.

RE: Microsoft: Our strategy with Silverlight has shifted | ZDNet

“Silverlight is our development platform for Windows Phone,” he said. Silverlight also has some “sweet spots” in media and line-of-business applications, he said. But when it comes to touting Silverlight as Microsoft’s vehicle for delivering a cross-platform runtime, “our strategy has shifted,” Muglia told me. via Microsoft: Our strategy with Silverlight has shifted | ZDNet . I think it is time to move away from the Microsoft platform.  I'm getting tired of having to learn a new framework every year just to keep up with their changes. I've been using Silverlight at work and I like it but if there is not going to be any support or they totally re-target the platform for just phones, whats the point? Time for python - html5 - JavaScript stack.

Asynchronous Programming in C#

Making Asynchronous Programming Easy Asynchronous Programming in C# [csharp]public async void AsyncIntroParallel() { Task<string> page1 = new WebClient().DownloadStringTaskAsync(new Uri("")); Task<string> page2 = new WebClient().DownloadStringTaskAsync(new Uri("")); Task<string> page3 = new WebClient().DownloadStringTaskAsync(new Uri("")); WriteLinePageTitle(await page1); WriteLinePageTitle(await page2); WriteLinePageTitle(await page3); }[/csharp] Async CTP has been released. Note: This is not automatically Multi-Threading! From the CTP: Merely sticking the "Async" modifier will not make a method run on the background thread. That is correct and by design. If you want to run code on a background thread, use TaskEx.Run(). Please read the overview for an explanation of asynchrony.

UOW: FileHelpers

The utility of the week is FileHelpers , a .Net library that works with delimited and fixed length files. It helps to import and export data from files, strings or streams. I found this recently as I needed to process several CSV files but I did not want to write by hand a parser. Been there, done that way too many times so I did a search and what do you know- someone smarter than me already did it. What I like about it is the wizard that comes with the library that helps to build plain old c# classes to work with the data rows. In about twenty minutes I had a working CSV processing engine complete with intellisense. The library is BSD License , GNU Library or Lesser General Public License (LGPL)

Threading AutoResetEvent Example

[csharp]public class Program { private static System.Threading.AutoResetEvent stopFlag = new System.Threading.AutoResetEvent(false); public static void Main() { ServiceHost svh = new ServiceHost(typeof(ServiceImplementation)); svh.AddServiceEndpoint( typeof(WCFSimple.Contract.IService), new NetTcpBinding(), "net.tcp://localhost:8000"); svh.Open(); Console.WriteLine("SERVER - Running..."); stopFlag.WaitOne(); Console.WriteLine("SERVER - Shutting down..."); svh.Close(); Console.WriteLine("SERVER - Shut down!"); } public static void Stop() { stopFlag.Set(); } }[/csharp]

Coding Horror: Because Everyone Needs a Router

Coding Horror: Because Everyone Needs a Router : "Buffalo Nfiniti Wireless-N High Power Router ($80)" Jeff Atwood discusses routers and what he did to build a new one. He used the Buffalo Nfiniti Wireless-N and DD-WRT to replace his aging yet functional DGL-4500.

The SMAQ stack for big data - O'Reilly Radar

The SMAQ stack for big data - O'Reilly Radar : "'Big data' is data that becomes large enough that it cannot be processed using conventional methods. Creators of web search engines were among the first to confront this problem. Today, social networks, mobile phones, sensors and science contribute to petabytes of data created daily." What other types of large data sets can we use this approach on? The Oil & Gas industry deals with tons of data so maybe SMAQ can be used with it.

Use Linq and Reflection to Activate Interface and Execute a Method.

I created a simple ICommand interface similar to the one in System.Windows.Input: [csharp]interface ICommand { string Description { get; } bool CanExecute(object parameter); void Execute(); }[/csharp] In my project I created a bunch of classes that implement my ICommand interface and I wanted to find and execute them all.  I came up with two ways to do this, using a List<ICommand> and reflection. List<ICommand> This is very direct and easy but as I added new commands the list began to grow. Also I had to remember to add my commands to the list as I created them. [csharp] string separator = new string('=', 100); var commandsToExec = new List<ICommand> { new Commands.TestEntityConnectionStringBuilderCommand(), new Commands.BenchmarkingExampleCommand(), new Commands.FastTokenizerBenchmarkCommand(), new Commands.LinqToXmlTest01() }; foreach (var cmd in commandsToExec) if (cmd.CanExecute(null)) { Console.WriteLine(&quo