Skip to content

Instantly share code, notes, and snippets.

View nateabele's full-sized avatar

Nate Abele nateabele

View GitHub Profile
@nateabele
nateabele / routes.php
Last active June 16, 2017 13:05
Lithium continuation route examples
<?php
/**
* Continuation routing examples. Handles URLs in the following forms:
*
* /posts
* /en/posts
* /admin/posts
* /admin/en/posts
* /admin/en/posts.json
* /admin/en/posts/4ef16ccc7f8b9aa331000064.json
@nateabele
nateabele / media.php
Created February 17, 2012 17:44
An example of how to completely reconfigure Lithium's templating engine
<?php
use lithium\net\http\Media;
/**
* This re-maps your template paths so you can have stuff like `pages/users_{username}.php`
* instead of the Lithium default.
*/
Media::type('html', 'text/html', array(
'view' => 'lithium\template\View',
@nateabele
nateabele / SepiaToneFilter.php
Created April 13, 2012 20:59
Proof-of-concept sepia tone filter for Imagine. My math is probably rong.
<?php
namespace moneygram\extensions\imagine;
use Imagine\Image\Box;
use Imagine\Image\Point;
use Imagine\Image\Color;
class SepiaToneFilter implements \Imagine\Filter\FilterInterface {
@nateabele
nateabele / Base.php
Created September 19, 2012 21:53
MongoDB-based model accessors (relationships) in Lithium
<?php
namespace my_app\models;
use MongoId;
use lithium\data\collection\DocumentArray;
use lithium\data\collection\DocumentSet;
use lithium\data\entity\Document;
use lithium\util\Inflector;
use lithium\core\Libraries;
@nateabele
nateabele / angular-autoload.js
Created May 20, 2013 03:43
A simple, naïve, and hacky proof-of-concept for auto-loading modules in AngularJS.
/**
* Naive AngularJS module autoloader; depends on require.js.
*
* Usage:
*
* angular.autoLoad({
* 'ngResource': '/js/angular-resource-1.0.1.min.js',
* 'google-maps': '/js/angular-google-maps.js',
* 'ui.bootstrap': '/js/ui/ui-bootstrap-custom-tpls-0.4.0.min.js',
* 'module.split.over.multiple.files': ['/js/file1.js', '/js/file2.js']
@nateabele
nateabele / action.php
Last active December 17, 2015 20:28
Example of configuring `li3_resources` queries to automatically extract values from request parameters, with fallbacks to default values. **Note:** exposing elements of a query to arbitrary input (i.e., high query limits) is not advisable. The needs and context of the application should always be considered, and input should be filtered and/or s…
<?php
/**
* Snippet extracted from `config/bootstrap/action.php`.
*/
/**
* ## Mapping HTTP Request Parameters to Query Parameters
*
* The `$replacer` function is used by the `Resources` filter below to allow resource classes to
* automatically map values from the `Request` object in their query configurations.
@nateabele
nateabele / libraries.php
Created September 23, 2013 14:30
How to integrate Stripe with Lithium
<?php
/** config/bootstrap/libraries.php **/
// ...
Libraries::add('stripe', array(
'path' => LITHIUM_APP_PATH . '/libraries/stripe/lib',
'prefix' => null
));
@nateabele
nateabele / Users.php
Last active December 23, 2015 17:59
Get the current user as an object
<?php
/** models/Users.php **/
use lithium\security\Auth;
class Users extends \lithium\data\Model {
// ...
@nateabele
nateabele / geospoof.js
Created September 26, 2013 12:16
Faking out the Geolocation API
navigator.geolocation.getCurrentPosition = function(callback) {
console.log("Hey look, I'm in London!");
callback({
"timestamp": (new Date()).getTime(),
"coords": {
"speed": null,
"heading": null,
"altitudeAccuracy": null,
"accuracy": 89,
@nateabele
nateabele / debug.js
Created September 26, 2013 17:14
Karma configuration for debugging UI-Router.
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '.',
// list of files / patterns to load in the browser
files: [
'lib/angular-1.1.4.js',
'test/lib/angular-mocks-1.1.4.js',
'test/testUtils.js',