Skip to content

Instantly share code, notes, and snippets.

View guywarner's full-sized avatar

Guy Warner guywarner

View GitHub Profile
@guywarner
guywarner / Encryptable.php
Created December 17, 2020 00:38
Laravel auto encrypt trait
<?php
namespace App\Traits;
use Crypt;
trait Encryptable
{
/**
* Get a models attribute on select
// OLD CODE
// Wait for one minute for data source operation status to be IDLE
// Database operation (add/remove records) is asynchronous
public function waitForIdle($dataSourceId)
{
$end = time() + 60; // up to one minute
while (time() < $end)
{
try
{
<?php
/*
* Copyright 2013 Disqus, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
@guywarner
guywarner / build.xml
Last active February 19, 2016 15:43
build.xml to run PHPUnit for CakePHP using DBTest by CakeDC
<?xml version="1.0" encoding="UTF-8"?>
<project name="name-of-project" default="build">
<target name="build"
depends="prepare,dbtest,cake,lint,phpcs-ci,phploc,pdepend,phpmd-ci,phpcpd"/>
<target name="build-parallel"
depends="prepare,dbtest,cake,lint,tools-parallel"/>
<target name="tools-parallel" description="Run tools in parallel">
@guywarner
guywarner / gist:7052190
Created October 19, 2013 06:13
Method to take a string and print all palindromes. Returns the longest or if none found throws an error.
<?php
function palindrome($string) {
$string = strtolower(ereg_replace("[^A-Za-z0-9]", "", $string ));
$palindromes = array();
$longest = "";
$word = "";
$length = strlen($string);
for ($i =0; $i <= $length; $i++) {
@guywarner
guywarner / CakePhpTestEngine.php
Last active December 23, 2015 17:59
A hacked up Phabricator PhpunitTestenge.php to work with CakePHP's console for unit testing. This needs a lot of work. But it does WORK. Working with Cake Console v2.3.2 and PHPUnit v3.7.24
<?php
/**
* PHPUnit wrapper
*
* To use, set unit.engine in .arcconfig, or use --engine flag
* with arc unit. Currently supports only class & test files
* (no directory support).
* To use custom phpunit configuration, set phpunit_config in
* .arcconfig (e.g. app/phpunit.xml.dist).