Category: What I Learned

  • A Hike Through the WordPress Database

    Just about everyday, I’m working on and committing code to a repository using Git. This is pretty standard for developers today, and just like any developer, I decided that writing out git status, git add -p, git commit -m..., etc., was just too much work 😂 🤓.

    This lead me to spend several hours putting together some quick Bash scripts (“scripts” sounds waaaaaay cooler than what I actually did). Here are the replacements I’ve made, and if you want to, you can add these to your .bash_aliases, and make sure that’s included in your .bash_profile, included in your PATH, etc. You can see the full gist of the alias commands below.

    The Basics

    These are the simple starters, commands I use all the time:

    • alias gits: is just shorthand that for getting the status of the branch.
    • alias gita: is also shorthand for staging changes in the current branch.
    • alias gitap: just adds the -p flag to the add command so I can step through changes one at time. I try to use this one by default, as I’ll catch things I didn’t mean to change.
    • alias gitco: is shorthand to checkout a branch.
    • alias gitcob: allows me to check out a specified branch, e.g. $ gitcob feature/cool-thing.

    Pretty standard, right?

    The Fun Stuff…

    Ok, here are some more, and where this whole project started to get fun:

    • alias gitcop: is a quick command to check out the previously checkout branch. As I’m usually switching back and forth between a feature branch and a develop this saves keystrokes and cognitive load. I don’t have to think “Which branch am I switching to? What’s the name again?” It just gos to the previous branch. 🤓
    • alias gitmprev: is the same idea as the above. When merging a branch, you are typically checking out a branch, and merging the branch you were on previously into the current branch. Again, no cognitive load, just merging the previous branch.
    • alias gitprettylog: this just gives more detail to the git log command, in a format I like. The main thing here is I don’t have to remember anything that comes after git log in this command. 😎
    • alias gitnah: I’m pretty sure this is from Jeffrey Way over at Laracasts. Just and easy way to clear out what I’ve been working on if I don’t want to keep it.

    The Really Fun Stuff

    These commands are the ones I enjoy the most:

    • alias gitdep: this combines the branch I’m usually deploying to, checks that out, merges the branch I was working on, pushes that deploy branch to our remote repo, and then checks out the previous branch. This six letter command is probably my favorite as both saving keystrokes and getting me back to the branch I was working on. I can’t tell you how many times I’ve forgotten to switch off a non-working branch… 🤦‍♂️
    • gitc: this is a function that replaces the standard commit plus message flag. I can just type gitc "this is what I did..." and I’m good to go.
    • gitcc: like the previous command, this takes in a message, but then formats it to our commit standards, again, so I don’t have to think about it. 😎
    • gitpo: pushes the current branch to the origin… so much nicer than typing out lots of words.

    The Full Gist

    Here’s the full gist if you want to see what it looks like:

    #############################
    # GIT STUFFS
    #############################
    alias gits="git status"
    alias gita="git add ."
    alias gitap="git add -p"
    alias gitco="git checkout"
    alias gitcop="git checkout @{-1}"
    alias gitcob="git checkout -b"
    alias gitmprev="git merge @{-1}"
    alias gitprettylog="git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
    alias gitnah="git reset --hard"
    alias gitdep="git checkout develop; gitmprev; gitpo; gitcop;"
    
    gitc () {
      git commit -m"$1"
    }
    
    gitcc () {
      BRANCH=$(git branch --show-current)
    
      # Which follows this syntax: string/pattern/replacement/global
      # 's/\//(/g' looks for all occurances of `/` and replaces with (
      # 's/-ABC-[0-9]\{4,\}/): $1/g' looks for all occurances of `-ABC-` appended with 4 or more digits and replace them with `: string-passed-in`
      echo $BRANCH | sed -e 's/\//(/g' -e "s/-ABC-[0-9]\{4,\}/): $1/g"
      MESSAGE=`echo $BRANCH | sed -e 's/\//(/g' -e "s/-ABC-[0-9]\{4,\}/): $1/g"`
      
      git commit -m"$MESSAGE"
    }
    
    gitpo () {
      BRANCH=$(git branch --show-current)
      
      git push origin $BRANCH
    }
    

    And that’s it! Nothing super fancy, just more “quality of life” improvements. While figuring some of these out took a couple hours and lots of testing, I’m glad I’ve got a Git workflow down that works for me and is easy to use.

    Have fun!


    Photo by Yancy Min on Unsplash

  • Local PHP and NodeJS Version Control

    When working on projects with your local computer, it’s essential to be able to test new versions of the languages you’re using. Browser JavaScript is fairly straightforward: use the browser, make sure it’s updated, etc.

    However, with server-side languages (like PHP, NodeJS, Python, Go, etc.), there’s a little more nuance. Some systems come with languages installed on them (I tend to work on a Mac), but they usually come with a single version, and there isn’t a UI or straightforward way to update them.

    We tend to have vertualized environments for this kind of thing, but if you’re looking to install and easily switch between local versions versions of a language you’re running, these two repositories might be helpful.

    Note: I’m on a Mac, so these are what I use.

    PHP

    I’ve been using Homebrew PHP for a bit now and really like how easy it is to get, use, and upgrade different PHP versions.

    There are installation instructions in the Github repo, as well as commands for downloading, upgrading, and changing PHP versions. Since those commands are hard to remember, I’ve created a few bash functions and put them in my .bash_aliases file:

    # PHP version management for Homebrew PHP
    # https://github.com/shivammathur/homebrew-php
    phpget () { brew install shivammathur/php/php@"$1" }
    phpswitch () { brew link --overwrite --force shivammathur/php/php@"$1" }
    phpupgrade () { brew upgrade shivammathur/php/php@"$1" }

    Now if I want to switch to a different PHP version, I just type phpswitch 8.2 into my terminal and I’m up and running with 8.2.x.

    This has made testing new PHP features and staying up to date with package requirements easy.

    NodeJS

    Similarly, using Node Version Manager has been a breeze for switching between versions of NodeJS.

    Installation instructions and commands are available in the repo.

    Here are some examples of commands you can use (from the repo):

    $ nvm use 16
    Now using node v16.9.1 (npm v7.21.1)
    
    $ node -v
    v16.9.1
    
    $ nvm install 12
    Now using node v12.22.6 (npm v6.14.5)
    
    $ nvm ls
           v10.23.0
           v12.20.0
           v14.18.1
    ->     v16.15.0
             system
    default -> 12.20.0 (-> v12.20.0)
    node -> stable (-> v16.15.0) (default)
    stable -> 16.15 (-> v16.15.0) (default)
    
    $ nvm ls-remote
    (will output all the versions available to install... too many to list here 🤓)

    Easy as that… and pie 🥧 😋.


    Photo by Ilya Pavlov on Unsplash

  • Setting Up or Resetting My Macbook

    Every now and then, fresh start is a good idea.

    These are some notes and links I’ve accrued from resetting my Macbook a time or two.

    These are just notes and links, they might be non-sensical, if you think I should polish them up, let me know.

    Backup:

    • get RaspberryPi and Linux images
    • SSH keys
    • .dotfiles and user files
    • file folders like Documents, Photos, etc.
    • double check all applications are in the Homebrew installs or accounted for

    Desktop and Screen Savers

    Ok, I’m ready, this is what I do

    Pretty much in this order…

    Remove Startup Chime

    In MacOS Monterey (at least), you can disable this in the System Preference (thank goodness!), otherwise, you can try:

    ###Catalina
    # Disable:
    sudo nvram SystemAudioVolume=%80
    #Enable:
    sudo nvram -d SystemAudioVolume
    
    ###Others
    # Disable
    sudo nvram StartupMute=%01 
    # Enable (why, I don't know)
    sudo nvram StartupMute=%00
    

    Keyboard

    • Key Repeat -> Fast
    • Delay Until Repeat -> Short
    • Disable
      • “Correct spelling automatically”
      • “Capitalize words automatically”
      • “Add period with double-space”
      • “Use smart quotes and dashes”
    • Make Spotlight something crazy

    Application setup

    1. Homebrew: install HB and then brew install everything else
    2. Set up my .dotfiles
    3. Get Fira Font for terminal and VSCode
    4. Oh my zsh and Spaceship prompt
    5. Chrome, set as default, log in should pull over all extensions and bookmarks
    6. Get old SSH keys or ssh key setup
    7. Node Version Manager and install latest version of Node and any other versions I need (current using 10, 12, 16)
    8. Composer global installs
    9. NPM global installs
    10. Install VSCode extensions
    11. Atom One Dark for VSC
    12. Install Logitch Options

    Homebrew Installs

    brew install \\
      4k-video-downloader \\
      alfred \\
      amazon-music \\
      authy \\
      bartender \\
      balenaetcher \\
      bitwarden \\
      boop \\
      cleanmymac \\
      clipy \\
      discord \\
      disk-inventory-x \\
      firefox \\
      fork \\
      google-chrome \\
      insomnia \\
      kindle \\
      lastpass \\
      lens \\
      licecap \\
      local \\
      macdown \\
      mamp \\
      nosql-workbench \\
      notion \\
      obs \\
      obsidian \\
      oracle-jdk \\
      pgadmin4 \\
      postman \\
      rectangle \\
      rocket \\
      screaming-frog-seo-spider \\
      sequel-ace \\
      simplenote \\
      skitch \\
      slack \\
      spotify \\
      tableplus \\
      toggl-track \\
      transmit \\
      tunnelblick \\
      visual-studio-code \\
      vlc \\
      whatsapp \\
      zoom \\
    

    Global NPM Installs

    npm install -g gatsby-cli netlify-cli serverless trash-cli typescript
    

    Global Composer Installs

    composer global require laravel/installer

    VSC Code

    code CLI will need to be installed:

    • Launch VS Code.
    • Open the Command Palette (⇧⌘P) and type ‘shell command’ to find the Shell Command: Install ‘code’ command in PATH command.
    • Restart VSCode
    • Then do the following to get the installed extensions
    Get a list of what I have installed: 
    code --list-extensions | xargs -L 1 echo code --install-extension
    
    Will output something like (copy, paste and hit enter in Terminal)
    code --install-extension aaron-bond.better-comments
    code --install-extension akamud.vscode-theme-onedark
    code --install-extension alexcvzz.vscode-sqlite
    code --install-extension anthonydiametrix.ACF-Snippet
    code --install-extension apollographql.vscode-apollo
    code --install-extension bmewburn.vscode-intelephense-client
    code --install-extension calebporzio.better-phpunit
    code --install-extension dbaeumer.vscode-eslint
    code --install-extension dsznajder.es7-react-js-snippets
    code --install-extension eamodio.gitlens
    code --install-extension EditorConfig.EditorConfig
    code --install-extension esbenp.prettier-vscode
    code --install-extension fabiospampinato.vscode-highlight
    code --install-extension file-icons.file-icons
    code --install-extension GraphQL.vscode-graphql
    code --install-extension hbenl.vscode-mocha-test-adapter
    code --install-extension hbenl.vscode-test-explorer
    code --install-extension ikappas.phpcs
    code --install-extension mariusschulz.yarn-lock-syntax
    code --install-extension mgmcdermott.vscode-language-babel
    code --install-extension mikestead.dotenv
    code --install-extension ms-azuretools.vscode-docker
    code --install-extension ms-python.python
    code --install-extension ms-python.vscode-pylance
    code --install-extension ms-vscode-remote.remote-containers
    code --install-extension ms-vscode.test-adapter-converter
    code --install-extension neilbrayfield.php-docblocker
    code --install-extension nikitaKunevich.snippet-creator
    code --install-extension onecentlin.laravel-blade
    code --install-extension onecentlin.laravel5-snippets
    code --install-extension patbenatar.advanced-new-file
    code --install-extension persoderlind.vscode-phpcbf
    code --install-extension Prisma.prisma
    code --install-extension ryannaddy.laravel-artisan
    code --install-extension sleistner.vscode-fileutils
    code --install-extension streetsidesoftware.code-spell-checker
    code --install-extension tungvn.wordpress-snippet
    code --install-extension wix.vscode-import-cost
    code --install-extension wordpresstoolbox.wordpress-toolbox
    code --install-extension xabikos.JavaScriptSnippets
    code --install-extension xdebug.php-debug
    
    

    Misc…

    Chrome: Sign into accounts, make sure to open preferences, and “On startup” should be set to “Continue where you left off”.

    Setup, PHPCS and Formatting

    intellij idea – Code reformatting on save in PhpStorm or other jetbrains ide – Stack Overflow

    PHP CodeSniffer and Code Formatting

    • SSH Keys to Strattic Code
    • Jira integration?
    • Set up AWS CLI with account and aws configure --profile strattic-dev it.
    • CleanMyMac license from old computer
    • Transmit license from old computer

    Third party mouse issues: https://www.isiko.de/how-to-disable/

    Connecting iMessage from iPhone: https://support.apple.com/en-us/HT208386


    Factory Reset

    Dev Setup resources:

    Ubuntu


    laptop computer 2006 to current” by elizabeth.hargis is marked with Public Domain Mark 1.0.

  • Wait, wuuut? Where did my CMS go?!

    Static, headless, decoupled, Jamstack, serverless (geez, are there any more names for this stuff?!) sites have already made their way into the mainstream of WordPress and other CMS development. While these sites offer speed, scalability, and security, there are also inherent pitfalls and “gotchas” to be aware of when building in this ways for WordPress and other CMS platforms. We’ll define some terms, talk about how to frame the issues of working in this way, and look at several options for building out reliable and resilient solutions for customers and clients in this area.

    (more…)
  • An Ideal WordPress Workflow Development & Deployment Workflow

    I know the title is a mouthful, but, this was a lot of fun to put together 🤓…

    This talk was for Certified Fresh Events (CFE.dev), and this was the abstract:

    At over 40% of the web, WordPress maintains a massive footprint on the Internet. While this platform, with its 20+ years of code, can easily be dreaded, misunderstood, and dismissed as antiquated, WordPress continues to evolve with the latest JavaScript technologies, is used and is beloved by marketers and enterprises to manage their content (that is, there is a lot of capital behind this CMS!). In this talk we’ll cover what you need to know about WordPress code, database, and file structure, as well as a development and deployment workflow that will serve you well in the headless/static ecosystem, and show you how to avoid common pitfalls of mixed up code and overwritten production databases.

    From CFE.dev
    (more…)