Skip to content

Instantly share code, notes, and snippets.

View dgowrie's full-sized avatar
🤘

David Gowrie dgowrie

🤘
View GitHub Profile
@dgowrie
dgowrie / unit-test_react-component-with-enzyme.sublime-snippet
Last active September 19, 2018 05:27
Sublime Text Snippet: Unit Test - React Component with Enzyme
<snippet>
<content><![CDATA[
/**
* Boilerplate and "right way to test" examples:
* https://medium.freecodecamp.org/the-right-way-to-test-react-components-548a4736ab22
*/
import React from 'react';
import { mount, shallow } from 'enzyme';
import ${1:${TM_FILENAME/(.+)\..+|.*/$1/:ComponentUnderTest}} from './${1:${TM_FILENAME/(.+)\..+|.*/$1/:ComponentUnderTest}}';
@dgowrie
dgowrie / README.md
Last active December 13, 2018 04:16
SQL queries for WordPress

Just a collection of SQL queries I find useful in WordPress management

@dgowrie
dgowrie / README.md
Last active December 18, 2018 18:30
Accessibility tips and tools

General Web Accessibility tips and tools

HTML Semantics

Good HTML semantics makes for good accessibility. This means using links, buttons, form elements, and labels appropriately, including:

  • <label> element for form controls with appropriate for / htmlFor (React) and id pairings
  • <fieldset> for groups of related inputs
  • <button> elements for UI controls

More info on semantic HTML as basis for accessibility on this MDN article:

@dgowrie
dgowrie / README.md
Last active January 28, 2019 18:26
UI Tests - resilient selectors

UI testing - use data types for selectors

Add data-testid attributes to elements as dedicated UI test selectors that provide context and are resilient to changes.

--

Reasons data-* type selector are recommended and will help avoid brittle tests:

@dgowrie
dgowrie / README.md
Created May 24, 2019 18:39
Organizing media queries in CSS with Sass and BEM

Assumptions:

  1. Using Sass with & ampersand selector, limited nesting, and modular / partials-based file organization
  2. Using BEM convention with limited nesting

Two lines of thought here:

  1. Organize media queries to be "inline" i.e. colocated with the selectors.
  • pro: close to the code, context is clear
  • con: potentially lots of media query declarations scattered throughout the CSS file
@dgowrie
dgowrie / page-template-post-meta.sql
Created June 19, 2019 03:03
SQL query for posts using specific page template in WordPress
SELECT post_title, ID, post_status, post_name
FROM wp_posts p
LEFT JOIN wp_postmeta m
ON p.ID = m.post_id
WHERE (m.meta_key = '_wp_page_template' AND m.meta_value = 'default')
@dgowrie
dgowrie / sql-search-wp-posts.sql
Created June 27, 2019 02:35
SQL query for string in WP posts content
-- Change wp_ to your database prefix
-- Change example.com to your domain
-- Change string to the text you want to search for
SELECT
ID as 'Post ID',
post_title as 'Title',
CONCAT('http://example.com/',post_name) as 'URL'
FROM `wp_posts`
WHERE post_type = 'post'
@dgowrie
dgowrie / sql-update-posts.sql
Created June 28, 2019 22:56
UPDATE string of text like URLs in WordPress posts SQL query
UPDATE wp_posts
SET post_content = replace(post_content, 'Existing string', 'Desired replacement string')
WHERE post_type = 'post'
-- can do a 'dry run' search, if the tool doesn't offer UI (phpMyAdmin does)
SELECT *
FROM wp_posts
AND post_content LIKE '%Existing string%'
@dgowrie
dgowrie / simple-recursion.js
Last active September 7, 2019 05:04
Simple example of recursion - web dev interview, discussion
// e.g. "write a simple function that logs out the factor of a given number"
// input '4' should return '24' since 4 * 3 * 2 * 1 = 24
// input '6' should return '720' etc...
// First, discuss and consider the basic utility of a `while` loop
function factor(number) {
let result = 1;
let count = number;
while (count > 1) {
result *= count;
@dgowrie
dgowrie / index.html
Last active September 14, 2019 07:01
Higher Order Function - Simple Demo, web dev interview, discussion
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="Higher Order Function - Simple Demo">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>