Skip to content

Instantly share code, notes, and snippets.

View dongilbert's full-sized avatar
😍
Mautic WOOOO

Don Gilbert dongilbert

😍
Mautic WOOOO
View GitHub Profile
@dongilbert
dongilbert / README.md
Created November 8, 2016 17:26 — forked from tjamps/README.md
Basic RESTful API with Symfony 2 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

Basic RESTful API with Symfony 2 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

The API we are creating in this gist will follow these rules :

  • The API only returns JSON responses
  • All API routes require authentication
  • Authentication is handled via OAuth2 with password Grant Type only (no need for Authorization pages and such).
  • API versioning is managed via a subdomain (e.g. v1.api.example.com)

The API will be written in PHP with the Symfony 2 framework. The following SF2 bundles are used :

@dongilbert
dongilbert / geocode.php
Created May 10, 2014 16:11
Geocode an address, passed as array params
<?php
/**
* Geocode an address.
*
* @param mixed $params Array containing address info or string address.
*
* @return array Array of longitude or latitude data.
*/
function getLatLng($params)
{
@dongilbert
dongilbert / formmod.php
Created May 7, 2014 17:17
System plugin to modify form inputs.
<?php
/**
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('JPATH_BASE') or die;
class plgSystemFormmod extends JPlugin
{
<?php
function benchmark($name, $iterations, Closure $function)
{
echo "Starting Benchmark: {$name} (".number_format($iterations)." Iterations)\n";
$start = microtime(true);
for ($i = 0; $i < $iterations; $i++) {
$function();
}
$elapsed = microtime(true) - $start;
@dongilbert
dongilbert / AbstractBaseEntity.php
Created April 25, 2014 20:46
AbstractBaseEntity - the solution to the problem was to wrap the constructor `$this->entityData = $data` in an `if(empty($data))` block.
<?php
namespace Entities;
abstract class AbstractBaseEntity
{
protected $entityData = [];
final public function __construct($data = [])
{

Keybase proof

I hereby claim:

  • I am dongilbert on github.
  • I am dongilbert (https://keybase.io/dongilbert) on keybase.
  • I have a public key whose fingerprint is 11E8 E1EB C4AC 096D 18B1 2D07 73BC 273C 63F2 EDFE

To claim this, I am signing this object:

@dongilbert
dongilbert / results
Created January 17, 2014 20:15
Benchmark newInstanceWithoutConstructor vs unserialize for object creation
ReflectionClass::newInstanceWithoutConstructor: 0.039168834686279
unserialize: 0.14324808120728
@dongilbert
dongilbert / ArrayOf.php
Created January 16, 2014 19:55
Abstract ArrayOf Class
<?php
abstract class ArrayOf implements ArrayAccess, Iterator
{
protected $type = null;
protected $data = [];
protected $index = 0;
@dongilbert
dongilbert / .profile
Created November 15, 2013 22:06
PHP Quick Switching I've linked up the libphp5.so to a symlinked version in `~/.phpenv/` and also linked up the current version's `bin` folder.
alias php53='brew unlink php53 > /dev/null; brew unlink php54 > /dev/null; brew unlink php55 > /dev/null; brew link php53 > /dev/null; ln -sf /usr/local/Cellar/php53/5.3.26/libexec/apache2/libphp5.so /Users/admin/.phpenv/libphp5.so; ln -sf /usr/local/Cellar/php54/5.3.26/bin /Users/admin/.phpenv/bin; sudo apachectl restart; echo "PHP 5.3 Enabled";'
alias php54='brew unlink php53 > /dev/null; brew unlink php54 > /dev/null; brew unlink php55 > /dev/null; brew link php54 > /dev/null; ln -sf /usr/local/Cellar/php54/5.4.19/libexec/apache2/libphp5.so /Users/admin/.phpenv/libphp5.so; ln -sf /usr/local/Cellar/php54/5.4.19/bin /Users/admin/.phpenv/bin; sudo apachectl restart; echo "PHP 5.4 Enabled";'
alias php55='brew unlink php53 > /dev/null; brew unlink php54 > /dev/null; brew unlink php55 > /dev/null; brew link php55 > /dev/null; ln -sf /usr/local/Cellar/php55/5.5.3/libexec/apache2/libphp5.so /Users/admin/.phpenv/libphp5.so; ln -sf /usr/local/Cellar/php54/5.5.3/bin /Users/admin/.phpenv/bin; sudo apachectl restart; e
<?php
class SomeClass
{
public function resortCsv()
{
$db = JFactory::getDbo();
$query = $db->getQuery(true)
->select('robot_id, title, address1, city, state, zip, sub_title, description')
->from('#__rv_resorts');