Skip to content

Instantly share code, notes, and snippets.

View jordymeow's full-sized avatar
🏝️
Enjoying life, always!

Jordy Meow jordymeow

🏝️
Enjoying life, always!
View GitHub Profile
@jordymeow
jordymeow / metakeys.json
Last active March 30, 2024 01:29
This JSON lists the metadata types Lightroom manages for photos, from creator details to location info, detailing each key with its data type and description. The photo:getFormattedMetadata(key) function in the Lightroom SDK retrieves this metadata in a user-friendly format for display, mirroring Lightroom's layout, rather than for parsing.
{
"additionalModelInfo": {"type": "string", "description": "Information about the ethnicity and other facets of models in a model-released image."},
"aperture": {"type": "string", "description": "The aperture (for example, 'f/2.8')."},
"artist": {"type": "string", "description": "The artist's name."},
"artworksShown": {"type": "table", "description": "A set of metadata about artwork or an object in the image. Each element in the table is a structure named ArtworkOrObjectDetails, as defined in the IPTC Extension spec."},
"brightnessValue": {"type": "string", "description": "The brightness value."},
"cameraMake": {"type": "string", "description": "The camera manufacturer."},
"cameraModel": {"type": "string", "description": "The camera model."},
"cameraSerialNumber": {"type": "string", "description": "The camera serial number."},
"caption": {"type": "string", "description": "The caption for photo."},
@jordymeow
jordymeow / mwai_stats_credits.php
Created June 5, 2023 13:29
AI Engine: Modify the number of credits allowed for specific user(s) and/or role(s)
<?php
// The purpose of the mwai_stats_credits filter is to alter the number of credits (which can represent a certain number of queries or amount of dollars) allowed in total for a specific user.
// In this implementation below, we'll attribute the number of credits based on the role the user has.
add_filter( 'mwai_stats_credits', function ( $credits, $userId ) {
// Retrieve user data
$user = get_userdata( $userId );
// Assign the initial credits provided as argument
@jordymeow
jordymeow / sse.php
Created May 27, 2023 01:28
SSE (Server-Sent Events) with PHP and JS / Streaming with PHP
<?php
// Various links
// https://serverfault.com/questions/488767/how-do-i-enable-php-s-flush-with-nginxphp-fpm
// https://stackoverflow.com/questions/72394213/nginx-configuration-for-server-sent-event
// https://serverfault.com/questions/801628/for-server-sent-events-sse-what-nginx-proxy-configuration-is-appropriate
// https://qiita.com/okumurakengo/items/cbe6b3717b95944083a1 (in Japanese)
// If '?SSE' is set, send Server-Sent events, otherwise we'll display the page.
if ( isset( $_GET['SSE'] ) ) {
@jordymeow
jordymeow / websearch.php
Last active March 8, 2024 14:37
Web Search (or similar) for AI Engine
<?php
add_filter( "mwai_context_search", 'my_web_search', 10, 3 );
function my_web_search( $context, $query, $options = [] ) {
// If the context is already provided, return it as is.
if ( ! empty( $context ) ) {
return $context;
}
@jordymeow
jordymeow / logchats.php
Last active July 2, 2023 01:06
AI Engine: Log the conversations to local files
<?php
add_filter( 'mwai_chatbot_reply', function ( $reply, $query, $params ) {
try {
global $mwai_core;
$newMessage = !empty( $params['newMessage'] ) ? $params['newMessage'] : "";
// We need to identify the user or session
$id = $mwai_core->get_user_id();
if ( empty( $id ) ) {
@jordymeow
jordymeow / useImage.js
Last active July 25, 2022 17:44
Simple React Hook which handles the status (loading, loaded or failed) of your images. It does a bit of caching.
const { useState, useEffect, useRef } = require('react');
function useImage({ src }) {
let [ image, setImage ] = useState({ src: null, status: 'loading' });
let imageElement = useRef();
let loadedUrls = useRef(new Set());
useEffect(() => {
const onload = () => {
setImage(img => {
@jordymeow
jordymeow / wplr_update_media_custom_meta.php
Created July 26, 2018 06:01
WP/LR Sync: Synchronize a custom meta/field with EXIF/IPTC data
add_action( "wplr_add_media", 'myapp_update_media_meta', 10, 2 );
add_action( "wplr_update_media", 'myapp_update_media_meta', 10, 2 );
function myapp_update_media_meta( $mediaId, $galleryID ) {
global $wplr;
$image = wp_get_attachment_url( $mediaId );
$size = getimagesize($image, $info);
if ( isset( $info['APP13'] ) ) {
$iptc = iptcparse( $info['APP13'] );
if ( isset( $iptc["2#090"][0] ) )
@jordymeow
jordymeow / mfrh_replace_rules.php
Last active July 24, 2018 23:03
Media File Renamer: Replace characters or strings
add_filter( 'mfrh_replace_rules', 'mfrh_replace_rules', 10, 1 );
function replace_s_by_z( $rules ) {
$rules['s'] = 'z';
return $rules;
}