Dec 19, 2011

Nagios: SMS Notification

http://securfox.wordpress.com/2009/03/30/how-to-configure-nagios-to-send-sms-to-your-mobile/

Dec 15, 2011

Mysql: Tuning Your Mysql Server

This post is jut the link where I get some tips on how to tune my mysql server and some important parameter need to consider in tuning your mysql server. I'm not sure yet if this really work because I did't try to hold a large traffic to mysql server. But this also work for me in small data.

http://www.mysqlperformanceblog.com/2006/09/29/what-to-tune-in-mysql-server-after-installation/

http://www.linuxweblog.com/tune-my.cnf

http://www.ibm.com/developerworks/library/l-tune-lamp-3/index.html

Dec 12, 2011

Dec 11, 2011

Web Server: Tuning Apache Server

http://www.devside.net/articles/apache-performance-tuning
http://2bits.com/articles/tuning-the-apache-maxclients-parameter.html
http://girlito.com/tune-apache-performance-using-mpm-prefork-module/
http://blog.nataprawira.com/tech/2009/07/25/how-to-tune-apache-and-mysql/

Nov 29, 2011

Linux: Arch dependent binaries in noarch package

create RPM

The error was encounter where I trying to create RPM that contains binary files. This files was the binary files from nagios plugin. Solution Add the data below on the upper section of your specs file

%define _binaries_in_noarch_packages_terminate_build 0
Reference: fedora-devel

Nov 25, 2011

Magento: Overriding Model

<config>
<global>
<models>
<review_mysql4>
<rewrite>
<review>Globe_Review_Model_Mysql4_Review</review>
</rewrite>
</review_mysql4>
<review>
<rewrite>
<review>Globe_Review_Model_Review</review>
</rewrite>
</review>
</models>
</global>
<frontend>
<routers>
<review>
<args>
<modules>
<Globe_Review before="Mage_Review">Globe_Review</Globe_Review>
</modules>
</args>
</review>
</routers>
</frontend>
</config>


Reference:
Magento overriding core files blocks models resources controllers

Nov 16, 2011

Magento: Overriding Product Controller.

Edit you Package/Module/etc/config.xml



<?xml version="1.0"?>
<config>
... Your Other config here ....
<frontend>
<routers>
<catalog>
<args>
<modules>
<Package_Catalog before="Mage_Catalog">Package_Catalog</Package_Catalog>
</modules>
</args>
</catalog>
</routers>
</frontend>
</config>


Now your controller already ready.



include(Mage::getBaseDir()."/app/code/core/Mage/Catalog/controllers/ProductController.php");
class Package_Catalog_ProductController extends Mage_Catalog_ProductController
{
public function viewAction(){
echo __METHOD__;
}
}
?>



Try to access: http://192.168.101.188/catalog/product/view


Nov 15, 2011

Magento: Custom category Field.

Add one row to eav_attribute


INSERT INTO `fl_mage`.`eav_attribute`
SET
`attribute_id` =0, -- AUto
`entity_type_id`=3,
`attribute_code`='category_url',
`attribute_model`=NULL ,
`backend_model`=NULL ,
`backend_type`='varchar',
`backend_table`=NULL ,
`frontend_model` =NULL,
`frontend_input` ='text',
`frontend_label`='Url' ,
`frontend_class`=NULL ,
`source_model`=NULL ,
`is_required` '0',
`is_user_defined`='0' ,
`default_value` =NULL,
`is_unique` ='0',
`note`=''
;

Add other one row to eav_entity_attribute


INSERT INTO `fl_mage`.`eav_entity_attribute`
SET
`entity_attribute_id` =NULL,
`entity_type_id` =3,
`attribute_set_id` =3,
`attribute_group_id` =3,
`attribute_id`=163, --Must be same to eav_attribute
`sort_order`=3
;

Finally one more row to catalog_eav_attribute


INSERT INTO `catalog_eav_attribute`
SET
`attribute_id`=163,
`frontend_input_renderer`=NULL,
`is_global`=0,
`is_visible`=1,
`is_searchable`=0,
`is_filterable`=0,
`is_comparable`=0,
`is_visible_on_front`=0,
`is_html_allowed_on_front`=0,
`is_used_for_price_rules`=0,
`is_filterable_in_search`=0,
`used_in_product_listing`=0,
`used_for_sort_by`=0,
`is_configurable`=1,
`apply_to`=0,
`is_visible_in_advanced_search`=0,
`position`=0,
`is_wysiwyg_enabled`=0,
`is_used_for_promo_rules`=0
;

