Skip to content

Instantly share code, notes, and snippets.

View angelxmoreno's full-sized avatar

Angel S. Moreno angelxmoreno

View GitHub Profile
@angelxmoreno
angelxmoreno / phpunit.xml.dist
Created August 31, 2018 20:34
LinkedEntities phpunit.xml.dist
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
colors="true"
verbose="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
@angelxmoreno
angelxmoreno / AfterSaveOrDeleteBehavior.php
Created August 23, 2018 04:34
CakePHP 3 Behavior to adds a Model\Table callback triggered after a save or after a delete
<?php
namespace FiveTalents\Model\Behavior;
use Cake\Datasource\EntityInterface;
use Cake\Event\Event;
use Cake\ORM\Behavior;
/**
* AfterSaveOrDelete behavior
@angelxmoreno
angelxmoreno / serverless-php.md
Last active August 14, 2018 01:16
Example of running PHP code on AWS Lambda
@angelxmoreno
angelxmoreno / function.php
Created September 22, 2017 17:14
Kahlan test
<?php
class Helper {
public function render(array $payment_methods, $error_saving_plans = false, $boleto_tab_checked = false)
{
$html = '';
foreach (self::TAB_NAMES as $tab_name) {
$payment_enabled = $this->isPaymentEnabled($tab_name, $payment_methods);
$tab_disabled = $this->isTabDisabled($tab_name, $error_saving_plans);
$checked = $this->shouldBeChecked($tab_name, $payment_enabled, $tab_disabled, $boleto_tab_checked);
@angelxmoreno
angelxmoreno / HomeController.php
Created April 18, 2017 01:19
Sample Slim Framework Controller
<?php
namespace App\Controllers;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
use Interop\Container\ContainerInterface as Container;
class HomeController
{
/**
<?php
public function longDbCall()
{
$cache_key = $this->cache->generateKey('longDbCall');
return $this->cache->remember($cache_key, function () {
return $this->__longDbCall();
});
}
<?php
use Phalcon\Mvc\Application as PhalconApplication;
use Phalcon\Config as PhalconConfig;
error_reporting(E_ALL);
define('DS', DIRECTORY_SEPARATOR);
define('WEBROOT_PATH', __DIR__ . DS);
define('ROOT_PATH', dirname(WEBROOT_PATH) . DS);
define('APP_PATH', ROOT_PATH . 'app' . DS);
require 'tic_tac_toe_cn'
game = Tic_Tac_Toe.new
board = Array.new(3) {Array.new(3)}
game.initBoard(board)
puts "Starting Tic Tac Toe"
puts "Player 1 choose X or O"
playerOne = gets.chomp.upcase
if playerOne == "X"
playerTwo = "O"
By adding this gem to our project we will be able to use methods of the Tic_Tac_Toe class (these methods are listed below)
.new - makes a new Tic Tac Toe object
.initBoard(board) - makes a cell block from the dimensions of board object
.winningRows(board) - checks the board object to see if a row contains 3 of the same symbol
.winningCols(board) - checks the board object to see if a col contains 3 of the same symbol
.winningDiagonals(board) - checks the board object to see if a diagonal contains 3 of the same symbol
.displayBoard(board) - displays board object in the terminal
.fullBoard(board) - checks to see if the board object is full
.turnPlayed(board,player,player_choice) - checks to see if a valid move was played by checking the board object, player symbol and location that the player picked
db.setSchema([
{
singular: 'author',
plural: 'authors',
relations: {
'books': {hasMany: 'book'}
}
},
{
singular: 'book',