$ date -d @1212312323
Sun Jun 1 13:25:23 GST 2008
Saturday, December 20, 2008
UNIX time to human readable
Sunday, November 30, 2008
How to have Undelete on your Linux command line.
When you spend most of your time on the shell you usually use the command "rm" to delete a file and this command doesn't support undelete once you issued the command.
First we need to learn not to use the command 'rm' to delete our files.
In your ~/.bashrc file add the following line:
alias del='mv -t ~/.local/share/Trash/files --backup=t'Deleting files now is done via
del filename.txt.
Then we need a script to clean up our trash folder occasionally.
Create a script and name it whatever you want, I named mine "cleantrash" and have the code below inside it.
#!/bin/bash
#
# This will delete all files in the trash directory
# that is older than the specified KEEPDAYS
#
# It can be run using a cron job or manually
#
TRASHDIR=~/.local/share/Trash/files/
KEEPDAYS=14
find $TRASHDIR -mtime +${KEEPDAYS} -exec /bin/rm -f {} \;
Make sure you do a
chmod +x cleantrash
so we can execute it.
Sunday, November 23, 2008
CakePHP Ajax Login using Auth Component.
Controller
app/controllers/users_controller.phpclass UsersController extends AppController { var $name = 'Users'; var $helpers = array('Html', 'Form'); var $components = array('Auth'); function beforeFilter() { parent::beforeFilter(); Auth->allow('logout'); } function login(){ if ($this->Auth->user()) { $this->User->id = $this->Auth->user('id'); $this->User->saveField('last_login', date('Y-m-d H:i:s')); $this->Session->setFlash(sprintf("Welcome %s!", $this->Auth->user('username'))); $this->redirect('/'); } } function logout() { $this->Session->destroy(); $this->redirect('/'); } }
View
views/users/login.ctp<div id="login-dialog"> <?php echo $form->create('User', array('action'=>'login'))?> <?php flash('Auth.login'); ?> <?php echo $form->input('username');?> <?php echo $form->input('password', array('type' => 'password'));?> <?php echo $form->submit('Login');?> <?php echo $html->link('Forgot my password', array('action' => 'forgot_password'));?> <?php echo $form->end();?> <?php echo $html->link('Register', array('admin' => false, 'action' => 'register'));?> </div>
Above code are typical Users controller and view files.
What we need:
- Latest Jquery to make life easy. Save it to your app/webroot/js folder.
- Form plugin to make dealing with form easy. Save it to your app/webroot/js folder.
- JQuery Helper to make using JQuery with CakePHP easy.
Changes we need to implement:
- Add the RequestHandler component to our app_controller.php or to the UsersController.
var $components = array('Auth', 'RequestHandler');
- Add the JQuery helper to our helpers.
var $helpers = array('Html', 'Form', 'Jquery');
Make sure to download the jquery helper from the link above and put it in your "app/views/helpers/" folder. - Add the code below:
Controller changes:
function login(){ if ($this->Auth->user()) { $this->User->id = $this->Auth->user('id'); $this->User->saveField('last_login', date('Y-m-d H:i:s')); $this->Session->setFlash(sprintf("Welcome %s!", $this->Auth->user('username'))); $this->redirect('/'); } if ($this->RequestHandler->isAjax()) { header('HTTP/1.0 401 Unauthorized'); die(); } }
View file changes
<div id="login-dialog"> <?php echo $form->create('User', array('action'=>'login'))?> <?php flash('Auth.login'); ?> <?php echo $form->input('username');?> <?php echo $form->input('password', array('type' => 'password'));?> <?php echo $form->submit('Login');?> <?php echo $html->link('Forgot my password', array('action' => 'forgot_password'));?> <?php echo $form->end();?> <?php echo $html->link('Register', array('admin' => false, 'action' => 'register'));?> </div> <?php $loginURL = Router::url(array('controller' => 'users', 'action' => 'login')); $jquery->uses('jquery.form'); $jquery->addScript( ' var options = {', ' url: "'.$loginURL.'",', ' success: function(data, statusText){', ' window.location = "/";', ' },', ' error: function(XMLHttpRequest, textStatus, errorThrown){', ' alert("Invalid Username and Password");', ' },', ' };', ' $("form#UserLoginForm").ajaxForm(options);' ); ?>
There is no need to make changes to the default layout since the JQuery helper already includes the jquery library in the head of the layout.
The jquery library being loaded by the helper is hard coded so you need to make sure you got the correct jquery version in your /app/webroot/js folder.
The code also redirects to the root folder on successful authentication.
Need proxy? Lowest priced starting at $0.71/proxy. Insane!
Buy Instagram Followers
Sunday, November 02, 2008
RPM for Everybody
rpm -qpl package-version.rpm
2. Unpacking of an RPM archive:
rpm2cpio < myfile.rpm | cpio -i --make-directories
all contents of the RPM package will be extracted into the current directory creating relative path..
3. Installing an RPM package.
rpm -ivh package-version.rpm
4. Upgradinga an RPM package.
rpm -Uvh package-version.rpm
5. Listing installed packaged on your system:
rpm -qai
This will list all packages installed via the RPM system.
6. Uninstalling RPM packages:
rpm -e package-version.rpm
7. Building RPM from source:
@todo
Wednesday, February 20, 2008
Reusable Calendar System
Feature and Capability List
- REST access (adding and retrieving events)
- Export to iCal, csv and text file
- Should handle (initially the following kinds of events)
- Event with no timespan.
- Event with timespan.
- Repeating event.
- Provide a notification system to the application using the system.
Initially we will try to use google calendar API. This will provide us with proven platform and a working calendar system.
Google Calendar API
Google calendar already handle all the initial requirements all that is left is to understand how to use the Google Calendar so we can have our reusable and reliable calendar system.
Google calendar API already uses REST access. They also uses their own GData protocol. Learning Google data API protocol is a good addition since it is also used by "All" Google apps.
Overview of the Google Calendar API
GData uses either of two standard XML-based syndication formats: Atom or RSS. RSS has been in the internet for a longer time and Atom is more recent but provide more features.
Atoms provides Atom Publishing Protocol(APP), an HTTP-based protocol for publishing and editing web resources. It provides the create, edit, delete resource command using POST, PUT, or DELETE respectively. This is the same access as WebDAV and the newer protocol the CalDAV.
In RSS you cannot provide a query to server to get a response containing list of matching results. GData uses the standard extension mechanism of Atom to allow queries.
Read a more thorough overview of the GData protocol here