Skip to content

Instantly share code, notes, and snippets.

View leek's full-sized avatar
🔌
Plugged in

Chris Jones leek

🔌
Plugged in
View GitHub Profile
@leek
leek / add_sri_attribute.php
Created April 2, 2021 05:44
Add SRI attribute to WordPress scripts and stylesheets.
<?php
/**
* Add SRI attributes to external JS resources
*/
function add_sri_attribute($tag, $handle, $src = null)
{
$known_hashes = array(
'https://code.jquery.com/jquery-1.12.4.min.js' => 'sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=',
);
@leek
leek / magento_2_dump_and_die.php
Last active October 12, 2024 07:45
Laravel dd() for Magento 2
<?php
function d($arg) {
if (is_object($arg)) {
echo PHP_EOL . 'CLASS: ' . get_class($arg) . PHP_EOL;
if ($arg instanceof \Magento\Framework\DB\Select) {
var_dump($arg->__toString());
}
if (method_exists($arg, 'getSelect')) {
var_dump($arg->getSelect()->__toString());
@leek
leek / optimize_media.sh
Created March 12, 2020 17:38
Magento 2 - Optimize Media
#!/bin/bash
if [ ! -f ./app/etc/config.php ]; then
echo "-- ERROR"
echo "-- This doesn't look like a Magento 2 install. Please make sure"
echo "-- that you are running this from the Magento main doc root dir"
exit
fi
echo -ne '\n'
@leek
leek / deploy.sh
Last active May 31, 2022 23:53
Magento 2 Deployment Script
#!/bin/bash
LOCKFILE=deploy.lock
if [ -e ${LOCKFILE} ] && kill -0 `cat ${LOCKFILE}`; then
echo "-- ERROR"
echo "-- Deployment is already running"
exit
fi
@leek
leek / _Magento2_DeleteTestData.md
Last active April 18, 2026 13:38
Magento 2 - Delete All Test Data

These set of scripts are for Magento 2. For Magento 1, see this Gist.

@leek
leek / homestead.md
Last active September 16, 2022 21:39
Instructions for setting up and using Homestead

Homestead Setup

  1. (Mac Only) Install Homebrew:

     /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    
  2. (Mac Only) Install Caskroom:

     brew tap caskroom/cask
    
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class ConfigServiceProvider extends ServiceProvider
{
/**
* Overwrite any vendor / package configuration.
@leek
leek / fizzbuzz.js
Created September 9, 2014 06:58
FizzBuzz solutions in various languages.
for (var i = 1; i <= 100; i++) {
if (i % 15 === 0) {
console.log('FizzBuzz');
} else if (i % 3 === 0) {
console.log('Fizz');
} else if (i % 5 === 0) {
console.log('Buzz');
} else {
console.log(i);
}

Includes:

  • Configuration
  • BrowserSync
  • Environments (e.g.,: --environment=production)
  • Image optimization (gif, jpg, png, and svg)
  • Sass compilation with external libraries
  • Bower installed Sass libraries example(s)
  • CSS processing with Pleeease
/**
* Disable and enable event on scroll begin and scroll end.
* @see http://www.thecssninja.com/javascript/pointer-events-60fps
*/
(function(r, t) {
window.addEventListener('scroll', function() {
// User scrolling so stop the timeout
clearTimeout(t);
// Pointer events has not already been disabled.
if (!r.style.pointerEvents) {