snapsvg

2013-04-29

Monsieur, with these simple one-job jQuery plugins you are really spoiling us.

Today's new jQuery plugin is the check-all plugin: https://github.com/propcom/jquery-checkall

It has a couple of bugs at the time of writing, but I'll probably have those fixed this week.

Usage is quite simple (obviously); you target the 'All' checkbox and tell the plugin how to recognise all the others:

    $('#check-all').checkAll({
        rel: '.normal-checkbox'
    });

As with all of my plugins, if the selector selects multiple things, it loops over them so each one gets its own context.

2013-04-17

Announcing two new jQuery plugins

I like to keep things simple. I get a bit tired of trawling through pages of misinformation trying to figure out how to use a behemoth library when all I want is a simple feature.

Yesterday I uploaded very alpha (but working for me) editions of two new jQuery plugins that I wrote to solve the problem of having to read too much.

sort-by


http://github.com/propcom/jquery-sortBy

jQuery doesn't provide a .sort() method, but if it did it would be wrong.

sort-by uses the Schwartzian Transform concept to sort the children of the element you run it on. It takes a function, and the function is provided each child. The function returns a value by which the child may be sorted, and then the children are sorted in-place based on that.

You can view an example at http://propcom.github.io/jquery-sortBy

Checkbox Linked Lists


https://github.com/propcom/jQuery-checkbox-linked-list

This plugin relies on sort-by and jQuery UI. jQuery UI sucks so I'd like to not use it but for now it does.

The plugin takes all children of an element and splits them into two lists; the first list contains all children that contained a checkbox that was checked, and the second contains all children that contained a checkbox that wasn't checked. Then the checkboxes are hidden and the items can be swapped between the two lists. The plugin changes the checkboxes as it runs so that posting the form works exactly as it did before you implemented it.

Examples to come! Enjoy!

2013-03-28

Cannot reassign $this?

PHP won't let you reassign $this because it is a readonly reference to the contextual object.


class Test {
    var $foo = "bar";

    function abc() {
        $this = "Hello!";
    }
}

$test = new Test();
$test->abc();

PHP Fatal error:  Cannot re-assign $this in - on line 14

Fatal error: Cannot re-assign $this in - on line 14

Since PHP has the flaw of allowing you to use variables as variables, however, you can put 'this' in a variable. PHP doesn't seem to notice that that's assigning to $this:


class Test {
    var $foo = "bar";

    function abc() {
        $thisStr = "this";
        $$thisStr = "Hello!";
    }
}

$test = new Test();
$test->abc();

Tricked you!


However, if you then use $this as an object, it's still $this! But if you don't, it's not:


class Test {
    var $foo = "bar";

    function abc() {
        var_dump($this);
        var_dump($this->foo);

        $thisStr = "this";

        $$thisStr->foo = "cats";

        $$thisStr = "Hello!";

        var_dump($this);
        var_dump($this->foo);
    }
}

$test = new Test();
$test->abc();

class Test#1 (1) {
  public $foo =>
  string(3) "bar"
}
string(3) "bar"
string(6) "Hello!"
string(4) "cats"

Surely someone's realised by now that the people behind PHP might not really know what they're doing.


Edit: turns out this already came from reddit

2013-03-08

Gnu Passive-Aggressive Public Licence (GPAPL)

This licence is for people reluctant to give away code but who understand the rationale behind it.

This program is free software. I wouldn't expect you to pay for it anyway.
You can and probably will redistribute it and/or modify it under the terms 
of the GNU General Public License as painstakingly published by the Free 
Software Foundation, either version 3 of the License, or (at your option, 
if you think that's best) any later version. I know you're going to anyway
so I might as well legitimise it. 

This program is distributed in the hope that it will be useful, not that you 
care, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, especially yours.  
If you can find the energy, see the GNU General Public License for more 
details, but it's OK if you don't. Most people don't. Whatever.

You should have received a copy of the GNU General Public License
along with this program.  If not, all I can really do is point you to this URL 
<http://www.gnu.org/licenses/> and assume you're going to follow it. I can't
force you so whatever. Just have it. 

The GPAPL is released under the WTFPL, as if you care.

2012-08-31

Oh go on

alias please='sudo $(history 2 | head -n1 | perl -pe "s/^\s*\d+\s+//")'

Update:

alias please='sudo $(fc -nl -1)'

2012-08-30

Catalyst::Authentication::Store::MongoDB 0.02 finally released

Took me a bit of time fighting CPAN to get it to index it (that'll teach me to try to use 1e-4 as a version number) but the patches that a kindly chap in the community sent to me (wasn't sure if he wanted to be named so I have erred on the side of caution) are now up on CPAN.

This means that both you and I can finally use MongoDB for our Auth stores, and I can finally continue working on the project I was working on before this debacle put me off.

Check it out here (http://metacpan.org/module/Catalyst::Authentication::Store::MongoDB), or here (http://search.cpan.org/~altreus/Catalyst-Authentication-Store-MongoDB-0.02/lib/Catalyst/Authentication/Store/MongoDB.pm) if you prefer the old-fashioned CPAN.

The module's on github, as is everything ever, here (https://github.com/Altreus/Catalyst-Authentication-Store-MongoDB).

2012-08-06

Mars Fiction

In recognition of the momentous occasion of NASA managing to fire things at a planet and not miss I thought I'd compile a list of recommended reading/watching/listening of stories set on or featuring Mars.

This list is almost certainly going to be entirely sci-fi. Men Are From Mars, Women Are From Venus absolutely does not count.

So without further ado:

Books

  • John Carter of Mars - Edgar Rice Burroughs
  • Martian Chronicles - Ray Bradbury
  • War of the Worlds - HG Wells
  • Out of the Silent Planet - CS Lewis

TV

  • Doctor Who: The Waters of Mars
Some others have been suggested tangentially so I'll record those too.

  • Y: The Last Man - Brian K. Vaughan (Comics)
More to come!