Sunday, 21 September 2014

Automate your Android with NFC tags

This blog is going to be different to anythingI've done before. I try and do a blog about what I have learnt each week. This normally comes from work (hence all the Joomla related blogs). However work has been pretty slow. My other option was to write about what I've been learning in Java as I am currently creating a new Android app. The issue with this is that I am still getting used to Java so I'm not yet at a stage where I am comfortable writing about it.

So instead this week I am going to show you what I have been doing with my phone since discovering NFC tags.
Ill start with NFC tags. NFC stands for near field communication and it is a form of wireless technology that allows the exchange of small amounts of data from a tag to a NFC compatible phone. The tags them selves don't need any batteries as they draw power from the receiving device.

The tag can be anything, they're commonly put in key rings and stickers but they can be put into anything really. The good thing about the technology is that it has been around for quite some time. Contactless bank cards, Oyster cards and key fobs for secure buildings all use this (or very similar) technology.

I'm going to go through a few apps you can download which make some tasks a lot easier. The first app is NFC Actions, this provides you with a list of common tasks you might want to automate. I used this app to connect to my WiFi network. You just pick your WiFi network and enter the password, write to the tag by placing it on the back of the phone. 

Once the tag was written I simply put the sticker on my router with the idea that if any of my guests come over and want to connect to the WiFi then they can just put there phone on the tag and viola! The only draw back to using these types of apps is that the receiving device needs to have the app as well.

Another notable app is AnyTag NFC Launcher. This reads any NFC tag and allows you to open an app. So I have it set to open the Natwest app when it detects my bank card and the Oyster Balance.  For more ideas regarding NFCs have a look at this blog.

Sunday, 14 September 2014

Creating a Custom 404 Page in Joomla

One thing I have noticed about Joomla that sort of snook in under the radar for me is that it doesn't have a built in facility to create your own 404 error page. After a bit of research I've found out how to get it done. It's not that complicated but it does involve popping into the back end and adding some PHP code.

Joomla does have it's own built in 404 page but as you can see here it's not very user friendly in the slightest:
It doesn't follow the style of the site and it's doesn't include the default navigation which means any users will more than likely just give up and leave the site. 
In order to create your own custom page you first need to a new 'uncategorised' article. This will serve as your 404 page, include some text like Sorry, we couldn't find what you're looking for... Well really you can put what you want on it really (I won't tell!) but the fact it's going to be an article means that once we are done you can treat it and manage it like any other Joomla page.
Once you have saved your new article make note of the alias as we'll need this for the next step. Before we get stuck into the PHP code we need to create a hidden menu item so that we can navigate to the article. I won't go into detail on how to do this as if you don't know then this task might be a bit to advanced for you. The next step is to go to your ftp client and navigate to templates>system>error.php
Copy this error.php file and replace the one located in your sites template folder. For example, if I was using a template named 'Puriity' I would copy the error.php file to the templates/cleancloud directory.
 if (($this->error->getCode()) == '404') {
header('Location: /404');
Above is the code you need to add to your error.php. This needs to be added just after the line which defines _JEXEC. You then just need to change the location URL to your error pages alias (don't forget the /). If you are using Joomla 1.5 or below the you will also need change getCode() to code in order to use this snippet.
Now when you try and go to a URL that doesn't exist you will be redirected to your nice and shiny new 404 page.
Didn't I tell you it was simple :).

Friday, 5 September 2014

Making Use of Scoped CSS

This week folks I'm going to talk about Scoped CSS. Yeah I've never heard of it before either, well until very recently at least. 
Scope is a new attribute in HTML5 that allows you to override styles for a particular child element by declaring some inline styles. So basically this mean the style block with the scoped attribute will overwrite the global styles generally found in the head (whether in a style block or linked stylesheet), but only on the sibling/descendent elements inside the same parent.
If you're still not sure look at the example code below with the outcome to see it in action.

CSS Scoped Code

and this is what it should look like...
CSS Scoped View
So what is the point or benefit  hear you moan. Well;
  • It may be desirable to keep the CSS of a particular interactive element together with the HTML. If the element in question is unique on the site (like a complex slider for example), there is no advantage to caching it with global styles.
  • Keeping the CSS with the HTML for organization may have value however.
  • When working with a team it can be a great way to allow for simultaneous development of various areas of the site without worrying about the state of the global CSS - I can see this as a short term solution.
  • If your article is getting aggregated by another site it's possible to customize styles on another website that would otherwise be beyond the reach of your global stylesheet.
  • If you enable tags in the comment section of your site you can give your readers the ability to style their... nevermind this is probably a terrible idea.
  • For use in widgets on third-party sites where the CSS is unknown and the in-widget styles shouldn't affect anywhere else. Although being able to reset the styles within the widget is the other half of that battle.
  • Finally (and most exciting to me), Scoped CSS is ideal for working within Content Management Systems where you have much less flexibility for adding unique markup to common templated areas, or no access to the existing stylesheets.