Skip to content

Instantly share code, notes, and snippets.

View Marko-M's full-sized avatar

Marko Martinović Marko-M

View GitHub Profile
@Marko-M
Marko-M / iptables-port-forward.sh
Last active May 7, 2016 07:08
Forward Vagrant forwarded ports to standard ports using iptables
#!/bin/bash
# Forward relevant Vagrant forwarded ports to standard ports using iptables (adjust 8080, 8443).
# To make persistent install and use "iptables-persistent" package. Just do a
# "sudo iptables-persistent save" and service will reload saved rules on each boot.
sudo iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 8080
sudo iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 443 -j REDIRECT --to-ports 8443
@Marko-M
Marko-M / gist:f9517c7acfcdff75e976d82fb750dbe3
Last active June 11, 2016 11:24
Vagrant 1.8.3 with Ubuntu 16.04 LTS
#!/bin/bash
# Marko Martinović
# https://devgenii.com/
#
# Workaround for issue where Vagrant fails to install plugins due to RubyGems > v2.3.0 and Bundler Gem v1.12.0:
#
# ... `block in sort_dependencies': undefined method `payload' for nil:NilClass (NoMethodError)
#
# For example Vagrant 1.8.3 installed from .deb package @ HashiCorp website on Ubuntu 16.04 LTS.
@Marko-M
Marko-M / gist:c91895a815b3d89896196367206b1d74
Last active September 10, 2016 11:16
Vagrant sudo NOPASSWD (Ubuntu 16.04)
sudo -i
cat > /etc/sudoers.d/10_vagrant <<EOF
Cmnd_Alias VAGRANT_EXPORTS_ADD = /usr/bin/tee -a /etc/exports
Cmnd_Alias VAGRANT_NFSD_CHECK = /etc/init.d/nfs-kernel-server status
Cmnd_Alias VAGRANT_NFSD_START = /etc/init.d/nfs-kernel-server start
Cmnd_Alias VAGRANT_NFSD_APPLY = /usr/sbin/exportfs -ar
Cmnd_Alias VAGRANT_EXPORTS_REMOVE = /bin/sed -r -e * d -ibak /*/exports
Cmnd_Alias VAGRANT_EXPORTS_REMOVE_2 = /bin/cp /*/exports /etc/exports
%sudo ALL=(root) NOPASSWD: VAGRANT_EXPORTS_ADD, VAGRANT_NFSD_CHECK, VAGRANT_NFSD_START, VAGRANT_NFSD_APPLY, VAGRANT_EXPORTS_REMOVE, VAGRANT_EXPORTS_REMOVE_2
@Marko-M
Marko-M / magento-nginx.conf
Created December 1, 2016 15:10 — forked from gwillem/magento-nginx.conf
Battle-tested Nginx configuration for Magento (source: www.hypernode.com)
# This is an annotated subset of the Nginx configuration from our Magento production platform @ www.hypernode.com
# See https://www.byte.nl/blog/magento-cacheleak-issue
# !!!! If you are a Hypernode customer, do not use this config as it will result in duplicate statements. !!!!!
user app;
worker_processes 4;
pid /var/run/nginx.pid;
events {
@Marko-M
Marko-M / customer-install-0.1.0.php
Created February 6, 2017 09:03 — forked from jzahedieh/customer-install-0.1.0.php
Magento Customer Attribute Setup
<?php
/* @var $installer Mage_Customer_Model_Resource_Setup */
$installer = Mage::getResourceModel('customer/setup','customer_setup');
$installer->startSetup();
if (!$installer->getAttributeId('customer', 'attribute_name')) {
$installer->addAttribute('customer', 'attribute_name', array( // TABLE.COLUMN: DESCRIPTION:
/** Standard values defined @see Mage_Eav_Model_Entity_Setup::_prepareValues() */
'label' => 'Label', // eav_attribute.frontend_label admin input label
'backend' => 'module/class_name', // eav_attribute.backend_model backend class (module/class_name format)
@Marko-M
Marko-M / magento2-maintenance-mode.sh
Last active February 21, 2017 17:56
Activate maintenance mode on Magento 2 w/ IP address exclusion list
#!/bin/bash
# Comma separated list of IPs to be excluded
echo "123.123.123.123,234.234.234.234">var/.maintenance.ip
# For the rest of the world we go down for maintenance NOW
touch var/.maintenance.flag
@Marko-M
Marko-M / soap-debug.php
Created November 23, 2015 08:07
Debug SOAP requests
<?php
/**
* Debug SOAP requests
*/
$client = new SoapClient(
'http://example.loc/index.php/api/v2_soap/?wsdl'
);
// Set yourself debug session cookie, for Xdebug and Phpstorm
@Marko-M
Marko-M / magento-dump-import-ssh.sh
Last active November 22, 2017 14:00
Almost one-liner dump and import of Magento database trough SSH (with ignore tables and triggers definer adjustment)
#!/bin/bash
# Marko Martinović
# Prints command traces
set -x
# Tables to ignore
IGNORE_TABLES=(dataflow_batch_export dataflow_batch_import log_customer log_quote log_summary log_summary_type log_url log_url_info log_visitor log_visitor_info log_visitor_online report_event index_event enterprise_logging_event_changes core_cache core_cache_tag core_session core_cache_tag)
# Source SSH
@Marko-M
Marko-M / nginx_access.log
Last active November 23, 2017 12:22
/checkout/cart/add/ DoS
123.123.123.123 - - [23/Nov/2017:11:39:48 +0000] "POST /checkout/cart/add/uenc/xyz/product/142/form_key/CSLLfXodh1AqB5KK/ HTTP/1.1" 444 0 "http://www.example.com" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.21 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.21"
234.234.234.234 - - [23/Nov/2017:11:39:48 +0000] "POST /checkout/cart/add/uenc/xyz/product/8086/form_key/CSLLfXodh1AqB5KK HTTP/1.1" 444 0 "http://www.example.com" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.21 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.21"
123.123.123.123 - - [23/Nov/2017:11:39:48 +0000] "POST /checkout/cart/add/uenc/xyz/product/3734/form_key/CSLLfXodh1AqB5KK/ HTTP/1.1" 444 0 "http://www.example.com" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.21 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.21"
123.123.123.123 - - [23/Nov/2017:11:39:48 +0000] "POST /checkout/cart/add/uenc/xyz/product/8086/form_key/CSLLfXodh1AqB5KK HTTP/1.1" 444 0 "http://www.example.com" "Mozilla/5.0 (Windows NT 6.1; WOW64) Appl
@Marko-M
Marko-M / magento_bundle_product_type_price_indexer.sql
Last active March 28, 2018 20:46
Magento Bundle Product Type Price Indexer
INSERT INTO `catalog_product_index_price_bundle_idx`
SELECT `e`.`entity_id`,
`cg`.`customer_group_id`,
`cw`.`website_id`,
IF(IF(Ifnull(tas_tax_class_id.value_id, -1) > 0, tas_tax_class_id.value, tad_tax_class_id.value) IS NOT NULL, IF(Ifnull(tas_tax_class_id.value_id, -1) > 0, tas_tax_class_id.value, tad_tax_class_id.value), 0) AS `tax_class_id`,
1 AS `price_type`,
IF(IF(IF(Ifnull(tas_special_from_date.value_id, -1) > 0, tas_special_from_date.value, tad_special_from_date.value) IS NULL, 1, IF(IF(Ifnull(tas_special_from_date.value_id, -1) > 0, tas_special_from_date.value, tad_special_from_date.value) <= cwd.website_date, 1, 0)) > 0
AND IF(IF(Ifnull(tas_special_to_date.value_id, -1) > 0, tas_special_to_date.value, tad_special_to_date.value) IS NUL