Archive for March, 2008
User Stats

I was just looking through some Google Analytics things and thought I would share some stats that I see on the sites that I monitor.

Browsers

  1. IE 7 (62%)
  2. Firefox (18%, mostly 2)
  3. IE 6 (15%)
  4. Safari (4%)
  5. Mozilla (1%)

I was surprized of how few IE6’s are still around

Screen Resolutions

92 to 98% (depending on site) of screen sizes are 1024×768 or bigger with the most common being 1024×768, 1280×768, and  1280×800

Connection

Around 5% to 10% are not connecting at high speed (DSL, Cable, T1, etc).  Cable is more popular than DSL.  Not surprisingly,  people spend the same amount of time on a site, but people with higher speeds see more pages per visit.

Work time

Google allows it’s people to work 20% of their work time on whatever they feel passionate about.  Recently, I read a post about 37 signals switching to 4 day work weeks.  It got me thinking

If you have the right type of people, it’s good to let them have freedom to play around with stuff, just experiment.  One they learn stuff, making them a better employee, it’s cheaper than college or often going to conferences.  Another thing is that the people are fresher, feel less bogged down.  Just a few random thoughts on that.

CakePHP User Auth

I am pretty new to cakephp, I have been using it for a about a month now, mostly with the 1.1 release. Upgraded to 1.2 on this one application. It went okay, it was a simple application. The toughest part was validation and login. For those who have struggled through this as well, getting user logged in and the new validation in 1.2. Here is the source of what I did.

app/models/user.php

