SnippetVamp

Parce que yen a marre de chercher ses bouts de code partout...



TODO 1 ajax 3 astuce 68 auto_ 2 bash 1 bootstrap 14 conversion 2 crossbrowser 3 css 50 debug 10 dothtaccess 1 effets 1 erreurs 1 evenements 2 fallback 1 fichiers 27 filter 1 fonctions 73 form 1 graphisme 11 html 39 javascript 39 jquery 26 lib 2 mail 1 markdown 2 mobile 2 parser 13 php 91 pluXML 4 python 10 responsive 8 securite 17 social 1 texte 16 vanilla 4

.

debug

aff - python

# aff(var)
def aff(var):
    import pprint
    pprint.pprint(var)

python debug

http://warriordudimanche.net

<iframe width="100%" height="254" src="http://snippetvamp.warriordudimanche.net/snippetvamp.php?embed=5aa7c36af1179" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 13/03/2018

aff v2.0

    function aff($var,$stop=true){
        $dat=debug_backtrace();$origin='<table>';
        echo '<div style="background-color:rgba(0,0,0,0.8);color:red;padding:5px">Arret ligne <em><strong style="color:white;font-weight:bold">'.$dat[0]['line'].'</strong></em> dans le fichier <em style="color:white;font-weight:bold">'.$dat[0]['file'].'</em></div>';
        echo '<pre style="background-color:rgba(0,0,0,0.8);color:#fff;padding:10px"><code>';var_dump($var);echo '</code></pre>';
        foreach (array_reverse($dat) as $data){
            $dir=dirname($data['file']).'/';
            $fil=basename($data['file']);
            $origin.='<tr><td style="width:50%"><em style="color:#888">'.$dir.'</em></td><td style="max-width:10%"><em style="color:white;font-weight:bold">'.$fil.'</em></td><td style="max-width:10%"><em style="color:yellow;font-weight:bold">'.$data['function'].'()</em></td><td style="max-width:10%"> <em style="color:lightblue;font-weight:bold">'.$data['line'].'</em> </td></tr>';
        }
        $origin.='</table>';
        echo '<div style="background-color:rgba(0,0,0,0.8);color:#aaa;padding:10px">'.$origin.'</div>';
        if ($stop){exit();}
    }

debug fonctions php

<iframe width="100%" height="416" src="http://snippetvamp.warriordudimanche.net/snippetvamp.php?embed=56cf33ce98957" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 27/02/2016

Forcer l'affichage des erreurs

<?php
  error_reporting(E_ERROR | E_WARNING | E_PARSE);
  ini_set('display_errors', true);
  ini_set('display_startup_errors', TRUE);
?>

astuce debug php

http://blog.medev.ch/content/afficher-les-erreurs-php

<iframe width="100%" height="272" src="http://snippetvamp.warriordudimanche.net/snippetvamp.php?embed=550ec0a505a5c" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 22/03/2015

afficher variables, fonctions et constantes déclarées

//afficher toutes les variables déclarées
exit('<pre>' . htmlspecialchars(print_r(get_defined_vars(), true)) . '</pre>');
//afficher toutes les constantes déclarées
exit('<pre>' . htmlspecialchars(print_r(get_defined_constants(), true)) . '</pre>');
//afficher toutes les fonctions déclarées
exit('<pre>' . htmlspecialchars(print_r(get_defined_functions(), true)) . '</pre>');

astuce debug php

http://php.net/manual/fr/function.get-defined-vars.php

<iframe width="100%" height="290" src="http://snippetvamp.warriordudimanche.net/snippetvamp.php?embed=52c83df7d81a8" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 04/01/2014

bloquer la diffusion des erreurs et réagir (même les fatales)

ini_set('display_errors', '0');         
register_shutdown_function('shutdown');
function shutdown() 
{ 
       $error = error_get_last();
       if ($error['type'] === E_ERROR) {

      //do your shutdown stuff here
      //be care full do not call any other function from within shutdown function
      //as php may not wait until that function finishes
      //its a strange behavior. During testing I realized that if function is called 
      //from here that function may or may not finish and code below that function
      //call may or may not get executed. every time I had a different result. 

      // e.g.

      other_function();

      //code below this function may not get executed

       } 

} 

php astuce debug

http://stackoverflow.com/questions/6861033/how-to-catch-the-fatal-error-maximum-execution-time-of-30-seconds-exceeded-in-p

<iframe width="100%" height="596" src="http://snippetvamp.warriordudimanche.net/snippetvamp.php?embed=51b3637ed2c09" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 08/06/2013

n_print: tracer les variables sans exit();

<?php
/**
* Améliore la sortie print
*
* @author Tatane http://www.tatane.info/index.php/print_rn
* @author http://www.blog.cactuscrew.com/77-print_rn.html
* @param $data (array) tableau ou variable à examiner
* @param $name (string) nom a afficher
* @return false affiche les clef valeur du tableau $data
* @example n_print($array, 'Tableau de valeur');
*/
function n_print($data, $name = '') {
$aBackTrace = debug_backtrace();
echo '<h2>', $name, '</h2>';
echo '<fieldset style="border: 1px solid orange; padding: 5px;color: #333; background-color: #fff;">';
echo '<legend style="border:1px solid orange;padding: 1px;background-color:#eee;color:orange;">', basename($aBackTrace[0]['file']), ' ligne => ', $aBackTrace[0]['line'], '</legend>';
echo '<pre>', htmlentities(print_r($data, 1)), '</pre>';
echo '</fieldset><br />';
}
?>

