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
Last active December 5, 2023 05:19
Craft CMS Videos Plugin GQL Setup
<?php
namespace modules;
use Craft;
use yii\base\Event;
use craft\events\DefineGqlTypeFieldsEvent;
use craft\gql\TypeManager;
use GraphQL\Type\Definition\Type;
use modules\types\VideoGqlType;
@a-am
a-am / .env
Created July 25, 2022 20:17
How to execute mysqldump locally using DBngin and Craft CMS
#DB Backup Restore *LOCAL ONLY*
#You can access other DB variables to add to the command. EX: {server}, {user}, {port}…
LOCAL_DB_BIN="/Users/Shared/DBngin/mysql/8.0.27/bin/"
BACKUP_COMMAND="${LOCAL_DB_BIN}mysqldump -h {server} -u {user} --port {port} --add-drop-table --comments --create-options --dump-date --no-autocommit --routines --set-charset --triggers --single-transaction --no-data --result-file=\"{file}\" {database} && ${LOCAL_DB_BIN}mysqldump -h {server} -u {user} --port {port} --add-drop-table --comments --create-options --dump-date --no-autocommit --routines --set-charset --triggers --no-create-info --ignore-table={database}.assetindexdata --ignore-table={database}.assettransformindex --ignore-table={database}.cache --ignore-table={database}.sessions --ignore-table={database}.templatecaches --ignore-table={database}.templatecachecriteria --ignore-table={database}.templatecacheelements --ignore-table={database}.templatecachequeries {database} >> \"{file}\""
RESET_COMMAND="${LOCAL_DB_BIN}mysql -h {s
@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;
@a-am
a-am / craft3_syntax_list.md
Last active January 23, 2018 01:32
Collection of syntax changes for CraftCMS 3

REQUEST

Craft::$app->getRequest()
Craft::$app->getRequest()->getAcceptsJson()
$this->asJson();

CURRENT USER

Craft::$app-&gt;getUser()-&gt;getIdentity()
(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(