skip to content

Opening Firefox tabs at the end of the tab row

January 21st, 2010

Firefox 3.6 was released today. I love it. Love it. One thing I wasn’t crazy about was a behaviour change when opening links in new tabs. Before 3.6, they opened at the end of the tab row, but now they open beside the tab you are currently on. Want to change it back?

  • “about:config” in your address bar.
  • search for “insertRelatedAfterCurrent”. The full config is “browser.tabs.insertRelatedAfterCurrent”.
  • Set it to “false” (just click it until it toggles).
browser.tabs.insertRelatedAfterCurrent

Enjoy!

Getting the value of a selected radio button out of a radio group in jQuery

January 29th, 2009

Just a quick tip, I needed to get the value of the selected radio button from a radio group using jQuery. While several custom selectors are available for forms, there isn’t a simple way to do it that I could find. I ended up using a solution that I quite like, and wanted to share.

$("input[name=radio_group]:checked").val(); 

Have I mentioned that I love jQuery?

Edit: This entry was directly attacked by the robots, and all comments were lost. Please leave one again if you left it earlier, and accept my sincerest of apologies.

 

PHP if statement explained with Robots and James Brown’s Sex Machine

October 28th, 2008

George Ornbo over at ShapeShed (an EE shop, go admire the majesty) wrote a cute introduction to the PHP "if" statment. If you can't have fun with your code... well, then you just plain can't have fun.

I get a fair few requests from designers asking for help with basic PHP. So I'm going to write a series on very basic PHP. It is not hard so let's start with a robot and the if statement.

Not normally worthy of a mention, but he uses robots to explain, and everyone knows I'm a fool for robots; but also offers this masterful bit of PHP code (slightly altered, for brevity).

if ($button == "pressed"{
    
echo "I am alive and will now perform Sex Machine by James Brown";
}
else {
    
echo "Malfunction! Broken, destroyed, smashed.";

Why do I get the sense that this title is going to get me banned from Google?

Adding time to jQuery UI Datepicker

October 21st, 2008

For some work I’m doing right now I needed the current time output into the input field that the (excellent) jQuery datepicker uses, but I don’t need it selectable by the user.  The default format is

mm/dd/yyyy 

but can be formatted using the formatDate parameter.  The list of formatting options is considerable, including predefined setups for ATOM, COOKIE, ISO_8601, various RFC dates, RSS, TIMESTAMP and even W3C.  Unfortunately none of the predefined formats, nor the large list of date components includes time.

Read on for my solution to this dilemna.
jQuery datepicker

Turning off smileys in iChat 4

July 10th, 2008

Instant message has become a part of my daily life.  I use it pretty much non stop for work, and my work involves writing a lot of code.  It isn’t uncommon for me to send something like

if ($a=($b+$c)) 

I like iChat (Adium of course is the old favourite, but hasn’t been used much since I moved to Leopard and Apple improved iChat so much), but sometimes it’s too cute for its own good.  This is especially true of the “helpful” way it converts :) and ;) into :) and ;) respectively. Helpful in the same way that Clippy was helpful.

This behaviour gets very annoying when one is trying to look at code.  The above code example becomes if ($a=($b+$c)).  You can image how annoying this is when every third line of chat is code.  So I went hunting through the iChat preferences to find a little box I could uncheck and turn off smileys, only there was no box to be found.

A quick trip through google didn’t turn up too much either, but I was able to figure out where iChat kept its preferences for that.  A minute later, I had figured out a way to turn them off.  Here’s how:

Browse to /Applications/iChat.app, and “Show Package Contents”.
Show Package Contents

Next up, browse into Contents/Resources/English.lproj and look for a file called SmileyTable.plist.  This is where all the smiley definitions are stored.  Without it, iChat can’t translate smiles, so rename it to “SmileyTable.plist.banished”.  If you ever want smileys back, just reverse the process!

code with no smiles in it

There, that feels better ;)

failed screencast

April 13th, 2008

