DNS Issues
Looks like this blog’s been down for a few days…
I’ve moved my DNS over to 123-reg and have had a few issues getting all the DNS records to work as expected…
Hopefully I’ve fixed it now…
Looks like this blog’s been down for a few days…
I’ve moved my DNS over to 123-reg and have had a few issues getting all the DNS records to work as expected…
Hopefully I’ve fixed it now…
Using CakePHP’s built in pagination system has saved me so much time in my current day job, but the latest designs I’m working on have drop-down box style pagination, as it’s possible to get many pages of results.
To change the named parameters in the current URL I’ve created this small javascript function that will amend the URL: read more…
I’ve been working on a CakePHP project lately and created a small component which was only needed in one of my controllers:
class CounterComponent extends Component { var $components = array( 'Session' ); function i() { if ($this->Session->check('Counter.i')) { $i = ($this->Session->read('Counter.i') + 1); } else { $i = 0; } $this->Session->write('Counter.i', $i); return $i; } function clear() { $this->Session->delete('Counter.i'); } }
I’ve been working on a CMS lately and having to create thumbnails for uploaded images is always a pain, lots of maths working out the correct sizes and such, so I’ve created a fairly small script to manipulate images in an object-oriented style.
For example:
scale(400, 300); $image->write('small-image.jpg'); $image2 = new Image('image2.jpg'); $image2->watermark = 'sample.png'; $image2->output();
I’ve only implemented a few of the GD library methods, but I think these are the most useful methods. I might have to work on something that rounds the corners too, but I don’t have any need for it just yet.
There’s a demo page as ever, and you can get the script here (It’s a bit big, because the sample image is included, here’s one without it).
I stumbled across something odd today in PHP:
$r = ''; $r .= $r .= $r .= 'a';
Now, personally, I’d have expected a syntax error from the above code, but the result was even more confusing at first…
print $r; // 'aaaa'
Not sure if this was the expected output or not I tested similar code in other languages:
Ruby:
r = '' r += r += r += 'a' puts r # 'a'
Python:
r = '' r += r += r += 'a' # File "", line 1 # r += r += r += 'a' # ^ # SyntaxError: invalid syntax
Javascript:
var r = ''; r += r += r += 'a'; alert(r); // 'a'
Perl:
my $r = ''; $r .= $r .= $r .= 'a'; print $r; // 'aaaa'
That explains it!
So the reason the string is ‘aaaa’ seems to be that the code is evaluated from right to left:
$r = ''; $r += $r += $r += 'a'; // How it works: // // $r += 'a'; // 'a' // $r += $r += 'a'; // 'a' + 'a'; // $r += $r += $r += 'a'; // 'aa' + ('a' + 'a')
I don’t think it’s a bug, well, at least I assume not, but is there a name for this?
Update: I asked some clever people for help understanding it.
Probably not the first person to implement this, but I wanted to make an automatic form AJAX-’ifier’ that could capture which submit button had caused the submit event to be fired too.
It’s implemented fairly simply:
$('form').ajaxify();
There’s a demo page or you can just download it and have a look.
Update: As pointed out by Andrea in the comments below, this would return the value of radio and checkboxes even if they weren’t selected. I have released 0.1a and updated the link above to fix this issue. Thanks Andrea!
Update 2: I have updated this plugin, view this post for more information.
I’ve been using the jQuery addCaptions plugin and have come across a couple of new features that I felt were required and have fixed a bug in the previous verison.
I have added an exclude option to the settings so you can prevent captions being added to elements not required (like a reCaptcha box…). It’s used like this:
$('div.demo').addCaptions({ 'exclude': { 'alt': [ /orange/ ] } });
This would exclude any images that have the word ‘orange’ in the the alt attribute.
I also fixed a minor bug in which the script would look for captions in elements in reverse order (whoops!).
The only other change is making the elements found within the container a selector instead of an element option and a class option.
There is an updated demo here, or you can just download the script here.
So I’ve updated the parallax script a little. It’s called in a more jQuery like manner now and has a couple of useful options for inverting the movement and changing the unit of measurement to any jQuery/CSS supported unit.
Example code:
$('div.parallax').parallax({ 'elements': [ { 'selector': 'body', 'properties': { 'x': { 'background-position-x': { 'initial': 0, 'multiplier': 0.1, 'invert': true } } } }, { 'selector': 'div.outer', 'properties': { 'x': { 'background-position-x': { 'initial': 50, 'multiplier': 0.02, 'unit': '%' } } } }, { 'selector': 'div.inner', 'properties': { 'x': { 'background-position-x': { 'initial': 0, 'multiplier': 0.3 } } } } ] });
You can see a demo of the updated script, or just download the package (includes jQuery 1.3.2).
So I thought I’d update the JSS script I wrote previously with a few changes I’ve been thinking about for a while.
The primary reason for the update is to add a new ‘non-CSS’ property of ‘include’. This property allows you to include styles that have already been defined in the current class. read more…