Skip to content

Instantly share code, notes, and snippets.

@hiephm
hiephm / di.xml
Last active February 5, 2016 02:37
<!-- To generate Interceptor, declare a plugin for virtualType, but plugin won't be executed with this alone -->
<type name="\Magento\LayeredNavigation\Block\Navigation\Category">
<plugin name="my-plugin" type="\MyVendor\MyModule\Plugin\BlockNavigation"/>
</type>
<!-- For plugin to be actually executed, declare the same plugin for actual class -->
<type name="\Magento\LayeredNavigation\Block\Navigation">
<plugin name="my-plugin" type="\MyVendor\MyModule\Plugin\BlockNavigation"/>
</type>
@hiephm
hiephm / magento1_oauth_testing.md
Last active March 18, 2017 12:27
How to do OAuth 1.0 manually (Magento 1)

How to do OAuth 1.0 manually (Magento 1)

0. Pre-requisites:

  • consumer_key: d208adaf663a85029c33f55ce73d2705
  • consumer_secrect: 9faba5ec4c19aa68ca96511201b20f69
  • Initiate url: http://domain.com/oauth/initiate
  • Authorize url: http://domain.com/admin/oauth_authorize
  • Token request url: http://domain.com/oauth/token
  • Callback url (for dumping returned oauth_token and oauth_verifier): http://domain.com/callback.php
@hiephm
hiephm / pQuery.js
Created March 9, 2016 09:40 — forked from niyazpk/pQuery.js
Add or update query string parameter
// Add / Update a key-value pair in the URL query parameters
function updateUrlParameter(uri, key, value) {
// remove the hash part before operating on the uri
var i = uri.indexOf('#');
var hash = i === -1 ? '' : uri.substr(i);
uri = i === -1 ? uri : uri.substr(0, i);
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
@hiephm
hiephm / install_magento2_with_db
Created March 29, 2016 03:43 — forked from wsakaren/install_magento2_with_db
Install script for magento2 with database, assumes you are running from www.localhost.com/20
#!/bin/bash
# Sets up a database with a magento2 installation. This assumes you are running from under your httpdocs/20 location and have www.localhost.com in your /etc/hosts file
# To run type : install_magento2 <dirname><password>
# password is used for the datbase user and the magento admin password
if [ $# -eq 0 ]; then
echo "No arguments supplied"
echo "Usage: `basename $0` <dirname><password>"
exit 1
fi
## Magento 2
WEBSERVER_GROUP="www-data"
alias m2="bin/magento"
alias m2rmgen="find var/generation -maxdepth 1 -mindepth 1 -type d -not -name 'Magento' -not -name 'Composer' -not -name 'Symfony' -exec rm -rf {} \;"
alias m2en="m2 module:enable"
alias m2s="m2 module:status"
alias m2f="m2 cache:flush"
alias m2up="sudo find var -type d -exec chmod 775 {} \; && sudo find var -type f -exec chmod 664 {} \; && m2en --all && m2 setup:upgrade && m2rmgen && m2f"
alias m2static="sudo rm -rf var/view_preprocessed/* pub/static/frontend/* pub/static/adminhtml/* pub/static/_requirejs/*"
alias m2fixgroup="sudo usermod -aG $WEBSERVER_GROUP `whoami`"
@hiephm
hiephm / .gitignore
Last active April 20, 2016 07:30
Magento 2 git ignore (NOT for composer installation)
/.idea
/app/etc/env.php
/app/etc/redis.php
/pub/media/*
!/pub/media/.htaccess
/pub/media/catalog/*
!/pub/media/catalog/.htaccess
/pub/media/customer/*
@hiephm
hiephm / gist:ae0a4e401c5490677287ca2fbd9dad7b
Created August 18, 2016 08:24
Debug helper functions
function __die($obj)
{
print_r($obj);die();
}
function __debug($message)
{
$file = __DIR__ . '/../var/log/dump.log';
file_put_contents($file, $message, FILE_APPEND);
file_put_contents($file, "\n", FILE_APPEND);
@hiephm
hiephm / apt-rdepends-tree
Created September 2, 2016 10:54 — forked from damphat/apt-rdepends-tree
debian dependency tree
#! /bin/bash
# Description: show dependency tree
# Author: damphat
if [ $# != 1 ]; then
echo 'Usage: apt-rdepends-tree <package>'
echo 'Required packages: apt-rdepends'
exit 1
fi
@hiephm
hiephm / bash-cheatsheet.sh
Created September 9, 2016 04:42 — forked from LeCoupa/bash-cheatsheet.sh
Bash CheatSheet for UNIX Systems
#!/bin/bash
#####################################################
# Name: Bash CheatSheet for Mac OSX
#
# A little overlook of the Bash basics
#
# Usage:
#
# Author: J. Le Coupanec
# Date: 2014/11/04

Principles of Adult Behavior

  1. Be patient. No matter what.
  2. Don’t badmouth: Assign responsibility, not blame. Say nothing of another you wouldn’t say to him.
  3. Never assume the motives of others are, to them, less noble than yours are to you.
  4. Expand your sense of the possible.
  5. Don’t trouble yourself with matters you truly cannot change.
  6. Expect no more of anyone than you can deliver yourself.
  7. Tolerate ambiguity.
  8. Laugh at yourself frequently.