Skip to content

Instantly share code, notes, and snippets.

View EmranAhmed's full-sized avatar
🏠
Working from home

Emran Ahmed EmranAhmed

🏠
Working from home
View GitHub Profile
@alexpaul
alexpaul / AccessToRootViewController.swift
Last active January 3, 2024 03:47
Getting access to the SceneDelegate window object in Xcode 11. SceneDelegate. Reset application window. Reset window. Reset rootviewcontroller. Root view controller. Scene delegate.
// accessing the window and changing the root view controller property
override func viewDidLoad() {
super.viewDidLoad()
// getting access to the window object from SceneDelegate
guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
let sceneDelegate = windowScene.delegate as? SceneDelegate
else {
return
}
let viewcontroller = UIViewController()
@bfintal
bfintal / cheatsheet.js
Last active April 11, 2024 00:22
Gutenberg Cheat Sheet
// Get the data of a block
wp.data.select( 'core/block-editor' ).getBlocks()[0]
// Update attributes of another block
// wp.data.dispatch( 'core/editor' ).updateBlockAttributes( clientID, attributes )
wp.data.dispatch( 'core/block-editor' ).updateBlockAttributes( '10d88a6d-95d6-4e07-8293-5f59c83a26c0', { heading: 'New Heading' } )
// Get currently selected block.
wp.data.select( 'core/block-editor' ).getBlockSelectionStart()
@kellymears
kellymears / webpack.mix.js
Created January 20, 2019 20:08
[Gutenberg Webpack Mix] #gutenberg #mix #js
const mix = require('laravel-mix');
const url = 'http://lab.tinypixel.test';
const app = './src';
const config = './config';
const resources = './resources';
const assets = './resources/assets';
const dist = './dist';
const externals = {
@mahlamusa
mahlamusa / extend-wp-rest-api.php
Last active June 1, 2023 10:38
Extend WordPress REST API with custom rest fields and endpoints
<?php
/**
* Register custom rest fields
*/
add_action( 'rest_api_init', 'register_custom_fields' );
/**
* Register rest fields and endpoint
*
@GeekPress
GeekPress / cache-woo-get-refreshed-fragment-request.php
Last active July 25, 2019 09:58
Cache WooCommerce Get Refreshed Fragment Request
<?php
if ( isset( $_GET['wc-ajax'] ) && 'get_refreshed_fragments' === $_GET['wc-ajax'] && ( !isset( $_COOKIE['woocommerce_cart_hash'] ) || empty( $_COOKIE['woocommerce_cart_hash'] ) ) && ( !isset( $_COOKIE['woocommerce_items_in_cart'] ) || empty( $_COOKIE['woocommerce_items_in_cart'] ) ) ) {
$data = get_transient( 'rocket_get_refreshed_fragments_cache' );
if ( ! empty( $data ) ) {
$data = json_decode( $data );
wp_send_json( $data );
}
ob_start();
@obiPlabon
obiPlabon / wc-template-override.php
Last active September 26, 2020 12:50
Helper class to override WooCommerce templates from plugin
<?php
/**
* WooCommerce template overriding class
*
* @author obiPlabon
*/
class WC_Template_Override {
/**
@obiPlabon
obiPlabon / wp-taxonomy-term-parent-child-relation.php
Last active January 25, 2018 19:07
Restrict hierarchical taxonomy term relation to a certain level.
<?php
/**
* Restrict category term relation to only parent-child
*
* @see https://wpseek.com/hook/post_edit_category_parent_dropdown_args/
* @see https://wpseek.com/hook/taxonomy_parent_dropdown_args//
*
* @param array $args
* @return array Modified arguments
*/
@royboy789
royboy789 / gutenberg_es6_modular_components.js
Last active January 23, 2018 03:00
Gutenberg Modular Components
import Input from './components/Input.es6';
const { __ } = wp.i18n;
const { registerBlockType } = wp.blocks;
const el = wp.element.createElement;
registerBlockType( 'learn-gutenberg/ex2-react', {
title: __( 'Learn Gutenberg Example 2: React', 'learn-gutenberg' ),
category: 'widgets',
supportHTML: false,
@royboy789
royboy789 / guten-vue.js
Created January 17, 2018 00:38
This is a Gutenberg Block built with Vue.js
( function( wp ) {
var el = wp.element.createElement;
var __ = wp.i18n.__;
wp.blocks.registerBlockType( 'learn-gutenberg/ex2-vue', {
title: __( 'Learn Gutenberg Example 2: VueJS', 'learn-gutenberg' ),
category: 'widgets',
supportHTML: false,
attributes: {
who: {
@blairanderson
blairanderson / conv.sh
Last active December 20, 2021 17:57
Optimize Videos for Web - Compress MP4 and remove Audio with FFMPEG. encodes as 264 with CRF 30, scales down to 1920x1080, strips audio
#! /bin/bash
# The Purpose of this Script is to batch convert and compress any video file to mp4 format
#
# WARNING: LOSSY COMPRESSION !!!
# Variable used:
# sourcedir is the directory where to be converted videos are. Converted video will be saved in the same folder
# usage: