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 / current-weather-openweathermap.js
Created March 12, 2019 08:05
Open Weather Map API Current Weather, node js, javascript, axios
// API specific settings https://openweathermap.org/current
const API_URL = 'https://api.openweathermap.org/data/2.5/weather';
const API_KEY = '';
const LOCATION_CODE = '';
const FULL_API_URL = `${API_CURRENT_URL}?id=${LOCATION_CODE}&appid=${API_KEY}`;
axios
.get(FULL_API_CURRENT_URL)
.then(response => {
// Assign vars to response data
@chuckreynolds
chuckreynolds / oxford.resp.json
Last active April 20, 2019 20:19
sample oxford dict api vs response to learn to loop through
{
"id": "average",
"metadata": {
"operation": "retrieve",
"provider": "Oxford University Press",
"schema": "RetrieveEntry"
},
"results": [
{
"id": "average",
@chuckreynolds
chuckreynolds / wordpress-get-child-page-ids.php
Created February 5, 2019 11:43
Gotta be a better way to get an array of Child Page IDs than this. WordPress
<?php
// basic idea here is a common function to pass a parent page ID
// and get back an array of it and its child page IDs only
function getChildPageIDs( $id ) {
$child_pages = get_pages('child_of='.$id);
$ids_to_remove = array($id); // we want to remove parent id too
foreach($child_pages as $child) {
array_push($ids_to_remove,$child->ID); // for every child add the id into array
}
@chuckreynolds
chuckreynolds / remove-jquery-migrate-wordpress.php
Created January 28, 2019 02:17
Removes jQuery Migrate script from WordPress. Reason: modern browsers don't need this anymore.
<?php
/**
* Remove jQuery Migrate script
*/
function ryno_remove_jquery_migrate( $scripts ) {
if ( isset( $scripts->registered['jquery'] ) ) {
$script = $scripts->registered['jquery'];
if ( $script->deps ) { // Check whether the script has any dependencies
$script->deps = array_diff( $script->deps, array( 'jquery-migrate' ) );
@chuckreynolds
chuckreynolds / fetch-dadjoke-api.php
Last active August 8, 2019 13:33
Fetches a dad joke from icanhazdadjoke.com
<?php
$url = 'https://icanhazdadjoke.com/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Accept:text/plain']);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
echo $data;
@chuckreynolds
chuckreynolds / json-discord-embeds-twitch.json
Last active August 27, 2020 21:36
JSON embed scripts for Discord webhooks via IFTTT. Allowed avatar_url to be dictated by Discord in the webhook config.
{
"username":"twitch.tv/{{ChannelName}} [via RynoBot]",
"content":"@everyone {{ChannelName}} just went LIVE on Twitch! See you in chat! clintusHYPE",
"embeds":[
{
"title":"{{ChannelUrl}}",
"url":"{{ChannelUrl}}",
"color":6570404,
"thumbnail":{
"url":"https://static-cdn.jtvnw.net/jtv_user_pictures/b26daa03-975b-4a5d-9dea-a7fe9505a63f-profile_image-300x300.png"
@chuckreynolds
chuckreynolds / shopify-products-json-async-await.html
Created June 15, 2018 03:13
Vanilla Javascript fetch Shopify Products JSON with Async Await. Built as a text case for something. Just change the domain in line 17 to whatever shopify domain. Display is just basic for display purposes. Comments / code review welcome.
<html>
<head>
<style>
.wrapper {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(200px, 220px));
grid-gap: 20px;
}
.box {
background-color: #ebebeb;
@chuckreynolds
chuckreynolds / affiliate-links.md
Last active March 7, 2024 23:45
Chuck's Affiliate links storage
Verifying that "chuckreynolds.id" is my Blockstack ID. https://onename.com/chuckreynolds
@chuckreynolds
chuckreynolds / sample-wordpress-options-cache.php
Created September 18, 2017 21:04
Sample WordPress options with time-based cache flag
<?php
function get_twitter_followers() {
$ttl = 2 * HOUR_IN_SECONDS;
$cache = get_option( 'my_twitter_followers' );
if ( empty( $cache['timeout'] ) || $cache['timeout'] < time() ) {
$followers = wp_remote_get( ... );
$cache = array(
'count' => $followers,