Skip to content

Instantly share code, notes, and snippets.

View andrewandante's full-sized avatar

Andrew Paxley andrewandante

  • Christchurch, New Zealand
View GitHub Profile
@andrewandante
andrewandante / PageController.php
Created December 7, 2021 11:02
How to hack your pagination - a guide
<?php
## use statments ##
class PageController extends BasePageController
{
public const PAGE_LENGTH = 10;
public const BIG_PAGE_LENGTH = 100;
@andrewandante
andrewandante / CustomVimeoEmbedShortcodeProvider.php
Last active October 19, 2021 04:35
Vimeo Embed Fix (for "Verify to Continue" error)
<?php
namespace App\Shortcode;
use Psr\Log\LoggerInterface;
use Psr\SimpleCache\CacheInterface;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\View\Shortcodes\EmbedShortcodeProvider;
use Throwable;
@andrewandante
andrewandante / PartyChecker.php
Created November 20, 2019 14:58
Bitbucket Pull Request Participation Checker (Partychecker)
<?php
/**
* Sample usage: php ./PartyChecker.php 'Guybrush Threepwood' 2019-01-01 2019-03-31
*
* Sample Output:
*
* ....xxxxxx.xx.xx..xx..xx.x.....xx.....x.x.x.x....xx.....x.....x...........xx......xxx.x.....x.x..........xxx
* .......x....x..........x...............x.....x.....x.....x............xx.....xxx.......x....................
* ..........x....xxxx.x......x.....x.xx.....x......x.......x..xxx..x.x.....x.x.x...x.xx.............xx..xxxxxx
@andrewandante
andrewandante / prepare-commit-msg
Created November 20, 2019 14:54
Git hook to prefix commit with beginning of branch name
#!/bin/bash
# To use - go into your root directory, and rename the file .git/hooks/prepare-commit-msg.sample to .git/hooks/prepare-commit-msg
# Then, copy this into that file. Make it executable (chmod +x .git/hooks/prepare-commit-msg) and then reload your terminal
# This will then prepend the start of the branch name to your commit messages e.g. [ABC-1234] My sick commit message
# This way you can customize which branches should be skipped when
# prepending commit message.
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master)
@andrewandante
andrewandante / unique.php
Last active April 9, 2018 13:00
Validate a unique DB Field
public function validate()
{
$result = parent::validate();
$this->ensureUnique('Title', $result);
return $result;
}
/**
* @param string $fieldName
@andrewandante
andrewandante / data.rb
Last active December 18, 2017 16:43
Testing File.exist? in Capistrano scripts
namespace :file_tests do
task :exists do
user = capture("whoami")
logger.debug "User is #{user}"
release_dir = capture("readlink /sites/dash/www").strip
logger.debug "Release directory is #{release_dir}"
file_exists("/etc/environment")
file_exists("/etc/not_really_there")
file_exists("/sites/dash/www/framework/sake")
file_exists("#{release_dir}")
@andrewandante
andrewandante / queryanalysis.php
Last active April 21, 2017 10:57
ShowQueriesStatsAnalysis
#!/usr/bin/php
<?php
/**
* To use - view source of a page with ?showqueries=1&isDev=1, save queries to a file, pass the file as an arg to the script
*/
function output() {
foreach (func_get_args() as $message) {
echo $message . PHP_EOL;
}