Flipkart
Thursday, August 26, 2010
IEs4Linux (Fedora)
yum -y install wine*
yum -y install cabextract
Logout and install IEs 4 Linux with your normal user account:
wget http://www.tatanka.com.br/ies4linux/downloads/ies4linux-latest.tar.gz
tar zxvf ies4linux-latest.tar.gz
cd ies4linux-*
./ies4linux
Tuesday, August 24, 2010
Installing rar and unrar programs in Linux or Unix
$ apt-get install unrar
If you are using Fedora core Linux then use yum command as follows:
$ yum install unrar
If you are using FreeBSD, you can use:
$ pkg_add -v -r unrar
If any of above, methods is not working, you can download binary package from official rarlab site and choose the right package for your machine... for example, i chose the latest (by the time i write this post):
$ cd /tmp
$ wget http://www.rarlab.com/rar/rarlinux-3.7.1.tar.gz
then untar the file:
$ tar -zxvf rarlinux-3.7.1.tar.gz
Both rar and unrar commands are located in rar sub-directory. Just go to rar directory:
$ cd rar
$ ./unrar
Now copy rar and unrar to /bin directory:
$ cp rar unrar /bin
Then you can use the same method on creating and extracting rar files in linux in my previous post.
Another thing to add, you can also test the integrity of archive, with this command:
$ unrar t filename.rar
or list the files inside the rar file using this command:
$ unrar l filename.rar
Thursday, August 12, 2010
Export Database Data to .XLS in PHP
$DB_Server = "localhost"; //your MySQL Server
$DB_Username = "username"; //your MySQL User Name
$DB_Password = "password"; //your MySQL Password
$DB_DBName = "databasename"; //your MySQL Database Name
$ttype = $DB_TBLName;
$sql = "Select * from $DB_TBLName";
$Connect = @mysql_connect($DB_Server, $DB_Username, $DB_Password)
or die("Couldn't connect to MySQL:
" . mysql_error() . "
" . mysql_errno());
//select database
$Db = @mysql_select_db($DB_DBName, $Connect)
or die("Couldn't select database:
" . mysql_error(). "
" . mysql_errno());
//execute query
$result = @mysql_query($sql,$Connect)
or die("Couldn't execute query:
" . mysql_error(). "
" . mysql_errno());
while($row = mysql_fetch_row($result))
{
$data = $row;
}
function cleanData(&$str) {
$str = preg_replace("/\t/", "\\t", $str);
$str = preg_replace("/\r?\n/", "\\n", $str);
if(strstr($str, '"'))
$str = '"' . str_replace('"', '""', $str) . '"';
}
# filename for download $filename = "website_data_" . date('Ymd') . ".xls";
header("Content-Disposition: attachment; filename=\"$filename\"");
header("Content-Type: application/vnd.ms-excel");
$flag = false;
foreach($data as $row) {
if(!$flag) { # display field/column names as first row echo implode("\t", array_keys($row)) . "\n";
$flag = true;
}
array_walk($row, 'cleanData');
echo implode("\t", array_values($row)) . "\n";
}
exit;
Thursday, August 5, 2010
Codeigniter Layout Library
< ?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Layout { var $obj; var $layout; function Layout($layout = "layout_main") { $this->obj =& get_instance();
$this->layout = $layout;
}
function setLayout($layout)
{
$this->layout = $layout;
}
function view($view, $data=null, $return=false)
{
$loadedData = array();
$loadedData['content_for_layout'] = $this->obj->load->view($view,$data,true);
if($return)
{
$output = $this->obj->load->view($this->layout, $loadedData, true);
return $output;
}
else
{
$this->obj->load->view($this->layout, $loadedData, false);
}
}
}
? >
Then load your library in your controller
You can use it in two ways. First and obvious is to place the following line in the controller’s constructor function.
$this->load->library('layout', 'layout_main');
The second is by enabling codeIgniter to autoload the library by editing /application/config/autoload.php
$autoload['libraries'] = array('layout');
in your controller you may do this:
$this->layout->view('welcome_message');
Master layout
/application/views/layout_main.php
Your view file must use $content_for_layout. For example:
<html>
<head>
<title><?=$title_for_layout?></title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="/css/main.css" type="text/css" />
</head>
<body>
<div id="pagewidth" >
<div id="header" ><img src="/images/header.jpg" width="700" height="200"></div>
<div id="wrapper" class="clearfix" >
<div id="twocols" class="clearfix">
<?php echo $content_for_layout?>
</div>
</div>
<div id="footer" > Footer </div>
</div>
</body>
</html>
Monday, August 2, 2010
Add JS and CSS files in *.tpl.php in Drupal6
if ($your_condition) {
drupal_add_css(path_to_theme(). "/filename.css", "theme");
$variables['styles'] = drupal_get_css();
drupal_add_js(file_directory_path() .'/javascript.js', 'inline');
$vars['scripts'] = drupal_get_js();
}
}