Skip to content

Instantly share code, notes, and snippets.

View dinhkhanh's full-sized avatar

Tran Dinh Khanh dinhkhanh

View GitHub Profile
@dinhkhanh
dinhkhanh / magento-get-customer-data.php
Created March 28, 2015 10:29
Magento get Customer's data
<?php
// Check if any customer is logged in or not
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
// Load the customer's data
$customer = Mage::getSingleton('customer/session')->getCustomer();
$customer->getPrefix();
$customer->getName(); // Full Name
SET FOREIGN_KEY_CHECKS=0;
-- Customers
TRUNCATE `customer_address_entity`;
TRUNCATE `customer_address_entity_datetime`;
TRUNCATE `customer_address_entity_decimal`;
TRUNCATE `customer_address_entity_int`;
TRUNCATE `customer_address_entity_text`;
TRUNCATE `customer_address_entity_varchar`;
TRUNCATE `customer_entity`;
@dinhkhanh
dinhkhanh / backup-restore-mysqldump-cli.sh
Created April 19, 2015 14:58
How to Back Up and Restore a MySQL Database
#Back up From the Command Line (using mysqldump)
#If you have shell or telnet access to your web server, you can backup your MySQL data by using the mysqldump command.
#This command connects to the MySQL server and creates an SQL dump file.
#The dump file contains the SQL statements necessary to re-create the database. Here is the proper syntax:
mysqldump --opt -u [uname] -p[pass] [dbname] > [backupfile.sql]
#For example, to backup a database named 'Tutorials' with the username 'root' and with no password to a file tut_backup.sql,
#you should accomplish this command
mysqldump -u root -p Tutorials > tut_backup.sql
@dinhkhanh
dinhkhanh / magent-remove-decimal-in-price-if-needed.php
Created May 22, 2015 09:44
Magento Remove decimal in price if needed
<?php
/**
* File: /app/code/core/Mage/Directory/Model/Currency.php
* Function: formatTxt
* Do: Add this before return;
*/
if (($price - intval($price)) == 0) {
$options['precision'] = 0;
}
@dinhkhanh
dinhkhanh / magento-cache-shell.php
Created May 26, 2015 16:09
Magento Cache Shell
<?php
/**
* Author: Nathan Wu
* Date: Nov 19, 2012
* Time: 12:54:29 AM
*
* Mage_Shell script that interfaces with the Magento cache.
*
*
* @category JoomlaCreator
<?php
Mage::app()
->getLocale()
->date(strtotime('now'), null, null, false)
->toString('H:m:s');
// distinguish 'm' in PHP and in Magento (month vs minute)
@dinhkhanh
dinhkhanh / add-transaction-detail.php
Created June 13, 2015 09:57
Add Transaction Detail
<?php
$payment->getTransaction($id)
->setAdditionalInformation(
Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS,
$data
)->save();
@dinhkhanh
dinhkhanh / .gitignore
Created July 2, 2015 14:51
Gitignore
app/etc/local.xml
**/.sass-cache/
var/
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
@dinhkhanh
dinhkhanh / backup.sh
Last active August 29, 2015 14:24
Command line to Backup directories
# For full scenario: https://help.ubuntu.com/community/BackupYourSystem/TAR
# to backup
tar -cvpzf /path/to/save/file/backup.tar.gz --exclude=/path/to/exclude/one --exclude=/path/to/exclude/two/etc --one-file-system /path/is/backed/up
# to restore
sudo tar -xvpzf /path/to/backup.tar.gz -C /path/to/write/files/to --numeric-owner

Mac OS X LEMP Configuration

This Gist is a collection of configuration files that can be used to easily setup a Homebrew-based LEMP stack on Mac OS X.

Files in this repository are numbered and named for ordering purposes only. At the top of each file is a section of metadata that denote what component the file belongs to and the default name & location of the file. Feel free to implement it however you want.

Note: some configuration files have hard-coded paths to my user directory -- fix it for your setup

Nginx