Skip to content

Instantly share code, notes, and snippets.

View mehlah's full-sized avatar
🎯

Mehdi Lahmam mehlah

🎯
View GitHub Profile
@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 / 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 / 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 / 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`
/**
* 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);
<?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
*
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;
})));
class BaseModel extends \lithium\data\Model {
public static function create(array $data = array(), array $options = array()) {
$defaults = array('defaults' => true, 'class' => 'entity');
$options += $defaults;
$model = get_called_class();
if (isset($data['_type']) && $data['_type']) {
list($namespace, $name) = preg_split("/\\\[^\\\]*$/", $model);
$model = $namespace . '\\' . Inflector::humanize(Inflector::pluralize($data['_type']));
$(document).on('pjax:popstate ', function(event) {
if(event.direction == "back") {
console.log('executes before page-change');
}
});
@mehlah
mehlah / index.html
Last active December 31, 2015 18:39
<!DOCTYPE html>
<meta charset="utf-8">
<style>
text {
font: 10px sans-serif;
}
</style>
<body>