Skip to content

Instantly share code, notes, and snippets.

View colinmollenhour's full-sized avatar

Colin Mollenhour colinmollenhour

View GitHub Profile
@colinmollenhour
colinmollenhour / gist:1541999
Created December 30, 2011 23:23
Mongo job queue
public function getNextJob()
{
$result = $this->_getWriteAdapter()->command(array(
'findAndModify' => $this->_collectionName,
'query' => array(
'status' => Cm_Mongo_Model_Job::STATUS_READY,
'execute_at' => array('$lte' => new MongoDate),
),
'sort' => array(
'priority' => 1,
@colinmollenhour
colinmollenhour / mage_index.txt
Created December 6, 2011 21:28
Mage_Index examination notes
Mage::getSingleton('index/indexer')->processEntityAction($entity, $entityType, $eventType)
'index/indexer'->logEvent($entity, $entityType, $eventType)
If indexer is locked, nothing happens
Creates a new 'index/event' instance, sets entity, type, data object, and primary key
Runs 'register' method of each 'index/process' which loads the indexer based on the xml config from 'global/index/indexer/<INDEXER>/model'
If event matches indexer using matchEvent method: (checks if the appropriate key/value is in indexer's _matchedEntities property)
Sets the event's namespace to the name of the indexer class
Calls the indexer's register method which matches the event again and calls the abstract method _registerEvent($event)
The indexer implementation now needs to add data to the eventusing addNewData
Adds the process id of the process to the event
@colinmollenhour
colinmollenhour / post-receive-redmine.sh
Last active September 1, 2023 21:56
gitolite update hooks to reject CRLF line endings and require formatted commit messages
#!/bin/bash
#
# see https://github.com/kahseng/redmine_gitolite_hook/blob/master/README.rdoc
#
# The "post-receive" script is run after receive-pack has accepted a pack
# and the repository has been updated. It is passed arguments in through
# stdin in the form
# <oldrev> <newrev> <refname>
# For example:
# aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
@colinmollenhour
colinmollenhour / redis_
Created August 29, 2011 03:26
Munin plugin for Redis with added options
#!/usr/bin/perl -w
#
## Copyright (C) 2011 Colin Mollenhour <http://colin.mollenhour.com/>
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; version 2 dated June,
## 1991.
##
@colinmollenhour
colinmollenhour / local.xml
Created August 26, 2011 00:17
Redis cache config example
<!-- this is a child node of config/global -->
<cache>
<backend>Zend_Cache_Backend_Redis</backend>
<backend_options>
<server>127.0.0.1</server>
<port>6379</port>
<database>2</database>
<use_redisent>0</use_redisent> <!-- 0 for phpredis, 1 for redisent -->
<automatic_cleaning_factor>20000</automatic_cleaning_factor> <!-- optional, 20000 is the default, 0 disables auto clean -->
</backend_options>
@colinmollenhour
colinmollenhour / makePhpstormMap.php
Last active October 6, 2023 13:26
Generate map of factory method arguments to resolved class names for Magento projects
<?php
/* This script generates a mapping of factory methods/parameters to the resulting class
* names in such a way that PhpStorm 6.0.1 can use for autocompletion and chaining.
*
* Example:
* cd [magento root]
* php ~/makePhpstormMap.php > .phpstorm.meta.php
*
*/
@colinmollenhour
colinmollenhour / Auth_Mongo.php
Created September 20, 2010 02:12
Auth_Mongo for Kohana
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* Mongo Auth driver. Adapted from Kohana_Auth_ORM.
*/
class Auth_Mongo extends Auth {
/**
* Checks if a session is active.
*
* @param string role name
/**
* Author: Colin Mollenhour
* Description: Wraps Raphael primitives with a set consisting of a primitive and an invisible
* clone used for handling mouse events.
* Access the overlay element and reset its opacity with: overlay()
* Access the set within overlay event handlers with: this.set
*/
Raphael.fn.mouseable = function(){
var args = Array.prototype.slice.call(arguments);
var type = args.shift();
Plotter = {};
Plotter.HOVER_SCALE = 1.5;
Plotter.EVENT_CORNER_RADIUS = 5;
Raphael.fn.gb = {};
Raphael.fn.gb.event = function(event,x,y,w,h){
console.debug('event', event, x,y,w,h);
var set = this.set();
set.rect = this.rect(x,y,w,h,5).attr({
fill:'red',
@colinmollenhour
colinmollenhour / buildhtaccess.sh
Created June 30, 2010 22:42
.htaccess combiner
#!/bin/bash
# Author: Colin Mollenhour
#
# Usage: Run from the webroot, .htaccess-combined will be created.
dest='.htaccess-combined'
pwd=`pwd`
echo -n "" > $dest
while read -r file; do
loc=`dirname $file`