debuggable

 
Contact Us
 
28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36

3 Jobs for skilled Bakers

Posted on 12/6/08 by Felix Geisendörfer

Hey folks,

it's only been a short while since the launch of the new job board for the CakePHP community and there are already 3 jobs posted. If you are currently seeking employment, you should consider the following opportunities:

If any of those jobs sound interesting to you, go ahead and apply. If you are looking for skilled bakers yourself, consider posting on the job board. It is $300 / post of which 50% are donated to the Cake Software Foundation.

All jobs posted within the next month are also going to be featured on debuggable.com including a back link to the company website.

-- Felix Geisendörfer aka the_undefined

 

How to do Group By conditions in Model find() calls in the CakePHP RC1

Posted on 11/6/08 by Tim Koschützki

Hey folks,

we have to thank Mark Story and wluigi for working on group by conditions for Cake's Model::find() method. Up until now, you would have to add your GROUP BY stuff to string'ed conditions in order to support a group by statement, which could be very ugly.

Have a look at the following:

$query = trim(low($query));
$conditions =
    "Product.active = '1' AND (LOWER(Product.name) LIKE '%{$query}%'
    OR LOWER(Product.description) LIKE '%{$query}%'
    OR LOWER(Product.sku) LIKE '%{$query}%') GROUP BY Product.name"
;
$this->paginate['Product']['conditions'] = $conditions;
$products = $this->paginate('Product');

Now with the new worked in group key you would just do:

$query = trim(low($query));
$conditions = array(
  'or' => array(
    'LOWER(Product.name) LIKE' => "%{$query}%",
    'LOWER(Product.description) LIKE' => "%{$query}%",
    'LOWER(Product.sku) LIKE' => "%{$query}%"
  ),
  'active' => 1
);

$this->paginate['Product']['conditions'] = $conditions;
$this->paginate['Product']['group'] = 'Product.name';
$products = $this->paginate('Product');

Much cleaner! Cool! Now let's see what we'd do if we wanted to group by over several columns:

$order = array('created' => 'desc', 'name' => 'asc');
$group = 'name, created';
$products = $this->paginate('Product', compact('order', 'group'));

The group statement currently works as a string. So you would have to separate multiple group by fields by a comma.

Kudos to wluigi and mark_story. Checkout the Changeset if you are interested in the underlying implementation.

Now who is not excited about the new release?

-- Tim Koschuetzki aka DarkAngelBGE

 

Crawl Google, they do the same to you ; )

Posted on 10/6/08 by Felix Geisendörfer

Hey folks,

Marc Grabanski just had the great idea of using google to help with the migration of your site to a new domain / url schema. Just get a list of all pages google has indexed from your site and then use that as your basis for checking if your migration worked or not. This is very convenient because you do not have to know all your own urls yourself, and you'll only get the relevant ones (if they are not in google they are unlikely to have traffic).

So here is some quick code for crawling Google instead of being crawled by them in CakePHP:

class GoogleIndexShell extends Shell {
  function main() {
    App::import('HttpSocket');
    list($site) = $this->args;
    $Socket = new HttpSocket();
    $links = array();

    $start = 0;
    $num = 100;
    do {
      $r = $Socket->get('http://www.google.com/search', array(
        'hl' => 'en',
        'as_sitesearch' => $site,
        'num' => $num,
        'filter' => 0,
        'start' => $start,
      ));
      if (!preg_match_all('/href="([^"]+)" class="?l"?/is', $r, $matches)) {
        die($this->out('Error: Could not parse google results'));
      }
      $links = array_merge($links, $matches[1]);
      $start = $start + $num;
    } while (count($matches[1]) >= $num);

    $links = array_unique($links);
    $this->out(sprintf('-> Found %d links on google:', count($links)));
    $this->hr();
    $this->out(join("\n", $links));
  }
}

Usage is as simple as running:

./cake google_index debuggable.com

Which should produce an output like this:

