iOS and Twitter OAuth Login

I have recently been working on a iOS (iPhone) application for a client. This app needed to have the ability to post things to Twitter and Facebook.

Facebook provides a really nice SDK which (with a few hacks) provides an inline login dialog which handles all the oAuth details for you. It looks good and works well.

Twitter unfortunately does not do the same and while there are hundreds of Twitter-iOS libraries out there, they are all overly complicated and provide a UI which is not consistent with how the Facebook SDK does things, which if i want my app to appear good and consistent then they must look and behave the same.

The other main reason was because the libraries were overly complicated, they used the “Out of band” oAuth authentication which means a user has to copy a pin from a web page into the application, which is hardly a nice thing to do. Yet Facebook doesn’t have to do this. After a bit of investigation i found out twitter didn’t have to either.

To solve all of this i have created a simple demo application and library, utilizing the Facebook-iOS-SDK and PlainOAuth (by Jaanus Kase) projects as a basis and building what i wanted on top.

A lot of the code should be self explanatory. And below is a screen shot of what the end result is. You can find the project on git hub here: https://github.com/lloydsparkes/unoffical-twitter-sdk

Some code snippets from my homepage: Part 2

In this part 2 of my series on the various parts i used to build my new homepage for my website i will cover how i put my RSS feeds on the page.

Again to start with you will need to use jQuery and the Google JavaScript API. So insert the following two lines into the header of your HTML if you do not already have them included. You can also substitute the jQuery import from the Google CDN with a local address or another CDN.

[javascript]


[/javascript]

The next bit is we need a place holder so somewhere in the body of the document

[javascript]

Recent Blog Posts

[/javascript]

Then we just need the following function to fetch the last entries, then to write them out into the placeholder:

[javascript]

[/javascript]
Finally the ready function so when the document is ready the function will be executed and the feed entries into the page.

[javascript]

[/javascript]

And thats loading a RSS feed into a page using JavaScript.

Some code snippets from my home page: Part 1

About 6 months ago i reorganized my website, this included a new homepage ( here ). A lot of the code was borrowed from a friends web page ( here ), recently a friend who likes it asked me how the code worked, and to go through it, so i thought it might be worth making a blog post on it.

All the code is under the license “Creative Commons Attribution-Noncommercial 2.0 UK: England & Wales License” and is copyright to Tom Brearley.

I assume a basic knowledge of HTML / JavaScript.

There are 4 parts to the web page in question, the tag line, recent blog posts (items from an RSS feed), recent tweets(items from twitter), recent music (from last.fm).

All of the code requires jQuery, i used it from the Google CDN but you can use it locally. The code to use it from the Google CDN is:

[javascript][/javascript]

Simply place this in the header of your HTML.

The Tag Line

This is rather simple. We have an array of tag lines, and we pick on random when the page loads.

The first this we need is a placeholder for the final message. Insert it in to the body of the page. Also include a fall-back message, which will be displayed if for some reason the JavaScript fails.

[javascript]is awesome[/javascript]

