Skip to content

Instantly share code, notes, and snippets.

View vladimirlukyanov's full-sized avatar
🗯️
It's during our darkest moments that we must focus to see the light

Vladimir Lukyanov vladimirlukyanov

🗯️
It's during our darkest moments that we must focus to see the light
View GitHub Profile
@vladimirlukyanov
vladimirlukyanov / listen_for_input_change_programatically.js
Last active February 6, 2024 14:35
Listen for input change programatically | Vanilla JS
<script type="text/javascript">
let event = new Event('change');
let inputBox = document.querySelector("#shipping_postcode");
const descriptor = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(inputBox), 'value');
Object.defineProperty(inputBox, 'value', {
set: function(t) {
if(t === '') return;
@vladimirlukyanov
vladimirlukyanov / render_vue_from_string_ajax_call.js
Created February 22, 2021 13:19
Render Vue.js from string or AJAX call context
let el = Vue.compile(`<MuiIcon icon="${icon}" />`);
el = new Vue({
components: {
MuiIcon
},
vuetify,
render: el.render,
staticRenderFns: el.staticRenderFns
}).$mount();
return el.$el.outerHTML;
@vladimirlukyanov
vladimirlukyanov / distinct.php
Created May 11, 2020 14:58
Implement a function distinct(...), which expects an array of integers and sorts these ascendingly. The array shall not contain repetitions of any integer value but '1'. Repetitions of '1' should be the last values of the array.
<?php
/**
* @param array $array
*
* @return array | false
*/
function distinct( array $arr ) {
if ( is_array( $arr ) ) {
@vladimirlukyanov
vladimirlukyanov / webpack hot reload disable nuxt.js
Last active November 8, 2023 10:20
webpack hot reload disable nuxt
// Add this to nuxt.config.js
build: {
publicPath: '/zenith/',
analyze: false,
hotMiddleware : {
reload:false
},
// watch: ['api', 'modules'],
extend(config, {isDev, isClient}) {
@vladimirlukyanov
vladimirlukyanov / programatically_add_route_nuxt.js
Created April 27, 2018 02:54
Nuxt.js programactically add route
const { resolve } = require('path');
module.exports = function() {
this.extendRoutes(routes => {
routes.push({
name: 'admin',
path: '/admin',
component: resolve('./pages/index.vue')
})
@vladimirlukyanov
vladimirlukyanov / 404-redirect.js
Last active April 23, 2018 07:23
Nuxt.js 404 error handling | Nuxt.js 404 redirect | Nuxt.js middleware routing
// Add this file to /middleware
export default function ({params, route, redirect}) {
if(route.matched.length === 0) { // route is not found, redirect to homepage
redirect('302', '/');
}
}
@vladimirlukyanov
vladimirlukyanov / Get list of taxonomies for CPT.php
Created January 17, 2017 13:02
Get list of taxonomy names for CPT
<?php
$args = array(
'object_type' => array( 'hotels' )
);
$output = 'names'; // or objects
$operator = 'and'; // 'and' or 'or'
$taxonomies = get_taxonomies( $args, $output, $operator );
if ( $taxonomies ) {
foreach ( $taxonomies as $taxonomy ) {
@vladimirlukyanov
vladimirlukyanov / hide_menus_for_non_admin_users_wordpress.php
Created November 16, 2016 13:29
Hide menu items for non-admin users WordPress
<?php
// remove unnecessary menus
function remove_admin_menus () {
global $menu;
// all users
$restrict = explode(',', 'Links,Comments');
// non-administrator users
@vladimirlukyanov
vladimirlukyanov / search_by_sku.php
Created November 1, 2016 03:01
WordPress WooCommerce search by SKU
<?php
/**
* Add sku, author, publisher and format to product search
*/
// hook into wp pre_get_posts
add_action('pre_get_posts', 'woo_search_pre_get_posts');
/**
* Add custom join and where statements to product search query
@vladimirlukyanov
vladimirlukyanov / shortcode_method_4.php
Created October 23, 2016 01:28
Shortcode style enqueue #4
<?php
function custom_shortcode_scripts() {
global $post;
if( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'myshortcode') ) {
wp_enqueue_script( 'my-script');
}
}
add_action( 'wp_enqueue_scripts', 'custom_shortcode_scripts');