Skip to content

Instantly share code, notes, and snippets.

View syammohanmp's full-sized avatar

Syam Mohan M P syammohanmp

View GitHub Profile
@syammohanmp
syammohanmp / list.php
Last active February 16, 2016 11:41
USA State List - PHP Array snippet ----State List (+District)
<?php
$list = array(
"AL"=>"Alabama",
"AK"=>"Alaska",
"AZ"=>"Arizona",
"AR"=>"Arkansas",
"CA"=>"California",
"CO"=>"Colorado",
"CT"=>"Connecticut",
@syammohanmp
syammohanmp / backup.sh
Last active February 16, 2016 11:41
Backup entire MySQL data folder
tar -zcvf /home/backup/archive.tar.gz /var/lib/mysql
@syammohanmp
syammohanmp / mysql_commands.txt
Last active July 19, 2017 06:08
mysql Commands
/*Backup all Databases*/
mysqldump -u <username> -p --all-databases > /home/tmp/backup/dbs.sql
/*Backup Single Database*/
mysqldump -u <username> -p db_name > /home/tmp/backup/db_name.sql
/*Backup Single Database - Compressed */
mysqldump -u <username> -p db_name --quick | gzip > /home/tmp/backup/db_name.sql.gz
/*Import gzipped database*/
@syammohanmp
syammohanmp / wordLimit.php
Last active February 16, 2016 11:39
Word Limit PHP Function
<?php
// Word limit
function wordLimit($str, $limit = 100, $end_char = '&#8230;')
{
if (trim($str) == '')
return $str;
// always strip tags for text
$str = strip_tags($str);
@syammohanmp
syammohanmp / characterLimit.php
Last active February 16, 2016 11:38
Character Limit PHP Function
<?php
// Character limit
function characterLimit($str, $limit = 150, $end_char = '...')
{
if (trim($str) == '')
return $str;
// always strip tags for text
$str = strip_tags(trim($str));
@syammohanmp
syammohanmp / addProduct.php
Last active February 16, 2016 11:37
Add Product Programatically in Magento
<?php
//$product = Mage::getModel('catalog/product');
$product = new Mage_Catalog_Model_Product();
echo time();
// Build the product
$product->setAttributeSetId(9);// #4 is for default
$product->setTypeId('simple');
$product->setName('Some cool product name');
@syammohanmp
syammohanmp / httpd.conf
Last active February 17, 2016 07:40
Virtual host Setup with External Folder ( Apache )
#Windows
#<Directory "D:/vhosts">
# Options Indexes FollowSymLinks Includes ExecCGI
# AllowOverride All
# Order allow,deny
# Allow from all
#</Directory>
#linux
<Directory "/var/vhosts">
@syammohanmp
syammohanmp / AppModel.php
Created February 24, 2016 18:12
Save HABTM relationships CakePHP 2
<?php
App::uses('Model', 'Model');
class AppModel extends Model {
public function beforeSave($options = array()) {
// save our HABTM relationships
foreach (array_keys($this->hasAndBelongsToMany) as $model){
@syammohanmp
syammohanmp / Vendor.php
Last active May 12, 2020 14:51
Create Custom Product Attribute with Source Model in Magento 1.9.x
<?php
class Mynamespace_Mymodule_Model_Product_Attribute_Source_Vendor extends Mage_Eav_Model_Entity_Attribute_Source_Abstract {
public function getAllOptions() {
// $options[] = array('value' => 0, 'label' => 'Select Vendor');
@syammohanmp
syammohanmp / index.html
Created April 27, 2016 10:47
A Basic HTML5 Template For Any Project
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>The HTML5</title>
<meta name="description" content="The HTML5 Herald">
<meta name="author" content="SitePoint">