Skip to content

Instantly share code, notes, and snippets.

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

noxd3v noxd3v

🏠
Working from home
View GitHub Profile
@noxd3v
noxd3v / functions.php
Last active April 14, 2019 14:55
WooCommerce product quick view (AJAX)
<?php
/* enqueue scripts */
function cp_enqueue_scripts() {
wp_enqueue_script( 'cp_modal_js', get_stylesheet_directory_uri() . '/js/modal.js', array( 'jquery' ));
wp_enqueue_script( 'cp_loc_file', get_stylesheet_directory_uri() . '/js/var.js');
wp_localize_script('cp_loc_file', 'cp_loc_ajaxpath', admin_url('admin-ajax.php'));
}
add_action('wp_enqueue_scripts', 'cp_enqueue_scripts');
@noxd3v
noxd3v / Popover.js
Last active November 12, 2020 23:14
Detect click outside of the box (ReactJS Hooks)
import { useEffect } from "react";
const useDetectOutsideClick = (ref, outsideClickHandler) => {
useEffect(() => {
const handleOutsideClick = (e) => {
if (ref.current && !ref.current.contains(e.target)) {
outsideClickHandler();
}
};
@noxd3v
noxd3v / simple-dropzone.js
Created November 3, 2019 22:45
Drag & drop image upload Firebase storage (using Dropzone)
import React, { useCallback, useState } from "react";
import { useDropzone } from "react-dropzone";
import firebase from "firebase/app";
import "firebase/storage";
import uuid from "uuid/v4";
const Dropzone = ({ droppedImage }) => {
const onDrop = useCallback(
@noxd3v
noxd3v / README.md
Created January 30, 2020 18:47 — forked from nikcub/README.md
Facebook PHP Source Code from August 2007
@noxd3v
noxd3v / Computed property names and methods.MD
Last active October 4, 2020 11:43
Computed property names and methods

Computed property names and methods ECMAScript 2015 adds a nice feature: computed property names in object literals and classes. The computed properties use a slight different syntax [methodName]() {...}, so the method definition looks this way:

const addMethod = 'add',
  getMethod = 'get';
const collection = {
  items: [],
  [addMethod](...items) {
@noxd3v
noxd3v / compose.js
Last active October 7, 2020 14:03
compose function
/* compose function for combining HOC in react */
export const compose = (...rest) => (x) => rest.reduceRight((y, f) => f(y), x);
/*
It's called functional composition and it has mathematical background (that causes y and x variables naming and reversed execution of functions). It decreases complexity of the way how you call written functions by eliminating variables extra definition and deep level of function wrapage.
*/
@noxd3v
noxd3v / Aggregate with filtering.js
Last active February 15, 2022 11:30
MongoDB snippets
Position.aggregate([
{
$project: {
_id: 1,
positions: {
$filter: {
input: "$newPositionsArray",
as: "position",
cond: {
/* multiple conditions */
@noxd3v
noxd3v / Arrays.js
Last active September 25, 2021 08:15
Array snippets
/* Change position of the item in array */
const list = [1, 2, 3, 4, 5, 6];
const changePosition = (arr, destinationIndex, sourceIndex) => {
// destructable, copy array before using splice
arr.splice(destinationIndex, 0, list.splice(sourceIndex, 1)[0]);
return arr;
};
@noxd3v
noxd3v / rearrangable-list-react-beautiful-dnd.js
Created December 3, 2020 12:52
Simple rearrangable sidebar list using react-beautiful-dnd
import React, { useState, useContext, useCallback } from "react";
import styled from "styled-components";
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
import { SidebarItem } from "../SidebarNavigation/SidebarNavigation.component";
import { FaPlus } from "react-icons/fa";
import { HiOutlineDotsVertical } from "react-icons/hi";
import { ModalContext } from "../../structure/Modal/modalContext";
import AddPositionForm from "./AddPositionForm";
const Wrapper = styled.div`
@noxd3v
noxd3v / merging cache.js
Last active January 17, 2022 12:20
Apollo Client
/* since apollo cache depends on unique identifiers, if it occurs that the fields are without id field we need to merge existing with incoming cache, or just accept the incoming one */
const cache = new InMemoryCache({
typePolicies: {
/* query */
getSinglePosition: {
fields: {
/* related field */
Files: {
merge(existing, incoming) {