Skip to content

Instantly share code, notes, and snippets.

View a-am's full-sized avatar

Adam Randlett a-am

View GitHub Profile
@a-am
a-am / module.php
Created June 24, 2022 04:16 — forked from daltonrooney/module.php
Clear Craft CMS cache after Entry save event
<?php
use yii\base\Event;
use Craft;
use craft\elements\Entry;
Event::on(
Entry::class,
Entry::EVENT_AFTER_SAVE,
function(ModelEvent $event) {
@a-am
a-am / group-objects-by-property.md
Created February 24, 2021 15:14 — forked from JamieMason/group-objects-by-property.md
Group Array of JavaScript Objects by Key or Property Value

Group Array of JavaScript Objects by Key or Property Value

Implementation

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;
<template>
<div>
<input v-model="emailAddress" type="email" placeholder="your@email.com" />
<button @click="submitForm">{{subscribeText}}</button>
</div>
</template>
<script>
export default {
data() {
return {
@a-am
a-am / simple-pagination.js
Created July 16, 2019 04:52 — forked from kottenator/simple-pagination.js
Simple pagination algorithm
// Implementation in ES6
function pagination(c, m) {
var current = c,
last = m,
delta = 2,
left = current - delta,
right = current + delta + 1,
range = [],
rangeWithDots = [],
l;
(function (m) {
/*
* PHP => moment.js
* Will take a php date format and convert it into a JS format for moment
* http://www.php.net/manual/en/function.date.php
* http://momentjs.com/docs/#/displaying/format/
*/
var formatMap = {
d: 'DD',
D: 'ddd',
@a-am
a-am / PHPtoICS.php
Created July 13, 2016 14:25 — forked from jakebellacera/ICS.php
A convenient script to generate iCalendar (.ics) files on the fly in PHP.
<?php
// Variables used in this script:
// $summary - text title of the event
// $datestart - the starting date (in seconds since unix epoch)
// $dateend - the ending date (in seconds since unix epoch)
// $address - the event's address
// $uri - the URL of the event (add http://)
// $description - text description of the event
// $filename - the name of this file for saving (e.g. my-event-name.ics)
//
@a-am
a-am / db.php
Created May 11, 2016 16:09 — forked from nfourtythree/db.php
Craft Environments Setup
<?php
/**
* Database Configuration
*
* All of your system's database configuration settings go in here.
* You can see a list of the default settings in craft/app/etc/config/defaults/db.php
*/
return array(
@a-am
a-am / toggle-remote-styles.js
Created October 8, 2015 17:53 — forked from gauntface/toggle-remote-styles.js
A book marklet to toggle styles.
javascript:(function(){var styles = document.querySelectorAll('link[rel=\'stylesheet\']'); for (var s = 0; s < styles.length; s++) {styles[s].mediax = styles[s].media;if (styles[s].media === 'only x') { styles[s].media = styles[s].mediax; } else if (styles[s].media !== 'print') {styles[s].media = 'only x';}}})();
{% set bread = craft.entries({ section: 'bread' }).limit(null) %}
{#
# Users with bread on 3 days
#}
{% set users3Days = craft.users({
group: 'customers',
relatedTo: [
'and',
{ targetElement: bread, field: 'breadForMonday' },
@a-am
a-am / jsbin.burut.html
Last active August 29, 2015 14:07 — forked from mojaray2k/jsbin.burut.html
CSS only custom-styled select Todd Parker - Filament Group Inc. How this works: This styles a native select consistently cross-platform with only minimal CSS. The native select is then styled so it is essentially invisible (no appearance, border, bg) leaving only the select's text visible. There is a wrapper around the select that has the majori…
<html>
<head>
<title>Select styles with CSS only</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
background-color: #fff;
font-family: helvetica, sans-serif;
margin: 4% 10%
}