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 :

<?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 / chapter.php
Last active December 10, 2015 17:49 — forked from drmmr763/chapter.php
Moved the query from the loop into a sub query and then optimized a little.
<?php
public function getSubmits()
{
$cid = JFactory::getApplication()->input->getInt('cid');
$db = $this->getDbo();
$query = $db->getQuery(true);
$query->select('a.*, i.username');
$query->select('(SELECT SUM(v.vote) FROM #__rootflick_vote AS v WHERE v.sub_id = a.id) AS vote');
@dongilbert
dongilbert / WPAssetLoader.php
Created April 22, 2011 13:23
Helper function for registering and enqueueing CSS and JavaScript files within a WordPress plugin or theme.
/**
* Helper function for registering and loading scripts and styles.
* Uses regex to determine if the file is CSS or JavaScript and calls
* the proper WordPress register and enqueue functions accordingly.
*
* @name ID to register with WordPress
* @file_path Path to actual file, relative to your plugin or theme, without preceding slash.
* @for Whether this is for a plugin or a theme.
*/
function load_file($name, $file_path, $for = 'plugin') {