Subscribe to RSS Subscribe to Comments

Alan Blaine Whitney

Inline Editing

Lately I have been using inline editing in web apps.  I really am falling in love with it.  By inline, I mean the user just clicks on an object in the interface.  Rather than a link, it changes a field into an edit able area, and then when you hit save, it updates the interface, all without updating the page.

General I use prototype’s form serialize and ajax updater to save the change.  I like to use an abouslutely positioned dive with a scriptaculous appear effect.

Maybe later I will give a more detailed technical explanation.

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

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-->/' {} \;

Last few weeks

Been very busy the last few days. Moved from cyberwurx to dreamhost for hosting. So far so good with dreamhost.

Launched a new website for my church. It includes news feed, sermon archives and podcasting. Check it out if you want at lincolncf.com

Email

I have figured something out. I get more done in the morning, plain and simple. As the day goes on, I get phone calls, have to have conversations with people, answer emails. The more of that I do, the more drained I become. In the morning my thoughts are clear. Even in the Bible, this concept exists. <br />
<br />
<blockquote>My voice shalt thou hear in the morning, O LORD; in the morning will I direct my prayer unto thee, and will look up. <em>Psalm 5:3</em></blockquote><br />
<br />
There is a concept all through Psalms about praying and reading the Word of God in the morning. I think it has something to do, at least a little bit, with your freshness in the morning, as well as setting the tone for the day.<br />
<br />
Something that I am going to try to do at work. I am going to come in first thing in the morning and not open email or anything else, but just work on a project. I get in to work at 8 and often it's at least 10 before everybody is in at the office. That's two hours where I could really hammer down.

« Previous PageNext Page »

Based on FluidityTheme Redesigned by Kaushal Sheth Sponsored by Send Flowers