Skip to content

Instantly share code, notes, and snippets.

View lukemorton's full-sized avatar

Luke Morton lukemorton

View GitHub Profile
@lukemorton
lukemorton / cache.conf
Created February 16, 2011 13:19
Apache config for nice caching
## By Luke Morton
# Set up caching on media files for 1 year (forever?)
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresActive On
ExpiresDefault A29030400
Header append Cache-Control "public"
</FilesMatch>
# Force media to revalidate
@lukemorton
lukemorton / jquery.shiftcheck.html
Created February 22, 2011 00:03
jquery.shift.js
<!doctype html>
<html>
<head>
<title>Shift Check</title>
<meta charset="utf-8" />
</head>
<body>
<h1>Shift Check</h1>
<p>Try the following combos:</p>
<ul>
@lukemorton
lukemorton / controllerSLASHcms.php
Created February 23, 2011 22:41
Example CMS controller
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_CMS extends Controller {
public function action_page()
{
$page = $this->request->param('id', 'home');
}
}
@lukemorton
lukemorton / mustache-lambda.php
Created March 1, 2011 23:20
Lambda example for Mustache.php
<?php
require_once('Mustache.php'); // Ensure feature/higher-order-sections branch !!
class MyMustache extends Mustache {
public function name()
{
return "Luke";
}
<?php
require_once('MustacheLambda.php'); // Ensure feature/higher-order-sections branch !!
class MyMustache extends Mustache {
public function name()
{
return "Luke";
}
@lukemorton
lukemorton / arrayplay.php
Created March 10, 2011 13:38
Array sorting class
<?php
/**
* ArrayPlay.
*
* An handy class for sorting arrays, more features as required.
*
* @author Luke Morton
* @example
* $original = array(
* array('name' => 'James', 'age' => 25),
@lukemorton
lukemorton / blog.php
Created March 18, 2011 11:37
Validation without exceptions
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Page extends Controller {
public function action_unpublish()
{
$validation = Model_Page::unpublish($this->request->param('id'), $this->user);
if ($errors = $validation->errors())
{
$this->response->body(
@lukemorton
lukemorton / text.php
Created March 22, 2011 11:48
Long word shortner and trunc middle methods for Kohana_Text
<?php
class Text extends Kohana_Text {
public static function long_words($string, $max_length = 20, $elipsis = '...')
{
$words = preg_split('/\s/', $string);
$elipsis_length = strlen($elipsis);
foreach ($words as $_word)
@lukemorton
lukemorton / logger-init.php
Created March 22, 2011 14:14
Just an example of Pimple DI
<?php
$logger = new Logger_Pimple(array(
'log_remote_endpoint' => 'https://secure.freeola.com',
'log_remote_user' => 'luke',
'log_remote_password' => 'luke',
));
$logger['log']->add(0, 'An error occured');
@lukemorton
lukemorton / example.php
Created March 24, 2011 17:36
Traits and datamapper in PHP
<?php
// Find user
$user = Model_User::find($id)
// Change name
->set('first_name', 'Luke')
// Save using default store
->save()