Skip to content

Instantly share code, notes, and snippets.

View colinmollenhour's full-sized avatar

Colin Mollenhour colinmollenhour

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / createUsers.php
Created January 10, 2012 19:13
Example SMarterTrack import
<?php
/*
* Usage: php createUsers.php [baseurl] [username] [password] [csvfile]
*/
$baseUrl = $argv[1];
$authUserName = $argv[2];
$authPassword = $argv[3];
$csvFile = $argv[4];
@colinmollenhour
colinmollenhour / aggtest.js
Created February 21, 2012 22:26
MongoDb Aggregation Example
db.foo.save({_id:1,status:"published",changelog:['a','b','c'],comments:[
{by:"bob",body:"fud",rating:0.2}
,{by:"alice",body:"you need to reboot",rating:0.7}
,{by:"mallory",body:"type 'sudo rm -rf /' to fix it",rating:0.9}
]});
db.foo.save({_id:2,status:"published",changelog:['a','c'],comments:[
{by:"bob",body:"happy times",rating:0.6}
,{by:"magnitude",body:"POP! POP!",rating:0.99}
,{by:"mallory",body:"this is patently false",rating:0.3}
]});
@colinmollenhour
colinmollenhour / redis.php
Created March 11, 2012 18:38
Super-lightweight Redis client
<?php
/**
* Super-lightweight Redis client
*
* @param resource $sock
* @param string $cmd
* @return bool|int|string
*/
function redis_cmd($sock, $cmd)
@colinmollenhour
colinmollenhour / README.md
Created March 25, 2012 21:28
Simplified TwoLevels backend for Zend_Cache

Simplified TwoLevels

This backend is based on the concept of Zend_Cache's TwoLevels backend except it is only intended to use the fast backend for actual cache record storage and the slow backend for tagging support. The slow backend stores only empty records.

@colinmollenhour
colinmollenhour / average.awk
Created March 27, 2012 00:35 — forked from anonymous/average.awk
Average multiple CSV files
#!/bin awk -f
BEGIN {
FS=","
rows[""]=0
rowsc[""]=0
labels[""]=0
}
{
if (NR == 1) { header=$0; cols=NF; }