Here are some code samples coming from the Rosetta
project, a website that translate simple algorithms in different languages.
C
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#define MAX_BUF 50
int main(void)
{
char buf[MAX_BUF];
time_t seconds = time(NULL);
struct tm *now = localtime(&seconds);
(void) printf("%d-%d-%d\n", now->tm_year + 1900, now->tm_mon + 1, now->tm_mday);
(void) strftime(buf, MAX_BUF, "%A, %B %e, %Y", now);
(void) printf("%s\n", buf);
return EXIT_SUCCESS;
}
lua
print( os.date( "%Y-%m-%d" ) )
print( os.date( "%A, %B %d, %Y" ) )
rust
use chrono;
fn main() {
let mut s = String::new();
let now = chrono::Utc::now();
s = now.format("%Y-%m-%d");
println!("{}", s);
s = now.format("%A, %B %d, %Y");
println!("{}", s);
}
sh
echo "Using a builtin function to showcase its highlighting."
date -I
date -R | sed 's/[^ ]* //4g'
vimscript
echo strftime("%Y-%m-%d")
echo strftime("%A, %B %d, %Y")
Markdown
# A big title
some text
> A quotation of someone anonymous.
cfg
[Category]
Variable=value
OtherVariable="escaped string"
LastVariable=100
TOML
[aspect]
consideration = false
XML
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<dict>
<key>author</key>
<string>la Fleur</string>
<key>name</key>
<string>some</string>
</dict>
SVG
<svg
xmlns="http://www.w3.org/2000/svg"
class="video-button"
viewBox="0 0 18 24"
stroke-width="2"
stroke-linecap="round"
stroke-linejoin="round"
fill="transparent"
stroke="white"
>
<rect fill="black" stroke="black" width="18" height="24" />
<polygon points="5 3 18 12 5 21 5 3"></polygon>
<text x="0" y="0">
<tspan dy=0>
Play !
</tspan>
</text>
</svg>
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sample page</title>
<script type="application/javascript">
let sample = "A sample string";
console.log(sample);
</script>
<style type="text/css">
p {
text-align: center;
}
</style>
</head>
<body>
<p>
Some text in the body.
</p>
</body>
</html>