Skip to content

Instantly share code, notes, and snippets.

View dgowrie's full-sized avatar
🤘

David Gowrie dgowrie

🤘
View GitHub Profile
@dgowrie
dgowrie / clean_code.md
Created July 19, 2021 21:16 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@dgowrie
dgowrie / keybindings.json
Created December 2, 2020 22:11
VS Code user key bindings
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "ctrl+cmd+g",
"command": "editor.action.selectHighlights",
"when": "editorFocus"
},
{
"key": "shift+cmd+l",
"command": "-editor.action.selectHighlights",
@dgowrie
dgowrie / git-fuzzy-find-branch.sh
Created April 3, 2020 15:23
git fuzzy find branch
fbr () {
local branches branch
branches=$(git branch --all --sort=-committerdate | grep -v HEAD) && branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) && git checkout $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
}
@dgowrie
dgowrie / type-the-time
Created January 23, 2020 23:43
Timestamp just the time - Automator quick action applescript
on run {input, parameters}
set theTime to (time string of (current date)) as string
tell application "System Events"
keystroke theTime
end tell
return input
end run
@dgowrie
dgowrie / array-methods-functional.js
Last active September 14, 2019 07:01
Map, Reduce, Filter, chained usage - web dev interview, discussion
const animals = ['cat', 'dog', 'fish'];
const lengths = animals.map(animal => animal.length);
console.log(lengths);
const reducer = (acc, word) => acc + word.length;
const letterCount = animals.reduce(reducer, 0);
console.log(letterCount);
const hasThree = word => word.length === 3;
@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>
@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 / 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 / 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 / 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')