That's simple as is, you can find the charm there. Happy reading.

TIPS: If you are confuse try to look the eav_attribute and compare the data on your admin category page.

Reference:

Sep 26, 2011

Java Heap Parameters


-Xmx2048m
-Xloggc:gc.log
-XX:-PrintGCDetails
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=./dump.hprof
-XX:+UseConcMarkSweepGC

Sep 21, 2011

Magento: How to check if has access to page?

Syntax:



Mage::getSingleton('admin/session')
->isAllowed('[resource_item1_path]/[resource_item1_child_path]')

Example:



$adminSession = Mage::getSingleton('admin/session');
// Checks the permission for managing of products
$adminSession->isAllowed('admin/catalog/products');

// Checks the permission for the order creation in Magento Admin
$adminSession->isAllowed('sales/order/create');

// Checks the permission for the order view in Magento Admin
$adminSession->isAllowed('sales/order/view'));


Reference:
Defining acl resources custom and admin menu

Sep 19, 2011

Magento: Get parent product for configurable product.


$_product = Mage::getModel('catalog/product')->load(YOUR_SIMPLE_PRODUCT_ID);
$parentIdArray = $_product->loadParentProductIds()->getData('parent_product_ids');
print_r($parentIdArray);

Get associated configurable product



/**
* Load product by product id
*/
$product = Mage::getModel('catalog/product')->(YOUR_PRODUCT_ID);

/**
* Get child products id (only ids)
$childIds = Mage::getModel('catalog/product_type_configurable')
->getChildrenIds($product->getId());

/**
* Get children products (all associated children products data)
*/
$childProducts = Mage::getModel('catalog/product_type_configurable')->getUsedProducts(null,$product);

Reference:
magento-how-to-get-all-associated-children-product-of-a-configurable-product
magento-get-parent-id-of-simple-product-associated-to-configurable-product

Linux; VI reference

Reference:
Nice One
VimReferenceCard.pdf

Sep 18, 2011

Mageno: Create Empty Template.

In your controller action issued this command.

$this->loadLayout(false); // Issue this to disable loading of your layout
$this->getResponse()->setHeader('Content-Type','text/xml'); // Set this depending on you file content type

/**
* .... Put you other code here
*/
$this->renderLayout(); // Finally render your layout


For complete details see also the source Custom controller actions result in blank template

Linux: How to create Public key using private key


$ ssh-keygen -f ~/.ssh/id_rsa -y > ~/.ssh/id_rsa.pub

Linux: Find file by size


find -type f -size +200 -exec gzip -q{}\;
or
find PATH -type f -size +100000k -exec ls -lh {} \; | awk ‘{ print $9 “: ” $5 }’


Reference:
Find files larger than size x
a-bash-script-to-find-large-files-on-a-linux-server

Sep 14, 2011

Symfony: Propel Custom Join

NOTE:
In Didn't try this yet. May I update this page after I test in my self too. Thsi will serve a reference for the mentime.

References
ApplyingCustomJoinsInDoSelect

Symfony: Propel Custom Query

Here's sample Code

$connection = Propel::getConnection();
$query = 'SELECT MAX(?) AS max FROM ?';
$statement = $connection->prepareStatement($query);
$statement->setString(1, ArticlePeer::CREATED_AT);
$statement->setString(2, ArticlePeer::TABLE_NAME);
$resultset = $statement->executeQuery();
$resultset->next();
$max = $resultset->getInt('max')


Reference
08-Inside-the-Model-Layer

Magento models.

AttributeSet
Mage::getModel("eav/entity_attribute_set");
Product
Mage::getModel("catalog/product");


Rerefence:
how-do-i-get-attribute-set-name

Aug 25, 2011

Magento: GRID Important functions

Adding Edit link on a row


protected function _prepareColumns()
{
// .... Some other code here
$this->addColumn('action',
array(
'header' => Mage::helper('catalog')->__('Action'),
'width' => '50px',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('catalog')->__('Edit'),
'url' => array(
'base'=>'*/*/edit',
'params'=>array(),
),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
)
);
}


Removing the Pager/Filter


Normally this is default on the magento grid already.

public function __construct()
{
parent::__construct();
$this->setFilterVisibility(false); // Remove Seach filtering
$this->setPagerVisibility(false); // Remove Pager of the grid
}


