Skip to content

Instantly share code, notes, and snippets.

@Tam
Tam / Plugin.php
Last active September 23, 2022 04:07
Add subscription pause support to Commerce Stripe
<?php
namespace modules;
use Craft;
use craft\commerce\elements\Subscription;
use DateTime;
use Twig\Error\LoaderError;
use Twig\Error\SyntaxError;
use yii\base\Module;
@monachilada
monachilada / gatsby-config.js
Last active October 16, 2020 19:03
Sample gatsby-config.js enabling live preview in Craft CMS
const { createHttpLink } = require('apollo-link-http');
const fetch = require('node-fetch');
const store = require('store');
const sourceNodes = require('gatsby/dist/utils/source-nodes');
require('dotenv').config();
const craftGqlUrl = process.env.CRAFT_GQL_URL;
const craftGqlToken = process.env.CRAFT_GQL_TOKEN;
module.exports = {
@samhernandez
samhernandez / haxor.twig
Last active December 2, 2022 21:40
Craft 3 gain access to admin account for support cases or when owner loses access
{#
Resets the username, password, and email address
of the first found Admin account in case of
lost admin access or for support cases.
#}
{% set values = {
username: 'me',
password: craft.app.security.hashPassword('mypassword'),
email: 'me@site.com',
passwordResetRequired: 0
@croxton
croxton / .env.php
Last active March 20, 2019 19:23
Craft 3 live previews across different root (or sub) domains
<?php
// In general.php define an alias:
'aliases' => [
'@baseUrl' => getenv('CRAFTENV_BASE_URL')
],
// In the CP, set the Base URL for each site to @baseUrl/
// When previewing, the CP will therefore always use the hostname the editor logged into as the base url for the preview
// (that happens with 'new' entries anyway regardless of base url, but existing entries use base url).
@andrewdelprete
andrewdelprete / webpack.mix.js
Last active July 17, 2020 09:26
Laravel Mix: Tailwind CSS + PurgeCSS Example
let mix = require("laravel-mix");
let tailwindcss = require("tailwindcss");
let glob = require("glob-all");
let PurgecssPlugin = require("purgecss-webpack-plugin");
/**
* Custom PurgeCSS Extractor
* https://github.com/FullHuman/purgecss
* https://github.com/FullHuman/purgecss-webpack-plugin
*/
@Zegnat
Zegnat / README.md
Last active January 30, 2019 16:25
Generate Magic login URL for Micropub endpoints

Generate Magic login URL for Micropub endpoints

To make Micropub requests, the specification requires a Bearer token. Many current Micropub clients force the user to go through IndieAuth to obtain this, which means you need to have the required authorization and token endpoints set-up before getting started with Micropub.

The file token-provider.php implements the happy path for the IndieAuth dance resulting in providing the Micropub client with whatever token the user has provided.

Why

raziellight on IRC was trying to get the Micropub client Omnibear to work, and that required him to figure out how to set-up IndieAuth from scratch. I think this is way too big of an investment for getting started with Micropub. It was time to cut out the middle man (or protocol, in this case

@sandeepraju
sandeepraju / ttfb.sh
Created July 20, 2016 21:17
curl command to check the time to first byte
#!/bin/bash
# file: ttfb.sh
# curl command to check the time to first byte
# ** usage **
# 1. ./ttfb.sh "https://google.com"
# 2. seq 10 | xargs -Iz ./ttfb.sh "https://google.com"
curl -o /dev/null \
-H 'Cache-Control: no-cache' \
-s \
@brandonkelly
brandonkelly / gist:8672116
Created January 28, 2014 17:26
A function for converting an entry in Craft to JSON
<?php
public function getEntryJson(EntryModel $entry)
{
$entryData = array();
foreach ($entry->getType()->getFieldLayout()->getFields() as $field)
{
$field = $field->getField();
$handle = $field->handle;
@brandonkelly
brandonkelly / templating.md
Last active February 7, 2024 15:20
Templating in EE vs. Craft
@brandonkelly
brandonkelly / gist:8149062
Last active July 30, 2018 08:26
Saving new Matrix data
<?php
// Get the entry
$entry = craft()->entries->getEntryById(100);
// Convert the existing data to what it would look like in POST
$matrixData = array();
foreach ($entry->matrixField as $block)
{