Skip to content

Instantly share code, notes, and snippets.

View jeremeamia's full-sized avatar
🌵
WFH in AZ

Jeremy Lindblom jeremeamia

🌵
WFH in AZ
View GitHub Profile
@jeremeamia
jeremeamia / gist:521940
Created August 12, 2010 23:05
tag-insert TinyMCE plugin
tinymce.create('tinymce.plugins.TagInsert',{
createControl: function(n, cm) {
switch (n) {
case 'taginsert':
var mlb = cm.createListBox('taginsert', {
title : 'Insert Template Tag',
onselect : function(v) {
tinyMCE.activeEditor.selection.setContent(v);
}
});
@jeremeamia
jeremeamia / gist:544378
Created August 22, 2010 22:48
Detecting large upload failure
<?php
function post_max_size_exceeded()
{
// Error occured if the POST array is empty, but the content length is not
return (bool)
(
$_SERVER['REQUEST_METHOD'] == 'POST'
AND
empty($_POST)
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* @package YurikoCMS
* @author Lorenzo Pisani - Zeelot
* @copyright (c) 2008-2010 Lorenzo Pisani
* @license http://yurikocms.com/license
*/
class YForm_Field_RadioMatrix extends YForm_Field_Group {
protected $_has_label = TRUE;
@jeremeamia
jeremeamia / gist:633632
Created October 19, 2010 04:51
PHP is so weird
<?php // Some lovely, valid php code that prints "foofoo"
echo${${($f='f').(${$o='o'}).${$o}}=${$f}.$${$$o}.$$${$$$o}};
echo$$$$$$$$$$$$$$$$$$$$${(${(${(${(${(${($$$foo)})})})})})};
<?php
/**
* A simple class for calculating holidays
*
* Able to calculate dates for holidays based on the stored derivations.
* Holidays other than Easter based on lunar cycles will not be able to be
* calculated. Work should be done to improve this with configuration abilities
*/
class Holiday {
@jeremeamia
jeremeamia / gist:907033
Created April 7, 2011 04:20
Warn user when they have changed a form, but not saved
(function($){$(function(){
// Make it so you are warned when navigating away from certain unsaved forms
if ($('form.remember-to-save-me').length){
$('form.remember-to-save-me').each(function(){
$(this)
.data('saved', false)
.data('serial', $(this).serialize())
.submit(function(){
$(this).data('saved', true);
});
@jeremeamia
jeremeamia / gist:1002974
Created June 1, 2011 18:42
Creating an ORM architecture compatible with dependency injection and unit testing
<?php
// Domain Classes
abstract class Domain { // Provides means to persist models and understand relationships
public function __construct(Database_Interface $database, Domain_Builder_Base $builder) {/* ... */}
public function find($unique_key) {/* ... */}
public function find_all($unique_key) {/* ... */}
public function save(Domain_Model $model) {/* ... */}
public function find_all_related_to(Domain_Model $model) {/* ... */}
/* ... */
@jeremeamia
jeremeamia / orm.php
Created July 9, 2011 22:02
View-Models for Kohana 3.2.x (ORM-specific)
<?php defined('SYSPATH') or die('No direct script access.');
class ORM extends Kohana_ORM {
protected $_as_object = NULL;
public function as_object($class)
{
$this->_as_object = $class;
@jeremeamia
jeremeamia / gist:1480490
Created December 15, 2011 09:22
Magic PHP - Get your properties any way you want
<?php
class MagicProperties implements ArrayAccess
{
protected $properties = array('foo' => 'bar');
public function __get($key)
{
return $this->properties[$key];
}
@jeremeamia
jeremeamia / gist:1488083
Created December 16, 2011 21:31
A fix for the AWS SDK for PHP v1.5 SQS class
<?php
/**
* This overwrites the default authenticate method in sdk.class.php to address SQS queue URLs.
*
* @return CFResponse Object containing a parsed HTTP response.
*/
public function authenticate($operation, $payload)
{
// Save the current hostname
$hostname = $this->hostname;