So, I just spent the last hour getting a screencast built to show how you can start using ExpressionEngine on your site now, even if you don’t “know” ExpressinEngine yet.  Good times.  Used Screenflow, had a sexy little video thing going… and then realized that I recorded the blasted thing nearly fullscreen on my computer (it’s a 24inch iMac).  I tried to scale it down so that it would fit onto 1 screen for most people, but then so much detail got lost that it looked like crap.

How frustrating.

So I’ll re-build it at some point in the near future, and for now, you can admire all my hard work in static, useless, image form ;)

the screencast in screenflow

Checking CodeIgniter out of the Subversion Repository

November 21st, 2007

If you’ve been following the CodeIgniter community, then you’ll know that some time ago, we made an subversion (SVN) repository available. Subversion is a version control system that we use internally to be sure we’re all working from the same page. The SVN is publicly available, and is committed to by 4 of the fine folks at EllisLab.  I’ve referred to it before, but I’ve never really talked about how to use it. Recently, there’s been some people interested in getting the latest and greatest CodeIgniter changes pre-release - and heck, why not, as there’s some fine work in there.  This post will talk about how you can use the SVN to keep up with the latest CodeIgniter changes.

SVNX screenshotFirst of all, the standard disclaimer: we make great efforts to be sure that the code in the repository is bug free and functioning, but as is the case with all “bleeding edge” releases, from time to time things may slip in there, so I don’t recommend you use it in a “mission critical” environment.

So, how to use it?  If you are a Mac user, there are 2 pretty nice graphical interfaces.  SCPlugin gets the most attention, but I really like SVNX

In windows?  Go for Tortoise SVN.  Integrates with Windows Explorer and has probably the most intuitive interface I’ve ever worked with.  In any event, pick a client ;)

Now create a folder on your computer somewhere, and rightclick to set up a new repository.  As your destination, choose “http://dev.ellislab.com/svn/CodeIgniter/trunk” which is where we keep our stuff.  Now your goto command is “update” and “show log”.  Update gets you the latest files, and “log” let’s you see what changed.  Here’s an example of the log file from today.

SVNX showing a log

Notice that most times when we check something in we make a comment? Sometimes a change is so minor that we don’t bother, but in general it’ll help you stay on top of what is new in the repository.

Changes tend to come in fits and spurts.  You might see nothing for two weeks, and then a dozen changes in two days.  In general, anything particularly noteworthy will be discussed here (on this blog), so you don’t need to check it every day, but you might want to keep an eye on future changes yourself.

Welcome to the cutting edge! ;)

Setting up “Live Look” in ExpressionEngine

November 16th, 2007

live look in ExpressionEngineA few days ago, I wrote about the release of ExpressionEngine 1.6.1.  In it, I highlighted the “live look” feature, as a great new addition.  Live look allows you to preview a post within a template, rather than previewing only isolated content.  So you can see what your content will look like inside your template.  This is great if you have a future entry, or a post that you are leaving “closed” until you have a chance to finish it up.

But there has been a bit of confusion about how live look should work.  Essentially, all it does is load your entry into a template, so if you have a future dated entry, or a closed entry, it won’t be visible by default.  The solution?  Create a “preview” template, and take advantage of the status and show_future_entries parameters.  Essentially, make it look like this

