Skip to content

Instantly share code, notes, and snippets.

View kanduvisla's full-sized avatar
😎

Giel Berkers kanduvisla

😎
View GitHub Profile
@kanduvisla
kanduvisla / gist:e5179e07951882fcf0bb93a87a743767
Created July 16, 2018 08:48
Magento 2 development defaults
php bin/magento config:set admin/security/session_lifetime 31536000
php bin/magento config:set customer/captcha/enable 0
php bin/magento config:set customer/password/password_reset_protection_type 0
@kanduvisla
kanduvisla / perf_test.php
Created July 10, 2018 13:20
PHP Performance test for isset() vs array_key_exists() vs coalesce operator
<?php
$iterations = 1000000;
$arr = ['foo' => 'bar'];
function testIsset()
{
global $iterations, $arr;
@kanduvisla
kanduvisla / phpstorm_find_and_replace_regexes.md
Last active July 11, 2017 10:54
Various PHPStorm Find and replace regexes

Create Getters from Setters

Example:

public function setDescription(string $description): SomeInterface;

to:

public function getDescription(): string;
@kanduvisla
kanduvisla / order-to-shipment.php
Created November 8, 2016 13:07
Magento 2 : Create shipment from order:
/**
* @var OrderRepositoryInterface
*/
protected $orderRepository;
/**
* @var \Magento\Sales\Model\Convert\Order
*/
protected $convertOrder;
@kanduvisla
kanduvisla / regex-for-mocking.md
Last active October 24, 2016 11:42
Regex to replace class signature to mock properties

Regexes for quickly mocking stuff

This is a small collection of regular expressions to find pieces of code and replace them with PHPUnit mocks. It's useful for copy/pasting existing pieces of code (a constructor signature for example) and transforming them into usefull code for mocking in PHPUnit, without having to type everything out.

Disclaimer: some small code formatting might be required afterwards, but hey it's better than nothing ...

@kanduvisla
kanduvisla / truncate-mage-2.sql
Created October 10, 2016 09:31
Truncate Magento 2 database
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE `gift_message`;
TRUNCATE TABLE `quote`;
TRUNCATE TABLE `quote_address`;
TRUNCATE TABLE `quote_address_item`;
TRUNCATE TABLE `quote_id_mask`;
TRUNCATE TABLE `quote_item`;
TRUNCATE TABLE `quote_item_option`;
TRUNCATE TABLE `quote_payment`;
TRUNCATE TABLE `quote_shipping_rate`;
<?php
/**
* Created by PhpStorm.
* User: Giel
* Date: 18/04/16
* Time: 22:15
*/
namespace Gielberkers\Example\Plugin\Magento\Framework\Event;
@kanduvisla
kanduvisla / ElephantData.php
Last active January 21, 2021 04:17 — forked from TommyKolkman/ElephantData.php
Observer to strip <p> tags for Magento 2 in pages and static blocks
<?php
namespace Elephant\CFParent\Helper;
class ElephantData extends \Magento\Framework\App\Helper\AbstractHelper
{
public function __construct(
\Magento\Framework\App\Helper\Context $context,
array $data = []
@kanduvisla
kanduvisla / gist:8cdf79c656386bbf438e
Last active August 29, 2015 14:15
Magento clean database
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE TABLE `catalog_category_entity`;
TRUNCATE TABLE `catalog_category_entity_datetime`;
TRUNCATE TABLE `catalog_category_entity_decimal`;
TRUNCATE TABLE `catalog_category_entity_int`;
TRUNCATE TABLE `catalog_category_entity_text`;
TRUNCATE TABLE `catalog_category_entity_varchar`;
TRUNCATE TABLE `catalog_category_product`;
TRUNCATE TABLE `catalog_category_product_index`;
@kanduvisla
kanduvisla / mapbox.js
Created March 1, 2013 16:10
mapbox - google maps box on the fly
/*
Simple MapBox to show Google Maps
mapBox.setLatLng(0, 0);
mapBox.mapOptions.zoom = 16;
mapBox.addMarker(0, 0, {
url : '/images/marker.png',
anchorX : 15,
anchorY : 30,