Andy@

Aug / 28 / 2009

Snow Leopard Install Problems?

Having problems installing Snow Leopard? I found that it got half way through, then wanted a reboot but it just spat out the disk and booted up in Leopard as normal. Fix … put the disk in and reboot holding down “c”; carried on as it should.

May / 21 / 2009

Where clauses in Kohana Many<>Many ORM relationships

I had need of using a where clause in an ORM relationship in Kohana. There is an events table, a users table and a pivot table to join them. Where normally, I would do this:

    1 <?php
    2     $events = ORM::factory('user', $user_id)->events;
    3 ?>

… to get all the events, belonging to a specific user; I wanted to only get the events that were in the future. To do so, I needed to explicitly write some of the magic code that the ORM normally hides:

    1 <?php
    2     $user = ORM::factory('user', $id);
    3     $dbe = new Database_Expression(
    4                             'SELECT event_id 
    5                                 FROM events_users 
    6                                 WHERE user_id='.$user->id );
    7                     
    8     $model = ORM::factory('event');
    9     
   10     $events = $model
   11               ->in($model->table_name.'.'.$model->primary_key, $dbe)
   12               ->where('event_date >=', date('Y-m-d H:i:s') )
   13               ->find_all();
   14 ?>
  • Get the user
  • Create a subquery to pull out the event_ids belonging to that user
  • Get the ORM object for events
  • Get all the events where the event is in the future AND belong to the user

Solved.

May / 06 / 2009

Quick Tip for Generating Sha1 Passwords

Using PHP from the command line:

php -r 'echo sha1("password")."\n";'

UPDATE: also; a different version

echo -n 'password' | openssl sha1
Apr / 23 / 2009

Does AJAX sometimes break? Check the domain ... (DOH!!!!)

I’ve been having n issue with a site I’ve been working on; where the AJAX would break on the client’s machine, but never any of the ones I tested on - browser wouldn’t matter, nor would OS. Which lead me the conclusion it must be a server-side issue … or is it?

Nothing seemingly wrong with the server … actually it boiled down to the security features of AJAX not allowing cross domain calls. The real issue was that I never put in the www and the client always does; but the ajax calls were all to the non-www version - so it always worked for me and failed for them.

With that in mind (and being as I usually build sites using Kohana), here is a quick domain check hook to check that you’re calling the correct domain:

    1 <?php defined('SYSPATH') or die('No direct script access.');
    2 
    3 class Domaincheck {
    4     public function check_domain()
    5     {
    6         if($_SERVER['SERVER_NAME'] != Kohana::config('config.site_domain'))
    7         {
    8             url::redirect();
    9         }
   10     }
   11 }
   12 
   13 Event::add('system.ready', array('Domaincheck', 'check_domain'));
Apr / 20 / 2009

PHP Reflection API

A simple example of how to use the PHP Reflection API (I found it to work better than ‘call’, which I had some issues with):-

    1 <?php 
    2 
    3 // arguments you wish to pass to constructor of new object 
    4 $args = array('a', 'b'); 
    5 
    6 // class name of new object 
    7 $className = 'myCommand'; 
    8 
    9 // make a reflection object 
   10 $reflectionObj = new ReflectionClass($className); 
   11 
   12 // use Reflection to create a new instance, using the $args 
   13 $command = $reflectionObj->newInstanceArgs($args); 
   14 
   15 // this is the same as: new myCommand('a', 'b'); 
   16 ?>
Apr / 20 / 2009
steamshift.net encoded as a QR Code (2d Barcode)

steamshift.net encoded as a QR Code (2d Barcode)

Apr / 09 / 2009

PHP, Cookies and Underscores

Hit a nasty little issue when using cookies in PHP; if the subdomain has an underscore in it then various browsers won’t store the cookie. Very tricky to track down. Hope this helps someone!

Mar / 25 / 2009

Terminal Tip: Open Finder Here ...

MAC OS X Tip:

Probably very obvious to most people, but I’d never used it until recently … if you are in the Terminal and want to open the current folder in the Finder, just do “open .”

As for the other way around; Marc Liyanage’s ‘Open Terminal Here’ script seems to be the way to go.

(Via Macworld: Mac Gems: Open Terminal Here.)

Technorati Tags: ,

Mar / 17 / 2009

Bizarre Error with CSVs in Excel:- SYLK: File format is not valid

From Microsoft help (http://support.microsoft.com/kb/323626):-

When you try to open a text file or a comma-separated variable (CSV) file, you may receive the following error message:-

	SYLK: File format is not valid

This problem occurs when you open a text file or CSV file and the first two characters of the file are the uppercase letters “I” and “D”. For example, the text file may contain the following text:

	ID, STATUS
	123, open
	456, closed

Note This problem does not occur if the first two letters are lowercase “i” and “d”.

Surely I’m not the only one to find this utterly insane!

Mar / 13 / 2009

TextMate Rocks (with MarsEdit as well)

2 great flavours that could taste great together MarsEdit and Textmate … mmm I wonder …

Turns out, there are 2 ways of accomplishing this; 1. set TextMate as the external editor for MarsEdit, then just create (or click to edit your post) and hit command-J (File -> Edit with TextMate); 2. Install the ‘Edit in TextMate…’ bundle, which will allow you to edit any text from any Cocoa application in TextMate.

Woohoo! How easy is that?!

SteamSHIFT out.

Technorati Tags: , , ,

Page 1 of 2