Updating the cPanel webmail welcome screen

Something I’ve always wanted to do is update the screen users see when they visit /webmail and log in on a cPanel server.

Now I know you can choose which webmail clients are available using whm, but I actually wanted to remove, move and change the look of some elements.

First thing I must state is that you need root level access to every folder on the server. Once you’ve logged in the location of the index.html which I was looking for is…

/user/local/cpanel/base/webmail/[TEMPLATE NAME eg x3]

In there you want to edit the file index.html using something like the command line tool vi.

If you need to you can also edit the css and javascript for that page by having a poke around the files in there.

jQuery ajax – headers are better than the success callback

If you’ve used jQuery for even a short period of time you will have probably come across the $.ajax method and several of it’s shortcut methods like $.getJSON or $.load

Within these methods there is usually a ‘success’ callback which fires when a 200 response is received from the server. 400 and 500 responses tend to trigger the ‘error’ callback.

So success and error are pretty generic all encompassing monsters who work for many tasks, but sometimes you need to be a little bit more clever about it.

Continue reading

Grouping by time periods or timeslices in Mysql

Sometimes when you pull back a whole load of results from a database table and order them by their timestamps you might want to either sum any result which happened at a time close to each other or you might want to only bring back one type of something within a period of time to stop that item flooding your results.

I’ve used this technique a couple of time now. The first time was to make lots and lots or data fit onto a relatively small graph, so I needed some form of average. The second time was because if the same event happened in a set period of time I only wanted to know about it once.

The query looks something like this once we include our timeslices / time periods in our select and then follow it up by grouping by them.

SELECT name, 
type, 
value,
ROUND((CEILING(UNIX_TIMESTAMP(`timestamp`) / 600) * 600)) AS timeslice
FROM reading
GROUP BY timeslice

Here I have selected timeslices of 10 minutes (600 seconds) but you can group larger or shorter periods of time if you require them.

So there you have it, grouping by timeslices for summing readings or limiting duplicates in results.

My current local development setup

Thought it was worth sharing my current local development setup. I run on mac, currently Lion 10.7.4 and these are the pieces of software I used…

Terminal
Used to run Git version control commands. If you’re going to do it, do it properly.

Sublime Text 2
If you take handcoding seriously, ditch your coda, your skEdit, your text wrangler etc, take a weekend installing and tweaking Sublime Text 2 and never look back.
Plugins, amazing autocomplete, unlimited flexability from highlighting to layout, projects, global find, powerful search, need I go on. Beautiful.

Transmit
Superb FTP client from Panic. Don’t edit live code. Download it, run a local site, update it and then use a purpose build ftp client to get the update online. No stupid mistakes.

Sequel Pro
A powerful and free MySql tool. Lots of nice touches like edit in pop-up, tabbed browsing and nice export tools.

LiveReload
Update the preview in your browser without reloading it manually. Instant for css and js, and almost instant for html, php etc. Saves a lot of cmd-R ing.

Google Chrome
Still my the browser of choice after 2 years. Great for dev work with inspector (cmd-alt-i)

FirefoxNightly
Firefox is crap, but it’s new responsive design tools can come in handy for mobile web development. Development software, so use at your own risk.

Others worth a mention…

I also use skitch for screen capture, dropbox for file sharing, Parallels for those times when you have to test windows browsers.

Enjoy and let me know what you think in the comments…

A jQuery plugin for the masses

Every wonder how to hit the ground running with a jQuery plugin? Here is the absolute complete basics for you (and me) to copy and paste…

First we need to define our Class. I’ll call mine Boom.


var Boom = function(element, options){
	this.init('boom', element, options);
};

So now we have something to focus our plugin at we can add a prototype method to it. This makes the ‘new Boom’ code super slick and gives us a better control over the ‘this’ variable because we can whack it inside a function…


Boom.prototype = {

	init:function(type, element, options)
	{
		// do stuff on create

		// makes it available almost anywhere as this.$element
		this.$element = $(element);

		// then maybe do something with the options
	},

	another_one:function()
	{
		// do some other clever stuff.
	}

};

And finally we need to connect it up to the jQuery bit…


$.fn.boom = function (options) {

	// return this makes it chainable
	return this.each(function ()
	{
		new Boom(this, options);
	});
};

$.fn.boom.Constructor = Boom;

Very basic, but worth having here for future use. You can now call it like so…


$('li.bang').boom();