Adding Mass proccess on the Grid



protected function _prepareMassaction()
{
$this->setMassactionIdField('trans_id');
//$this->getMassactionBlock()->setFormFieldName('download');
$this->getMassactionBlock()->addItem('delete', array(
'label'=> Mage::helper('download')->__('Delete'),
'url' => $this->getUrl('*/*/massDelete'),
'confirm' => Mage::helper('download')->__('Are you sure?')
));

$this->getMassactionBlock()->addItem('status', array(
'label'=> Mage::helper('download')->__('Change status'),
'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
'additional' => array(
'visibility' => array(
'name' => 'status',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('download')->__('Status'),
'values' => array("x1" => "Yow", "x2"=>"secret")
)
)
));
}

Aug 23, 2011

Linux: Get SSL certificate


openssl s_client -connect 203.177.165.154:443


Reference: http://curl.haxx.se/docs/sslcerts.html

Magento: Exporting button on your data in a grid.


Adding Export button


In your Grid class(Package_Module_Block_Grid), find the method named _prepareColumns and add the code below.
$this->addExportType('*/*/exportCsv', Mage::helper('download')->__('CSV'));
$this->addExportType('*/*/exportXml', Mage::helper('download')->__('XML'));


Implement Export method/Action


In your action controller class (Package_Module_Adminhtml_DownloadController) create two methods.

class Globe_Download_Adminhtml_DownloadController extends Mage_Adminhtml_Controller_Action{

public function exportXmlAction() {
}
public function exportCvsAction() {
}
protected function _prepareDownloadResponse($fileName, $content, $contentType = 'application/octet-stream', $contentLength = null)
{
$session = Mage::getSingleton('admin/session');
if ($session->isFirstPageAfterLogin()) {
$this->_redirect($session->getUser()->getStartupPageUrl());
return $this;
}
$this->getResponse()
->setHttpResponseCode(200)
->setHeader('Pragma', 'public', true)
->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
->setHeader('Content-type', $contentType, true)
->setHeader('Content-Length', is_null($contentLength) ? strlen($content) : $contentLength)
->setHeader('Content-Disposition', 'attachment; filename=' . $fileName)
->setHeader('Last-Modified', date('r'))
->sendHeaders(); // Need to call this method after all you send the Headers.
if (!is_null($content)) {
$this->getResponse()->setBody($content);
}
return $this;
}

}



Thanks to the other author for sharing what they knows about magento development. In this post I only put the part of the code that I understand or I use it in my application.


Rerefences:
  • http://subesh.com.np/2010/03/create-download-xls-report-file-magentos-core/
  • http://www.webspeaks.in/2010/08/create-admin-backend-module-in-magento.html

Zend: Join Statement and example

http://zendgeek.blogspot.com/2009/07/zend-framework-sql-joins-examples.html

Aug 21, 2011

Magento: Add custom renderer for a custom column grid

Good Example Here:
http://inchoo.net/ecommerce/magento/how-to-add-custom-renderer-for-a-custom-column-in-magento-grid/

Aug 7, 2011

Linix: Create/Extract tar file

Create tar.gz file



tar -cvzf mytarfile.tar.gz <directory>


this means:
-c = create new archive
-v = be verbose
-z = compress using gzip
-f = filename to create for the new archive

Extract tar.gz file



tar -xzf mytarfile.tar.gz




Create tar.bz2 file



tar -cvjf mytarfile.tar.gz <directory>


this means:
-c = create new archive
-v = be verbose
-j = compress using bzip2
-f = filename to create for the new archive


Extract tar.bz2 file



tar -xpjf file.tar.bz2

Aug 3, 2011

Linux: perl-Net-SSLeay dependency error when installing Memcached with yum

Needs to update the packages.
Get data packages here depends on your system.
wget http://packages.sw.be/perl-Net-SSLeay/perl-Net-SSLeay-1.36-1.el5.rfx.i386.rpm
wget http://packages.sw.be/perl-Net-SSLeay/perl-Net-SSLeay-1.36-1.el5.rfx.x86_64.rpm
wget http://packages.sw.be/perl-IO-Socket-SSL/perl-IO-Socket-SSL-1.34-1.el5.rfx.noarch.rpm

How to install reviewboard in centOS?

