Skip to content

Instantly share code, notes, and snippets.

@brandonkelly
brandonkelly / cherrypath.php
Created June 8, 2024 13:58
cherrypath: git-cherry filtered by path
#!/usr/bin/env php
<?php
// -----------------------------------------------------------------------------
// Usage: `cherrypath.php <upstream> <head> <path>`
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Runs `git cherry -v <upstream> <head>` and filters the output
// to only include SHAs where <path> was modified.
// -----------------------------------------------------------------------------
@brandonkelly
brandonkelly / keybase.md
Created January 18, 2022 13:06
keybase.md

Keybase proof

I hereby claim:

  • I am brandonkelly on github.
  • I am brandonkelly (https://keybase.io/brandonkelly) on keybase.
  • I have a public key ASBSTBHBxc0E6qGHlzL0iNPFzO-j9rWbFHyjoGuYIxhbygo

To claim this, I am signing this object:

@brandonkelly
brandonkelly / LogTarget.php
Last active January 15, 2021 14:39
How to capture DB query logs in Yii2
<?php
namespace foo\bar;
use yii\log\Target;
/**
* Define a LogTarget class that only collects the log messages, but never flushes them out anywhere
*/
class LogTarget extends Target
{
@brandonkelly
brandonkelly / Module.php
Last active April 11, 2020 23:16
Custom Preview Target for Craft 3.2
<?php
// -- modules/Module.php --
namespace modules;
use Craft;
use craft\base\Element;
use craft\elements\Entry;
use craft\events\RegisterPreviewTargetsEvent;
@brandonkelly
brandonkelly / comparisons.md
Last active February 13, 2017 14:30
Craft Benchmarks

Test Info

  • Hardware: 2016 MacBook Pro w/ 2.9 GHz Intel Core i7, 16 GB 2133 MHz LPDDR3
  • MAMP Pro 4.1
  • Nginx 1.11.4
  • MySQL 5.6.34
  • PHP 5.6.28 / 7.1.0 (CGI mode, OPcache enabled)
  • ApacheBench 2.3
  • Craft CMS 2.6.2958 / 3.0.0-beta.1
<?php
namespace Craft;
class CompatibilityPlugin extends BasePlugin
{
function getName()
{
return Craft::t('Browser Compatibility');
}
<?php
namespace Craft;
class CompatibilityPlugin extends BasePlugin
{
function getName()
{
return Craft::t('Browser Compatibility');
}
@brandonkelly
brandonkelly / FieldsVariable.php
Created March 10, 2014 18:55
craft.fields.getFieldByHandle()
<?php
// ...
public function getFieldByHandle($handle)
{
return craft()->fields->getFieldByHandle($handle);
}
{% macro entryLink(entry, selEntry) %}
{% if entry.type == 'link' %}
<a href="{{ url(entry.linkUrl) }}">{{ entry.title }}<span class="external"></span></a>
{% elseif entry.type == 'headingOnly' %}
{% set nextEntry = entry.getNext() %}
{% if nextEntry %}
<a href="{{ nextEntry.url }}">{{ entry.title }}</a>
{% else %}
{{ entry.title }}
{% endif %}
@brandonkelly
brandonkelly / HttpRequestVariable.php.diff
Created February 17, 2014 23:35
Add a craft.request.getPageNum() function to Craft
diff --git Source/craft/app/variables/HttpRequestVariable.php Source/craft/app/variables/HttpRequestVariable.php
index fad31b7edab84f5c428e3ce2c3b3ec6e8d92e7ef..430e1adcdf801cccabaf67c89001465c8835fba7 100644
--- Source/craft/app/variables/HttpRequestVariable.php
+++ Source/craft/app/variables/HttpRequestVariable.php
@@ -201,4 +201,14 @@ class HttpRequestVariable
{
return craft()->request->isMobileBrowser($detectTablets);
}
+
+ /**