Skip to content

Instantly share code, notes, and snippets.

Avatar
🌮

Josh Pollock Shelob9

🌮
View GitHub Profile
View Queries:
This works:
GET team_1/_search
{
"query" : {
"match" : {
"eventType" : "login"
}
},
"sort": { "time": "desc"}
}
@Shelob9
Shelob9 / MetaSidebar.js
Last active Aug 16, 2021
Create WordPress Sidebar Plugin for meta fields
View MetaSidebar.js
import { __ } from "@wordpress/i18n";
import { PanelBody } from "@wordpress/components";
import { PluginSidebar } from "@wordpress/edit-post";
import { key } from "@wordpress/icons";
import { registerPlugin } from "@wordpress/plugins";
import { TextControl, CheckboxControl } from "@wordpress/components";
import { useSelect, useDispatch } from "@wordpress/data";
const SideBar = () => {
const { meta_one, meta_two } = useSelect((select) =>
@Shelob9
Shelob9 / centered-order-list.html
Created Aug 13, 2021
Tailwind centered, ordered list.
View centered-order-list.html
<div class="flex">
<div class="m-auto">
<ul>
<li class="inline">One</li>
<li class="inline">Two</li>
</ul>
</div>
</div>
@Shelob9
Shelob9 / resolve.php
Created Aug 13, 2021
Resolve from Laravel service container, with dependency
View resolve.php
//Resolve from service container
app()->makeWith(Replacer::class, [
'build' => $build
]);
//Similar to:
new Replacer($build);
View FormWithRef.jsx
import { useRef } from "react";
export default function Form({ onSubmit }) {
const inputEl = useRef(null);
const handleSubmit = (e) => {
e.preventDefault();
onSubmit({
input: inputEl.current.value,
});
}
View batch-cli.php
<?php
function batch_cli( $command, $totalPages,$loop ) {
$state = new \stdClass();
$state->page = 1;
$state->totalPages = $totalPages;
$state->command = $command;
$createProcess = function($state){
return new Process(sprintf( "%s --page=%n", $state->command, $state->page );
};
View pasteEventHandler.js
{
paste(evt) {
console.log('on paste', evt.clipboardData.items[0].toString());
},
}
@Shelob9
Shelob9 / roy.tsx
Created Aug 22, 2020
Simple React context example, with TypeScript. See: https://codesandbox.io/s/react-context-tldr-bey3y
View roy.tsx
const RoyContext = React.createContext<{
hi: boolean;
setHi: (set: boolean) => void;
}>(null);
const RoyProvider = ({ children }) => {
const [hi, setHi] = useState<boolean>(true);
return (
<RoyContext.Provider value={{ hi, setHi }}>{children}</RoyContext.Provider>
);
View error.sh
TypeError
Cannot read property 'length' of undefined
at QuickInserter (https://u8k01.csb.app/node_modules/
wordpress/block-editor/build-module/components/inserter/quick-inserter.js:80:59
renderWithHooks
https://u8k01.csb.app/node_modules/react-dom/cjs/react-dom.development.js:14803:18
mountIndeterminateComponent
https://u8k01.csb.app/node_modules/react-dom/cjs/react-dom.development.js:17482:13
beginWork
https://u8k01.csb.app/node_modules/react-dom/cjs/react-dom.development.js:18596:16
View addQueryArgs.js
function(endpoint,args={}){
//parse url
//https://developer.mozilla.org/en-US/docs/Web/API/URL
let url = new URL(endpoint);
//Add params
Object.keys(args).forEach( arg => {
//https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/URLSearchParams
url.searchParams.append( arg, args[arg] );
});