Skip to content

Instantly share code, notes, and snippets.

View ben-rogerson's full-sized avatar

Ben Rogerson ben-rogerson

View GitHub Profile
@ben-rogerson
ben-rogerson / debounce.js
Created March 25, 2018 06:39
Cheap Ass Debouncing
let counter = 0
const isTimeToUpdate = (updateRate = 10) => counter++ % updateRate === 0
@ben-rogerson
ben-rogerson / BetterWordPressValetDriver.php
Created May 14, 2018 21:00
Driver to allow correct image proxying with Valet and Wordpress
<?php
class BetterWordPressValetDriver extends BasicValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri
#set ($releaseId = ${execution.to_revision.revision} + '-' + ${execution.id} )
mkdir -p deploy-cache
mkdir -p shared
mkdir -p releases
if [ "${execution.refresh}" = "true" ]; then echo "Removing: deploy-cache" && rm -rf deploy-cache/*; fi
if [ -d "releases/${releaseId}" ] && [ "${execution.refresh}" = "true" ]; then echo "Removing: releases/${releaseId}" && rm -rf releases/${releaseId}; fi
@ben-rogerson
ben-rogerson / equal-columns-in-twig.twig
Created June 14, 2018 05:12
Equal columns in Twig
{% set items = [...] %}
{% set itemsPerColumn = (items|length / 2)|round %}
{% for column in items|batch(itemsPerColumn) %}
<div class="column">
{% for item in column %}
<div class="item">
@ben-rogerson
ben-rogerson / scss.json
Created July 8, 2018 13:12
SCSS Snippits for VSCode
{
// Place your snippets for scss here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
@ben-rogerson
ben-rogerson / base.twig
Last active October 6, 2018 14:14
Craft 3 Templates: Experimenting with Twig Objects as HTML building blocks
{#
# Craft 3 Templates: Experimenting with Twig Objects as HTML building blocks
Ben Rogerson <[email protected]> 2018
This Gist explores a way to create HTML from a formatted TWIG object.
I found it encourages a different way of thinking when writing HTML.
Here's an example that uses the emmet shorthand to create a `<button>` with a `<main>` parent.
@ben-rogerson
ben-rogerson / search.twig
Created October 11, 2018 23:34
How to include search queries into your Craft searches
{% set activeQuery = craft.app.request.getParam('q')|default('') %}
{% set searchResults = activeQuery ?
craft.products({
search: {
query: activeQuery,
subRight: true,
},
order: 'score',
})|merge(
@ben-rogerson
ben-rogerson / search.js
Last active October 18, 2018 19:07
Vue Craft GraphQL Search Component
import Vue from 'vue/dist/vue.esm';
import axios from 'axios';
Vue.config.productionTip = false
// Information needed for connecting to our CraftQL endpoint
const apiToken = '[ADD KEY HERE]';
const apiUrl = '/api';
@ben-rogerson
ben-rogerson / mapping.scss
Last active November 12, 2018 23:01
SASS Mapping Example
// Helper: Get a map item from an object that is a few levels deep
@function map-deep-get($map, $keys...) {
@each $key in $keys {
$map: map-get($map, $key);
}
@return $map;
}
// Define the theme within your project palette
@ben-rogerson
ben-rogerson / base.twig
Last active February 23, 2020 02:31
Config for agency-webpack-mix-config and Craft Twigpack
{# This is the base twig layout file #}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">