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
@defunkt
defunkt / god.rb
Created November 18, 2008 18:04 — forked from mojombo/gist:26183
rails_root = "/data/github/current"
20.times do |num|
God.watch do |w|
w.name = "dj-#{num}"
w.group = 'dj'
w.interval = 30.seconds
w.start = "rake -f #{rails_root}/Rakefile production jobs:work"
w.uid = 'git'
class AppBuilder < Rails::AppBuilder
include Thor::Actions
include Thor::Shell
def test
append_test_gems
rspec
cucumber
jasmine
end
<?php
Validator::add('array', function(&$value, $format = null, array $options = array()) {
$options += array(
'threshold' => 0,
'validator' => 'notEmpty'
);
if (is_array($value)) {
$failed = 0;
$valueCount = count($value);
foreach ($value as $item) {
@CHH
CHH / function_currying.php
Created December 6, 2010 12:10
Prefill the arguments of functions (Currying)
<?php
function func_curry($fn)
{
$args = array_slice(func_get_args(), 1);
return function() use ($fn, $args) {
$args = array_merge($args, func_get_args());
return call_user_func_array($fn, $args);
};
@CHH
CHH / function_wrapping.php
Created December 6, 2010 12:21
Wrap a function inside another function
<?php
function func_wrap($fn, $wrapper)
{
// Unify calling of the wrapped function
if(is_array($fn) or is_string($fn)) {
$original = function() use ($fn) {
return call_user_func_array($fn, func_get_args());
};
} else {
<?php
// pipes each function's return value as input into the next function in the chain
function func_compose()
{
$fns = func_get_args();
$composition = function() use ($fns) {
$input = func_get_args();
foreach ($fns as $fn) {
$return = call_user_func_array($fn, $input);
@dawsontoth
dawsontoth / app.js
Created March 4, 2011 00:44
Customize the look of the tab bar in iOS Appcelerator Titanium
Ti.include('overrideTabs.js');
/*
This is a typical new project -- a tab group with three tabs.
*/
var tabGroup = Ti.UI.createTabGroup();
/*
Tab 1.
:+1:
:-1:
:airplane:
:art:
:bear:
:beer:
:bike:
:bomb:
:book:
:bulb:
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@prozacgod
prozacgod / synchro.js
Created June 9, 2011 20:43
node.js synchronize multiple actions
/*
A simple and elegant function to synchronize multiple functions that expect callback as their last parameter.
example:
sync(func1, [parms], func2, func3, func4, [parms], callback);
Public domain!!
please leave me a comment if you like it!
*/