Devenet Devenet

Liens en vrac

Quelques 337 marque-pages glanés pendant ma navigation sur le Web.

47 résultats pour #code×

RSS ATOM

Extremely light templating system in PHP

https://stackoverflow.com/questions/4065418/php-extremely-light-templating-system

/**
* Renders a single line. Looks for {{ var }}
*
* @param string $string
* @param array $parameters
*
* @return string
*/
function renderString($string, array $parameters)
{
   $replacer = function ($match) use ($parameters)
   {
       return isset($parameters[$match[1]]) ? $parameters[$match[1]] : $match[0];
   };

   return preg_replace_callback('/{{\s*(.+?)\s*}}/', $replacer, $string);
}

Le guide complet pour centrer en CSS

http://putaindecode.fr/posts/css/le-guide-complet-pour-centrer-en-css/

Centrer en CSS, c’est la base, et parfois, ce n’est pas si simple. Ce guide liste les techniques les plus connues pour réaliser cet effet centré.

7 lines JavaScript library for calling asynchronous functions

http://krasimirtsonev.com/blog/article/7-lines-JavaScript-library-for-calling-asynchronous-functions

Il y a aussi http://stackoverflow.com/questions/899102/how-do-i-store-javascript-functions-in-a-queue-for-them-to-be-executed-eventuall

// Function wrapping code.
// fn - reference to function.
// context - what you want "this" to be.
// params - array of parameters to pass to function.
var wrapFunction = function(fn, context, params) {
   return function() {
       fn.apply(context, params);
   };
}

// Create my function to be wrapped
var sayStuff = function(str) {
   alert(str);
}

// Wrap the function.  Make sure that the params are an array.
var fun1 = wrapFunction(sayStuff, this, ["Hello, world!"]);
var fun2 = wrapFunction(sayStuff, this, ["Goodbye, cruel world!"]);

// Create an array and append your functions to them
var funqueue = [];
funqueue.push(fun1);
funqueue.push(fun2);

// Remove and execute all items in the array
while (funqueue.length > 0) {
   (funqueue.shift())();  
}