Skip to content

Instantly share code, notes, and snippets.

View kjbrum's full-sized avatar
🤘

Kyle Brumm kjbrum

🤘
View GitHub Profile
@kjbrum
kjbrum / inViewport.js
Last active March 15, 2017 20:10
Test if an element is in the viewport.
var inViewport = function(el, side) {
var win = window;
var viewport = {
top: win.scrollY,
left: win.scrollX
};
viewport.right = viewport.left + win.outerWidth;
viewport.bottom = viewport.top + win.outerHeight;
@kjbrum
kjbrum / responsive_media.scss
Created June 16, 2016 17:20
Make embedded media elements responsive.
.video-wrapper {
position: relative;
padding-bottom: 56.25%;
height: 0;
iframe,
object,
embed {
position: absolute;
top: 0;
@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)';
@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 / 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)

#!/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 / 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 / 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 / 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 / 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