Skip to content

Instantly share code, notes, and snippets.

@kjbrum
kjbrum / php-switcher.sh
Last active March 21, 2018 19:14
Easily switch between PHP versions with Homebrew and Laravel Valet.
#!/usr/bin/env bash
# PHP Switcher
# Easily switch between PHP versions with Homebrew and Laravel Valet.
# Copyright (C) Kyle Brumm <http://kylebrumm.com>
#
# Credit/Resources:
# https://gist.github.com/bgarrant/b9a2f7fb8ff06c9a45086359ded7a95e
# https://raw.githubusercontent.com/conradkleinespel/sphp-osx/master/sphp
@kjbrum
kjbrum / gitrinse.md
Last active September 29, 2022 13:16 — forked from nicktoumpelis/repo-rinse.sh
Clean and reset a Git repo and/or it's submodules.

Clean and reset a Git repo and/or it's submodules

Remove untracked/ignored files/directories and uncommitted changes.

Repo and submodules

$ git clean -xfd
$ git submodule foreach --recursive git clean -xfd
$ git reset --hard
@kjbrum
kjbrum / letsencrypt-serverpilot.md
Last active January 23, 2018 16:28
Installing Let's Encrypt with Certbot on DigitalOcean w/ServerPilot

Let's Encrypt on DigitalOcean w/ServerPilot

  • APP_NAME - ServerPilot App Name (serverpilot/apps/example)
  • DOMAIN_NAME - Domain name (example.com)

1. SSH as root into the server

$ ssh root@SERVER_IP_ADDRESS
@kjbrum
kjbrum / wordpress-ajax.md
Last active May 29, 2018 20:50
Quick example of how to use AJAX with WordPress.

WordPress Ajax

Template

<form class="form">
    <label for="password">Password</label>
    <input name="password" type="password">
    <?php wp_nonce_field( 'password_check_form' ); ?>
@kjbrum
kjbrum / dewidow.php
Last active October 27, 2017 20:02
Make sure a string never has a widow.
<?php
/**
* Make sure a string never has a widow.
*
* @param string $text The string to dewidow
* @param int $min_words Minimum number of words to dewidow
* @return string The dewidowed string
*/
function dewidow( $text = '', $min_words = 3 ) {
$return = trim( $text );
@kjbrum
kjbrum / theme_include.php
Last active August 22, 2018 16:39
Include a theme partial and pass data to it.
<?php
/**
* Include a theme partial and pass data to it.
*
* @param string $partial Partial file to include
* @param array $data Data to pass to the partial
* @return void
*/
function theme_include( $partial, $data = [] ) {
if ( ! strstr( $partial, '.php' ) ) {
@kjbrum
kjbrum / magento2-bootstrap.sh
Last active August 2, 2018 19:52
Vagrant files for Magento 2 (Credit: https://github.com/klierik/magento2-vagrant)
#!/usr/bin/env bash
echo "=================================================="
echo "Setting up Magento 2 Vagrant box with..."
echo "- Ubuntu 14.04 LTS"
echo "- Apache 2.4"
echo "- PHP 7.0"
echo "- MySQL 5.6(manual)"
echo "- Git"
@kjbrum
kjbrum / cubic-bezier-curves.md
Created February 14, 2017 03:28
Cubic Bezier Curves

In-Out Bounce

cubic-bezier(0.68, -0.55, 0.265, 1.55)

In-Out Cubic

cubic-bezier(0.645, 0.045, 0.355, 1)

@kjbrum
kjbrum / r_search_array.php
Last active May 8, 2018 18:48
Check if an array key/val(optional) exist in an array and optionally return the values
<?php
/**
* Check if an array key/val(optional) exist in an array and optionally return the values
*
* @param array $array The array to check for the key/val
* @param string $key Key to search for
* @param string $value Value to search for
* @return bool
*/
function r_search_array($array, $key, $value=null, $return=false) {
@kjbrum
kjbrum / parallax.js
Last active July 4, 2018 04:03
Easy parallax with a few lines of JavaScript.
// Initialize Parallax
var parallax_el = document.querySelectorAll('[data-parallax]');
var speed = 0.25;
function updateElementPosition() {
[].slice.call(parallax_el).forEach(function(el,i) {
var speed = el.dataset.parallax || 0.25;
var offset = (-(window.pageYOffset - el.offsetTop) * speed);
el.style.transform = 'translate3d(0, ' + offset + 'px, 0)';
el.style.OTransform = 'translate3d(0, ' + offset + 'px, 0)';