Posts Categorized: code

Stanza Catalog Update

Posted by & filed under code.

I’ve continued enhancing the Stanza catalog I created earlier. New features include purchase links and Google Analytics tracking. I reverse-engineered the FeedBooks API and the AllRomanceBooks.com feeds to figure out how to do some of these things. Also I’ve been reading the OPDS spec (an industry-standard successor to the Stanza format) to add support for […]

Get the MD5 hash of a file in .Net

Posted by & filed under code.

MSDN has a page on how to get the MD5 hash of a string. Easy enough, but if you follow their example exactly for a file and use File.ReadAllText() to get the string, you will get the wrong MD5 string for binary files. Instead, use File.ReadAllBytes() to bypass encoding issues. (This also applies to SHA1 […]

Creating a Stanza Catalog with ASP.Net MVC 2.0

Posted by & filed under code.

Stanza is a book reader for the iPhone/iPad.  One of Stanza’s features is the ability to browse specially formatted book catalogs.  While it has a number of built-in catalogs, you can also add your own.  I have created such a catalog with ASP.Net MVC 2.0 (screenshots).  The Stanza catalog format is pretty simple – just AtomPub with some […]

Add a Facebook Like button to your page

Posted by & filed under code.

Adding a “Like” button using the Facebook JavaScript API is easy: <div> &lt;fb:like href=&quot;"&gt; </div>   window.fbAsyncInit = function () { FB.init({ appId: ‘your app id’, status: true, cookie: true, xfbml: true }); }; (function () { var e = document.createElement(‘script’); e.async = true; e.src = document.location.protocol + ‘//connect.facebook.net/en_US/all.js’; document.getElementById(‘fb-root’).appendChild(e); } ());

Continuous paging in Windows Phone 7

Posted by & filed under code.

Here’s a quick and dirty implementation of continuous paging with Windows Phone 7. These code snippets are from a project using the GalaSoft MVVM Light Toolkit and Ninject, however you can adapt to fit your model. The paging and data binding functionality is abstracted in the base class PagedListViewModelBase so that the paging functionality can […]

Using Reflection to serialize DTO’s

Posted by & filed under code.

Suppose that you have a DTO (data transfer object) that you want to convert into a parameter array to be saved to file or sent over the web. You could serialize it and convert it to XML or JSON. But maybe you want to send it in an HTTP POST or GET and you don’t […]

Rotating content with JQuery, JTemplates & AJAX

Posted by & filed under code.

The following JavaScript is used here to rotate the featured product every 30 seconds. I will leave the implementation of the JSON-emitting REST api for another post. <!–mce:0–> <!–mce:1–>   <!–mce:2–> <div class="outerbox"></div> <textarea> &lt;div class="outerbox"&gt; &lt;div class="box featured"&gt; &lt;h2 &gt; Featured&lt;/h2&gt; &lt;div class="item"&gt; &lt;div class="bord-se"&gt; &lt;div class="bord-ne"&gt; &lt;div class="bord-s"&gt; &lt;a href="/store/Product.aspx?ProductId={$T.ProductId}&amp;utm_source=Homepage&amp;utm_medium=FeaturedProd&amp;utm_term=Widget&amp;utm_campaign=Featured_Widget" mce_href="/store/Product.aspx?ProductId={$T.ProductId}&amp;utm_source=Homepage&amp;utm_medium=FeaturedProd&amp;utm_term=Widget&amp;utm_campaign=Featured_Widget" id="A1"&gt; &lt;img […]

AES encryption strategies with .Net

Posted by & filed under code.

I did a presentation last week on AES encryption techniques in .Net. I’ll post some details here later, but for now, I’ve uploaded a zip file with the project code. Here’s the key bit:   string key = "1234567891123456"; string secret = @"This is a secret.";   Console.WriteLine("basic:"); EncryptString(key, secret); Console.ReadKey();   Console.WriteLine("salt the secret:"); […]

Using the MySql ADO.Net adapter

Posted by & filed under code.

public DataSet ExecuteQuery(string commandText) { DataSet ds = new DataSet(); using (var connection = new MySqlConnection(connString)) { connection.Open(); var command = connection.CreateCommand(); command.CommandText = commandText; using (var data = new MySqlDataAdapter { SelectCommand = command }) { data.Fill(ds); connection.Close(); } } return ds; }