Skip to content

Instantly share code, notes, and snippets.

@6ui11em
6ui11em / clearurl.sh
Last active June 12, 2020 16:07
Command: Clear url from varnish #varnish #cache #purge
# Enter varnish admin
varnishadm
# clear cache for index home page only
ban req.http.host ~ windparadise.com && req.url ~ "^/$"
# clear cache for specific page
@6ui11em
6ui11em / bold-hover-without-shift.scss
Last active October 21, 2020 08:13
CSS: Bold on Hover without layout shift #css #scss #bold #hover
/*
By Ryan Mulligan
Source: https://css-tricks.com/bold-on-hover-without-the-layout-shift/
*/
.menu-link {
display: inline-flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 1rem 1.5rem;
@6ui11em
6ui11em / autoincrement_allow_0.sql
Created December 30, 2020 17:43
Mysql: Allow 0 for autoincrement when import #mysql #autoincrement #import
SET [GLOBAL|SESSION] sql_mode='NO_AUTO_VALUE_ON_ZERO'
@6ui11em
6ui11em / entity_atributes.sql
Created January 13, 2021 11:19
Magento: Query atributos entidades #magento #sql #eav #attributes
-- Category:
SET @entity_id = 1;
(SELECT e.attribute_code, 'varchar' AS type, v.store_id, v.value FROM catalog_category_entity_varchar v
JOIN eav_attribute e ON e.attribute_id = v.attribute_id WHERE v.entity_id = @entity_id)
UNION
(SELECT e.attribute_code, 'datetime' AS type, v.store_id, v.value FROM catalog_category_entity_datetime v
JOIN eav_attribute e ON e.attribute_id = v.attribute_id WHERE v.entity_id = @entity_id)
UNION
(SELECT e.attribute_code, 'decimal' AS type, v.store_id, v.value FROM catalog_category_entity_decimal v
@6ui11em
6ui11em / duplicate.sql
Last active February 15, 2022 11:05
SQL: Find duplicate values #mysql #sql #select #duplicate
SELECT
col,
COUNT(col)
FROM
table_name
GROUP BY col
HAVING COUNT(col) > 1;
---
@6ui11em
6ui11em / emulateAreaCode.php
Created April 15, 2021 13:26
Magento 2: Emulate Area Code #magento2 #areacode #state #frontend #adminhtml
# File: vendor/magento/framework/App/State.php
public function emulateAreaCode($areaCode, $callback, $params = [])
{
$currentArea = $this->_areaCode;
$this->_areaCode = $areaCode;
$this->_isAreaCodeEmulated = true;
try {
$result = call_user_func_array($callback, $params);
} catch (Exception $e) {
$this->_areaCode = $currentArea;
@6ui11em
6ui11em / route.xml
Created May 5, 2021 08:19
Magento 2: Route #magento2 #route
<?xml version="1.0"?>
<!--
Credits: https://mdotacademy.snippets.cc/collection/magento-2/create-route
Place this file in either the "frontend" or "adminhtml" folder to define either
a frontend or admin route, respectively:
ex. app/code/Foo/Bar/etc/frontend/routes.xml
The "urn:magento:framework:App/etc/routes.xsd" file is used to validate this
XML file. You can inspect it at vendor/magento/framework/App/etc/routes.xsd
@6ui11em
6ui11em / youtube-id.php
Created May 13, 2021 00:11
Regexp: Get Youtube ID from Url #regexp #youtube
<?php
// Here is a sample of the URLs this regex matches: (there can be more content after the given URL that will be ignored)
// http://youtu.be/dQw4w9WgXcQ
// http://www.youtube.com/embed/dQw4w9WgXcQ
// http://www.youtube.com/watch?v=dQw4w9WgXcQ
// http://www.youtube.com/?v=dQw4w9WgXcQ
// http://www.youtube.com/v/dQw4w9WgXcQ
// http://www.youtube.com/e/dQw4w9WgXcQ
// http://www.youtube.com/user/username#p/u/11/dQw4w9WgXcQ
@6ui11em
6ui11em / youtube-api.php
Created May 13, 2021 00:12
Youtube: Get Video Information API call PHP #youtube #php #api #video
$api_key = "API Key"
$video_id = "Video ID"
$url = "https://www.googleapis.com/youtube/v3/videos?id=" . $video_id . "&key=" . $api_key . "&part=snippet,contentDetails,statistics,status";
$json = file_get_contents($url);
$getData = json_decode( $json , true);
foreach((array)$getData['items'] as $key => $gDat){
$title = $gDat['snippet']['title'];
}
// Output title
echo $title;
@6ui11em
6ui11em / addProductVideo.php
Created May 13, 2021 00:15
Magento 2: Add Youtube Video to product #video #magento2 #youtube
<?php
/* Source: https://mage2.pro/t/topic/1741/11 */
namespace Yourcompany\Yourmodule\Controller\Test;
use Magento\Framework\Api\Data\VideoContentInterface;
use Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface;
use Magento\Framework\App\Action\Context;
use Magento\ProductVideo\Model\Product\Attribute\Media\ExternalVideoEntryConverter;
use Magento\Store\Model\Store;
use Magento\Framework\Exception\InputException;