Requirements: Database:
MySQL v5.0.31 or newer
Web Server:
Apache + mod_python or fastcgi lighttpd + fastcgi
Start reviewboard Installation

TO BE CONTINUED: Thanks for visiting

Magento: Custom admin module.

custom_module_with_custom_database_table

Jul 28, 2011

Magento: Forms prototype javascript validation

Custom Form Validation
Adding Javascript validation to your own forms is extremely simple. First, you need to create a Form (form.js) object to represent your form.




Acknowledge to the Original Poster.

Jul 26, 2011

Email: Sendmail puts exclamation marks(!) in a body/content of email.

I past day I encountering the error on email message. In some part on the email has added special character !.

Reason Causing the Case:
Ask check on the blog one blogger I found that the email have only limit of character every line, and this is only 1000. In every after 1000 character in one line this will happen, it added exclamation mark(!).

Fixed:
You must need to break the line before reached the 1000 character length.

As acknowledge to the Author.
exclamation-marks-at-end-of-lines-in-e-mail

Jul 11, 2011

Jul 7, 2011

Jul 6, 2011

Symfony: Create project


php symfony/data/bin/symfony generate:project PROJECT_NAME --orm=Propel

php symfony configure:database "mysql:host=localhost;dbname=DB_NAME" DB_USER DB_PASS

php symfony generate:app frontend

symfony propel:generate-module --with-show --non-verbose-templates frontend registration Registration

Jun 29, 2011

