Skip to content

Instantly share code, notes, and snippets.

View oddevan's full-sized avatar

Evan Hildreth oddevan

View GitHub Profile
@oddevan
oddevan / post.mermaid
Created August 29, 2024 23:53
Smolblog event sourcing take 3?
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@oddevan
oddevan / chapter_to_scenes.php
Created August 9, 2024 18:46
Break a single markdown file up by horizontal lines (either --- or ***). I use this to move a draft from writing (all in one file) to editing (scenes as separate files).
#!/opt/homebrew/bin/php
<?php
if (!isset($argv[1])) {
echo "Need to supply a file!";
die(1);
}
$source_file_path = str_starts_with($argv[1], DIRECTORY_SEPARATOR) ? $argv[1] : getcwd() . DIRECTORY_SEPARATOR . $argv[1];
$destination_dir = isset($argv[2]) ? (
rtrim(
@oddevan
oddevan / New Event Structure.mermaid
Created September 12, 2023 02:12
New Event Structure
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@oddevan
oddevan / challenge.md
Last active May 18, 2021 00:59 — forked from devinsays/challenge.md
WooCommerce MySQL Challenge

1. Get the order ids for all orders that have a shipping state of "New Jersey".

SELECT orders.ID
FROM `wp_posts` orders
  INNER JOIN `wp_postmeta` meta ON meta.post_id = orders.ID
WHERE
  orders.post_type = 'shop_order' AND
  meta.meta_key = '_shipping_state' AND
  meta.meta_value = 'NJ';
async function fetchAndSetResponse(url, setAttributes) {
const oEmbedUrl = `oddevan/v1/devArtProxy?url=${encodeURIComponent(url)}`;
try {
const response = await apiFetch({ path: oEmbedUrl });
setAttributes({ embedData: response });
} catch(e) {
console.log('Error in DA block', { url: oEmbedUrl, error: e });
setAttributes({ embedData: {} });
}
<?php
function proxy_deviantart_oembed( $data ) {
$url = $data->get_param( 'url' );
if ( ! is_valid_url( $url ) ) {
return new WP_Error(
'error',
'Error: not a DeviantArt URL',
[ 'input' => $data ],
);
}
<?php
function proxy_deviantart_oembed_security() {
// Should only be used by logged-in users capable of using the editor.
return current_user_can( 'edit_posts' );
}
<?php
add_action( 'rest_api_init', function () {
register_rest_route( 'oddevan/v1', '/devArtProxy/', array(
'methods' => 'GET',
'callback' => __NAMESPACE__ . '\proxy_deviantart_oembed',
'permission_callback' => __NAMESPACE__ . '\proxy_deviantart_oembed_security',
) );
} );