A safe program to replace unix command ‘rm’

[sourcecode]
#!/usr/bin/perl -w

## A safer program to replace unix command "rm"
## Author: Hongyu Zhang

if($#ARGV < 0) {
die("Usage: $0 filename\n");
}

$dir = `echo ~/dumpster`;
chomp $dir;
mkdir $dir unless(-d $dir);

for($i=0; $i<=$#ARGV; $i++) {
croak("Directory $ARGV[$i] not existed") unless(-e $ARGV[$i]);
my @arr = split /\//, $ARGV[$i];
if(-e "$dir/$arr[$#arr]") {
$command = "rm -rf $dir/$arr[$#arr]";
system("$command");
croak("error running command: $command") if($?);
}

$command = "mv -fv $ARGV[$i] $dir";
system("$command");
croak("error running command: $command") if($?);
}
[/sourcecode]

My common .bashrc setup

[sourcecode]
alias vi=’vim’
alias mv=’mv -i’
alias cp=’cp -i’
alias rm=’rm -i’
alias h=’history | tail -200′
alias ls=’ls -CF –color ‘
alias ll=’/bin/ls -lFat –color ‘
alias lh=’/bin/ls -lFth –color ‘
alias l="/bin/ls -lF –color "
alias lt="/bin/ls -lFt –color "
alias new=’/bin/ls -lt | head -10’
alias loc=’find . -name ‘
alias lo=exit
alias m=more
alias s=source
alias cl=clear
alias ldir=’ls -lt | grep "^d" |more’
alias dir=l
alias p=pine
alias grep=’grep -i –color’
alias myps="ps -ef | grep $WHOAMI"

#Cygwin only
alias ping=’$SYSTEMROOT/system32/ping’

export CDPATH=.:~:~/work

## set for perl environment
export PERL5LIB=/home/hzhang/tools/perllib:/home/hzhang/tools/perllib1
[/sourcecode]

Zend Framework quick start

  • create project
    [sourcecode]zf.sh create project rsvp[/sourcecode]
  • Link library
    [sourcecode]ln -s /path/to/ZendFramework-1.11.11-minimal/library/Zend .[/sourcecode]
  • set up access permission for application/ folder by add .htaccess file with line:
    [sourcecode]deny from all[/sourcecode]
  • To set the project as a sub-folder instead of document root (common in shared hosting), one has to set up path redirect. First, we need to change .htaccess file under the project folder to add path rewrite function (Note: need to make sure apache httpd.conf has the “AllowOverride All” set for the folder)

    [sourcecode]
    RewriteRule (.*) ./public/$1
    [/sourcecode]

    Second, we can edit configs/application.ini and add a line
    [sourcecode]settings.baseUrl = "/rsvp"[/sourcecode]

    Third, edit Bootstrap.php and add a function
    [sourcecode]
    protected function _initBaseUrl()
    {
    $options = $this->getOptions();
    $baseUrl = isset($options[‘settings’][‘baseUrl’])
    ? $options[‘settings’][‘baseUrl’]
    : null; // null tells front controller to use autodiscovery, the default
    $this->bootstrap(‘frontcontroller’);
    $front = $this->getResource(‘frontcontroller’);
    $front->setBaseUrl($baseUrl);
    }
    [/sourcecode]

  • create layout
    [sourcecode]zf.sh enable layout[/sourcecode]
    and then edit application/layouts/layout.phtml to add necessary header/footer inclusion.
  • set up database by editing application/configs/application.ini file
    [sourcecode]
    resources.db.adapter = PDO_MYSQL
    resources.db.params.host = localhost
    resources.db.params.username = my_username
    resources.db.params.password = my_password
    resources.db.params.dbname = my_db
    [/sourcecode]

  • create controller
    [sourcecode]zf.sh create controller controllername[/sourcecode]
  • create action
    [sourcecode]
    zf.sh create action add controllername
    zf.sh create action edit controllername
    zf.sh create action delete controllername
    [/sourcecode]
  • create model
    [sourcecode]
    zf.sh create db-table controlername db_table_name
    [/sourcecode]

    and then modify application/models/DbTable/ProjectName.php to add CRUD DB functions.