Skip to content

Instantly share code, notes, and snippets.

<?php
class Object {
private $__instanceMixins = array();
private static $__classMixins = array();
public function mixinInstanceMethod($class, $method = null) {
$reflection = self::reflect($class, $method);
$method = $reflection->getName();
$toAppend = self::methodToAppend($reflection);
<?php
class People extends Iammike_Db_Table_Abstract {
protected $_name = 'people';
// $select is an instance of Iammike_Db_Table_Select
// The rest of the params are what was passed to the finder
public function oldFinder($select) {
return $select->where('people.age > 60');
<?php
$people = new People;
$young = $people->select()->young();
$youngMale = $young->male();
$youngFemale = $young->female();
$maleWithDocuments = $people->select()->male()->withDocuments();
$publishedBetween2001And2005 = $maleWithDocuments->publishedBetween('2001-01-01 00:00:00', '2005-12-31 23:59:59');
<?php
set_include_path("/home/mike/Downloads/ZendFramework-1.10.7/library/:" . get_include_path());
require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
$options = array(
'host' => 'localhost',
'username' => 'root',
'password' => '',
-- MySQL dump 10.13 Distrib 5.1.41, for debian-linux-gnu (x86_64)
--
-- Host: localhost Database: testing
-- ------------------------------------------------------
-- Server version 5.1.41-3ubuntu12.6
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
QUERY: SELECT `people`.* FROM `people` WHERE (people.age < 20) AND (people.sex = "m")
RESULTS:
Name: baby joe bloggs
Age: 1
Sex: m
-------
QUERY: SELECT `people`.* FROM `people` WHERE (people.age < 20) AND (people.sex = "f")
RESULTS:
Name: baby joanna bloggs
class Range
def min
first > last ? last : first
end
def max
last > first ? last : first
end
def clamp(v)
% irb
>> require "clamp.rb"
=> true
>> (0..360).clamp(370)
=> 360
>> (360..0).clamp(370)
=> 360
>> (360..0).clamp(-10)
=> 0
#!/usr/bin/env ruby
class Ctags
attr_reader :tags_file, :target_dir
def initialize(target_dir, tags_file=nil)
@target_dir = target_dir + '/'
tags_file ||= File.join(target_dir, '.autotags')
@tags_file = tags_file
refresh_tags
h = 0 if h < 0
h = 360 if h > 360
s = 0 if s < 0
s = 1.0 if s > 1.0
v = 0 if v < 0
v = 1.0 if v > 1.0