Then the code which will actually pick a tag line and insert it correctly into the document. In the head of the document, create a script tag, and insert the following function (modifying the tags to your taste). This simple function just creates an array called “phrases”. Then using the jQuery notation, sets the HTML property of the tag with the name “tagline” with a random phrase.
[javascript]
function go(){
var phrases = Array(
“uses <a href=”http://www.bing.com”>Bing!</a>”,
“loves <a href=”http://www.microsoft.com/windows”>Windows</a>”,
“uses <a href=”http://www.microsoft.com/ie”>Internet Explorer 9</a>”,
“loves <a href=”http://www.microsoft.com/windowsphone”>Windows Phone 7</a>”,
“uses <a href=”http://www.microsoft.com/windows”>Visual Studio 2010</a>”,
“is a <a href=”http://www.conservatives.com/default.aspx”>Conservative</a>”,
“reads <a href=”http://conservativehome.blogs.com/”>Conservative Home</a>”,
“dislikes <a href=”http://www.apple.com/macosx/”>OS X</a>”,
“loves his <a href=”http://www.apple.com/macbookpro/”>MacBook Pro</a>”,
“used to be a <a href=”http://en.wikipedia.org/wiki/Scouting”>Scout</a>”,
“programs in <a href=”http://en.wikipedia.org/wiki/C_Sharp_(programming_language)”>C#</a>”,
“prefers <a href=”http://en.wikipedia.org/wiki/Dogs”>dogs</a> over <a href=”http://en.wikipedia.org/wiki/Cat”>cats</a>”
)
$(“#tagline”).html( phrases[ Math.floor(Math.random() * phrases.length) ] )
}[/javascript]

Finally we need to call this function once the page is loaded. To do this insert the following code just before the “go()” function.
[javascript]
$(document).ready(function(){
go()
})
[/javascript]
And that is Part 1, watch out soon for the final 3 parts.

So I bought an iPad

I have been looking at tablets for quite a while and was trying to decided between the Motorola Xoom and the iPad. It was quite a difficult choice between the two but I decided on the iPad for one simple reason, the quality of the device ( hardware and software ) is just so much better than the Xoom or any other android tablets. If I had gotten the android one I would have spent a lot of time hacking around with android to get it to work well, like I did with my phone when I had a HTC Hero. The iPad just works much like my Windows Phone 7 HTC HD7.

That said it’s not perfect, it doesn’t fit in with my microsoft dominated computer setup that I use, and it is just a stop gap solution to when Microsoft bring out there tablets next year.

It is a very good device, and very able to do a lot of. The things I wanted a tablet to do but there are a number of key features missing that I believe Microsoft will be including in there tablets from the way the development of Windows 8 is going. The first issue is the lack of user account or begin able to put the device into a “guest mode” so that i can lend my device to someone else without worrying that they can access all my email, social networking and work details. I believe Microsoft will have this feature in there tablet version of Windows 8. This feature would mean that a family or couple could share an iPad without having their different account settings clashing with each other. The second issue that I have noticed is that the keyboard always just has the capital letters on the keys, rather than switching between lowercase and uppercase letters when suitable during the writing process, or when the shift key is pressed, as a better indication of the change, because as i am writing this article on my iPad using both hands I cannot see the shift keys, and therefore can see if it is capitalised or not.

I will follow up this article once I have spent more time on the device, but so far it seems to be really good even if it isn’t perfect for my needs, it will be a far more pleasurable year to spend using it rather than the android equivalent.

Windows and Software Installation

In a number of recent discussions with some of my friends at university they complained that installing software on Windows is hard or complicated, or more so than it needs to be, or compared to their favorite operating system.

So in this post i aim to see if i can uncover what the issue is, and possible fixes for this issue. I will also look at the common ways of installing software on other platforms, and if they are better, or if they have similar issues.

Windows – The Process (and Issues)

Installers on Windows generally work using a Wizard interface (Nullsoft, MSI), that after a sequence of steps, it then copies files to an appropriate place (hopefully %programfiles%) and registers its self with the system so it appears in Add/Remove programs.

One of the advantages of MSI is that it does a good job of managing upgrading previously installed software, without simply overwriting the old files (it will detect if a previous was installed, then remove the old version and install the new version), it can also be installed without a GUI which is good for corporate usage and systems management.

A few years ago Microsoft introduced a new system called Click Once. This installs an application in the users personal %appdata% directory which ensures security to an extent, due to this most applications can be installed by the user, without the help of an administrator. The final benefit to this new system is that it can do automatic application updates. Unfortunately very few developers have taken advantage of this method, although notable developers who have are Google who use it for chrome, and a large number of Twitter applications.

Uninstalling an application is rather simple, you just find it in Add/Remove Applications, then click uninstall. This can be slightly painful when it comes to big complex bits of software like Visual Studio that have a large number of different components to be un-installed in turn.

The only other time un-installation can be a problem, is if an older application uses an installer that does not register its self properly, it can sometimes be a bit of a pain to find the uninstaller.

There are a number of issues when it comes to software installation on Windows. The first is that there are a large number of inconsistent installation systems that developers use, and they all provide a number of different features and work in slightly different ways, but the key here is that there is no consistency in what the user can expect.

One thing that i must mention here is that now most installation systems actually use MSI (Windows Installer or Microsoft Installer) underneath but present the user with a special GUI, but there are still plenty of developers using the Nullsoft system especially in the open source arena.

Pros:
General – Good management of Uninstallers
Click Once – Automated Updater, Simple only a few clicks, doesn’t require administrator permissions
MSI – Scriptable, Software versioning

Cons:
General – Inconsistent UI, a large number of legacy installers, complex software can make uninstalling painful having to uninstall each sub package manually.

Mac OS X – The Process (and Issues)

OS X is actually very similar to Windows but i will just go through it, but there are a number of ways.

The first way, that is most widely used is a .app file(although its actually a folder) for distribution, this can be downloaded directly, or be distributed in a .dmg file, then drag it into the “Applications” folder (or any where else if the user does not have permission to the Applications folder). The App Store automates this process even further.

The second method is to use a .pkg or .mpkg installer. From my research this is simply a modified .tar.gz file, with a special folder structure. .mpkg installers can also be used to install a number of .pkg’s. The way its done means that Apple provide the installer GUI so it is always consistent, but it can also be scripted.

The final way you can install software is the “Unix” from source way. You can do your usual “./configure && make && make install”.

Un-installation and clearing up from some programs can be a bit problematic though. To remove a .app installed program you just delete the .app file, although this will leave the application preferences behind which you may want to manually clean up. To uninstall a .pkg or .mpkg it can be slightly more problematic, generally having to find and execute a script to do the heavy lifting for you and the same for reversing the “Unix” way of installing software.

None of their installers have a way for automated updating, but there is a 3rd party library that is widely used called Sparkle. The new App Store also handles updating automatically.

Pros:
.app – Simple Install / Uninstall
.pkg/.mpkg – Consistent UI

Cons:
.app – Uninstall leaves user specific application data behind
.pkg/.mpkg – Needs a script to uninstall

Linux – The Process (and Issues)

On Linux you generally have three options. Install the “Unix” way from source, which we have already discussed with OS X. Install using the package manager from repositories OR install using a package manager and a manually downloaded package.

The later two ways make installation and un-installation fairly easy (through command line or a GUI). They are also a good way to distribute updates.

But there are problems with this, the repositories do not tend to stay up to date with the latest versions of the software, but may be a few versions behind. This leads to using the other installation options to get the latest versions, which complicate the management of installed software. Although this is not so much of an issue where servers are concerned where stable software is ensured through the repositories. The other problem left is that the “official” methods of installing software is restricted to users with root permissions although they can install and setup software manually within their own directories, although this can be very complicated.

Pros:
Stability, security.

Cons:
Out of date locked down to just users with root/sudo permissions

What can Microsoft do?

So Microsoft and Windows is actually already in pretty good shape, and with the Windows App Store, this should solve a large number of the inconsistencies, and it should also handle updating.

But there is more Microsoft can do. They need to really push tools and software to work with Click Once and MSI with detailed documentation on why developers should use them, and which one is suitable for their particular application.

It should be a rather simple sell and distinction between what to use for different programs.

Click Once should be used for utility applications, so twitter clients, irc clients, ftp, paint (yes you Paint.Net), notepad, putty (just putty, not the rest of the suite)

MSI’s should be used for software that requires to be installed system wide, larger installations, and software which requires background services, system services, or have some complexity which means they might not be suitable for Click Once, so for example, Office, Visual Studio, Putty (with pageant)

They should enforce a single consistent UI for MSI’s which would help users, and provide some consistency for the user.

They also need to have a global update center, where everything installed can register itself (including MS software updated through Windows Update) so that all updates are centralized, and easy for the user to access, and the developers to take advantage of.

Finally they should improve the Add/Remove Programs files, so that when applications like Visual Studio is installed all the sub-packages are hidden beneath the top level as to simply the window. It might also be beneficial to separate applications into just the Click Once ones they installed, and the applications which are installed globally.