Skip to content

Instantly share code, notes, and snippets.

View dinhkhanh's full-sized avatar

Trần Đình Khánh dinhkhanh

View GitHub Profile
@dinhkhanh
dinhkhanh / MenuBuilder.php
Created August 8, 2016 07:33 — forked from cklm/MenuBuilder.php
Custom KnpMenuBundle navigation bar twig template to support Font Awesome icons & Twitter bootstrap lay-out
<?php
namespace Acme\HelloBundle\Menu;
use Knp\Menu\FactoryInterface;
use Symfony\Component\DependencyInjection\ContainerAware;
class MenuBuilder extends ContainerAware
{
public function mainMenu(FactoryInterface $factory, array $options)
@dinhkhanh
dinhkhanh / grep-backdoor.sh
Last active July 19, 2016 16:39
Search backdoor (malicious codes) in directories
#bin/bash
grep -RPn "(passthru|shell_exec|system|phpinfo|base64_decode|chmod|mkdir|fopen|fclose|readfile|php_uname|eval|tcpflood|udpflood|edoced_46esab) *\(" /path/to/source/dir/
@dinhkhanh
dinhkhanh / urlrewrite.php
Created March 18, 2016 08:05 — forked from byjujohn/urlrewrite.php
Magento: Programatically add custom URL Rewriting
<?php
define('MAGENTO', realpath(dirname(__FILE__)));
ini_set('memory_limit', '32M');
set_time_limit (0);
require_once MAGENTO . '/app/Mage.php';
Mage::app();
Mage::getModel('core/url_rewrite')->setIsSystem(0)->setOptions('RP')->setIdPath('Imported-Old-Website-URL-test1')->setTargetPath('alicia-suspender-skirt-32360')->setRequestPath('SHOPONLINE.aspx?Product=Alicia Skirt&amp;Brand=Lascivious Test&amp;PID=1975')->save();
Mage::getModel('core/url_rewrite')->setIsSystem(0)->setOptions('RP')->setIdPath('Imported-Old-Website-URL-test2')->setTargetPath('alicia-suspender-skirt-32360')->setRequestPath('SHOPONLINE.aspx?Product=Alicia Skirt&Brand=Lascivious Test&PID=1975')->save();

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

@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
@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 / 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();
<?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 / 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
@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;
}