Skip to content

Instantly share code, notes, and snippets.

View thinkingmedia's full-sized avatar

cgTag thinkingmedia

View GitHub Profile
class main
{
public $nothing = 'some text';
public static $variable = "new variable";
public static function doSomething($main)
{
echo "Do something";
echo "<br>";
echo $main->nothing;
public boolean isPrime(int n)
{
int divisor = 2;
int limit = n-1 ;
if (n == 2)
{
return true;
}
@thinkingmedia
thinkingmedia / gist:8b85f275f48ac22814e9
Created September 24, 2014 13:33
My take on your code.
public function saveKeyValues(Model $Model, $data){
if(empty($data) || !isset($data[$Model->alias]) || empty($data[$Model->alias]))
{
return false;
}
$optionKey = $this->options[$Model->alias]['fields']['key'];
$optionValue = $this->options[$Model->alias]['fields']['value'];
// I don't understand this part.
@thinkingmedia
thinkingmedia / q.cmd
Created January 18, 2016 15:37
Type `g` on the Windows command to show details about the current working directory in Git.
@ECHO OFF
git remote -v
git status
git branch
@thinkingmedia
thinkingmedia / gitty.cmd
Created January 18, 2016 15:38
Type `gitty` in a Windows prompt to add, commit and push with one command.
@ECHO OFF
git status
IF %ERRORLEVEL% NEQ 0 (EXIT /B -1)
git add --all
IF %ERRORLEVEL% NEQ 0 (EXIT /B -1)
IF "%~1"=="" GOTO END_BATCH
git commit -m %1
IF %ERRORLEVEL% NEQ 0 (GOTO END_BATCH)
@thinkingmedia
thinkingmedia / nano.cmd
Created January 18, 2016 15:47
An alias for Windows that lets you start NotePad++ when you type `nano filename.txt` on the command line.
@ECHO OFF
start notepad++ %*
@thinkingmedia
thinkingmedia / gist:7dafb8e27ed999440038
Created March 29, 2016 13:44
Fix for registration and signed in.
<?php
namespace App\Controller;
use CakeDC\Users\Controller\Traits\LoginTrait;
use CakeDC\Users\Controller\Traits\RegisterTrait;
class UsersController extends AppController {
use RegisterTrait {
@thinkingmedia
thinkingmedia / GemsAssert.php
Created November 9, 2016 12:44
A handler for ORM read/write operations
<?php
namespace Gems\Tools;
use Cake\Datasource\EntityInterface;
use Cake\Error\PHP7ErrorException;
use Cake\Log\Log;
use Cake\ORM\Table;
use Cake\Utility\Hash;
use Error;
@thinkingmedia
thinkingmedia / disposable.php
Last active January 13, 2017 13:52
Disposable pattern implemented in PHP
<?php
/**
* Wraps the callable in a try/finally before calling dispose()
*
* @param GemsDisposable $obj
* @param callable $worker
* @return mixed
*/
function using(GemsDisposable $obj, callable $worker)
{
class RestCreateComponent extends RestComponent
{
public $components = ['RestError'];
public function initialize(array $config)
{
parent::initialize($config);
$con = $this->getController();
$this->eventManager($con->eventManager());
}
public function create() {