Skip to content

Instantly share code, notes, and snippets.

View chuckreynolds's full-sized avatar
🤖
building things

Chuck Reynolds chuckreynolds

🤖
building things
View GitHub Profile
@chuckreynolds
chuckreynolds / wme-article-vs-structured-contents.md
Created August 6, 2024 00:33
As of 08-2024 fields unique and similar in On-demand API production endpoint v2/articles/ vs beta v2/structured-contents/ endpoints. https://enterprise.wikimedia.com/docs/on-demand/

/v2/articles/{name}

  • name, identifier, abstract, date_created, date_modified, date_previously_modified, version, previous_version, url, watchers_count, namespace, in_language, main_entity, additional_entities, categories, templates, redirects, is_part_of, article_body, license, event, image

Fields unique to v2/articles:

•	date_previously_modified
•	previous_version
•	watchers_count
•	namespace
•	categories
•	templates
@chuckreynolds
chuckreynolds / wme-auth-postman.js
Last active August 8, 2024 18:08
This script manages the authentication process and token refresh mechanism for Wikimedia Enterprise API requests in Postman. It checks the validity of the access and refresh tokens before each request, performing re-authentication or token refresh as needed. The script uses environment variables to store tokens and their generation times, ensuri…
/**
* This script manages the authentication process and token refresh mechanism for Wikimedia Enterprise API requests in Postman.
* It checks the validity of the access and refresh tokens before each request, performing re-authentication or token refresh
* as needed. The script uses environment variables to store tokens and their generation times, ensuring the tokens are
* up-to-date and minimizing the need for repeated login requests.
*
* ## Author/Support
* - @chuckreynolds on X
* - e: [email protected]
*
@chuckreynolds
chuckreynolds / top-level-field-names-postman.js
Created August 5, 2024 18:35
Show Top-level field names in console on a Postman API response
// Parse the JSON response body
const responseBody = pm.response.json();
// Check if the response is an array and has elements
if (Array.isArray(responseBody) && responseBody.length > 0) {
// Get the keys (top-level field names) from the first object in the array
const topLevelFields = Object.keys(responseBody[0]);
// Log the top-level field names as a comma-separated string to the Postman console
console.log("Top-level field names in the JSON response: " + topLevelFields.join(', '));
@chuckreynolds
chuckreynolds / abstract.json
Last active December 15, 2023 23:14
Wikimedia Enterprise API — Results for article "Squirrel" @ 2023 Dec 15. On-demand API response for Article Body, both Wikitext and HTML (provided exclusively by Wikimedia Enterprise), Abstract, Short Description fields, and beta endpoint resp for Infobox & article body Sections. https://enterprise.wikimedia.com
"abstract": " Squirrels are members of the family Sciuridae, a family that includes small or medium-size rodents. The squirrel family includes tree squirrels, ground squirrels, and flying squirrels. Squirrels are indigenous to the Americas, Eurasia, and Africa, and were introduced by humans to Australia. The earliest known fossilized squirrels date from the Eocene epoch, and among other living rodent families, the squirrels are most closely related to the mountain beaver and to the dormice.",
@chuckreynolds
chuckreynolds / abstract.json
Created December 15, 2023 22:34
Wikimedia Enterprise API — Results for article "Squirrel
"abstract": " Squirrels are members of the family Sciuridae, a family that includes small or medium-size rodents. The squirrel family includes tree squirrels, ground squirrels, and flying squirrels. Squirrels are indigenous to the Americas, Eurasia, and Africa, and were introduced by humans to Australia. The earliest known fossilized squirrels date from the Eocene epoch, and among other living rodent families, the squirrels are most closely related to the mountain beaver and to the dormice.",
@chuckreynolds
chuckreynolds / wordpress-remove-block-suggestions.php
Created October 7, 2022 17:30
WordPress Remove Block Suggestions when viewing the Block Directory in WP Admin.
// Remove Block Suggestions in wp-admin Block Directory
function chuckdev_remove_block_directory() {
wp_add_inline_script(
'wp-block-editor',
"wp.domReady( () => wp.plugins.unregisterPlugin( 'block-directory' ) )"
);
}
add_action( 'admin_enqueue_scripts', 'chuckdev_remove_block_directory' );
@chuckreynolds
chuckreynolds / wikimedia-enterprise-auth-postman-prerequest.js
Created January 20, 2022 00:34
Postman Collection Pre-Request script to get access token for Wikimedia Enterprise Auth
const wmeAuthUrl = 'https://auth.enterprise.wikimedia.com/v1/login';
const wmeUsername = pm.collectionVariables.get("wmeUsername");
const wmePassword = pm.collectionVariables.get("wmePassword");
const getTokenRequest = {
method: 'POST',
url: wmeAuthUrl,
header: 'Content-Type:application/json',
body: {
mode: 'application/json',
@chuckreynolds
chuckreynolds / twitch-helix-oauth2-postman-prerequest.js
Last active January 8, 2022 02:06
Postman Pre-Request script to get access token for Twitch OAuth2
/*
* Twitch Helix OAuth2 Postman Pre-Request Script
* @see https://dev.twitch.tv/docs/authentication#registration
* @see https://learning.postman.com/docs/writing-scripts/pre-request-scripts/
*/
const authUrl = 'https://id.twitch.tv/oauth2/token';
const clientId = pm.collectionVariables.get('clientId');
const clientSecret = pm.collectionVariables.get('clientSecret');
@chuckreynolds
chuckreynolds / nodejs-github-webhook-webservice.md
Created October 21, 2019 23:56
How to Use Node.js and Github Webhooks to Keep Remote Projects in Sync - works for public repos only. Just storing this here for reference.
client.on('message', (channel, tags, message, self) => {
if(self) return;
const { badges, 'badge-info': badgeInfo } = tags;
let isSubscriber = false;
let monthsSubbed = -1;
if(badges) {
isSubscriber = badges.subscriber || badges.founder;
if(isSubscriber) {
monthsSubbed = badgeInfo.subscriber || badgeInfo.founder;
}