Archive for May, 2013

English Dictionary API served with MongoDB

As an exercise with the no-SQL database platform MongoDB, I created a free account on mongolabs, created a database called webtropy, and within this, created a collection with the name “dictionary”. I then downloaded a English dictionary in text format from (TWL06), Importing this into Mongo was mongoimport, specifying fields as “word”.

They offer a REST API via their HTTP interface, such as:{‘word’:’HELLO‘}

Where “HELLO” is the word being checked. If the word is missing, i.e. “HELLOY” then the result is an empty JSON array “[]”

For the full English dictionary in JSON format, you can download this from at

Categories: Uncategorized

NAX Advertising WP7 App

Sometimes you just realize that an app won’t sell on an app store. If you’ve had no sales on an app in 30 days, then, give up, and try a different business model…

There is a Windows Phone app for this blog, but, since the blog is very readable on a mobile device, I guess nobody would be willing to pay 0.99, so I tried using Nokia’s Ad Exchange, to add adverts to the app, so I could release the app for free. Instead. Also, it’s part of the DVLUP Challenges – So worth a T-shirt anyway!

I signed up to Nokia’s NAX program, added the details of my app, then downloaded the Windows Phone 7 SDK from Inneractive. Unfortunately the one-liner setup code didn’t work in the 10 second video didn’t work… probably because they never show the XAML!, I then checked out their sample, downgrading it from 7.1 to 7 by modifying the csproj, and the WMAppManifest – then copied (and simplified) their code as follows:

C# Code (In MainPage_Loaded):

var optionalParams = new Dictionary<InneractiveAd.IaOptionalParams, string>();
InneractiveAd iaBanner = new InneractiveAd(“OpenMerchantAccount_NetworkProgramming_WP”,
InneractiveAd.IaAdType.IaAdType_Banner, 60, optionalParams);
// Add the banner to the grid

XAML (Within panorama control)

<controls:PanoramaItem Header=”Ads” VerticalAlignment=”Top”>
<Grid x:Name=”Grid0″ Grid.Row=”0″ />

There’s more you can do with the ads, but I’m just learning…

Categories: Uncategorized

Load Cross Domain JSON via JSONP Proxy

A well known security constraint on modern browsers, is that AJAX requests can only be made to the server which served the page. To get around this, you can use CORS for modern browsers, or JSONP.

JSONP, however does require that the data provider wraps their JSON response in a function call, which they may not do. Therefore, an easy solution is to create a proxy that wraps JSON in a function call, such as:

public partial class JsonProxy : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
string link = Request.QueryString[“url”];
if (link == null || link == “”)
Response.Write(“Requires url parameter”);
WebClient wc = new WebClient();
string strJson = wc.DownloadString(link);
Response.Write(“jsonp_callback(” + strJson + “);”);

Then, on the client side, a this can be used as follows (JQuery version):

<script type=”text/javascript” src=”jquery.js”></script>
<script language=”javascript”>
function init()

function jsonp_callback(data)
$(“body”).html(“Found ” + data.broadcasts.length + ” upcoming comedy shows”);

function LoadJson(url)
var s = document.createElement(“script”);
s.type = “text/javascript”;
s.src = “; + url;
Please Wait.


Categories: Uncategorized

Hosting files on Adobe’s Cloud

Adobe’s creative cloud allows 2GB of free storage, which is handy for uploading large files for personal use. But you can also use these to serve images and files on websites, like the image above. With a little trick.





1. Upload your image or file to Adobe’s cloud

2. Click on the arrow, and select send link

3. Change the slider to public

4. Select Allow Download

5. Select the link icon, and copy the url.

Now, modify the URL as follows:

Where {GUID} will be different in your case.

Categories: Uncategorized

Cordova/PhoneGap for WP7 in Windows XP

Normally, I develop my apps for WP7 natively using Silverlight for Windows Phone, but I thought that some of my apps would be easier to port, if I could use Phonegap (Cordova).

My home PC runs Windows XP, and VS 2010, which means that Windows Phone apps can’t be emulated, but can still be run on a real device (A better experience in any case).  Unfortunately, the XNA framework for Windows Phone is not compatible with Windows XP, and Cordova / Phonegap relies heavily on this library.

So, I decided to take PhoneGap / Cordova version 2.4.0 for Windows Phone 7, take the standalone model, and then strip out all the code that relied on the XNA framework, or just anything that didn’t compile. I understand, that this does cripple many features, such as audio recording, video recording, some file operations, and perhaps other features. However, the code compiles and runs on a Windows Phone 7 device, and renders the HTML page.

You can download this library, from – Should you want to develop Cordova / Phonegap Windows Phone 7 applications on Windows XP.

Categories: Uncategorized

iOS6 support for PhoneGap 0.9.4

