Skip to content

Instantly share code, notes, and snippets.

@AugustMiller
AugustMiller / HelpersPlugin.php
Last active February 19, 2019 00:53
Basic asset cache busting plugin for Craft CMS.
<? namespace Craft;
# craft/plugins/helpers/HelpersPlugin.php
class HelpersPlugin extends BasePlugin
{
public function getName()
{
return Craft::t('Helpers');
}
@AugustMiller
AugustMiller / svg-classname.coffee
Last active January 20, 2017 19:50
SVG Classname Utility
getClass = (el) ->
if el.hasAttribute 'class'
el.getAttribute('class').split ' '
else
[]
hasClass = (el, className) ->
-1 < getClass(el).indexOf className
addClass = (el, className) ->
@AugustMiller
AugustMiller / mailgun-html.php
Created November 14, 2016 23:07
Kirby + Mailgun HTML Email service
<? email::$services['mailgun-html'] = function($email) {
if(empty($email->options['key'])) throw new Error('Missing Mailgun API key');
if(empty($email->options['domain'])) throw new Error('Missing Mailgun API domain');
$url = 'https://api.mailgun.net/v2/' . $email->options['domain'] . '/messages';
$auth = base64_encode('api:' . $email->options['key']);
$headers = array(
'Accept: application/json',
@AugustMiller
AugustMiller / Gulpfile.js
Created September 27, 2016 22:06
Craft + Gulp Setup
var gulp = require('gulp'),
gutil = require('gulp-util'),
coffee = require('gulp-coffee'),
coffeeify = require('gulp-coffeeify'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
sass = require('gulp-sass'),
test = require('gulp-if'),
del = require('del'),
rename = require('gulp-rename'),
@AugustMiller
AugustMiller / date-range-query.twig
Created April 24, 2016 23:36
Fetch entries with a custom date field set between two other dates
{% set entriesWithDateInRange = craft.entries({
section: 'section',
type: 'type',
order: 'customDate asc',
customDate: ['and', '>= ' ~ now, '<= ' ~ (now.year + 1)]
}) %}
@AugustMiller
AugustMiller / try_snippet.php
Last active April 4, 2018 12:15
Kirby snippet fallback function
<?php function try_snippet($try, $data = [], $return = false) {
$snippets = kirby::instance()->roots()->snippets();
foreach ( $try as $snippet ) {
$file = $snippets . DS . $snippet . '.php';
if ( f::exists($file) ) {
return tpl::load($file, $data, $return);
} else {
continue;
}
}
@AugustMiller
AugustMiller / image-notifier.coffee
Last active October 1, 2015 18:59
Image Load Notifier
module.exports = class LazyLoad
constructor: (@el, @callback) ->
if @is_loaded() then @after() else @listen()
listen: ->
@el.on 'load', (e) => @after()
is_loaded: ->
@loaded = @el.get(0).complete
@AugustMiller
AugustMiller / field-as-email.php
Created August 28, 2015 18:12
Quickly transform a Kirby email field into a clickable email link
<?php field::$methods['asEmail'] = function($field) {
return html::a('mailto:' . $field->value, $field->value);
};
@AugustMiller
AugustMiller / field-json.php
Created May 18, 2015 04:08
Kirby JSON Field Method
<?php field::$methods['json'] = function($field, $property = null) {
$data = (array)json_decode($field->value);
return ($property && isset($data[$property]) ? $data[$property] : $data);
};
@AugustMiller
AugustMiller / snow.js
Last active August 29, 2015 14:11
Snow Storm!
var Holiday, Snow, Flake;
Snow = function (density, intensity) {
var self = this;
self.flakes = [];
self.options = {
container: $('<div />').attr({'id': 'snow'}).appendTo(document.body),
count: density,
intensity: intensity,