Monthly Archives: July 2013

Australian Tax File Number Generator (TFN)

Hey everyone,

I came across an old VB Script used to generate random TFNs for testing. I’ve just done up a quick JavaScript bookmarklet to replace it. Just drag the link below to your bookmarks bar and you’ll be able to generate random TFNs.

Click to Generate (or drag to your bookmarks bar): TFN Generator

A bookmarklet to generate random TFNs

A bookmarklet to generate random TFNs

For info on how it all works, checkout the Wikipedia page: Australian Tax File Number

Sample Australian Tax File Numbers/Test Australian Tax File Numbers:
865414088
459599230
112474082
565051603
907974668

UPDATE:
If you’re using IE, right click on the link and press add to favourites. Once you’ve added it, click the link in your favourites sidebar. The generator will appear in the top right hand corner of the page.

Let me know if you have any trouble. If you’d like to a custom or corporate copy please contact me.

Recording AJAX Requests with Google Analytics

Hey everyone,

I’ve just finished setting this up on an AJAX-heavy site I’m working on. It’s all pretty easy to setup, copy the following code and use it to replace your standard analytics code:

This:

1
2
3
4
5
6
	(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
	(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
	m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
	})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
	ga('create', 'UA-xxxxxxxx-x', 'xxxx.com');
	ga('send', 'pageview');

Becomes this:

1
2
3
4
5
6
7
8
9
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
  _gaq.push(['_trackPageview']);
 
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

And the last step is to add this JavaScript whereever your ajax request is being made, for instance: _gaq.push([‘_trackPageview’, ‘/contents/get_content_by_id/’ + id]);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
        //Prepare ajax
	$.ajax({
		mtehod: 'GET',
		url: '/contents/get_content_by_id/' + id,
		dataType: 'JSON',
		success: function(data){
 
			//Handle response
			handle_ajax_response(data);
 
			//Push view to analytics
			_gaq.push(['_trackPageview', '/contents/get_content_by_id/' + id]);
		},
		error: function(){
 
			//Remove loader and display error
			remove_loader(target_selector, null);
		}
	})

Just add the line commented Push view to analytics and you’re done. To test it, I just used to the real-time analytics – it shows up straight away. If you run into any trouble the docs are pretty decent: https://developers.google.com/analytics/devguides/collection/gajs/

How to Customise ShareThis Settings – ShareThis

Hey everyone,

I’ve just added ShareThis to a website I’m currently working on. It’s basically a generator for all your typical social network plugins (Facebook Like, Twitter Share, Google+ etc). The main advantage I’ve found with using it is the detailed analytics.

While I haven’t had any major issues, there were a few customisations I had to make:

Change Title in ShareThis
Changing the title is pretty easy, simply use the st_title attribute:

<span class='st_googleplus_vcount' displayText='Google+' st_title='My Title'>
</span>

Change/Set the URL that is Shared
I needed to set this when generating content via ajax to ensure that the correct URL was shared. Again, it’s pretty straight forward – just use the st_url attribute.

<span class='st_googleplus_vcount' displayText='Google+' st_url='www.test.com/123' st_title='My Title'>
</span>

Re-initialising ShareThis buttons when using ajax
A follow on from the last issue is that ShareThis buttons will need to be reinitialised if additional content is generated via ajax:

//Re-initialise ShareThis
if (stButtons){
     stButtons.locateElements();
}

There’s a bit more info here, via this StackOverflow post:

Missing Partial (JSON Response) – Ruby on Rails

Hey everyone,

I’ve just added pagination (Kaminari) to make an infinite scroll list a little easier to use. Unfortunately, I ran into the following error – had me stumped for a while:

Missing partial /contents/content_list_item with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder, :coffee]}. Searched in:  * "/home/chris/funny/app/views"  * "/home/chris/.rvm/gems/ruby-1.9.3-p327/gems/kaminari-0.14.1/app/views"

The solution was fairly simple, but adding a few things at once had me looking at it the wrong way. Because I was using the same nested partials for an HTML response as my JSON one, the file extensions weren’t what rails was expecting. To get around this, all I needed to do was fully qualify the partial filenames. For instance:

1
2
3
4
5
#The original
<%= render :partial => '/contents/content_list_item', :locals => { :@content_item =>  content} %>
 
#Became this
<%= render :partial => '/contents/content_list_item.html.erb', :locals => { :@content_item => content} %>

Stop a Link from Going Anywhere – CSS/JavaScript

Hey everyone,

Another quick one – how to stop a link from doing anything. I’ve just come across a need to use a link that acts as a button. A slight UI issue with this is that clicking a hyperlink will with an href value of ‘#’ will push scroll to the top of the page.

There are a couple of ways to go about fixing this. Note the href value in the following:

1
<a href='javascript:void(0)' class='btn_show_reply' data-comment_id="<%= comment.id %>">Reply</a>

The second option is probably already familiar to anyone using ajax forms, simply have your function return false:

1
2
3
4
5
6
7
8
9
10
11
12
<a href='javascript:void(0)' onClick='myFunction()' id='my_awesome_link' data-comment_id="<%= comment.id %>">Reply</a>
 
<script type='text/javascript'>
function myFunction(){
 
   //Do some awesome stuff
   // ...
 
   //Return false to prevent link from affecting anything
   return false;
}
</script>

The third option is simply a jQuery-ish rehash of number 2:

1
2
3
4
5
6
7
8
<script type='text/javascript'>
 
/* Does some awesome stuff while preventing the calling link from directing the user */
$('#my_awesome_link').click(function(e) {
 
   //Do some awesome stuff and then prevent the link from directing user
   e.preventDefault();
});

Disable Word-Wrap – Sublime Text

Hey everyone,

This one is pretty obvious, but just in case anyone is having trouble finding it:

- View > Word Wrap

If you want to alter the default settings, the following seems to work:

  • Preferences
  • Settings – User
  • Add the following and then save:
{
	"word_wrap": "false"
}

Once unchecked any overflow simply results in a horizontal scroll bar.

ORA-28000: the account is locked – PeopleSoft

Hey everyone,

Just a small PeopleSoft issue I ran into while running an SQR:

(SQR 5528) ORACLE OCISessionBegin(RDBMS) error 28000 in cursor 0:
   ORA-28000: the account is locked
(SQR 4701) Cannot logon to the database.

SQR for PeopleSoft: Program Aborting.

For some reason the sysadm account had been locked, thankfully there’s a fairly easy fix:

1
ALTER USER sysadm ACCOUNT UNLOCK;

If you don’t have access you may need to get a DBA to run it.