php fonctions debug

http://shaarlet.knah-tsaeb.org/?HsF04A

<iframe width="100%" height="542" src="http://snippetvamp.warriordudimanche.net/snippetvamp.php?embed=51778cead8721" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 24/04/2013

auto_error_handler

<?php
# Error handler by bronco@warriordudimanche.net #################
function showline($line,$file){
    $f=file($file);$r='';
    for ($l=$line-2;$l<$line+2;$l++){
        if (isset($f[$l])){
            if ($l==$line-1){
                $r.='<em style="color:white;text-shadow:0 0 2px black"><strong>'.$l.' >> </strong> '.$f[$l].'</em>';
            }else{
                $r.='<strong>'.$l.' >> </strong> '.$f[$l];
            }
        }
    }
    return $r;
}
function error_handler($number, $message, $file, $line, $vars){
    echo "
        <div style='word-wrap: break-word;Box-sizing: Border-box ;border-radius:5px;padding:15px;margin-bottom:20px;box-shadow:0 2px 1px maroon;font-family:courier;position:absolute;top:0;left:0;background-color:rgba(255,100,100,0.2);width:100%;height:auto;position:relative;min-width:320px;'>
            <h1 style='color:red;border-radius:5px;background-color:pink;padding:5px;box-shadow:0 2px 1px maroon'>Erreur $number</h1>
            <p style=''> <em>$message </em> a la ligne <strong style='font-size:24px'>$line</strong> dans le fichier <strong style='font-size:24px'>file: $file.</strong></p>
            
            <pre style='font-weight:bold;padding:20px;margin-left:10px;color:orange;text-shadow:0 1px 1px maroon;box-shadow:inset 0 2px 1px maroon;border-radius:5px;background-color:red;'><code>".showline($line,$file)."</pre></code>
            <h1 style='color:red;border-radius:5px;background-color:pink;padding:5px;box-shadow:0 2px 1px maroon'>Variables</h1>
            <pre style='overflow:scroll;height:200px;'>";
            var_dump($vars) ;
            echo "</pre>
            <a style='display:block;text-align:right;font-size:14px;color:maroon;text-decoration:none;font-weight:bold;font-styl:italic;' href='http://warriordudimanche.net/'>Error handler par warriordudimanche.net</a>
        </div>";

    if ( ($number !== E_NOTICE) && ($number < 2048) ) {die("Erreur fatale.");}
}

set_error_handler('error_handler');
#################################################################
?>

php fonctions securite debug auto_

http://warriordudimanche.net

<iframe width="100%" height="812" src="http://snippetvamp.warriordudimanche.net/snippetvamp.php?embed=5173b7347d31f" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 23/04/2013

Email les erreurs au lieu de les afficher (handler)


// Our custom error handler
function nettuts_error_handler($number, $message, $file, $line, $vars){
    $email = "
        <p>An error ($number) occurred on line
        <strong>$line</strong> and in the <strong>file: $file.</strong>
        <p> $message </p>";

    $email .= "<pre>" . print_r($vars, 1) . "</pre>";

    $headers = 'Content-type: text/html; charset=iso-8859-1' . "rn";

    // Email the error to someone...
    error_log($email, 1, 'you@youremail.com', $headers);

    // Make sure that you decide how to respond to errors (on the user's side)
    // Either echo an error message, or kill the entire project. Up to you...
    // The code below ensures that we only "die" if the error was more than
    // just a NOTICE.
    if ( ($number !== E_NOTICE) && ($number < 2048) ) {
        die("There was an error. Please try again later.");
    }
}

// We should use our custom function to handle errors.
set_error_handler('nettuts_error_handler');

// Trigger an error... (var doesn't exist)
echo $somevarthatdoesnotexist;

php fonctions debug

<iframe width="100%" height="704" src="http://snippetvamp.warriordudimanche.net/snippetvamp.php?embed=516d38ac4213f" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 16/04/2013

Récupérer le code source d'une page en numérotant les lignes

// display source code
$lines = file('http://google.com/');
foreach ($lines as $line_num => $line) { 
    // loop thru each line and prepend line numbers
    echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>n";
}

php texte debug

http://perishablepress.com/code-snippets/#code-snippets_php

<iframe width="100%" height="290" src="http://snippetvamp.warriordudimanche.net/snippetvamp.php?embed=516d37f4bf364" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 16/04/2013

Fonction d'arrêt et de débuggage: AFF()

function aff($a,$stop=true){echo 'Arret a la ligne '.__LINE__.' du fichier '.__FILE__.'<pre>';var_dump($a);echo '</pre>';if ($stop){exit();}}

php fonctions debug

<iframe width="100%" height="218" src="http://snippetvamp.warriordudimanche.net/snippetvamp.php?embed=5167b5d528215" type="text/html"></iframe>

Texte seul - Permalink - Snippet public posté le 21/05/2013

Flux RSS de cette page


SnippetVamp 1.84 par Bronco - Page générée en 0.019 s