Monthly Archives: January 2010

MonoTouch SQLite Performance Tip

DataReaders are the fastest ways to access data in .Net, and most MonoTouch SQLite tutorials use them to access SQLite data using the following  syntax:

string variable = reader["MyDBField"];

This syntax is very easy to read however it doesn't perform very well.  The data reader has several inbuilt methods for reading values including:

  • GetInt32()
  • GetDouble()
  • GetString()

Using these methods improved the performance of my MonoTouch - SQLite application by a little over 60%.  The only downside is that you need to access the data colums using their ordinal values. i.e.

string variable = reader.GetString(0);

This can be a little harder to maintain, however provided you aren't using "select *" syntax, the extra effort will result in a nice performance increase.

 

Recommended social media avatar sizes

If you are looking to create a new avatar to use for your online presence, the following list will show you the recommended sizes for each of the online services.  The original source of this information can be found here.  All sizes below are in pixels unless otherwise stated.

  • Twitter - 73x73
  • LinkedIn - 80x80
  • Facebook - 200x200
  • Skype - 96x96
  • Google - 96x96
  • FriendFeed - 75x75
  • Gravatar - 50x50
  • MySpace - 158x158
  • Digg - 120x120
  • StumbleUpon - 48x48

FTP upload with .Net

If you are looking for a simple way for your application to move files between remote servers than it is worth considering FTP.  The following code shows how simple it is to upload a file via FTP with c#.

// File to be uploaded
string fileName = @"c:\temp\MyFile.zip";

// URL containg remote location and name of file
string remoteServer = "ftp://[ServerName]/" + Path.GetFileName(fileName);

// Please don't store userNames and passwords like this!
string userName = "";
string pass = "";

//Create the request
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(remoteServer);
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(userName, pass);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;

// Read the file to be uploaded into a byte array
FileStream stream = File.OpenRead(fileName);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
stream.Close();

// Get the stream for the request and write the byte array to it
Stream reqStream = request.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();

Blog4Umbraco database cleanup

I recently set about consolidating the tags I use on my blog posts to make the category listing and tag cloud smaller and more user friendly. In addition reducing the the number of tags and making them more generic means the remaining pages will contain more content and should rank better on the search engines.

Having completed the cleanup in the umbraco client I then turned my attention to the database to see what old tag information remained.

The following SQL Command will show you the unused tags in your database.

select * from cmstags where id not in (select tagid from cmsTagRelationship)

select * from cmstags where id not in (select tagid from cmsTagRelationship)

To delete these unused tags simply run:

delete from cmstags where id not in (select tagid from cmsTagRelationship)

If you would like to remove a tag that is still associated with one or more posts simply run:

delete from cmsTagRelationship where tagId in (select id from cmsTags where tag = 'OLDTAG')

which will delete the relationship and then:

delete from cmsTags where tag = 'OLDTAG'

Which will remove the tag itself.

@ismailmayat has also created an umbraco package for tag management that can be found at http://our.umbraco.org/projects/tagmanager.

Google Labs

Google is constantly developing and testing new ideas, most of which are made available to the public early during their development cycle.  If you would like to see what is next on Google's ever expanding horizons, check out http://www.googlelabs.com/.

GoogleLabs

As of this post, their most recent tool is Follow Finder.  This tool allows you to enter a twitter user name and then goes off to analyse the social graph attached to that name (following/followers) to produce a recommended list of twitter users for you to follow.

Some of the projects (or experiments as Google likes to call them), never get out of the Labs, however a lot go on to become fully fledged Google products.  So check it out and be one of the first to see what the future holds!

mtouch failed with no output solved

Whilst trying to build my latest application I came across a strange "mtouch failed with no output" error.  The error would only occur when building for the iPhone (not the simulator) and despite checking all the forums I was unable to find a solution that would work.

There are a number of forum posts highlighting that spaces in folder paths will cause MonoTouch builds to fail, however it also appears that having a space in the Project name will also cause this to occur.

Screen shot 2010-04-06 at 20.39.23

When I tried to build my project with a space in the Name (as shown in the screenshot above) the build would fail.  Removing the space solved the problem.

Finding nearby locations with iPhone GPS and MonoTouch

Whilst developing my latest application I was faced with the issue of finding nearby locations from a SQLite database containing over 60,000 records.  Each record contained a latitude, longitude and location name.

The problem was how to quickly find the closest locations without having to calculate the distance between the current location and target location for every record.

The solution I came up with has two parts.  First, I applied a limit clause to my select statement to only return the top 100 rows within +/- 1 degree of my current latitude and longitude.

One degree equals approximately 111km (61 miles) so by filtering for +/- 1 degree we are effectively selecting the top 100 records within a 222km radius of the current location.

It is then a relatively simple task to calculate the distance between the current location and selected locations and order by distance.

Fake Flash Memory

As it is the first of April I thought I would share my recent experience purchasing a 16GB memory stick on eBay and how I was fooled into buying a fake product.

The big mistake I made was not reading the sellers feedback.  I did check the seller had 100% positive feedback (from 100+ sales) however I didn't read the comments.

After I started experiencing problems with my memory stick I went back  to read the comments from other buyers.  It quickly became obvious that a number of other people had experienced problems but had still given positive feedback.

Further research into the issue of fake flash memory has shown that one of the tactics sellers use is threating not to give a refund if negative feedback is given.  The problem of fake memory is now quite an issue and a number of websites have sprung up to combat it.

If you are interested in finding out more about fake memory and how to determine if you have got what you paid for check this site: http://sosfakeflash.wordpress.com/

Programmatic document creation in umbraco

The umbraco API is extremely powerful and can easily be used to create content pages via code.  Recently I created an umbraco website where I needed to be able to take data from a genealogy file and create a page on the site for each individual in the file.

To create a document via code is fairly simple, first add the following two references to your code:

using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.web;

The code to create a document can be seen here:

// Get a reference to the docType 'Family' is my docType Alias
DocumentType dt = DocumentType.GetByAlias("Family");
    
// User 0 is the admin user
User author = umbraco.BusinessLogic.User.GetUser(0);

// Create a document with a name, a type, an umbraco user, and the ID of the 
// document's parent page. 
Document doc = Document.MakeNew("New Page Name", dt, author, 1376);
   
// Set document properties
doc.getProperty("pageTitle").Value = "";
doc.getProperty("metaKeywords").Value = "";
doc.getProperty("bodyText").Value = "";

// Prepare for publishing 
doc.Publish(author);

// Publish the document
umbraco.library.UpdateDocumentCache(doc.Id);
return doc.Id;

This code can then be put into a webservice and copied onto your umbraco site.  It can then be called from any application or system that needs to create content on your site.

Encoding video for the iPhone

I have used a number of tools in the past for encoding video in an iPhone friendly format, however they have all required the user to know a lot about codecs, bit rates, screen resoloutions etc...

Whilst encoding some recent holiday footage I went searching for a new tool and found a free Video to iPhone Converter application from DVDVideoSoft.com.

What makes this tool unique is that all you have to do is select your source file, the destination folder and the level of quality you would like (Economy, Standard, High).

Converting a four minute AVI file took around three minutes on my laptop using the standard settings and the quality is excellent.

As with most free software these days, the program prompts you to install a search toolbar as part of the installation process as well as attempting to get you to change your default search page.  Simply deselect these options however and you have an easy to use tool for converting video for the iPhone.