Bac à sable de présentation de codes sources avec

https://code.google.com/p/google-code-prettify

Styles disponibles: Prettify, Doxy, Sons of obsidian, Desert et Sunburst


Exemple en Language C

enum states { 
  LED_ON,
  LED_OFF
};

enum states state = LED_OFF;

while(1) {
  if(state == LED_OFF {
    led_on("ON");
    state = LED_ON;
  } else {
    led_off("OFF");
    state = LED_OFF;
  }
  sleep(1); // sleep for a second
}

Exemples en PHP

function passwdgenerator ($nb, $valeurs, $nbvaleurs)
{
        $resultat;
 
        for($i = 0; $i < $nb; $i++) {
                $alea = rand(0, $nbvaleurs-1);
                $val = $valeurs[$alea];
                if (strlen($val) == 0) {
                        // Prise d'une valeur "exclue" ;-)
                        $i--;
                        continue;
                }
                $resultat = $resultat.$val;
        }
 
        return $resultat;
}
<html>
  <head>
    <title><?= 'Fibonacci numbers' ?></title>

    <?php
      // PHP has a plethora of comment types
      /* What is a
         "plethora"? */
      function fib($n) {
        # I don't know.
        $a = 1;
        $b = 1;
        while (--$n >= 0) {
          echo "$a\n";
          $tmp = $a;
          $a += $b;
          $b = $tmp;
        }
      }
    ?>
  </head>
  <body>
    <?= fib(10) ?>
  </body>
</html>

Exemple en JavaScript

    <script type="text/javascript">
    // Say hello world until the user starts questioning
    // the meaningfulness of their existence.
    function helloWorld(world) {
    for (var i = 42; --i >= 0;) {
    		alert('Hello ' + String(world));
    	}
    }
    </script>
    <style>
    p { color: pink }
    b { color: blue }
    u { color: "umber" }
    </style>