Computer Programming

Yes, a bit specific, but I need to store some links!

Developing admin-ajax.php Handlers with PHPUnit and Curl (WordPress WP)

The typical way I've made AJAX handlers that hook into admin-ajax.php is with Firebug and little bits of Javascript code to exercise the REST API. The problem with this is that you lose all the development code. This note shows how to use PHPUnit to write your code as tests, and develop the REST API using something like test driven development (TDD).

WordPress: How to use get_shortcode_regex()

get_shortcode_regex() (GSR() from now on) is used to parse shortcodes from a post's text.

I was writing a filter to take the post text, parse the shortcodes, and modify them by adding an "id" parameter.

After I spent some time writing a regex to parse the shortcodes, I discovered GSR(). GSR() was better and more complete.

Now I just had to learn to use it - and there weren't any docs.

Let's Review How to Use Shortcodes

You've basically got five ways to use shortcodes:

[[fe-escape]]
[[fe-escape] ...

Re: Destructured Objects as Parameters

Re: https://css-tricks.com/new-favorite-es6-toy-destructured-objects-parameters/#more-244951

Since the comments were closed, I'm noting here, that Python figured this out a while back.

Function parameters start with required positional parameters, followed by optional positional parameters, followed by named parameters.

def fun(a, b, c=10, **kwargs):

In JS this would be:

function fun(a, b, c, obj) {
    c = (c === undefined ?

Faster Mobile Web Apps with Offline-First

https://nolanlawson.com/2016/10/13/progressive-enhancement-isnt-dead-but-it-smells-funny/

Makes me want to re-revive sf-active-js, which had some caching features to let you flip through headlines quickly.

The trick was to decouple retrieving data from the network, from drawing data to the screen. The screen has to keep polling the local data-sync service rather than the network.

What Many Other Books Don't Tell You about CSS

CSS

A lot of other books out there don't discuss selector specificity and the Cascade in enough detail. They don't talk about ways to organize your code, either. When you read this ebook, it'll make sense.

Python-Fu: Rename a file to match a caption

This script renames a directory full of XCF files so that the filename is derived from the first line of a layer named "caption".

I wrote this to enhance the file names for Koya Hand Crafts.

Email Cloaking Script (Email Hiding)

Originally from: 2007-09-26 15:17:44 -0700

Here's a perl script that takes email addresses as arguments, and returns javascript code that hides your email address from web spiders. The email address is also linked so it's clickable.

CSS Font and Style Switcher (jQuery)

This is a bit of code to add a floating box to your page that will let you switch stylesheets and fonts. I wrote it specifically to start trying out different "themes" and fonts, not to allow the end user to do these things. But the client will be using it to preview.

It's not fully parameterized, nor does it generate the HTML for the selects, so you'll need to hack the code.

Contemporary PHP Coding

Some of the notes here are really old, and use old practices. This is a rundown of contemporary practices circa 2016. I'm a few years behind, so, it's more like 2013 practices, but, there are still tutorials being written that don't use these better techniques. Get with the times.

Don't set up Apache. Instead use "php -S localhost:8000" to start a local server from the shell. The docroot will be in the current directory, and error logs go to the screen.

Python-Fu: Save different versions of an XCF file (branded, watermarked, thumbnail)

It took forever, but I finally hunkered down and learned some Python-Fu. It's really nice, especially being able to use Python's libraries, but, like programming Gimp in Scheme, it was kind of hard.

The most important thing, which I learned only after working at it three hours, is to use the "Browser..." tool in the Python console (in Gimp). This helps you find predefined commands to do all the expected operations. Use the "Apply" button to paste an example into the console.

Adventures in Screenshotting

I'm having one of those mornings, where nothing works quite right.

LibreOffice is a Faster Tool to Load Excel Data into an SQL Database

We wanted to know how Bernie Sanders did in several electoral districts.

What are our data sources.

There are two public databases that can help us discover these vote totals. One is the election results broken down by voting precinct. The other is a database that maps the precinct numbers to district numbers.

lavote.net's precinct reports

The Los Angeles County Registrar Recorder publshes vote tallies aggregated by precinct. The problem is, these are reports, not raw or cooked data.

PHP Frameworks get weird

I was getting the itch to write a small web application and started looking around. I had played with Laravel a while back, but it's just a little too large. I wanted to deploy cheaply on my slow server.

The features I wanted were: REST API support, OAuth (client), Routes, User Auth

Phalcon was the most interesting. It's written in C as an extension, and is fast. It does mostly traditional, Laravel style MVC. It can do REST APIs as well, but the example isn't good. It needs some more code to do REST right. Being compiled it is fast. The features resemble Laravel and Twig.

WordPress Multisite Problems with Vagrant

I had some problems setting up Multisite on WP with the Vagrant environment.

The big issue is that the the domains and URLs need to be set just right. This is a little more complicated than a typical server setup because dev setups usually take shortcuts on DNS.

You need to fix the domain names in all the locations where they're resolved.

First, set up DNS. Set up domain names for all the domains you're going to develop, but use local names like "foobar.lo" instead of "foobar.com". They can all point to the IP address your dev server exposes via Vagrant, usually 192.168.33.10.

A Small Library to Change WordPress Options (useful for E2E WP Testing with Selenium)

I was messing with E2E testing of WordPress, and it was going okay, but I hit a wall when I needed to mess with one of the options, to turn of a CAPTCHA. You don't want to use deal with CAPTCHAs during a test, at least not every test. There may be some where you want to see the CAPTCHA.

The right way to do this is to flip options on and off.

Syndicate content