13

Photography – #164

Starbucks mermaid A post shared by @ twwoodward on Mar 8, 2018 at 4:46pm PST #subgenius A post shared by @ twwoodward on Mar 11, 2018 at 12:03pm PDT

13

Follow the Cursor Arrows in Javascript

Matt came up with a really interesting visual idea where arrows follow the cursor. He found this codepen example which was pretty close to what he envisioned (only with pill shapes). The problem was that this version used Babel, jQuery, and Underscore. That’s good if you know all those pieces but less good if you don’t. I don’t. Could I do this with just plain javascript? Make the Boxes First, I didn’t want to cut and paste a whole bunch of divs (or use pug) so I figured javascript should make them. Since I think I’m funny my arrow boxes are in the arrow class and the div they’re inserted before has the id quiver. I’m making 300 boxes in this example and the CSS sets the arrows as background images. Watch the Cursor This bit watches the body element for the mouse move. The cursorFinder piece gets the X and Y coordinates of the mouse. In this case, we’re also spitting it out at the bottom of the page so we can see what’s going on. It’s pretty much from the W3 example. Now that we can see where the mouse is we need to tilt the divs based on where they are and where the mouse is. Tilting the Divs First, we have to get all the arrow […]

Four people wandering up a large sand dune with a blue sky and some clouds.

WordPress Avoid Running save_post Functions on Trashed Posts

This may be one of those things that everyone knows but it was new to me. I’m also duplicating the information I found in the StackOverflow post because I think it’s good to have information in multiple places where it might be found by other people. Additionally, writing the post makes it easy for me to find later when I forget and the act of writing the post helps get it stuck in my own head. With all of that as the lead up . . . A common way to trigger events in WordPress is the save_post action. It runs any time the post is created, published, or updated. What I found out though was that it also runs when you try to delete the post. That makes sense. It is an update and it’s no big deal if the function is relatively small and/or if you’re not trying to get rid of a ton of posts. My current experiment had both a fairly involved function and a couple hundred posts I wanted deleted. Luckily, I found this post on StackOverflow. Now I can set a simple check at the beginning of the function that looks to make sure it’s the right post type (site) and it’s a trashed post. In either of those cases the function gets skipped.

11

Weekly Web Harvest for 2018-03-04

Promisees · Courtesy of ponyfoo.com Inside Einstein’s head – an explorable explanation of relativistic spacetime The Disconnect – Issue One Please Disconnect from the Internet. This is an offline-only magazine of commentary, fiction, and poetry. Just disable your WiFi to view this issue. Rage against the machine: self-driving cars attacked by angry Californians | Technology | The Guardian The two human-on-robot assaults are not the first time San Franciscans have fought back – physically – against robots. In December, the local SPCA animal shelter removed its 400lb Knightscope security robot from the streets around its building amid backlash from residents and the homeless population who complained the robot was harassing them. While most residents simply complained about the robot’s presence, one person reportedly “put a tarp over it, knocked it over and put barbecue sauce on all the sensors”. The Wire, 10 years on: ‘We tore the cover off a city and showed the American dream was dead’ | Television & radio | The Guardian Greek tragedy for the new millennium,” with sclerotic institutions playing the role of callous, indifferent gods AllSides Bias Rating (ABR) – AllSides –ripe for all kinds of issues The AllSides patented bias detection and display technology drives arguably the world’s most effective and up-to-date bias detection engine. It’s powered by a combination of wisdom-of-the-crowd technology […]

07

Google Script – Plain Text

Google Sheets often thinks it’s smarter than you. That’s helpful at times and irritating at other times.1 The Google Form to Sheets path is one place where that can come up repeatedly and in ways that are hard to see. For instance, if you use the Time entry on forms, Google Sheets tries to coerce it into a date structure while leaving you seeing just the time in the sheets view. That leads to weird and unpredictable stuff if you’re trying to use Google Scripts to interact with that cell data based on what you see. For instance, this is data from the time entry field as seen on the sheet side. Note the two places you might expect to see truth. Now if we get that same data via Google Script . . . Cell data that you’d expect to just be that time element returns as Sat Dec 30 1899. The time is right though. If you manually change the format of that column to plain text things work . . . but it gets re-set on all subsequent submissions. My solution so far has been the following Google Script set to fire on every new form submission. In my case, I’m changing the format of the latest entry in the spreadsheet in columns F and G to […]

06

jQuery & the WordPress Rest API – 1st Image as Background

