CodePrinter

/* This is demo of JavaScript syntax * Below you can change some editor options */ function hello(arg) { var string = arg.join(''); if (/^H\w{2}.o\s*$/i.test(string)) { return string; } } var result = hello(['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!']); console.log(result); <?php namespace Vehicles; class car { var $fuel; function drive($distance) { if ($fuel - $distance > 0) { $fuel -= $distance; echo "Driving $distance miles"; } else echo "You don't have enough gas to go that far."; } function refuel($amount) { $fuel += $amount; } } ?> /* CSS example */ body { background-color:white; background-image:url("image.png"); color:#12345; /* invalid hexadecimal */ font-size:14pt; top:-40px; } div#container > p { font-family:"Helvetica Neue", Helvetica; font-style:italic; } <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>CodePrinter HTML example</title> <script type="text/javascript" src="CodePrinter.js"></script> <style type="text/css"> /* CSS syntax in HTML */ body { background-color:yellow; } </style> </head> <body> <div id="container"> <!-- html comment --> </div> </body> </html> /* C++ Hello World */ #include <iostream> using namespace std; int main(int argc, const char * argv[]) { cout << "Hello World!" << endl; return 0; } # Ruby Demo def bubble_sort(list) return list if list.size <= 1 # already sorted loop do swapped = false 0.upto(list.size-2) do |i| if list[i] > list[i+1] list[i], list[i+1] = list[i+1], list[i] # swap values swapped = true end end break unless swapped end list end import java.util.Scanner; import java.io.File; import java.io.IOException; public class ReadAndPrintScores { public static void main(String[] args) { try { Scanner s = new Scanner(new File("scores.dat")); while (s.hasNextInt()) { System.out.println(s.nextInt()); } } catch (IOException e) { System.out.println(e); } } } #!/usr/bin/perl use strict; use warnings; use Path::Class; my $dir = dir('foo','bar'); # foo/bar # Iterate over the content of foo/bar while (my $file = $dir->next) { # See if it is a directory and skip next if $file->is_dir(); # Print out the file name and path print $file->stringify . "\n"; } #!/bin/sh # This is a comment echo "List of files:" ls -lA FILE_LIST="`ls *.html`" echo FILE_LIST: ${FILE_LIST} RESULT="" for file in ${FILE_LIST} do FIRST_LINE=`head -2 ${file}` RESULT=${RESULT}${FIRST_LINE} done echo ${RESULT} | cat >FILE_HEADS echo "'$RESULT' written Script done. " # Assignment: number = 42 opposite = true # Conditions: number = -42 if opposite # Functions: square = (x) -> x * x # Arrays: list = [1, 2, 3, 4, 5] # Objects: math = root: Math.sqrt square: square cube: (x) -> x * square x # Splats: race = (winner, runners...) -> print winner, runners # Existence: alert "I knew it!" if elvis? # Array comprehensions: cubes = (math.cube num for num in list) -- -- Simple array example. -- with Gnat.Io; use Gnat.Io; procedure Arr1 is A: array(1..5) of Integer; -- Array subscripts 1 to 5. I: Integer; begin -- Read 'em in. for I in 1..5 loop Put("> "); Get(A(I)); end loop; -- Put 'em out in reverse order. Put("["); for I in reverse A'Range loop Put(A(I)); if I > A'First then Put(' '); end if; end loop; Put_Line("]"); end Arr1; Heading ======= Sub-heading ----------- Paragraphs are separated by a blank line. Text attributes *italic*, **bold**, `monospace`. A [link](http://example.com). Shopping list: * apples * oranges * pears Numbered list: 1. apples 2. oranges 3. pears The rain---not the reign---in Spain. -- SQL example SELECT Book.title AS Title, COUNT(*) AS Authors FROM Book JOIN Book_author ON Book.isbn = Book_author.isbn GROUP BY Book.title; CREATE TABLE tbl_1(id INT); INSERT INTO tbl_1(id) VALUES(1); INSERT INTO tbl_1(id) VALUES(2); COMMIT; UPDATE tbl_1 SET id=200 WHERE id=1; SAVEPOINT id_1upd; UPDATE tbl_1 SET id=1000 WHERE id=2; ROLLBACK TO id_1upd; SELECT id FROM tbl_1; CASE WHEN n > 0 THEN 'positive' WHEN n < 0 THEN 'negative' ELSE 'zero' END <?xml version="1.0"?> <!-- XML Example --> <svg width="20" height="20" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill-opacity="0.2"> <rect x="0" y="0" width="10" height="10" fill="white" /> <rect x="10" y="0" width="10" height="10" fill="black" /> <rect x="0" y="10" width="10" height="10" fill="black" /> <rect x="10" y="10" width="10" height="10" fill="white" /> </svg>