Skip to content

Instantly share code, notes, and snippets.

View mehlah's full-sized avatar
🎯

Mehdi Lahmam mehlah

🎯
View GitHub Profile
Libraries::add('play', array('default' => true, 'resources' => call_user_func(function() {
if (!is_dir($resources = str_replace("//", "/", sys_get_temp_dir() . '/resources'))) {
$paths = array($resources, "{$resources}/tmp/logs", "{$resources}/tmp/cache/templates");
foreach ($paths as $path) {
mkdir($path, 0777, true);
}
}
return $resources;
})));
<?php
namespace app\extensions\action;
/**
* Observer for the Observer pattern. When a subject sends a notification for an event,
* the registered listeners can act upon it.
*
* @author hdonner
*
/**
* Generates a form field with a label, input, and error message (if applicable), all contained
* within a wrapping element.
*/
public function field($name, array $options = array()) {
if ($this->_binding && $this->_binding->errors($name)) {
$options['wrap']['class'] = 'error';
}
return parent::field($name, $options);
@mehlah
mehlah / queries_logger.php
Created November 10, 2012 10:40
Li3 database queries logger
<?php
use lithium\analysis\Logger;
use lithium\data\Connections;
use lithium\core\Environment;
use lithium\action\Dispatcher;
/**
* This filter intercepts the `run()` method of the `Dispatcher`
@mehlah
mehlah / gist:3832962
Created October 4, 2012 11:01
Descending sort of Ruby files in a repository by number of commits
git log --name-only --no-merges | grep \.rb$ | sort | uniq -c | sort -nr
@mehlah
mehlah / application-ujs.js
Created July 26, 2012 14:58
Unobtrusive scripting adapter for jQuery, lithified
/**
* Unobtrusive scripting adapter for jQuery, lithified
*
* Requires jQuery 1.6.0 or later.
*/
(function($, undefined) {
// Shorthand to make it a little easier to call public lithium functions from within lithium.js
var lithium;
@mehlah
mehlah / rackspace-private-iptables.py
Created July 19, 2012 10:10
Rackspace private iptables
#!/bin/env python
#
# Script to get internal IPs of all your Rackspace Cloud Servers
# and output iptables commands to restrict access to the internal
# interfaces to your servers (so other Rackspace customers can't
# scan/discover/see/exploit your internal services)
#
# Note that this script will wipe anything you have configured
# in iptables and will leave the public Internet-facing interface
# wide open. You will need to apply this script on each of your
@mehlah
mehlah / gitmodules.sh
Created July 2, 2012 00:27
Batch git submodule add
#!/bin/sh
set -e
git config -f .gitmodules --get-regexp '^submodule\..*\.path$' |
while read path_key path
do
url_key=$(echo $path_key | sed 's/\.path/.url/')
url=$(git config -f .gitmodules --get "$url_key")
git submodule add $url $path
@mehlah
mehlah / fixtures_factories
Created June 22, 2012 12:10
Fixtures vs. Factories
http://blog.ludovf.net/fixtures-vs-factories/http://metabates.com/2010/08/15/fixtures-v-factories-cant-we-all-just-get-along/
http://www.dan-manges.com/blog/38
http://blog.oncompare.com/2011/01/21/herding-your-test-data-in-rails/
http://robots.thoughtbot.com/post/159807023/waiting-for-a-factory-girl
https://gist.github.com/1044506
http://www.youtube.com/watch?v=OG8i9Udqm_s
@mehlah
mehlah / li3_changelog.md
Created June 11, 2012 18:53
Lithium 0.10 -> ? Changelog

Manually selected commits to highlight

  • Added Collection::reduce() f583206420e4ee0bafb68aa6d506a15fdae3bfd5
  • Added multibyte support for strpos(), strrpos() and substr().
  • Added a --verbose mode when running tests, and better tests output formatting
  • \template\View now allow subclasses to switch out adapter path
  • Added support for multiple bindings to FormHelper (#455)
  • Dispatcher rules now accepts callbaks (#408) dc3e17de251ad36d939bb7418b2fe51d130253c6
  • Added formatters for route parameters 2dc40c9b6e5bc55a790cd37cd05efb510a8a6517
  • We are on Travis! 007a6ea7d28e321989ec22a5d35e6722b9419727