Welcome to CakePHP v1.2.0.7125 beta Console
---------------------------------------------------------------
App : app
Path: /Users/felix/dev/www/php5/debuggable/app
---------------------------------------------------------------
-> Found 293 links on google:
---------------------------------------------------------------
http://debuggable.com/
http://debuggable.com/contracting
http://debuggable.com/contact
http://debuggable.com/workshops
http://debuggable.com/open-source/fixtures-shell
http://debuggable.com/open-source/google-analytics-api
http://debuggable.com/posts/thinking-what:480f4dd5-5f1c-4d37-99b0-4768cbdd56cb
http://debuggable.com/posts/jquerycamp07:480f4dd6-8d40-44e1-8551-4a58cbdd56cb
...

Oh and if you want to see more shell sample code, also check out our FixtureShell and the blog post for it.

-- Felix Geisendörfer aka the_undefined

PS: Please note that this is a quick hack, and any non-trivial change in the markup google uses will break. This is only meant for temporary usage.

 

Better array syntax for PHP: Here's your chance to weigh in

Posted on 9/6/08 by Nate Abele

Hi folks.

Recently there's been some discussion on the PHP internals mailing list about providing an alternate array declaration syntax for PHP.

Instead of:

$fields = array('id', 'name', 'created');

it would be possible to do

$fields = ['id', 'name', 'created'];

Simpler, cleaner and very familiar to anyone who has done development in almost any other modern web language, especially JavaScript.

Well, there's a patch available, but 2/3 of the active PHP committers (who participated in the vote) voted against its inclusion. However, of the end-users participating in the discussion, 17 out of 20 voted in favor. Shortly before the voting was concluded, there was a call for some user-land input, so I decided to humbly submit my two pennies.

This fact has been pointed out previously, but it bears repeating: the
divide between users and committers on this issue is stark: only 1/3
of committers are in favor, but almost all users who have voiced
opinions on the issue are in favor. The people actually using the
language want something new, because in this case something new is
better. Come on guys, arrays are our bread and butter. PHP has more
support for working with arrays than it does for doing pretty much
anything else.

I can't imagine I'll be taken very seriously. I also find it hard to believe that many actual users of PHP would be against this, a fact which is all the more tragic given the rhetoric of the core committers who are against it (a full summary of the discussion can be seen at http://markmail.org/message/rsi4welftwou24p3, please note that this is not updated in real-time).

Fortunately PHP, like Cake, is an Open Source project, and even I've been known to implement and support features which I personally don't like or have no use for, if the community support behind the idea is strong enough. The same goes for PHP, so here's your chance to make your voice heard. Blog, leave comments, post to the internals list, lobby your local PHP core committer (remember to be nice).

Obviously a feature like this, even though we wouldn't be able to directly take advantage of it anytime soon, would be a great help in pushing all PHP projects, especially ours, forward to the future.

 

New Header Design, Convenience Features and TAB Completion

Posted on 9/6/08 by Tim Koschützki

Hey folks,

there are some changes to the website that we would like to tell you about.

1. The old header design ....

Many liked it and some didn't (hah)... Whatever.

As we were waiting for a designer we recently have been working with for a new mockup, Felix had a very cool idea for a new header design which he implemented. The result of it is what you are seeing. The hover effect is going to change a little tomorrow. Any ideas are always welcome. Now is this a design improvement?

2. We added some subscriber-counter to the top right corner right below our "blurb". If you like what we are writing about, you can click on it in order to subscribe to our RSS feed.

3. From now on you can print posts, digg them, stumble them and add them to delicious with some easy links below each post.

4. There is some cool feature now in the comment box I have been working on.

You can now enter the first characters of the name of any person who has commented on the post so far.

Then you hit tab and it completes the name for you.

So this is a very easy means to reply to several people very quickly:

It still needs some tweaking to allow "navigating" through several names that all start with the same chars. As it uses the tab key, it won't work together with the navigation through page elements (that the tab key is normally used for) very well. However, Safari will still focus the next page element.. Oh well.

But hey, if you guys like it, this can be turned into an open source project and receive many more features and feedback.

Oh by the way: I basically stole the idea from Colloquy, one of the famous Mac IRC Clients.

What do you think about the new stuff?

-- Tim Koschuetzki aka DarkAngelBGE

PS: There is some more dough waiting to be mixed in the kitchen.

 
28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36