Screen shot 2013-05-16 at 20.37.52
After 1st May 2013, Apple has begun enforcing iOS6 support, and effectively outlawed  access to methods that access device UDID, for security reasons.

However, if your application is based on PhoneGap, and even if you do not access the device UDID via javascript, since the underlying PhoneGap library accesses the UDID, then Apple will reject the application. Now, the solution is to either upgrade to the latest version of PhoneGap – or a one line change 🙂

Double click on PhoneGapLib.xcodeProj then open the PhoneGapDelegate.m file, then scroll down to

– (NSDictionary*) deviceProperties

Then comment out the line

//[devProps setObject:[device uniqueIdentifier] forKey:@”uuid”];

Save the file, and then recompile your application. No more error!

Categories: Uncategorized

Ajax HTTP status code 0 (zero)

I find that when I encounter a HTTP status code of 0 when using Ajax, it means there is some network error between the client and server, for example, a firewall issue, a network failure, or such forth.

The type of issue was spotted in code that looks like this;

// Success case
if (xhr.status == 0)
// Network problem?

Of course, this is only likely to occur in cross-domain ajax, since it is unlikely for a server to serve a page, and then immediately become unreachable to ajax.

Categories: Uncategorized

Capture webcam to file (VB.NET)

I decided to take a look again at my webcam streamer software that I wrote a few years ago for  – to see if I could improve upon it. One of my biggest gripes with the software, was that it used the clipboard to hold the temporary image from the webcam prior to upload. This meant while the webcam software was running, the clipboard was useless.

I used the avicap32 API, which is much lower-level than the DirectX equivalent, and much more awkward to use, since you are dealing with a DLL that was never designed to work with .NET.

I’m omitting the setup code, you can probably get this from another site if you search, I just wanted to include the few lines of code required to take the image from the camera to a file:

Dim sFileName As String
sFileName = System.IO.Path.GetTempFileName
Call SendMessageAsString(lwndC, WM_CAP_FILE_SAVEDIB, 0&, sFileName)
Dim bmp As New System.Drawing.Bitmap(sFileName)

Now, SendMessageAsString is an alias of the ubiquitous SendMessage API call, with a twist as follows;

    Declare Function SendMessageAsString Lib “user32” Alias “SendMessageA” (ByVal hWnd As Integer, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr

WM_CAP_FILE_SAVEDIB is defined as  WM_USER + 25 (&H400S), and lwndC is a window handle to the capture window, which is set up with capCreateCaptureWindowA.



Categories: Uncategorized

Upload screencapture Windows Phone 7.8

After upgrading my phone to Windows Phone 7.8 from 7.1, I noticed that my screen capture app stopped working. Which was very unfortunate, since there doesn’t appear to be another way of capturing images via Windows Phone 7 (I’m not talking about WP8)

I found a snippet of code that captures screenshots from within your own app, and saves it in your media library, which is cool, but as soon as I tried to resolve the reference to new MediaLibrary(), I saw that you needed to include the Microsoft XNA framework for Wndows Phone 7, which wouldn’t be a problem, only I’m running on Windows XP, and XNA for WP7 does not install in Windows XP!

In frustration, I decided to see if I could upload the image to my server, using a script I wrote earlier to store camera images from a iPhone app, – Changing the upload folder, of course, so that I wouldn’t mix up the images.

private void Panorama_ManipulationCompleted(object sender, 
ManipulationCompletedEventArgs e)

WriteableBitmap bmpCurrentScreenImage = new 
WriteableBitmap((int)this.ActualWidth, (int)this.ActualHeight);
bmpCurrentScreenImage.Render(LayoutRoot, new 


public void SaveToMediaLibrary(WriteableBitmap bitmap, int quality)
using (var stream = new System.IO.MemoryStream())
// Save the picture to the Windows Phone media library.
bitmap.SaveJpeg(stream, bitmap.PixelWidth, 
bitmap.PixelHeight, 0, quality);
stream.Seek(0, SeekOrigin.Begin);
var byteArray = stream.ToArray();
string strBase64 = Convert.ToBase64String(byteArray);
WebClient webClient = new WebClient();
webClient.Headers[HttpRequestHeader.ContentType] = 
var uri = new 
Uri("", UriKind.Absolute);
string strPostData = "image=" + 
webClient.Headers[HttpRequestHeader.ContentLength] = 
webClient.UploadStringAsync(uri, "POST", strPostData);

Note that I attached this to Panorama_ManipulationCompleted, which basically means it gets triggered every time the panorama control is scrolled, or touched, which tends to upload quite a large number of screenshots, but more is better than too few for my needs. Obviously, this code should be commented out before submitting to Microsft!

Categories: Uncategorized
%d bloggers like this: