Blog

Firefox Reporting Disqus Hosts as Missing from default-src

Published: April 13, 2020

Tags:

I recently set up a Content Security Policy (CSP) on this website.

My site uses Disqus, so my Content-Security-Policy had their domains whitelisted something like this:

default-src
  'self';

script-src
  'self'
  c.disquscdn.com
  ...;

Adding a Content Security Policy (CSP) with Cloudflare Workers

Published: April 11, 2020

Tags:

I had been interested in adding a Content Security Policy (CSP) to this website for a while. However, the site is built with Jekyll and hosted on GitHub pages, which doesn’t allow you to set custom HTTP response headers such as Content-Security-Policy1. I did a bit of research and found it would be possible to add them through Cloudflare (which I use as a CDN / DNS provider) via their “Cloudflare Workers” feature. In this post I want to walk through the setup process.

Diff-ing MySQL and Elasticsearch

Published: April 9, 2020

Tags:

Recently I had to troubleshoot an issue where some products that were expected to be indexed in Elasticsearch were not. The client wasn’t sure which / how many products were missing, so I wrote a script which diffs products stored in MySQL (catalog_product_entity) against the Elasticsearch index. I’ve decided to share the script here in case others find it useful.

Magento Image Cache Storage Requirements

Published: March 5, 2020

Tags:

Recently I’ve been working with a client whose server is running low on disk space. I found that their media/catalog/product folder was 174 GB, 128 GB of which was in media/catalog/product/cache. This seemed like a lot to me, so I did some quick math and realized that the size of their image cache was nearly 3X that of the total size of the source images. This made me curious…what does this ratio look on other Magento installations? I decided to do a little research on this and wanted to share my findings.

Get Lines of Code Changed in git diff Excluding Directory

Published: March 3, 2020

Tags:

Recently I was faced with large amount of code requiring review. I needed to get back to the individual who requested the review with an estimate of how long it would take.

To give an informed estimate, it’s useful to have a sense of how many lines of code have changed. This is generally easy to do with the --shortstat diff option (GitHub also conveniently displays this when looking at a pull request):

$ git diff --shortstat 2.0.0 2.3.0
 209 files changed, 30020 insertions(+), 2531 deletions(-)

However a quick glance at the changeset told me that the majority of the changes were unit test files, which I wasn’t particularly interested in reviewing here (this was a review of 3rd party code). I wanted to figure out how many lines of code had changed, excluding test files.

Render a Category page via a Standalone script in Magento 2

Published: February 5, 2020

Tags:

In this post I’ll share a standalone script that can be used to render a Magento 2 category page programmatically. This script can come in handy when debugging production issues on category pages (e.g. unexpected product set). For example, it can be executed under strace to review files opened, queries sent, and their corresponding results.