Skip to content

Instantly share code, notes, and snippets.

View dotherightthing's full-sized avatar

Dan Smith dotherightthing

  • Do The Right Thing
  • Wellington, New Zealand
View GitHub Profile
@dotherightthing
dotherightthing / unit-testing-phpunit-cypress.md
Last active October 8, 2019 09:19
[Unit testing: PHPUnit + Cypress]

Unit testing: PHPUnit + Cypress

I've been testing my gallery plugin using local and remote URLs.

This seemed reasonable until I realised that it breaks the release process.

This is because the release needs to test an updated environment, but the environment is only updated by the release. So my tests would pass on local dev, but fail when run through the CI, which could only see the remote URL.

Note: I just remembered that there's actually a way to expose a local URL to other internet users, I didn't try this.

@dotherightthing
dotherightthing / unit-testing-handling-dependencies.md
Last active October 3, 2019 12:54
[Unit testing: Handling dependencies] #quokka #funfunfunction #cypress #mocks #dependencyinjection

Unit Testing: Handling dependencies

I'm already familiar with unit testing, but there are gaps in my knowledge.

I like to test real code, so I have been trying to test some of my custom Gulp modules.

Problem 1: Can't test modules with dependencies

Module:

@dotherightthing
dotherightthing / using-postman-to-test-google-docs-api.md
Last active October 1, 2019 12:52
Using Postman to test Google Docs API

Using Postman to test Google Docs API

1. Get credentials from Google

  1. Using OAuth 2.0 to Access Google APIs > Basic steps

Visit the Google API Console to obtain OAuth 2.0 credentials such as a client ID and client secret that are known to both Google and your application.

  1. Credentials > Create credentials > OAuth client ID > Other
  2. Close the window containing your Client ID and Client Secret
  3. In the Credentials list, click on the name of the new OAuth 2.0 client ID
  4. Click DOWNLOAD JSON
@dotherightthing
dotherightthing / soft-hyphen.md
Created September 30, 2019 23:05
[Soft hyphen] #break
­
@dotherightthing
dotherightthing / camelCaseToSentence.js
Created September 27, 2019 07:17
Convert camelCase to sentence
/**
* Function: camelCaseToSentence
*
* Parameters:
* string - An UpperCamelCase or lowerCamelCase string
*
* Returns:
* A sentence string
* _____________________________________
*/
@dotherightthing
dotherightthing / wordpress-seo.md
Last active September 10, 2019 15:15
[WordPress SEO] #yoast #sitemapxml

WordPress SEO

Meta descriptions

  1. (Yoast) SEO
  2. Search Appearance
  3. Content Types
  4. [Content Type]
  5. Meta description
  6. Insert snippet variable
@dotherightthing
dotherightthing / Post-meta-vs-separate-database-tables.md
Last active April 17, 2025 03:17
[Post meta vs separate database tables] #database #wordpress

Post meta vs separate database tables

An interesting read from Post meta vs separate database tables

If your plugin is going to have A LOT of data, then using the wp_postmeta is NOT a good idea as demonstrated below:

Taking Woocommerce as an example,

In a store with ~30,000 products, say there will be an average of ~40 post meta (attributes and everything) per product, 5 product images per product, which means there will be ~4 image meta for each image:

@dotherightthing
dotherightthing / check-whether-a-string-contains-invisible-characters.md
Created September 7, 2019 05:33
[Check whether a string contains invisible characters] #php
@dotherightthing
dotherightthing / type-declarations.md
Last active September 6, 2019 04:47
[Type declarations] #php #javascript #naturaldocs #phpdocumentor #typescript #typehinting

Type declarations

AKA Type hinting.

Background

I used to use phpDocumentor. It had this nice feature where you could document:

  1. the type of input that was expected
  2. the type of output that was expected
@dotherightthing
dotherightthing / remove-incorrect-authentication-password-from-composer-config.md
Last active September 5, 2019 04:52
[Remove incorrect authentication password from Composer config] #github

Remove incorrect authentication password from Composer config

Background

Whilst migrating my Yeoman dependency install to a bash script (that I could also run later), I inadvertently set my Github OAuth password to the string "process.env.GH_TOKEN".

Error

[UnexpectedValueException]