Skip to content

Instantly share code, notes, and snippets.

View MTheProgrammer's full-sized avatar

Matt Chad MTheProgrammer

View GitHub Profile
$=~[];$={___:++$,$$$$:(![]+"")[$],__$:++$,$_$_:(![]+"")
[$],_$_:++$,$_$$:({}+"")[$],$$_$:($[$]+"")[$],_$$:++$,$$
$_:(!""+"")[$],$__:++$,$_$:++$,$$__:({}+"")[$],$$_:++$,$
$$:++$,$___:++$,$__$:++$};$.$_=($.$_=$+"")[$.$_$]+
($._$=$.$_[$.__$])+($.$$=($.$+"")[$.__$])+((!$)+"")[$._$
$]+($.__=$.$_[$.$$_])+($.$=(!""+"")[$.__$])+($._=(!""+"")
[$._$_])+$.$_[$.$_$]+$.__+$._$+$.$;$.$$=$.$+(!""+"")
[$._$$]+$.__+$._+$.$+$.$$;$.$=($.___)[$.$_][$.$_];$.$
($.$($.$$+"\""+$.$_$_+(![]+"")[$._$_]+$.$$$_+"\\"+$.__
$+$.$$_+$._$_+$.__+"("+$.__$+")"+"\"")())();
<?php
/** @var \Magento\Framework\Event $event */
$reflectionClass = new \ReflectionClass(get_class($event));
$reflectionProperty = $reflectionClass->getProperty('_data');
$reflectionProperty->setAccessible(true);
/** @var \Psr\Log\LoggerInterface $logger */
$logger->debug(implode(', ' , array_keys($reflectionProperty->getValue($event))));
<?php
/** @var \Magento\Catalog\Model\ProductFactory $productFactory */
/** @var \Magento\Catalog\Model\Product $product */
$product = $productFactory->create();
$product->getIdBySku($sku);
<?php
use Magento\Framework\Lock\LockManagerInterface;
/** @var LockManagerInterface $lock */
if ($lock->isLocked($uniqueIdentifier)) {
throw new CouldNotSaveException(__("You can't do this"));
}
try {
@MTheProgrammer
MTheProgrammer / extension_attributes.xml
Last active November 3, 2020 05:43
Magento 2 - Example extension attributes with types
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Catalog\Api\Data\ProductRenderInterface">
<attribute code="is_customer" type="boolean"/>
<attribute code="gift_cards_amount" type="float" />
<attribute code="source_code" type="string" />
<attribute code="tax_grandtotal_details" type="Magento\Tax\Api\Data\GrandTotalDetailsInterface[]" />
<attribute code="ddg_categories" type="string[]"/>
<attribute code="test_customer_group_id" type="int">
<resources>
<resource ref="permission"/>
// require([
// "jquery",
// "mage/url"
// ], function ($, url)
//
// ...
$.ajax({
url: url.build('example/url/path'),
data: {
@MTheProgrammer
MTheProgrammer / requirejs-conig.js
Last active May 5, 2021 09:16
Magento 2 custom checkout validation with dynamic message (or other parameters). Use it in a checkout layout xml or in your layout processor.
var config = {
config: {
mixins: {
'Magento_Ui/js/lib/validation/validator': {
'Lucid_DogeValidation/js/rule-dynamic-message-doge-mixin': true
}
}
}
}
@MTheProgrammer
MTheProgrammer / Magento OAuth.postman_collection.json
Created September 15, 2021 08:43
Magento 2 REST OAuth1.0 Postman collection
{
"info": {
"_postman_id": "69120f2b-dc21-441f-842c-197e6d359a2f",
"name": "Magento OAuth",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "MSI",
"item": [
@MTheProgrammer
MTheProgrammer / load_env.sh
Created September 28, 2022 07:54
Load bash .env file
#!/bin/sh
## Usage:
## . ./load_env.sh ; $COMMAND
## . ./load_env.sh ; echo ${MINIENTREGA_FECHALIMITE}
unamestr=$(uname)
if [ "$unamestr" = 'Linux' ]; then
export "$(grep -v '^#' .env | xargs -d '\n')"
elif [ "$unamestr" = 'FreeBSD' ] || [ "$unamestr" = 'Darwin' ]; then
export "$(grep -v '^#' .env | xargs -0)"
@MTheProgrammer
MTheProgrammer / generate_pkce_challenge.ex
Created November 3, 2022 09:54
Elixir Phoenix quickies
defp generate_pkce_challenge() do
code_verifier = Ecto.UUID.generate() <> Ecto.UUID.generate()
code_challenge =
:crypto.hash(:sha256, code_verifier)
|> Base.url_encode64(padding: false)
{code_verifier, code_challenge}
end