Ordinarily it’s pretty easy to get the featured image from the WordPress API. You just have to remember to add the _embed element like so https://bionicteaching.com/wp-json/wp/v2/posts?_embed But maybe there’s some reason you don’t want to set the featured image but want to get the first image from the body of the post. This chunk of so very uncool jQuery gets the JSON data and finds the first img src URL in the post body. I’ve gone over the basic pieces previously so here’s the portion that differs. It’s just regex searching for anything with the img src pattern and spitting back out the URL. See the Pen antonio – jquery demo by Tom (@twwoodward) on CodePen.

06

Weather API + Google Sheets

I have many little robot scripts busy saving data to Google Sheets. Here’s one I made based on a little comment from one of my kid’s teachers. It goes to a very kind URL that returns the data structure at the bottom of the page. http://api.wunderground.com/api/YOUR_API_KEY/conditions/q/VA/Richmond.json It’s a pretty nice starter script for anyone wanting to play with an API and Google Scripts. The full Google Script is below and I’ve tried to comment it up pretty thoroughly. I’ll also break it down below for those of you who want to play at home. Get the Data The first variable ‘url’ is the API endpoint we’re getting the data from. Where it says YOUR_API_KEY, you should put your API Key. I recall early on trying to do this stuff I’d get confused when people did different things to indicate that an API Key should go somewhere. People would put it in quotes or surrounded by asterisk or something else. I’d end up confused about what should go there because I had no baseline to judge this against. It’s fairly obvious now but I haven’t forgotten that feeling of basic confusion. Sometimes it helps to be very basic. Google has a nice UrlFetchApp class that you use in Google Script instead of fetch like you’d use in vanilla javascript land. Since […]

04

Weekly Web Harvest for 2018-02-25

Mitigation of Shock: 6 Steps (with Pictures) The project transports you into a London flat, thirty five years in the future. A future where extreme weather has caused global supply chains to falter. Everyday items are often either out of stock or have become expensive luxuries. In response, living space has been increasingly given over to experimental forms of domestic agriculture. Food computers have been improvised from the detritus of a technological utopia that never quite arrived. apache/incubator-superset: Apache Superset (incubating) is a modern, enterprise-ready business intelligence web application h/t Downes Plotting the Course Through Charted Waters Heat maps, stacked area plots, mosaic plots, choropleths – oh my! There are so many different ways to visually convey relationships and patterns in data! In this workshop on data visualization literacy, you’ll learn to recognize many popular types of charts and how to glean insights from them. The Appendix contains some examples of data visualization as visual essays and it also includes links to resources for learning how to create your own.

01

Google Form to Google Sheets to Vue Website

When @cogdog & @twoodwar Were Building Websites From Google Spreadsheets Years Ago https://t.co/Im7oCecvpg — Keegan?Long-Wheeler (@KeeganSLW) February 28, 2018 This post from Keegan kicked of this demo.1 The goal is to create a pretty flexible template for using Google Forms to Google Sheets to simple website. I opted to do this one in Vue but may get around to doing it in plain JS or jquery if time allows. The first thing you need to do is make the form and put in some entries. You’ll be happier if your form prompts aren’t super long. Make them readable just keep them concise.2 Once you’ve made a few entries so you have some data to work with, publish your spreadsheet as HTML. File>Publish to the Web. Click OK and what not. Don’t bother going to that link as Google has made that a fake promise. You just need the ID of the document in your current view. It’ll be something painful like 12WsyLvtfIPJkCXgEXsRkrI6dS0_K6brJikZqzkQa8TU and is visible in the URL after the /d/ but before the /edit. You can see the spreadsheet here. It doesn’t really matter but !full transparency! With that ID in hand, you want to go to a URL like so. You could manipulate the number in the URL to hit different pages in the spreadsheet. https://spreadsheets.google.com/feeds/list/12WsyLvtfIPJkCXgEXsRkrI6dS0_K6brJikZqzkQa8TU/1/public/values?alt=json You should […]

26

Add Custom Field to WordPress API & Filter

I found myself in a strange situation where I needed to know if a page had a child. Natively the WP API lets you know if a page has a parent but not the reverse. First I had to write a function that writes some data to a custom field if a page has a child. Then I started writing this post and realized I needed to do the reverse and now I’ve written a function that writes data to a parent when the child is created. Now that I had the data being written to the custom field, I needed to make that data visible in the WP REST API. Luckily, Jeff put up a snippet for that not too long ago. Now I also wanted to be able to return data based on the contents of the has_children field. This filter1 does that. Now a URL like the one below will give me pages with children but without parents. /wp-json/wp/v2/pages?_embed&per_page=30&has_children=1&parent=0 This will help me make a fairly large menu structure more manageable and I figured having something like this all in one place might help someone else. 1 I usually call things ‘chunks’ of code but I’m trying to improve my vocab.