class User extends AppModel {

var $name = 'User';
var $useTable = 'users';
var $validate = array(
'username' => array(
VALID_NOT_EMPTY,
'alphanumeric' => array(
'rule' => 'alphanumeric',
'message' => 'Username may only consist of letter and numbers'),
'length' => array(
'rule' => array('between', 6, 20),
'message' => 'Username must be between 6 and 20 characters in length'),
'unique' => array(
'rule' => 'checkUniqueUser',
'message' => 'Username already taken'),

),
'password' => array(
VALID_NOT_EMPTY,
'length' => array(
'rule' => array('minLength', 6),
'message' => 'Password must be at least 6 characters in length'),
),
'email' => array(
'email' => array(
'rule' => 'email',
'message' => 'Invalid Email',
),
'unique' => array(
'rule' => 'checkUniqueEmail',
'message' => 'Email already in use',
),
),
);

//The Associations below have been created with all possible keys, those that are not needed can be removed
var $hasMany = array(
'Comment' => array('className' => 'Comment',
'foreignKey' => 'user_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);

function checkUniqueUser($data) {
return $this->isUnique(array('username' => $this->data['User']['username']));
}

function checkUniqueEmail($data) {
return $this->isUnique(array(’email’ => $this->data['User']['email']));
}

// The basic login stuff
function validateLogin($data)
{
$user = $this->find(array(’username’ => $data['username'], ‘password’ => md5($data['password'])), array(’id’, ‘username’));
if(empty($user) == false)
return $user['User'];
return false;
}

}
?>

app/controllers/users_controller.php

class UsersController extends AppController {

var $name = 'Users';

// This is to know
function login()
{
if(empty($this->data) == false)
{
if(($user = $this->User->validateLogin($this->data['User'])) == true)
{
$this->Session->write(’User’, $user);
$this->Session->setFlash(’You\’ve successfully logged in.’);
$this->redirect(’/');
exit();
}
else
{
$this->Session->setFlash(’Sorry, the information you\’ve entered is incorrect.’);
exit();
}
}
}

function logout()
{
$this->Session->destroy(’User’);
$this->Session->setFlash(’You\’ve successfully logged out.’);
$this->redirect(’/');
}

function view($id = null) {
if (!$id) {
$this->Session->setFlash(__(’Invalid User.’, true));
$this->redirect(array(’action’=>’index’));
}
$this->set(’user’, $this->User->read(null, $id));
}

function add() {
if (!empty($this->data)) {
$this->User->create();
if ($this->User->save($this->data)) {
$this->Session->setFlash(__(’The User has been saved’, true));
$this->redirect(array(’action’=>’index’));
} else {
$this->Session->setFlash(__(’The User could not be saved. Please, try again.’, true));
}
}
}

}
?>

app/app_controller.php

class AppController extends Controller {

var $helpers = array('Html', 'Form', 'Javascript', 'Ajax');

function checkSession()
{
// If the session info hasn't been set...
if (!$this->Session->check('User'))
{
$this->Session->setFlash('The URL you\'ve followed requires you login.');
$this->redirect('/users/login');
}
}
}

?>
And then just call $this->checkSession() in your controllers to force a login

Tough

I have to go through a bunch of templates and change the text in them. Every template is different and require personal attention. This is a little snippet from my shell for those of you who know bash.
for I in `grep -n -r -i "bill_of_sale" * | cut -d ":" -f 1 | sort -u ` ; do gvim $I ; done
Not so fun.

Web 3.0

So it seems that we are currently in the peak of Web 2.0. It seems that the Web 2.0 form of thinking is now permeating businesses and more and more web 2.0 apps are aimed for businesses.

Before we begin on this road, we should specify something, Web 2.0 is loosely defined, Web 3.0 is hardly defined. It’s like a crap shout of what people think is going to happen. Lots of people like it will involve a form of artificial intelligence. Like you can search for a string like “I want to see a funny movie and eat at a buffet” and google will return movie listings and close by buffets. Yet others think it will be faster connections to the internet. Yet others think it will be greater advances in graphics.

Those things may all happen. Here is what I think. It will be the rise of the Semantic Web.  The real basic definition is a set of design principles for data.  I think the big think will be the information sharing between web apps.  That’s my pick

Keyboard Shortcut

I have found the keyboard shortcuts in gmail very useful. They really have spend up how I use gmail. I would like to start using keyboard shortcuts in my web apps, here is how I intend to do it, with prototype

Event.observe(window, 'load', function() {
Event.observe(document, 'keypress', function(e){
var code;
if (!e) var e = window.event;
if (e.keyCode) code = e.keyCode;
else if (e.which) code = e.which;
var character = String.fromCharCode(code);
alert('Character was ' + character);
});
});

Pretty cool I think, you replace the alert with whatever you are doing

Work Enivorment

Lately I have been thinking about my work environment.  On Friday I was trying to focus on something and although I was largely unbothered, I continual had people walking around me, heard people have conversations, heard phones ringing.  Tons of things to take my focus.

Office settings tend to not work for programmers.  It’s too easy for somebody to come ask them a question or call their extension and ruin the last and next 15 minutes of focus for that.

Working alone seems like a good  idea.  I have tried it a few times.  It’s cool, but at times lonely.  And you can’t throw ideas off each other like you can in a group setting.

Large groups have never worked for me, usally to unorganized and you spend too much time with analysis paralysis.

What works for me is a small ground, 2 to 4 people in a place where people can’t interrupt them.  The small group is easy to organize, quick to get working.  It’s nice to be able to talk with someone to bounce ideas off of them from time to time.  I really like the library reading room, it’s quiet enough, but you can talk softly if you need to, but you should not need to talk too much.

RSS comments

RSSI use Google reader quite a bit and I am very pleased with it. It allows me to quickly scan through news and blogs that I read and get the most important information very quickly, but it occurred to me lately that there is a feature that I would fight to see blog and Google reader.

That’s feature is the ability to read comments. I think it would be nice that it’s somehow in the RSS feed, you could have a link to the RSS feed for the comments, than you could read a post and then you could scan through the comments just like a post.

Force the Use of a domain

Do you find yourself needing to redirect a website to use only one domain. For example you have www.example.com, example.com, example1.com, www.example1.com, www.example2.com but you always what www.example.com to show up.

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule .? http://www.example.com%{REQUEST_URI} [R=301,L]

Here is a real world example.

# Use one domain

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.smbiz4me\.com$ [NC]
RewriteRule ^/(.*)$ http://www.smbiz4me.com/$1 [R=301,L]

Recursive Find and Replace

At my job, I often need to recursivly find and replace certain strings. I always fumble around for the syntax, here is the syntax so I don’t forget

find ./ -type f -exec sed -i 's/ReplaceThis/WithThis/' {} \;

And you can add all of the custom stuff to find like name if you want, here is a real world example.

find ./ -name '*php' ! -name '.*' -exec sed -i 's/<noindex follow>/<!--sphider_noindex-->/' {} \;