tail: cannot watch `/var/log/messages': No space left on device

Solution:

$ sudo su
# sysctl fs.inotify.max_user_watches
fs.inotify.max_user_watches = 8192
#
# sysctl -w fs.inotify.max_user_watches=16384
fs.inotify.max_user_watches = 16384


Im not sure why we need to higher the


Reference:
tail-cannot-watch-varlogmessages-no

kernel-inotify-watch-limit-reached

Jun 27, 2011

Symfony/Zend: Download Attach File in the Action Controller.

Synfony


public function executeDownload(sfWebRequest $request)  
{  
$response = $this->getContext()->getResponse();  
$response->clearHttpHeaders();  
$response->addCacheControlHttpHeader('Cache-control','must-revalidate, post-check=0, pre-check=0');  
$response->setContentType('application/octet-stream',TRUE);      
$response->setHttpHeader('Content-Transfer-Encoding', 'binary', TRUE);  
$response->setHttpHeader('Content-Disposition','attachment; filename='.$request->getParameter('filename'), TRUE);  
$response->sendHttpHeaders(); // Need to send the HttpHeaders to handle a large file size
readfile(readfile('xxx.mp3'));  
return sfView::NONE;  
}

* Always dont omit the line to send the headers

Zend


$this->getResponse()->setHeader("Pragma","public");
$this->getResponse()->setHeader("Expires", "0");
$this->getResponse()->setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
$this->getResponse()->setHeader("Cache-Control","private", false);
$this->getResponse()->setHeader("Content-Type","audio/x-mp3");
$this->getResponse()->setHeader("Content-Disposition","attachment; filename=\"xxx.mp3\"");
$this->getResponse()->setHeader("Content-Transfer-Encoding","binary");
$this->getResponse()->setHeader("Content-Length", filesize('xxx.mp3'));
$this->getResponse()->setHeader("Content-Description","File Transfer");
$this->getResponse()->sendHeaders(); // Need to send the HttpHeaders to handle a large file size
$this->getResponse()->setBody(readfile('xxx.mp3'));

Jun 14, 2011

Magento: Saving Attribute

Magento: Saving Attribute



$_product->getResource()->saveAttribute($_product, 'vas_rating');


For bulk UPDATE



//Get the product Ids you want to affect. For me it was all downloadable products
$downloadableProductIds = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('type_id', Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE)
->getAllIds();
//Now create an array of attribute_code => values
$attributeData = array('my_attribute_code' => 'my_attribute_value);
//Set the store to affect. I used admin to change all default values
$storeId = 0; //A.K.A Admin
//Now Update the attribute(s) for the given products.
Mage::getSingleton('catalog/product_action')
->updateAttributes($downloadableProductIds, $attributeData, $storeId);

Jun 5, 2011

MYSQL: Error 1062 - Duplicate key

Slave Replicate SLAVE_SKIP_COUNTER


In some reason this mostly happened when your slave server already out of synchronization to the master server.

The exercise, we need to skip that error Duplicate key and can be done by adding the line in the mysql config my.cnf



slave-skip-errors = 1062


If you encounter this kind of error. Just easy, you need only to skip the counter by by 1 until you fix it.



mysql> SLAVE STOP;
mysql> SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1;
mysql> START SLAVE;

Jun 3, 2011

May 31, 2011

Linux - FTP User restrict to home access only

http://www.linuxforums.org/forum/servers/7243-keeping-ftp-users-their-home-directory.html

May 24, 2011

Search and replace in multiple files.




  • find app/code/local/Flux/Catalog/ -name "*.php" -print | xargs sed -i 's/Mage_Catalog/Flux_Catalog/g'


  • perl -w -i -p -e "s/search_text/replace_text/g" filename


  • perl -w -i -p -e "s/search_text/replace_text/g" *.php


  • find /www_root -name "*.php"|xargs perl -w -i -p -e "s/Perl is good/perl is great/g"


Linux User Expiration

Check password expiration date


[winsftp@FRNAPROD ~]$ chage -l username
Sample Output:
[winsftp@FRNAPROD ~]$ chage -l fluxsftp
Last password change : Jul 07, 2012
Password expires : Aug 06, 2012 Password inactive : never
Account expires : never
Minimum number of days between password change : 30
Maximum number of days between password change : 30
Number of days of warning before password expires : 7

May 19, 2011

HTACCESS: Rewrite all HTTP request to HTTPS


RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]


Reference:
1 http://www.askapache.com/htaccess/ssl-example-usage-in-htaccess.html
2 http://joseph.randomnetworks.com/2004/07/22/redirect-to-ssl-using-apaches-htaccess/

May 18, 2011

JS Prototype - How to access value in FORM input text?

For example, if you have an input named "company" in a form with an ID "contact":

var form = $('contact');
var input = form['company'];

Form.Element.getValue(input);

// but, the preferred call is:
$(input).getValue(); // we used the $() method so the node gets extended

// you can also use the shortcut
$F(input);


http://particletree.com/features/quick-guide-to-prototype/

http://xavisys.com/using-prototype-javascript-to-get-the-value-of-a-radio-group/

Mar 22, 2011

Simple CSS TAB


border-radius: 5px 5px 0 0;
-moz-border-radius: 15px 5px 0 0;
-webkit-border-top-left-radius: 15px;
-webkit-border-top-right-radius: 5px


Orginal page

Feb 2, 2011

Java - Absolute path

Tricks here is first create a temporary and get the absolute path.

package com.mkyong.file;

import java.io.File;
import java.io.IOException;

public class GetTempFilePathExample
{
public static void main(String[] args)
{
try{
//create a temp file
File temp = File.createTempFile("temp-file-name", ".tmp");

System.out.println("Temp file : " + temp.getAbsolutePath());

//Get tempropary file path
String absolutePath = temp.getAbsolutePath();
String tempFilePath = absolutePath.
substring(0,absolutePath.lastIndexOf(File.separator));

System.out.println("Temp file path : " + tempFilePath);
}catch(IOException e){
e.printStackTrace();
}
}
}

Jan 25, 2011

Java Simple Code

PHp var_dump for Java Equivalent



import java.lang.reflect.*;
....
//o Object..
Field[] fields = o.getClass().getDeclaredFields();
for (int i = 1; i < fields.length; i++
try {
System.out.println(fields[i].getName() + " - " + fields[i].get(o));
} catch (java.lang.IllegalAccessException e) {
System.out.println(e);
}

Jan 23, 2011

Setting Up WikiPedia

Download: http://www.mediawiki.org/wiki/Download

Extract the file.

Set the config dir to writable.

Access the site

Configure the database setting

Set to private data


edit the includes/DefaultSetting.php

$wgGroupPermissions['*']['createaccount'] = false;
$wgGroupPermissions['*']['read'] = false;
$wgGroupPermissions['*']['edit'] = false;
$wgGroupPermissions['*']['createpage'] = true;
$wgGroupPermissions['*']['createtalk'] = true;
$wgGroupPermissions['*']['writeapi'] = true;

to

$wgGroupPermissions['user']['createaccount'] = true;
$wgGroupPermissions['user']['read'] = true;
$wgGroupPermissions['user']['edit'] = true;
$wgGroupPermissions['user']['createpage'] = true;
$wgGroupPermissions['user']['createtalk'] = true;
$wgGroupPermissions['user']['writeapi'] = true;