On Smoking
Thursday, November 17, 2011 at 2:43PM I've just published the first of a new weekly column I'll be writing for PostDesk. This week I talk about smoking. I think it's really interesting.
And lots of people think I'm an idiot.
Jamie on Software is the online journal of web developer and writer Jamie Rumbelow.
Jamie likes books, guitars, programming, open source and food. He writes about these things too. This is where he puts the things he writes.
Thursday, November 17, 2011 at 2:43PM I've just published the first of a new weekly column I'll be writing for PostDesk. This week I talk about smoking. I think it's really interesting.
And lots of people think I'm an idiot.
Monday, November 7, 2011 at 3:45PM I've just had an article published in .net magazine, and I'd absolutely love it if you could read it. It's an opinion piece on why you should take advantage of communities and make a shedload of cash.
Teenage developer Jamie Rumbelow is all for open source but argues that creating a side business surrounding a community can actually help it grow and flourish.
Saturday, November 5, 2011 at 1:09PM This is the belated finale in the trilogy of articles I'm writing about how to customise your ExpressionEngine config.php file to allow for a much more dynamic and customisable ExpressionEngine install.
In Part 1, we looked at the basics, why and how to use the config file most effectively and we built a simple example. In Part 2, we extended our config file to allow for multiple servers without changing any values. Today, in Part 3, we'll look at tidying up our config file and we'll take a look at some of the extensive hidden configuration variables.
Let's take a look at our config file so far:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/* Dynamic Configuration
-------------------------------------------------------------------*/
$ext = ($_SERVER['SERVER_ADDR'] == '127.0.0.1') ? ‘.local’ : ‘.com’;
$base_url = $base_url = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$base_url .= "://".$_SERVER['HTTP_HOST'].$ext;
$admin_url = $base_url . '/admin.php';
/* ExpressionEngine Configuration
-------------------------------------------------------------------*/
$config['app_version'] = "213";
$config['license_number'] = "0000-0000-0000-0000";
$config['debug'] = "1";
$config['install_lock'] = "";
$config['system_folder'] = "system";
$config['is_system_on'] = "y";
$config['allow_extensions'] = "y";
$config['site_url'] = $base_url;
$config['server_path'] = FCPATH;
$config['cp_url'] = $admin_url;
$config['theme_folder_url'] = $config['site_url']."/themes/";
$config['theme_folder_path'] = $config['server_path']."/themes/";
$config['save_tmpl_files'] = "y";
$config['tmpl_file_basepath'] = $config['server_path']."/templates/";
$config['avatar_url'] = $base_url."/uploads/system/avatars/";
$config['avatar_path'] = $config['server_path']."/uploads/system/avatars/";
$config['photo_url'] = $base_url."/uploads/system/member_photos/";
$config['photo_path'] = $config['server_path']."/uploads/system/member_photos/";
$config['sig_img_url'] = $base_url."/uploads/system/signature_attachments/";
$config['sig_img_path'] = $config['server_path']."/uploads/system/signature_attachments/";
$config['prv_msg_upload_path'] = $config['server_path']."/uploads/system/pm_attachments/";
/* CodeIgniter Configuration
-------------------------------------------------------------------*/
$config['base_url'] = $config['site_url'];
$config['uri_protocol'] = 'AUTO';
$config['language'] = 'english';
$config['charset'] = 'UTF-8';
$config['subclass_prefix'] = 'EE_';
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\\-';
$config['enable_query_strings'] = FALSE;
$config['directory_trigger'] = 'D';
$config['controller_trigger'] = 'C';
$config['function_trigger'] = 'M';
$config['log_threshold'] = 0;
$config['log_path'] = '';
$config['log_date_format'] = 'Y-m-d H:i:s';
$config['time_reference'] = 'local';
/* End of file config.php */
/* Location: ./system/expressionengine/config/config.php */
This is already nice and tidy. But it'd be great to consolidate our database information in here too, wouldn't it? That way, we can change all our system configuration in one file. This is how we do it:
/* Universal database connection settings
-------------------------------------------------------------------*/
$active_group = $ext;
$active_record = TRUE;
$db['.local']['hostname'] = 'localhost';
$db['.local']['username'] = 'root';
$db['.local']['password'] = 'root';
$db['.local']['database'] = 'some_database';
$db['.local']['dbprefix'] = "exp_";
$db['.com']['hostname'] = 'localhost';
$db['.com']['username'] = 'user';
$db['.com']['password'] = 'password';
$db['.com']['database'] = 'database';
$db['.com']['dbprefix'] = "exp_";
$db[$active_group]['dbdriver'] = "mysql";
$db[$active_group]['pconnect'] = FALSE;
$db[$active_group]['swap_pre'] = "exp_";
$db[$active_group]['db_debug'] = FALSE;
$db[$active_group]['cache_on'] = FALSE;
$db[$active_group]['autoinit'] = FALSE;
$db[$active_group]['char_set'] = "utf8";
$db[$active_group]['dbcollat'] = "utf8_general_ci";
$db[$active_group]['cachedir'] = $config['server_path'].$config['system_folder']."/expressionengine/cache/db_cache/";
By extracting out the majority of the variables (the ones that probably won't change depending on environment), and then using the $ext variable to switch the $active_group, we can adjust the database connection settings automatically depending on environment. There's one more thing we need to do. Open up your config/database.php file, empty it, and give it a solitary line:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require 'config.php';
/* End of file database.php */
/* Location: ./system/expressionengine/config/database.php */
Now, all references to the database configuration will be brought through the DB config file from the config.php file.
Alongside the standard configuration - paths, debug settings, URLs etc - we can customise a lot of ExpressionEngine's behaviour through a little-known technique called hidden configuration variables. A quick TextMate project search for 'Hidden Configuration Variable' bears 33 different variables with which to customise behaviour. Let's look at a couple of them:
$config['allow_textarea_tabs'] = 'y';
If you wish to preserve tabs in textareas, or let the user add a tab character, rather than shift focus to the next input, you can set this config item and all textareas in MarkItUp mode will preserve their tabs. Turning it off is as simple as setting it to 'n'.
Is the automatic JavaScript login reminder in the CP annoying you? Turn it off:
$config['login_reminder'] = 'n';
Do you want your formatted text links to automatically open in a new window?
$config['popup_link'] = 'y';
I'm sure you get the idea. There's a comprehensive list of the hidden configuration variables in the user guide.
I hope that this series has taught you one or two things about customising and using your config.php file to best effect. It's a fantastically powerful weapon to have in your arsenal, and it should make creating dynamic websites with ExpressionEngine much simpler.
expressionengine
Monday, October 31, 2011 at 11:36AM For the past few months I've been working full-time for a fantastic company with some fantastic people. VIA has empowered me and brought me satisfaction and happiness. But it's time to spread my wings and move on.
I've decided to go back to college and finish my education. I want to go to University, study and grow as a person. I realise that moving out so early on was a wrong choice. It wasn't a mistake; I'm very happy in Bath and I'm really enjoying my life. I just feel like I can do so much more, get so much further and grow so much more.
The problem is, I'm too late into the term to start back at college. The solution, thankfully, is simple. Take my gap year :)
So, I'm now looking for freelance/contract work, in any language - preferably PHP, Ruby or CoffeeScript - in any country. I'm a fast, able and independent developer. I love working with other people and can manage myself independently. I'm charismatic, friendly and energetic. Historically, I've specialised in CodeIgniter and ExpressionEngine development, but I'm happy to work with any other platforms. I'm willing to relocate anywhere in the world too for a few months - hell, I'd love it. I speak decent Spanish and am willing to invest time in learning any other languages.
I'm also looking for writing and speaking gigs. I want to use the next year to diversify and work on a range of different things, and I really enjoy engaging with the community and allowing my creative side to flourish.
Email me on jamie@jamierumbelow.net or telephone me on +44 (0)7956 363875. I can't wait to hear from you.
freelancing,
life
Monday, September 12, 2011 at 4:02PM I'm a sucker for short, concise syntax. One of the beautiful features about CoffeeScript - the JavaScript/Ruby lovechild that I'm slowly learning to adore - is its single line function declaration. Using this powerful syntax one can write really expressive functions with terse code.
Let's demonstrate this with a quick function. Let's say we want to remove a specific element from an array. My first guess would be to write:
var arr = [ 1, 2, 3, 4 ];
delete arr[0]; // [ nil, 2, 3, 4 ]
The issue with this, of course, is that we are left with a stray nil. That's not particularly convenient if we're using the array a lot. Instead, let's write a function and patch it onto the Array class.
Array::remove = ( element ) ->
if (@indexOf(element)) > -1
@splice @indexOf(element), 1
We're using the built-in splice() method to remove the element at the index of our element. That isn't such a bad first attempt, but it's not particularly terse or pleasant. Let's remove the repetition and move index's assignment into the conditional:
Array::remove = ( element ) ->
if (index = @indexOf(element)) > -1
@splice index, 1
We can use CoffeeScript's keyword syntax and bracketless method calling to clean it up a bit further:
Array::remove = ( element ) ->
if (index = @indexOf element) isnt -1
@splice index, 1
And finally we can push it all into one line:
Array::remove = ( e ) -> @splice i, 1 if (i = @indexOf e) isnt -1
If we compare this to the JavaScript it generates:
Array.prototype.remove = function(e) {
var i;
if ((i = this.indexOf(e)) !== -1) {
return this.splice(i, 1);
}
};
…it's a no-brainer. CoffeeScript is a wonderful way of making JavaScript cleaner, more concise and altogether much more pleasant to work with. I'd highly recommend downloading a copy and trying it out.