zen of coding

Checking for SSL and then some…

A simple way to check and enforce SSL can be done by using the RequestHandler component. Here’s an example: private function checkHttps() {   if(!$this->RequestHandler->isSSL()) {     return $this->redirect(’https://’ . env(’SERVER_NAME’) . $this->here);   } } Simple enough, right? Yet there is a little caveat, which causes a problem[…]

Read More »

Type checking vs too much typing…

This had me pondering for a minute. Quite often I write code along the lines of: public function doStuff($stuff, $complex = FALSE) {   if ($complex) {       echo ‘Doing complex stuff<br />’;   } else {       echo ‘Doing simple stuff<br />’;   } }[…]

Read More »

Show git branch in your bash prompt

Quite a convenient little snippet. Thought I would share it with all my dear readers and git lovers. (Thanks to the original author, whom I cannot remember right now. I’ll gladly post the link to the original source if someone reminds me) Add the snippet below to your .bash_profile (Don’t[…]

Read More »

Helpful jQuery modals

This post is actually mostly about jQuery (with some cake sprinkles), but why not… Let’s examine a typical situation: We have a Product model, which belongsTo a Category model. Now we need to add some products… An admin interface would have a category select input (or drop-down) and a few[…]

Read More »

Very hacky way to get client’s country code based on IP

You’d think that by now there should be an easier way to accomplish something like this. (i.e. Send a client IP to some service, and get their country or other location information). All my research just pointed to some some API’s, complicated components and way to much extra leg work[…]

Read More »

Catch database errors before it’s too late

A quiet, little method inside model.php, can actually help us out quite a bit. I am talking about the onError() callback. Here’s a snippet from the API: /** * Called when a DataSource-level error occurs. * * @access public * @link http://book.cakephp.org/view/1048/Callback-Methods#onError-1056 */ function onError() { } And the little[…]

Read More »

FU … IE7

Sorry, but this one had me going nuts (not bolts) for 2 days. When AJAX request was sent to the server in IE7, it would “magically” reset the session ID. Of course, this would cause serious problems for the end-user. Mind you, this worked perfectly well in every other browser.[…]

Read More »

Job openings

Hello All, Our company is looking for CakePHP developers, PHP developers and front-end engineers (jQuery ninjas with PHP skills). If you are interested please use the contact me form to send a one-two paragraph summary about why we should hire you… examples of work are pretty much a must. I[…]

Read More »

Speeding things up with materialized views and MySQL

First let’s see what Wikipedia says about materialized views: A materialized view takes a different approach [from the regular sql view] in which the query result is cached as a concrete table that may be updated from the original base tables from time to time. This enables much more efficient[…]

Read More »

A simple shell to hash your passwords

If you are moving data into a CakePHP environment and the passwords in the existing DB aren’t hashed, you can use the simple shell provided below to hash them according to the cake’s standard. In case the passwords are already hashed using a different method, this is not going to[…]

Read More »
%d bloggers like this: