Skip to content

Instantly share code, notes, and snippets.

@kvasss
kvasss / parser.php
Created May 21, 2024 21:13 — forked from mekela/parser.php
parser for wordpress
<?php
#откуда будем парсить информацию:
$content=file_get_contents('URL донора');
#начало забираемого контента:
$pos=strpos($content,'код, размещенный перед контентом');
#Отрезаем все, что идет до нужной нам позиции:
$content=substr($content,$pos);
@kvasss
kvasss / CustomSidebar.js
Created October 28, 2023 16:15 — forked from carlodaniele/CustomSidebar.js
A custom Gutenberg block with a custom sidebar to add and manage custom meta fields in WordPress
import { __ } from '@wordpress/i18n';
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/edit-post';
import { PanelBody, PanelRow, TextControl, DateTimePicker } from '@wordpress/components';
const CustomSidebar = ( { postType, metaFields, setMetaFields } ) => {
if ( 'post' !== postType ) return null;
@kvasss
kvasss / .gitlab-ci.yml
Created March 13, 2023 00:57 — forked from superjose/.gitlab-ci.yml
This is an example of a .gitlab-ci.yml that is required for Continuous Integration on GitLab projects.
# Reference: https://www.exclamationlabs.com/blog/continuous-deployment-to-npm-using-gitlab-ci/
# GitLab uses docker in the background, so we need to specify the
# image versions. This is useful because we're freely to use
# multiple node versions to work with it. They come from the docker
# repo.
# Uses NodeJS V 9.4.0
image: node:9.4.0
# And to cache them as well.

ES6 Method

handleChange: function (e) {
    // 1. Make a shallow copy of the items
    let items = [...this.state.items];
    // 2. Make a shallow copy of the item you want to mutate
    let item = {...items[1]};
    // 3. Replace the property you're intested in
    item.name = 'newName';
@kvasss
kvasss / useAnimation.tsx
Created August 7, 2022 19:30 — forked from whoisryosuke/useAnimation.tsx
AFrame / React / AnimeJS - useAnimation hook for animating A-Frame's Entities. Uses the ThreeJS Object3D properties for performance.
import React, { useLayoutEffect, useRef } from "react";
export type VectorCoordinate = {
x: number;
y: number;
z: number;
};
export type useAnimationProps = {
from: {
[key: string]: VectorCoordinate | number | string;
@kvasss
kvasss / useMedia.jsx
Created August 7, 2022 19:29 — forked from whoisryosuke/useMedia.jsx
An example of checking on a media query with React Hooks
function useMedia(query) {
const [matches, setMatches] = useState(window.matchMedia(query).matches)
useEffect(() => {
const media = window.matchMedia(query)
if (media.matches !== matches) {
setMatches(media.matches)
}
const listener = () => {
setMatches(media.matches)
@kvasss
kvasss / fetch-post-request.js
Created August 7, 2022 19:29 — forked from whoisryosuke/fetch-post-request.js
JS - Fetch POST request as async function
(async () => {
const rawResponse = await fetch('https://httpbin.org/post', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({a: 1, b: 'Textual content'})
});
const content = await rawResponse.json();
@kvasss
kvasss / useMousePosition.md
Last active February 3, 2022 12:24 — forked from whoisryosuke/useMousePosition.md
React Hooks - Track user mouse position

Hook

import { useState, useEffect } from "react";

const useMousePosition = () => {
  const [mousePosition, setMousePosition] = useState({ x: null, y: null });

  const updateMousePosition = ev => {
 setMousePosition({ x: ev.clientX, y: ev.clientY });
<?php
/**
* Add checkbox field to the checkout
**/
add_action('woocommerce_after_order_notes', 'my_custom_checkout_field');
function my_custom_checkout_field( $checkout ) {
echo '<div id="my-new-field"><h3>'.__('My Checkbox: ').'</h3>';
// Array#forEach
var data = [ { name: 'foo', type: 'fizz', val: 9 }, { name: 'boo', type: 'buzz', val: 3 }, { name: 'bar', type: 'fizz', val: 4 }, { name: 'car', type: 'buzz', val: 7 }, ],
res = {};
data.forEach(v => res[v.val] = v.name);
console.log(res);
// Array#reduce
var data = [ { name: 'foo', type: 'fizz', val: 9 }, { name: 'boo', type: 'buzz', val: 3 }, { name: 'bar', type: 'fizz', val: 4 }, { name: 'car', type: 'buzz', val: 7 }, ],
res = data.reduce(function(s,a){