{exp:weblog:entries weblog="default_site" status="open|closed" show_future_entries="yes"

I’d further recommend that you take advantage of Template Access Restriction in your preview template.  Without it, anyone who guesses your preview template will be able to see upcoming or closed content.  Probably a good idea to restrict it to the same member groups as your authors.

Happy ExpressionEngineering!

Ordering Database results by “random” in CodeIgniter

August 14th, 2007

A recent CodeIgniter bug report had got me looking into the depths of the database results functions of the framework.  Essentially, the orderby() function of CI’s Active Record says that you can sort by ASC (ascending), DESC (descending) or RAND().  Imagine this:

$query "SELECT * FROM table ORDER BY RAND()"

Anyone familiar with PHP probably looks and that and thinks of the native PHP rand() function.  This is pretty neat actually, and I’d never really thought about randomly ordering things.  But on further investigation, it became clear that this code wasn’t as nice as it initially seemed.  Firstly, its non-standard SQL, reducing its portability greatly.  While MySQL uses RAND(), other databases have their own way of doing things:

  • MySQL uses ORDER BY RAND()
  • PostgreSQL uses ORDER BY RANDOM()
  • Oracle uses a subquery with ORDER BY dbms_random.value
  • SQL Server users ORDER BY NEWID()

So then, how would one randomly order their database results?  Read on for my solution…

Giving your Helpers a little Help

August 12th, 2007

CodeIgniter is one of the most flexible, powerful, unobtrusive frameworks you could choose to use. It’s so useful in many ways, including pre-existing convenience libraries (I can’t live without the email library anymore), plugins (for handy little tools such as javascript calendars and CAPTCHA creation) and the appropriately named “helpers”.

In the world of CodeIgniter libraries, plugins and helpers, the libraries are Rock Stars. They get most of your attention, they do most of the heavy lifting. They date super-models, party in Europe, and return on Monday to keep your application humming along (sometimes Tuesday… you know those darned unreliable rock stars). They can be extended, overwritten, and you can create your own, wholly new libraries just for your application. Wow. No wonder super-models want to date them.

One of the most handy aspects of libraries, is that you can create a libraries folder in system/application/libraries, and leave the existing CodeIgniter libraries untouched. This makes upgrading to newer versions of CI a breeze, as you never need to worry about going in and re-implementing all the changes you made to a library.  From the userguide:

As an added bonus, CodeIgniter permits your libraries to extend native classes if you simply need to add some functionality to an existing library. Or you can even replace native libraries just by placing identically named versions in your application/libraries folder.

And while libraries are doing all this work, we’re left with the humble, but infinitely handy helper. Here’s what the userguide has to say about helpers.

Helpers, as the name suggests, help you with tasks. Each helper file is simply a collection of functions in a particular category.

Makes them sound like one-trick ponies; but they are not. Helpers, while not quite as flexible as libraries, are tremendously useful. They are written procedurally, instead of object oriented (as the rest of CodeIgniter is). And while they can’t be extended as libraries can, a little known fact is that they can be overwritten. Better yet, is the method in which you’d override them. Much like libraries, the trick lies in creating a folder underneath system/application for helpers. Then, when CodeIgniter loads helpers, it looks first in your application/helpers folder, and only if that folder can’t be found does it then fall back on the default system/helpers folder. So you can add your own helpers, or overwrite existing ones.

Here’s a case study. In BambooInvoice I use the date helper’s timespan() function to determine exactly how overdue an invoice might be. My problem is that the default timespan() function keeps tabs down to the second of the span of time. When tracking invoices, I don’t care how many hours, minutes and seconds have passed, only how many days and weeks (or months if you have a really bad-paying client ;)) So for use in Bamboo, I want that helpers default output changed. The solution, to remove or comment out those lines of the helper.

But the problem with modifying the system helper is that in the next upgrade, that helper gets overwritten again. Since I use BambooInvoice as part of my testing codebase for vetting new CodeIgniter code, I tend to overwrite these files a lot. This then required carefully keeping track of what helpers were modified, and introduced some other problems. A preferable approach would be to simply make a copy of system/helpers/date_helper.php in application/helpers. Now, the application helper will be loaded preferentially, and I can modify to my hearts content without ever fearing I’ll accidentally overwrite my changes.

Application based helpers are a handy feature indeed. There have been discussions about changing the procedural structure of helpers to allow for extending and over-riding, but for now, the simplicity of helper functions are preserved, and you can easily maintain your own modified versions.

How are you using CodeIgniter helpers? If you’ve modified any of the base helpers, or created your own, I’d love to hear about it here.

 1 2 3 >  Last »

Derek Allard

I'm Derek Allard, a programmer, author, and award-winning instructor. I'm also Technology Architect at EllisLab, and the programmer behind BambooInvoice, a simple, Open Source, web-based invoicing application. [more about Derek]

Categories