Skip to content

Instantly share code, notes, and snippets.

View radist2s's full-sized avatar

Alex Batalov radist2s

  • Georgia, Tbilisi
View GitHub Profile
@radist2s
radist2s / functions.php
Created May 23, 2019 08:54
Fix WooCommerce chosen Shipping Method during Address/ZIP code change on Form Totals update
<?php
add_filter('woocommerce_shipping_chosen_method', function ($default, $rates = [], $chosen_method = null) {
$rates = $rates ? (array)$rates : [];
if ($chosen_method and isset($rates[(string)$chosen_method])) {
return $chosen_method;
}
return $default;
}, 10, 3);
@radist2s
radist2s / php-to-blade-converter.php
Created May 20, 2019 03:20
PHP to Blade converter for WordPress templates (WooCommerce mostly)
<?php
$file_path = $argv[1] ?? null;
$file_path_abs = '';
if (!$file_path) {
throw new \Error('No file Path arg provided');
}
if (is_readable($file_path)) {
$file_path_abs = $file_path;
@radist2s
radist2s / bem-block-rename.php
Last active May 4, 2019 22:52
Tool for renaming BEM Blocks
<?php
/**
* Usage
* bem-block-rename.php ./templates/ .renaming-block-name .destination-block-name # will change every `.blade.php` in directory
* bem-block-rename.php .renaming-block--with-mod .dest-block--with-renamed-mode # will change every `.blade.php` in CWD directory
* bem-block-rename.php specified-file.php .renaming-block-name__child .destination-block-name__renamed-child # will change only `specified-file.php`
*/
namespace BemClassesTools;
@radist2s
radist2s / readme.md
Created April 14, 2019 20:30
Multiple Blade subviews extending a master template only works once

Multiple Blade subviews extending a master template only works once

Problem Solution

@extend('app')

@section('stuff')
 Stuff goes here...
@radist2s
radist2s / functions.php
Last active April 8, 2019 12:18
Wordpress Menu BEM-style classes
<?php
/**
* Adds classes for menu link
* If menu container has classes [base-menu baseMenu]
* than links will get classes [base-menu--link baseMenuLink]
*/
add_filter('nav_menu_link_attributes', function ($atts, $item, $args, $depth)
{
$classes = explode(' ', $args->container_class ?: $args->menu_class);
@radist2s
radist2s / bem-and-sass.md
Created March 25, 2019 15:07
BEM & SASS best practices

BEM & SASS best practices

Every block should be in separated file named as block.

Filename: rating-star.scss

.rating-star {
    $font-size: 0.5em;
    
    display: inline-block; // `display` style may be set freely
@radist2s
radist2s / readme.md
Created February 21, 2019 21:33
Trellis does not yet support Python 3.6.4 Troubleshooting
Use virtualenvwrapper
Installation
pip install virtualenvwrapper
source /usr/local/bin/virtualenvwrapper.sh
mkvirtualenv p3 # make default python 3.x environment
mkvirtualenv -p /usr/bin/python2.7 p2 # install python 2.7 environment
workon p2
pip install ansible==2.5.3.0
@radist2s
radist2s / .env
Last active June 14, 2020 10:13
WP Attachment Multiple Origin support plugin. Helps to override Sage`s `UPLOADS_URL` filter with proper origin.
# For production no filters will be applied
WP_ENV=development
WP_HOME=http://example.com
WP_SITEURL=${WP_HOME}/wp
# Should be defined for staging and development, has no effect for production
UPLOADS_URL='http://example.com/app/uploads'
# Should be defined for development, maybe skipped for staging if Bedrock used
UPLOADS_URL_STAGING='//stage.example.com/app/uploads'
@radist2s
radist2s / Readme.md
Last active February 1, 2019 20:21
Valet / Valet+ any domains

Introduction

Allows to link any domain to use with Valet / Valet+. You a free to use any domain name, e.g.: dev.exmaple.com, google.com, etc. Not only .test domains.

Installation

Add new config file for Dnsmasq:

sudo echo "conf-file=$HOME/.valet/dnsmasq-extra-domains.conf" >> $(brew --prefix)/etc/dnsmasq.conf
@radist2s
radist2s / ColumnsInspectorControls.jsx
Created January 9, 2019 05:32
WordPress Gutenberg core/columns wrapping and custom attributes adding
import VerticalAlignOptions from "./VerticalAlignOptions.jsx"
const
{InspectorControls} = wp.editor,
{PanelBody} = wp.components,
{__} = wp.i18n
export default function ColumnsInspectorControls(props) {
const {attributes, setAttributes, usePanel} = props