Skip to content

Instantly share code, notes, and snippets.

View mehlah's full-sized avatar
🎯

Mehdi Lahmam mehlah

🎯
  • Grinta
  • Saint-Etienne, France
  • X @mehlah
View GitHub Profile
@mehlah
mehlah / li3_map_reduce.php
Created May 25, 2011 09:05
Li3 Map reduce exemple
<?php
$db = Model::connection();
// construct map and reduce functions
$map = new \MongoCode("function() {}");
$reduce = new \MongoCode("function(k, vals) {}");
$metrics = $db->connection->command(array(
'mapreduce' => 'collection',
@mehlah
mehlah / li3_custom_filter.php
Created May 29, 2011 14:15
Li3 custom filter
Dispatcher::applyFilter('_callable', function($self, $params, $chain) {
$chain = $chain->next($self, $params, $chain);
$chain->applyFilter('custom_filter', function($self, $params, $chain) {
$params['text'] = 'filtered text';
return $chain->next($self, $params, $chain);
});
return $chain;
});
//controller action
@mehlah
mehlah / li3_before_after_filter.php
Created May 29, 2011 14:18
Li3 before and after filters
Dispatcher::applyFilter('_callable', function($self, $params, $chain) {
$chain = $chain->next($self, $params, $chain);
$chain->applyFilter('__invoke', function($self, $params, $chain) {
var_dump("before filter");
$chain = $chain->next($self, $params, $chain);
var_dump("after");
return $chain;
});
return $chain;
});
@mehlah
mehlah / scan_logs.ksh
Created August 11, 2011 14:38
Shell script to scans logs for specific signatures
#!/bin/ksh
#
# Original author: Lance Spitzner, April 1999
#
# Shows last 10 entries of critical system logs.
# Build in some "artificial intelligence" using
# greps and sorts. You can select a specific
# hosts logs, or you can select all hosts logs.
# Define input
@mehlah
mehlah / MetaObject.php
Created August 31, 2011 17:19 — forked from CHH/MetaObject.php
PHP does Meta Programming too! (Requires PHP 5.4)
<?php
namespace CHH;
trait MetaObject
{
protected static $metaClass;
static function setMetaClass(MetaClass $metaClass)
{
@mehlah
mehlah / index.html
Created September 5, 2011 12:28 — forked from jdonaldson/index.html
taken from block #1191530
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>bar</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.js"></script>
<script type="text/javascript" src="jquery.tipsy.js"></script>
<link rel="stylesheet" href="tipsy.css" type="text/css"/>
@mehlah
mehlah / li3_map_reduce.php
Created November 4, 2011 15:59
Li3 mapReduce
/**
* Execute a Map/Reduce query against a MongoDb connection
*
* @param string $map The Javascript Map function code, or if $systemJs=true the stored map procedure
* @param string $reduce The optional reduce function code, or if $systemJs=true the stored reduce procedure
* @param boolean $systemJs If true, $map/$reduce will be considered stored procs in system.js
*
* @return object A result of the map/reduce query
*/
public static function mapReduce($map, $reduce = null, $systemJs = false, $options = array()) {
@mehlah
mehlah / ArticleControllerTest.php
Created December 18, 2011 11:48 — forked from icambridge/ArticleControllerTest.php
Controller testing lithium
<?php
namespace app\tests\cases\controllers;
use app\tests\mocks\MockArticlesController;
use app\tests\mocks\action\MockControllerRequest as Request; //Mocking the Request
class ArticlesControllerTest extends \lithium\test\Unit {
protected $_controller;
@mehlah
mehlah / li3_errors.php
Created December 18, 2011 17:17
Lithium Error handler
<?php
use lithium\core\ErrorHandler;
use lithium\action\Response;
use lithium\net\http\Media;
use lithium\analysis\Debugger;
use lithium\analysis\Logger;
use lithium\core\Environment;
/**
@mehlah
mehlah / README.md
Created January 6, 2012 01:55
Lithium lines spent

#Lithium lines spent since 0.10 (2011-06-18)

[...] if we wish to count lines of code, we should not regard them as "lines produced" but as "lines spent": 
the current conventional wisdom is so foolish as to book that count on the wrong side of the ledger.
-- 
Edsger W. Dijkstra http://www.cs.utexas.edu/~EWD/transcriptions/EWD10xx/EWD1036.html

Each bar represents a commit.Green represents added lines, red removed lines. Each bar is centered at the cumulative added/removed count from my commits: the first commit is centered at 0, and if it net added code, the next commit is shifted accordingly. Hovering a bar shows part of the commit message.