1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-01 19:02:22 +01:00

Merge branch 'master' into improved-benchmark

This commit is contained in:
Ethan P
2021-01-02 21:35:58 -08:00
committed by GitHub
244 changed files with 13830 additions and 1340 deletions

View File

@@ -4,10 +4,6 @@ snapshots/** text=auto eol=lf
syntax-tests/source/** text=auto eol=lf
syntax-tests/highlighted/** text=auto eol=lf
# BAT/CMD files always need CRLF EOLs
*.[Bb][Aa][Tt] text eol=crlf
*.[Cc][Mm][Dd] text eol=crlf
examples/* linguist-vendored
snapshots/* linguist-vendored
benchmarks/* linguist-vendored

View File

@@ -1,7 +1,9 @@
use bat::assets::HighlightingAssets;
/// This test ensures that we are not accidentally removing themes due to submodule updates.
/// It is 'ignore'd by default because it requires themes.bin to be up-to-date.
#[test]
#[ignore]
fn all_themes_are_present() {
let assets = HighlightingAssets::from_binary();
@@ -12,6 +14,8 @@ fn all_themes_are_present() {
themes,
vec![
"1337",
"Coldark-Cold",
"Coldark-Dark",
"DarkNeon",
"Dracula",
"GitHub",
@@ -26,13 +30,11 @@ fn all_themes_are_present() {
"Solarized (light)",
"Sublime Snazzy",
"TwoDark",
"ansi-dark",
"ansi-light",
"ansi",
"base16",
"base16-256",
"gruvbox",
"gruvbox-dark",
"gruvbox-light",
"gruvbox-white",
"zenburn"
]
);

View File

@@ -1,8 +1,8 @@
#!/usr/bin/env bash
cd "$(dirname "${BASH_SOURCE[0]}")"
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
if ! which hyperfine > /dev/null 2>&1; then
if ! command -v hyperfine > /dev/null 2>&1; then
echo "'hyperfine' does not seem to be installed."
echo "You can get it here: https://github.com/sharkdp/hyperfine"
exit 1

View File

@@ -1,10 +1,10 @@
#!/usr/bin/env bash
cd "$(dirname "${BASH_SOURCE[0]}")"
cd "$(dirname "${BASH_SOURCE[0]}")" || exit
# Check that Hyperfine is installed.
if ! which hyperfine > /dev/null 2>&1; then
echo "'hyperfine' does not seem to be installed." 1>&2
echo "You can get it here: https://github.com/sharkdp/hyperfine" 1>&2
if ! command -v hyperfine > /dev/null 2>&1; then
echo "'hyperfine' does not seem to be installed."
echo "You can get it here: https://github.com/sharkdp/hyperfine"
exit 1
fi

View File

@@ -405,6 +405,16 @@ fn pager_disable() {
.stdout(predicate::eq("hello world\n").normalize());
}
#[test]
fn pager_value_bat() {
bat()
.arg("--pager=bat")
.arg("--paging=always")
.arg("test.txt")
.assert()
.failure();
}
#[test]
fn alias_pager_disable() {
bat()
@@ -570,6 +580,18 @@ fn empty_file_leads_to_empty_output_with_grid_enabled() {
.stdout("");
}
#[test]
fn empty_file_leads_to_empty_output_with_rule_enabled() {
bat()
.arg("empty.txt")
.arg("--style=rule")
.arg("--decorations=always")
.arg("--terminal-width=80")
.assert()
.success()
.stdout("");
}
#[test]
fn filename_basic() {
bat()
@@ -668,6 +690,48 @@ fn header_padding() {
.stderr("");
}
#[test]
fn header_padding_rule() {
bat()
.arg("--decorations=always")
.arg("--style=header,rule")
.arg("--terminal-width=80")
.arg("test.txt")
.arg("single-line.txt")
.assert()
.stdout(
"File: test.txt
hello world
────────────────────────────────────────────────────────────────────────────────
File: single-line.txt
Single Line
",
)
.stderr("");
}
#[test]
fn grid_overrides_rule() {
bat()
.arg("--decorations=always")
.arg("--style=grid,rule")
.arg("--terminal-width=80")
.arg("test.txt")
.arg("single-line.txt")
.assert()
.stdout(
"\
────────────────────────────────────────────────────────────────────────────────
hello world
────────────────────────────────────────────────────────────────────────────────
────────────────────────────────────────────────────────────────────────────────
Single Line
────────────────────────────────────────────────────────────────────────────────
",
)
.stderr("\x1b[33m[bat warning]\x1b[0m: Style 'rule' is a subset of style 'grid', 'rule' will not be visible.\n");
}
#[cfg(target_os = "linux")]
#[test]
fn file_with_invalid_utf8_filename() {
@@ -749,3 +813,41 @@ fn show_all_mode() {
.stdout("hello·world␊\n├──┤␍␀␇␈␛")
.stderr("");
}
#[test]
fn plain_mode_does_not_add_nonexisting_newline() {
bat()
.arg("--paging=never")
.arg("--color=never")
.arg("--decorations=always")
.arg("--style=plain")
.arg("single-line.txt")
.assert()
.success()
.stdout("Single Line");
}
// Regression test for https://github.com/sharkdp/bat/issues/299
#[test]
fn grid_for_file_without_newline() {
bat()
.arg("--paging=never")
.arg("--color=never")
.arg("--terminal-width=80")
.arg("--wrap=never")
.arg("--decorations=always")
.arg("--style=full")
.arg("single-line.txt")
.assert()
.success()
.stdout(
"\
───────┬────────────────────────────────────────────────────────────────────────
│ File: single-line.txt
───────┼────────────────────────────────────────────────────────────────────────
1 │ Single Line
───────┴────────────────────────────────────────────────────────────────────────
",
)
.stderr("");
}

View File

@@ -19,17 +19,27 @@ snapshot_tests! {
grid: "grid",
header: "header",
numbers: "numbers",
rule: "rule",
changes_grid: "changes,grid",
changes_header: "changes,header",
changes_numbers: "changes,numbers",
changes_rule: "changes,rule",
grid_header: "grid,header",
grid_numbers: "grid,numbers",
grid_rule: "grid,rule",
header_numbers: "header,numbers",
header_rule: "header,rule",
changes_grid_header: "changes,grid,header",
changes_grid_numbers: "changes,grid,numbers",
changes_grid_rule: "changes,grid,rule",
changes_header_numbers: "changes,header,numbers",
changes_header_rule: "changes,header,rule",
grid_header_numbers: "grid,header,numbers",
grid_header_rule: "grid,header,rule",
header_numbers_rule: "header,numbers,rule",
changes_grid_header_numbers: "changes,grid,header,numbers",
changes_grid_header_rule: "changes,grid,header,rule",
changes_grid_header_numbers_rule: "changes,grid,header,numbers,rule",
full: "full",
plain: "plain",
}

View File

@@ -7,7 +7,7 @@ import shutil
def generate_snapshots():
single_styles = ["changes", "grid", "header", "numbers"]
single_styles = ["changes", "grid", "header", "numbers", "rule"]
collective_styles = ["full", "plain"]
for num in range(len(single_styles)):

View File

@@ -0,0 +1,26 @@
───────┬────────────────────────────────────────────────────────────────────────
│ File: sample.rs
───────┼────────────────────────────────────────────────────────────────────────
1 │ struct Rectangle {
2 │ width: u32,
3 │ height: u32,
4 │ }
5 │
6 _ │ fn main() {
7 │ let rect1 = Rectangle { width: 30, height: 50 };
8 │
9 │ println!(
10 ~ │ "The perimeter of the rectangle is {} pixels.",
11 ~ │ perimeter(&rect1)
12 │ );
13 + │ println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
14 │ }
15 │
16 │ fn area(rectangle: &Rectangle) -> u32 {
17 │ rectangle.width * rectangle.height
18 │ }
19 + │
20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
21 + │ (rectangle.width + rectangle.height) * 2
22 + │ }
───────┴────────────────────────────────────────────────────────────────────────

View File

@@ -0,0 +1,26 @@
──┬─────────────────────────────────────────────────────────────────────────────
│ File: sample.rs
──┼─────────────────────────────────────────────────────────────────────────────
│ struct Rectangle {
│ width: u32,
│ height: u32,
│ }
_ │ fn main() {
│ let rect1 = Rectangle { width: 30, height: 50 };
│ println!(
~ │ "The perimeter of the rectangle is {} pixels.",
~ │ perimeter(&rect1)
│ );
+ │ println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
│ }
│ fn area(rectangle: &Rectangle) -> u32 {
│ rectangle.width * rectangle.height
│ }
+ │
+ │ fn perimeter(rectangle: &Rectangle) -> u32 {
+ │ (rectangle.width + rectangle.height) * 2
+ │ }
──┴─────────────────────────────────────────────────────────────────────────────

View File

@@ -0,0 +1,24 @@
───────┬────────────────────────────────────────────────────────────────────────
1 │ struct Rectangle {
2 │ width: u32,
3 │ height: u32,
4 │ }
5 │
6 _ │ fn main() {
7 │ let rect1 = Rectangle { width: 30, height: 50 };
8 │
9 │ println!(
10 ~ │ "The perimeter of the rectangle is {} pixels.",
11 ~ │ perimeter(&rect1)
12 │ );
13 + │ println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
14 │ }
15 │
16 │ fn area(rectangle: &Rectangle) -> u32 {
17 │ rectangle.width * rectangle.height
18 │ }
19 + │
20 + │ fn perimeter(rectangle: &Rectangle) -> u32 {
21 + │ (rectangle.width + rectangle.height) * 2
22 + │ }
───────┴────────────────────────────────────────────────────────────────────────

View File

@@ -0,0 +1,24 @@
──┬─────────────────────────────────────────────────────────────────────────────
│ struct Rectangle {
│ width: u32,
│ height: u32,
│ }
_ │ fn main() {
│ let rect1 = Rectangle { width: 30, height: 50 };
│ println!(
~ │ "The perimeter of the rectangle is {} pixels.",
~ │ perimeter(&rect1)
│ );
+ │ println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
│ }
│ fn area(rectangle: &Rectangle) -> u32 {
│ rectangle.width * rectangle.height
│ }
+ │
+ │ fn perimeter(rectangle: &Rectangle) -> u32 {
+ │ (rectangle.width + rectangle.height) * 2
+ │ }
──┴─────────────────────────────────────────────────────────────────────────────

View File

@@ -0,0 +1,23 @@
File: sample.rs
1 struct Rectangle {
2 width: u32,
3 height: u32,
4 }
5
6 _ fn main() {
7 let rect1 = Rectangle { width: 30, height: 50 };
8
9 println!(
10 ~ "The perimeter of the rectangle is {} pixels.",
11 ~ perimeter(&rect1)
12 );
13 + println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
14 }
15
16 fn area(rectangle: &Rectangle) -> u32 {
17 rectangle.width * rectangle.height
18 }
19 +
20 + fn perimeter(rectangle: &Rectangle) -> u32 {
21 + (rectangle.width + rectangle.height) * 2
22 + }

View File

@@ -0,0 +1,23 @@
File: sample.rs
struct Rectangle {
width: u32,
height: u32,
}
_ fn main() {
let rect1 = Rectangle { width: 30, height: 50 };
println!(
~ "The perimeter of the rectangle is {} pixels.",
~ perimeter(&rect1)
);
+ println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
}
fn area(rectangle: &Rectangle) -> u32 {
rectangle.width * rectangle.height
}
+
+ fn perimeter(rectangle: &Rectangle) -> u32 {
+ (rectangle.width + rectangle.height) * 2
+ }

View File

@@ -0,0 +1,22 @@
1 struct Rectangle {
2 width: u32,
3 height: u32,
4 }
5
6 _ fn main() {
7 let rect1 = Rectangle { width: 30, height: 50 };
8
9 println!(
10 ~ "The perimeter of the rectangle is {} pixels.",
11 ~ perimeter(&rect1)
12 );
13 + println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
14 }
15
16 fn area(rectangle: &Rectangle) -> u32 {
17 rectangle.width * rectangle.height
18 }
19 +
20 + fn perimeter(rectangle: &Rectangle) -> u32 {
21 + (rectangle.width + rectangle.height) * 2
22 + }

View File

@@ -0,0 +1,22 @@
struct Rectangle {
width: u32,
height: u32,
}
_ fn main() {
let rect1 = Rectangle { width: 30, height: 50 };
println!(
~ "The perimeter of the rectangle is {} pixels.",
~ perimeter(&rect1)
);
+ println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
}
fn area(rectangle: &Rectangle) -> u32 {
rectangle.width * rectangle.height
}
+
+ fn perimeter(rectangle: &Rectangle) -> u32 {
+ (rectangle.width + rectangle.height) * 2
+ }

View File

@@ -0,0 +1,26 @@
─────┬──────────────────────────────────────────────────────────────────────────
│ File: sample.rs
─────┼──────────────────────────────────────────────────────────────────────────
1 │ struct Rectangle {
2 │ width: u32,
3 │ height: u32,
4 │ }
5 │
6 │ fn main() {
7 │ let rect1 = Rectangle { width: 30, height: 50 };
8 │
9 │ println!(
10 │ "The perimeter of the rectangle is {} pixels.",
11 │ perimeter(&rect1)
12 │ );
13 │ println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
14 │ }
15 │
16 │ fn area(rectangle: &Rectangle) -> u32 {
17 │ rectangle.width * rectangle.height
18 │ }
19 │
20 │ fn perimeter(rectangle: &Rectangle) -> u32 {
21 │ (rectangle.width + rectangle.height) * 2
22 │ }
─────┴──────────────────────────────────────────────────────────────────────────

View File

@@ -0,0 +1,26 @@
────────────────────────────────────────────────────────────────────────────────
File: sample.rs
────────────────────────────────────────────────────────────────────────────────
struct Rectangle {
width: u32,
height: u32,
}
fn main() {
let rect1 = Rectangle { width: 30, height: 50 };
println!(
"The perimeter of the rectangle is {} pixels.",
perimeter(&rect1)
);
println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
}
fn area(rectangle: &Rectangle) -> u32 {
rectangle.width * rectangle.height
}
fn perimeter(rectangle: &Rectangle) -> u32 {
(rectangle.width + rectangle.height) * 2
}
────────────────────────────────────────────────────────────────────────────────

View File

@@ -0,0 +1,24 @@
─────┬──────────────────────────────────────────────────────────────────────────
1 │ struct Rectangle {
2 │ width: u32,
3 │ height: u32,
4 │ }
5 │
6 │ fn main() {
7 │ let rect1 = Rectangle { width: 30, height: 50 };
8 │
9 │ println!(
10 │ "The perimeter of the rectangle is {} pixels.",
11 │ perimeter(&rect1)
12 │ );
13 │ println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
14 │ }
15 │
16 │ fn area(rectangle: &Rectangle) -> u32 {
17 │ rectangle.width * rectangle.height
18 │ }
19 │
20 │ fn perimeter(rectangle: &Rectangle) -> u32 {
21 │ (rectangle.width + rectangle.height) * 2
22 │ }
─────┴──────────────────────────────────────────────────────────────────────────

View File

@@ -0,0 +1,24 @@
────────────────────────────────────────────────────────────────────────────────
struct Rectangle {
width: u32,
height: u32,
}
fn main() {
let rect1 = Rectangle { width: 30, height: 50 };
println!(
"The perimeter of the rectangle is {} pixels.",
perimeter(&rect1)
);
println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
}
fn area(rectangle: &Rectangle) -> u32 {
rectangle.width * rectangle.height
}
fn perimeter(rectangle: &Rectangle) -> u32 {
(rectangle.width + rectangle.height) * 2
}
────────────────────────────────────────────────────────────────────────────────

View File

@@ -0,0 +1,23 @@
File: sample.rs
1 struct Rectangle {
2 width: u32,
3 height: u32,
4 }
5
6 fn main() {
7 let rect1 = Rectangle { width: 30, height: 50 };
8
9 println!(
10 "The perimeter of the rectangle is {} pixels.",
11 perimeter(&rect1)
12 );
13 println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
14 }
15
16 fn area(rectangle: &Rectangle) -> u32 {
17 rectangle.width * rectangle.height
18 }
19
20 fn perimeter(rectangle: &Rectangle) -> u32 {
21 (rectangle.width + rectangle.height) * 2
22 }

View File

@@ -0,0 +1,23 @@
File: sample.rs
struct Rectangle {
width: u32,
height: u32,
}
fn main() {
let rect1 = Rectangle { width: 30, height: 50 };
println!(
"The perimeter of the rectangle is {} pixels.",
perimeter(&rect1)
);
println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
}
fn area(rectangle: &Rectangle) -> u32 {
rectangle.width * rectangle.height
}
fn perimeter(rectangle: &Rectangle) -> u32 {
(rectangle.width + rectangle.height) * 2
}

View File

@@ -0,0 +1,22 @@
1 struct Rectangle {
2 width: u32,
3 height: u32,
4 }
5
6 fn main() {
7 let rect1 = Rectangle { width: 30, height: 50 };
8
9 println!(
10 "The perimeter of the rectangle is {} pixels.",
11 perimeter(&rect1)
12 );
13 println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
14 }
15
16 fn area(rectangle: &Rectangle) -> u32 {
17 rectangle.width * rectangle.height
18 }
19
20 fn perimeter(rectangle: &Rectangle) -> u32 {
21 (rectangle.width + rectangle.height) * 2
22 }

View File

@@ -0,0 +1,22 @@
struct Rectangle {
width: u32,
height: u32,
}
fn main() {
let rect1 = Rectangle { width: 30, height: 50 };
println!(
"The perimeter of the rectangle is {} pixels.",
perimeter(&rect1)
);
println!(r#"This line contains invalid utf8: "<22><><EFBFBD><EFBFBD><EFBFBD>"#;
}
fn area(rectangle: &Rectangle) -> u32 {
rectangle.width * rectangle.height
}
fn perimeter(rectangle: &Rectangle) -> u32 {
(rectangle.width + rectangle.height) * 2
}

View File

@@ -16,11 +16,32 @@ BAT_OPTIONS = [
"--italic-text=always",
]
SKIP_FILENAMES = [
"LICENSE.md",
"README.md",
"bat_options",
]
def get_options(source):
options = BAT_OPTIONS.copy()
source_dirpath = path.dirname(source)
options_file = path.join(source_dirpath, "bat_options")
try:
with open(options_file, "r") as f:
options.extend(map(lambda x: x.rstrip(), f.readlines()))
except FileNotFoundError:
pass
return options
def create_highlighted_versions(output_basepath):
root = os.path.dirname(os.path.abspath(__file__))
sources = path.join(root, "source", "*")
for source in glob.glob(path.join(root, "source", "*", "*")):
for source in glob.glob(path.join(sources, "*")) + glob.glob(path.join(sources, ".*")):
try:
env = os.environ.copy()
env.pop("PAGER", None)
@@ -31,16 +52,18 @@ def create_highlighted_versions(output_basepath):
env.pop("BAT_TABS", None)
env["COLORTERM"] = "truecolor" # make sure to output 24bit colors
bat_output = subprocess.check_output(
["bat"] + BAT_OPTIONS + [source], stderr=subprocess.PIPE, env=env,
)
source_dirname = path.basename(path.dirname(source))
source_filename = path.basename(source)
if source_filename == "LICENSE.md":
if source_filename in SKIP_FILENAMES:
continue
bat_output = subprocess.check_output(
["bat"] + get_options(source) + [source],
stderr=subprocess.PIPE,
env=env,
)
output_dir = path.join(output_basepath, source_dirname)
output_path = path.join(output_dir, source_filename)
@@ -65,7 +88,10 @@ def create_highlighted_versions(output_basepath):
)
sys.exit(1)
except FileNotFoundError:
print("Error: Could not execute 'bat'. Please make sure that the executable is available on the PATH.")
print(
"Error: Could not execute 'bat'. Please make sure that the executable "
"is available on the PATH."
)
sys.exit(1)

View File

@@ -0,0 +1,36 @@
<html>
<body>
<!-- #include file ="headers\header.inc" -->
<%
For i = 0 To 5
Response.Write("The number is " & i & "<br />")
Next
%>
<%
Response.Write("Hello World!")
%>
<%
Dim x(2,2)
x(0,0)="Volvo"
x(0,1)="BMW"
x(0,2)="Ford"
x(1,0)="Apple"
x(1,1)="Orange"
x(1,2)="Banana"
x(2,0)="Coke"
x(2,1)="Pepsi"
x(2,2)="Sprite"
for i=0 to 2
response.write("<p>")
for j=0 to 2
response.write(x(i,j) & "<br />")
next
response.write("</p>")
next
%>
</body>
</html>

View File

@@ -0,0 +1,75 @@
import flash.events.*;
import flash.events.MouseEvent;
package TestSyntax {
 public class TestSyntax extends flash.display.Sprite {
 public static const TEST_CONSTANT:Number = 33.333;
 var testAttribute:int = 1;
 public namespace TestNamespace;
 TestNamespace function Method2():void { }
 /**
 * Multi-line comment
 */
 override public function set x(value:Number):void
 {
 super.x = Math.round(value);
 }
 /**
 * Actual multi-line comment
 * Takes up multiple lines
 */
 override public function set y(value:Number):void
 {
 super.y = 0;
 }
 public function testFunction() {
 var test:String = 'hello';
 // arrays
 var testArray:Array = ["a", "b", "c", "d"];
 for (var i:uint = 0; i < testArray.length; i++)
 trace(testArray[i]);
 // objects
 var testObject:Object = {foo: 20, bar: 40};
 for (var key:String in testObject) {
 trace(testObject[key]);
 }
 for each (var objectValue:int in testObject) {
 trace(objectValue);
 }
 // dynamic variables
 var testDynamic:*;
 testDynamic = 75;
 testDynamic = "Seventy-five";
 // regex
 var testRegExp:RegExp = /foo-\d+/i;
 // XML
 var testXML:XML =
<employee>
 <firstName>Harold</firstName>
 <lastName>Webster</lastName>
</employee>;
 }
 private function anotherFunc(a:int, arg2:uint, arg3:Function, ... args) {
 }
 [Embed(source="sound1.mp3")] public var soundCls:Class;
 public function SoundAssetExample()
 {
 var mySound:SoundAsset = new soundCls() as SoundAsset;
 var sndChannel:SoundChannel = mySound.play();
 }
 }
}

View File

@@ -0,0 +1,42 @@
# This is a comment
#
ServerRoot ""
Listen 80
LoadModule mpm_event_module /usr/lib/apache2/modules/mod_mpm_event.so
<IfModule unixd_module>
User daemon
Group daemon
</IfModule>
ServerAdmin you@example.com
<Directory />
 AllowOverride none
 Require all denied
</Directory>
DocumentRoot "/usr/share/apache2/default-site/htdocs"
<Directory "/usr/share/apache2/default-site/htdocs">
 Options Indexes FollowSymLinks
 AllowOverride None
 Require all granted
</Directory>
<Files ".ht*">
 Require all denied
</Files>
ErrorLog "/var/log/apache2/error_log"
LogLevel warn
<IfModule log_config_module>
 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
 CustomLog "/var/log/apache2/access_log" common
</IfModule>
<IfModule alias_module>
 ScriptAlias /cgi-bin/ "/usr/lib/cgi-bin/"
</IfModule>
<IfModule mime_module>
 TypesConfig /etc/apache2/mime.types
 AddType application/x-compress .Z
 AddOutputFilter INCLUDES .shtml
</IfModule>
<IfModule proxy_html_module>
Include /etc/apache2/extra/proxy-html.conf
</IfModule>

View File

@@ -0,0 +1,25 @@
-- This is a comment
property defaultClientName : "Mary Smith"
on greetClient(nameOfClient)
 display dialog ("Hello " & nameOfClient & "!")
end greetClient
script testGreet
 greetClient(defaultClientName)
end script
run testGreet
greetClient("Joe Jones")
set myList to {1, "what", 3}
set beginning of myList to 0
set end of myList to "four"
myList
tell application "TextEdit"
 paragraph 1 of document 1
end tell

View File

@@ -0,0 +1,86 @@
global enlight
section .data
 red dq 0 ; some comment
 green dq 0
 blue dq 0
 data dq 0
 N dd 0
 M dd 0
 change dd 0
 delta db 0
section .text
enlight:
 call assign_arguments
 call set_data
 call make_deltas
 ret
assign_arguments:
 mov qword[red], rdi
 mov qword[green], rsi
 mov qword[blue], rdx
 mov dword[N], ecx
 mov dword[M], r8d
 mov dword[change], r9d
 mov al, byte[rsp + 16]
 mov byte[delta], al
 ret
set_data:
 mov eax, dword[change]
 cmp eax, 1
 jne not_1
 mov rax, qword[red]
 mov qword[data], rax
 ret
not_1:
 cmp eax, 2
 jne not_2
 mov rax, qword[green]
 mov qword[data], rax
 ret
not_2:
 mov rax, qword[blue]
 mov qword[data], rax
 ret
make_deltas:
 mov ecx, dword[N]
 mov eax, dword[M]
 imul ecx, eax
loop_start:
 call make_delta
 loop loop_start
 ret
make_delta:
 mov rax, qword[data]
 add rax, rcx
 dec rax
 mov dl, byte[delta]
 cmp dl, 0
 jl substracting
adding:
 add dl, byte[rax]
 jc adding_overflow
 mov byte[rax], dl
 ret
adding_overflow:
 mov byte[rax], 255 
 ret
substracting:
 mov r9b, dl
 mov dl, 0
 sub dl, r9b
 mov r8b, byte[rax]
 sub r8b, dl
 jc substracting_overflow
 mov byte[rax], r8b
 ret
; another comment
substracting_overflow:
 mov byte[rax], 0
 ret

View File

@@ -0,0 +1,59 @@
@echo off
:: Change to your LLVM installation
set "LLVMPath=C:\Program Files\LLVM"
:: Change to your Visual Studio 2017 installation
set "VSPath=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community"
set "VSVersion=14.10.25017"
:: Change to your Windows Kit version & installation
set "WinSDKVersion=10.0.15063.0"
set "WinSDKPath=C:\Program Files (x86)\Windows Kits\10"
:: Change this to your resulting exe
set "OUTPUT=test.exe"
:: Setup
set "VSBasePath=%VSPath%\VC\Tools\MSVC\%VSVersion%"
set "PATH=%PATH%;%LLVMPath%\bin;%VSBasePath%\bin\HostX64\x64"
:: Compiler Flags
set CFLAGS= ^
 -std=c++14 -Wall -Wextra
set CPPFLAGS= ^
 -I "%VSBasePath%\include" ^
 -I "%WinSDKPath%\Include\%WinSDKVersion%\shared" ^
 -I "%WinSDKPath%\Include\%WinSDKVersion%\ucrt" ^
 -I "%WinSDKPath%\Include\%WinSDKVersion%\um"
:: Linker Libs
set LDFLAGS= ^
 -machine:x64 ^
 -nodefaultlib ^
 -subsystem:console
set LDLIBS= ^
 -libpath:"%VSBasePath%\lib\x64" ^
 -libpath:"%WinSDKPath%\Lib\%WinSDKVersion%\ucrt\x64" ^
 -libpath:"%WinSDKPath%\Lib\%WinSDKVersion%\um\x64" ^
 libucrt.lib libvcruntime.lib libcmt.lib libcpmt.lib ^
 legacy_stdio_definitions.lib oldnames.lib ^
 legacy_stdio_wide_specifiers.lib ^
 kernel32.lib User32.lib
:: Compiling
@echo on
@for %%f in (*.cc) do (
 clang++.exe "%%~f" -o "%%~nf.o" -c %CFLAGS%
)
:: Linking
@set "LINK_FILES="
@for %%f in (*.o) do (
 @set "LINK_FILES=%LINK_FILES% %%~f"
)
lld-link.exe %LINK_FILES% -out:"%OUTPUT%" %LDFLAGS% %LDLIBS%

View File

@@ -0,0 +1,18 @@
@book{knuth1997art,
 title={The art of computer programming},
 author={Knuth, Donald Ervin},
 volume={3},
 year={1997},
 publisher={Pearson Education}
}
@article{egholm1993pna,
 title={PNA hybridizes to complementary oligonucleotides obeying the Watson--Crick hydrogen-bonding rules},
 author={Egholm, Michael and Buchardt, Ole and Christensen, Leif and Behrens, Carsten and Freier, Susan M and Driver, David A and Berg, Rolf H and Kim, Seog K and Norden, Bengt and Nielsen, Peter E},
 journal={Nature},
 volume={365},
 number={6446},
 pages={566--568},
 year={1993},
 publisher={Springer}
}

View File

@@ -0,0 +1,16 @@
# This is a file for testing syntax highlighting.
cmake_minimum_required(VERSION 3.13)
project(hello-bat VERSION 0.0.1 LANGUAGES C)
set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/")
file(GLOB_RECURSE SOURCES "${SOURCE_DIR}/*.c")
add_executable(hello-bat SOURCES)
find_package(assimp CONFIG)
target_link_libraries(hello-bat assimp)
option("ENABLE_TESTS" OFF)
if(ENABLE_TESTS)
 add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/tests/")
endif()

View File

@@ -0,0 +1,115 @@
/*Scrolling*/
html { scroll-behavior: smooth; }
/*Header text*/
.jumbotron {
 background-image: linear-gradient(90deg, #849EB5, #30394A);
 padding-bottom: 20px;
 padding-top: 20px;
 text-shadow: 0px 2px 4px #000000;
}
.container {
 margin-top: -25px;
}
/*Background related*/
body {
 background: #161616;
}
/*Text related CSS*/
h4 {
 font-size: 70px;
 color: #FFFFFF;
 font-family: News Cycle, serif;
}
h3 {
 color: #e5e5e5;
}
p {
 font-size: 17px;
 font-family: News Cycle, serif;
 color: #DEDEDE;
}
p2 {
 font-size: 24px;
 color: #DEDEDE;
 font-family: News Cycle, serif;
}
date {
 font-family: News Cycle, serif;
 font-style: italic;
 font-size: 17px;
 color: #DEDEDE;
}
jobtitle {
 font-size: 17px;
 font-weight: bold;
 font-family: News Cycle, serif;
 color: #DEDEDE;
}
jobtilenolink {
 font-size: 17px;
 font-weight: bold;
 font-family: News Cycle, serif;
 color: #DEDEDE;
}
li {
 font-family: News Cycle, serif;
 color: #DEDEDE;
}
a {
 color: #4A8ECC;
}
p a:visited {
 color: #4A8ECC;
}
.href {
 color: #4A8ECC;
}
a:visited {
 color: #4A8ECC;
}
p a:hover {
 color: #4FB1F4;
}
a:hover {
 color: #4FB1F4;
}
jobtitle:hover {
 color: #4FB1F4;
}
/*Section*/
section {
 background-color: #1B1B1B;
 padding: 20px;
 margin: -5px;
 margin-bottom: 30px;
 box-shadow: 0px 2px 4px rgba(0,0,0,0.3);
}
/*Icon related*/
.icon {
 position: relative;
 top: 3px;
 right: 5px;
}

View File

@@ -0,0 +1,7 @@
first,last,address,city,zip
John,Doe,120 any st.,"Anytown, WW",08123
a,b
1,"ha 
""ha"" 
ha",120 any st.,"Anytown, WW",08123
3,4,120 any st.,"Anytown, WW",08123
Can't render this file because it contains an unexpected character in line 2 and column 276.

View File

@@ -0,0 +1,58 @@
(ns clojure-sample.core
 (:gen-class))
 
 (require '[clj-time.core :as t])
 (require '[clj-time.format :as f])
 
 ;; Product record
 (defrecord Product [id name available price])
 
 ;; Positional constructor
 (def product1 (->Product "1" "T-Shirt 1" true 15.00))
 
 ;; Map constructor
 (def product2 (map->Product
 {:id "2"
 :name "T-Shirt 2"
 :available true
 :price 20.00}))
 
 ;; Nested
 (def product3 {:id "1"
 :name "Product 1"
 :available true
 :sellers [{:id "1"
 :name "Seller 1"
 :stock 3},
 {:id 2
 :name "Seller 2"
 :stock 5}]})
 
 ;; Set
 (def categories #{"shirts" "shoes" "belts"})
 
 ;; List
 (def wishlist '(1 2))
 
 ;; Recursion
 (defn factorial [value] (cond
 (<= value 1) 1
 :else (* value (factorial (- value 1)))))
 
 (def basic-formatter (f/formatter "YYYY-MM-dd hh:mm:ss"))
 (defn now [] (f/unparse basic-formatter (t/now)))
 (defn log
 ([] (println (now) "No message"))
 ([message] (println (now) message)))
 
 (defn -main
 [& args]
 (println (:id product1))
 (println (:name product2))
 (println (:name (get (:sellers product3) 0)))
 (println (first categories))
 (println wishlist)
 (println (factorial 5))
 (log)
 (log "Message"))
 

View File

@@ -0,0 +1,45 @@
processor : 0
model name : ARMv7 Processor rev 3 (v7l)
BogoMIPS : 270.00
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3
processor : 1
model name : ARMv7 Processor rev 3 (v7l)
BogoMIPS : 270.00
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3
processor : 2
model name : ARMv7 Processor rev 3 (v7l)
BogoMIPS : 270.00
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3
processor : 3
model name : ARMv7 Processor rev 3 (v7l)
BogoMIPS : 270.00
Features : half thumb fastmult vfp edsp neon vfpv3 tls vfpv4 idiva idivt vfpd32 lpae evtstrm crc32
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xd08
CPU revision : 3
Hardware : BCM2711
Revision : b03111
Serial : 1000000095fd9fc5
Model : Raspberry Pi 4 Model B Rev 1.1

View File

@@ -0,0 +1,117 @@
# An example file to test Crystal syntax highlighting in bat
my_var : Nil = nil
my_var_also : Int32 = 42
my_other_var = 4.0
another_float = 4.0_f32
another_float_2 = 4e10
another_float_3 = -0.5
big_one = 1_000_000.111_111e-4
ternary = 1 > 2 : 3 ? 4
my_symbol = :ThisOne?
my_other_symbol = :No_That_One!
plus = :+
minus = :-
my_string : String = "this string right here, with an interpolated value of #{my_var_also}"
my_array : Array(Int32) = [1,2,3,4]
my_tuple : Tuple(Int32, Int32, Int32, Int32) = {1,2,3,4}
my_named_tuple : NamedTuple(one: Int32, two: Int32) = {"one": 1, "two": 2}
my_hash : Hash(String, Int32) = {"one" => 1, "two" => 2}
my_proc : Proc(Int32, Int32) = ->(x : Int32){ x * x}
my_other_proc : Proc(String) = ->{ "Wow, neat!" }
puts my_string
puts(my_string)
enum Colors
 Red
 Green
 Blue
end
class Greeter
 @instance_field = Colors::Red
 @@class_field = Colors::Green
 def initialize(@name = "world")
 end
 def greet 
 puts "Hello, #{@name}"
 end
 def render_greeting : String
 "Hello, #{@name}"
 end
 def with_greeting
 yield render_greeting
 end
 def is_color_default?
 @instance_field == @@class_field
 end
 def self.greet_static(name : String) : Unit
 puts "Hello, #{name}"
 end
end
greeter = Greeter.new("bat")
greeter.with_greeting do |greeting|
 puts greeting
end
puts <<-EOF
 this is a heredoc and it has a value in it of #{greeter.render_greeting}!
EOF
# This is a command:
`echo yay!`
$?.success?
my_color = Colors::Red
puts 
 case my_color
 when Colors::Red, .red?
 "Red"
 when Colors::Green, .green?
 "Green"
 when Colors::Blue, .blue?
 "Blue"
 else
 "I dunno, man. Chartreuse? Maroon?"
 end
class MyGenericClass(T)
 def initialize(@wrapped_value : T)
 end
 def get
 return @wrapped_value
 end
end
def do_stuff_with_range(r : Range(Int|String))
 return if r.empty?
 return unless !(r.empty?)
 r.each do |item|
 if /e/.match(item.to_s)
 puts "#{item} contains the letter e!"
 elsif item.to_s.empty?
 break
 else
 next # this is unnecessary, but whatever
 end
 end
end
macro print_range(range)
 {% for i in range %}
 puts {{i.id}}
 {% end %}
end
print_range(1..3)
print_range(1...3)

View File

@@ -0,0 +1,44 @@
// selective import
import std.stdio : writeln, writefln;
// non-selective import
import std.algorithm;
/* a multiline comment
*
* this function is safe because it doesn't use pointer arithmetic
*/
int the_ultimate_answer() @safe {
 // assert1on
 assert(1 != 2);
 // now we can safely return our answer 
 return 42;
}
void main()
{
 // function call with string literal
 writeln("Hello World!");
 // an int array declaration
 int[] arr1 = [1, 2, 3];
 // an immutable double
 immutable double pi = 3.14;
 // a mutable double
 double d1 = pi;
 // a pointer
 double* dp1 = &d1;
 // another pointer to the same thingy
 auto a1 = &d1;
 // a constant bool
 const bool b1 = true;
 if (b1) {
 // another function call 
 writefln("%s\n%s\n%s\n", arr1, d1, the_ultimate_answer());
 }
 else if (!b1) {
 writeln("this seems wrong");
 }
 else {
 writeln("I'm giving up, this is too crazy for me");
 }
}

View File

@@ -0,0 +1,353 @@
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ced88213..973eba9a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,11 @@
 
 
 ## Features
+
+- Add a new `--diff` option that can be used to only show lines surrounding
+ Git changes, i.e. added, removed or modified lines. The amount of additional
+ context can be controlled with `--diff-context=N`. See #23 and #940
+
 ## Bugfixes
 ## Other
 ## `bat` as a library
diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs
index e5221455..f0f519ea 100644
--- a/src/bin/bat/app.rs
+++ b/src/bin/bat/app.rs
@@ -15,7 +15,7 @@ use console::Term;
 
 use bat::{
 assets::HighlightingAssets,
- config::Config,
+ config::{Config, VisibleLines},
 error::*,
 input::Input,
 line_range::{HighlightedLineRanges, LineRange, LineRanges},
@@ -196,13 +196,23 @@ impl App {
 }
 })
 .unwrap_or_else(|| String::from(HighlightingAssets::default_theme())),
- line_ranges: self
- .matches
- .values_of("line-range")
- .map(|vs| vs.map(LineRange::from).collect())
- .transpose()?
- .map(LineRanges::from)
- .unwrap_or_default(),
+ visible_lines: if self.matches.is_present("diff") {
+ VisibleLines::DiffContext(
+ self.matches
+ .value_of("diff-context")
+ .and_then(|t| t.parse().ok())
+ .unwrap_or(2),
+ )
+ } else {
+ VisibleLines::Ranges(
+ self.matches
+ .values_of("line-range")
+ .map(|vs| vs.map(LineRange::from).collect())
+ .transpose()?
+ .map(LineRanges::from)
+ .unwrap_or_default(),
+ )
+ },
 style_components,
 syntax_mapping,
 pager: self.matches.value_of("pager"),
diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs
index c7344991..85edefde 100644
--- a/src/bin/bat/clap_app.rs
+++ b/src/bin/bat/clap_app.rs
@@ -105,6 +105,34 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
 data to bat from STDIN when bat does not otherwise know \
 the filename."),
 )
+ .arg(
+ Arg::with_name("diff")
+ .long("diff")
+ .help("Only show lines that have been added/removed/modified.")
+ .long_help(
+ "Only show lines that have been added/removed/modified with respect \
+ to the Git index. Use --diff-context=N to control how much context you want to see.",
+ ),
+ )
+ .arg(
+ Arg::with_name("diff-context")
+ .long("diff-context")
+ .overrides_with("diff-context")
+ .takes_value(true)
+ .value_name("N")
+ .validator(
+ |n| {
+ n.parse::<usize>()
+ .map_err(|_| "must be a number")
+ .map(|_| ()) // Convert to Result<(), &str>
+ .map_err(|e| e.to_string())
+ }, // Convert to Result<(), String>
+ )
+ .hidden_short_help(true)
+ .long_help(
+ "Include N lines of context around added/removed/modified lines when using '--diff'.",
+ ),
+ )
 .arg(
 Arg::with_name("tabs")
 .long("tabs")
@@ -339,6 +367,7 @@ pub fn build_app(interactive_output: bool) -> ClapApp<'static, 'static> {
 .takes_value(true)
 .number_of_values(1)
 .value_name("N:M")
+ .conflicts_with("diff")
 .help("Only print the lines from N to M.")
 .long_help(
 "Only print the specified range of lines for each file. \
diff --git a/src/config.rs b/src/config.rs
index d5df9910..3c24b77f 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -5,6 +5,32 @@ use crate::style::StyleComponents;
 use crate::syntax_mapping::SyntaxMapping;
 use crate::wrapping::WrappingMode;
 
+#[derive(Debug, Clone)]
+pub enum VisibleLines {
+ /// Show all lines which are included in the line ranges
+ Ranges(LineRanges),
+
+ #[cfg(feature = "git")]
+ /// Only show lines surrounding added/deleted/modified lines
+ DiffContext(usize),
+}
+
+impl VisibleLines {
+ pub fn diff_context(&self) -> bool {
+ match self {
+ Self::Ranges(_) => false,
+ #[cfg(feature = "git")]
+ Self::DiffContext(_) => true,
+ }
+ }
+}
+
+impl Default for VisibleLines {
+ fn default() -> Self {
+ VisibleLines::Ranges(LineRanges::default())
+ }
+}
+
 #[derive(Debug, Clone, Default)]
 pub struct Config<'a> {
 /// The explicitly configured language, if any
@@ -39,8 +65,8 @@ pub struct Config<'a> {
 #[cfg(feature = "paging")]
 pub paging_mode: PagingMode,
 
- /// Specifies the lines that should be printed
- pub line_ranges: LineRanges,
+ /// Specifies which lines should be printed
+ pub visible_lines: VisibleLines,
 
 /// The syntax highlighting theme
 pub theme: String,
@@ -62,10 +88,7 @@ pub struct Config<'a> {
 fn default_config_should_include_all_lines() {
 use crate::line_range::RangeCheckResult;
 
- assert_eq!(
- Config::default().line_ranges.check(17),
- RangeCheckResult::InRange
- );
+ assert_eq!(LineRanges::default().check(17), RangeCheckResult::InRange);
 }
 
 #[test]
diff --git a/src/controller.rs b/src/controller.rs
index 09c6ec2a..f636d5fd 100644
--- a/src/controller.rs
+++ b/src/controller.rs
@@ -1,9 +1,13 @@
 use std::io::{self, Write};
 
 use crate::assets::HighlightingAssets;
-use crate::config::Config;
+use crate::config::{Config, VisibleLines};
+#[cfg(feature = "git")]
+use crate::diff::{get_git_diff, LineChanges};
 use crate::error::*;
 use crate::input::{Input, InputReader, OpenedInput};
+#[cfg(feature = "git")]
+use crate::line_range::LineRange;
 use crate::line_range::{LineRanges, RangeCheckResult};
 use crate::output::OutputType;
 #[cfg(feature = "paging")]
@@ -68,6 +72,32 @@ impl<'b> Controller<'b> {
 no_errors = false;
 }
 Ok(mut opened_input) => {
+ #[cfg(feature = "git")]
+ let line_changes = if self.config.visible_lines.diff_context()
+ || (!self.config.loop_through && self.config.style_components.changes())
+ {
+ if let crate::input::OpenedInputKind::OrdinaryFile(ref path) =
+ opened_input.kind
+ {
+ let diff = get_git_diff(path);
+
+ if self.config.visible_lines.diff_context()
+ && diff
+ .as_ref()
+ .map(|changes| changes.is_empty())
+ .unwrap_or(false)
+ {
+ continue;
+ }
+
+ diff
+ } else {
+ None
+ }
+ } else {
+ None
+ };
+
 let mut printer: Box<dyn Printer> = if self.config.loop_through {
 Box::new(SimplePrinter::new())
 } else {
@@ -75,10 +105,18 @@ impl<'b> Controller<'b> {
 &self.config,
 &self.assets,
 &mut opened_input,
+ #[cfg(feature = "git")]
+ &line_changes,
 ))
 };
 
- let result = self.print_file(&mut *printer, writer, &mut opened_input);
+ let result = self.print_file(
+ &mut *printer,
+ writer,
+ &mut opened_input,
+ #[cfg(feature = "git")]
+ &line_changes,
+ );
 
 if let Err(error) = result {
 handle_error(&error);
@@ -96,13 +134,31 @@ impl<'b> Controller<'b> {
 printer: &mut dyn Printer,
 writer: &mut dyn Write,
 input: &mut OpenedInput,
+ #[cfg(feature = "git")] line_changes: &Option<LineChanges>,
 ) -> Result<()> {
 if !input.reader.first_line.is_empty() || self.config.style_components.header() {
 printer.print_header(writer, input)?;
 }
 
 if !input.reader.first_line.is_empty() {
- self.print_file_ranges(printer, writer, &mut input.reader, &self.config.line_ranges)?;
+ let line_ranges = match self.config.visible_lines {
+ VisibleLines::Ranges(ref line_ranges) => line_ranges.clone(),
+ #[cfg(feature = "git")]
+ VisibleLines::DiffContext(context) => {
+ let mut line_ranges: Vec<LineRange> = vec![];
+
+ if let Some(line_changes) = line_changes {
+ for line in line_changes.keys() {
+ let line = *line as usize;
+ line_ranges.push(LineRange::new(line - context, line + context));
+ }
+ }
+
+ LineRanges::from(line_ranges)
+ }
+ };
+
+ self.print_file_ranges(printer, writer, &mut input.reader, &line_ranges)?;
 }
 printer.print_footer(writer, input)?;
 
diff --git a/src/pretty_printer.rs b/src/pretty_printer.rs
index 0c78ea90..13bd5dbc 100644
--- a/src/pretty_printer.rs
+++ b/src/pretty_printer.rs
@@ -6,7 +6,7 @@ use syntect::parsing::SyntaxReference;
 
 use crate::{
 assets::HighlightingAssets,
- config::Config,
+ config::{Config, VisibleLines},
 controller::Controller,
 error::Result,
 input::Input,
@@ -205,7 +205,7 @@ impl<'a> PrettyPrinter<'a> {
 
 /// Specify the lines that should be printed (default: all)
 pub fn line_ranges(&mut self, ranges: LineRanges) -> &mut Self {
- self.config.line_ranges = ranges;
+ self.config.visible_lines = VisibleLines::Ranges(ranges);
 self
 }
 
diff --git a/src/printer.rs b/src/printer.rs
index 5eed437e..2b245cfd 100644
--- a/src/printer.rs
+++ b/src/printer.rs
@@ -24,7 +24,7 @@ use crate::config::Config;
 use crate::decorations::LineChangesDecoration;
 use crate::decorations::{Decoration, GridBorderDecoration, LineNumberDecoration};
 #[cfg(feature = "git")]
-use crate::diff::{get_git_diff, LineChanges};
+use crate::diff::LineChanges;
 use crate::error::*;
 use crate::input::OpenedInput;
 use crate::line_range::RangeCheckResult;
@@ -90,7 +90,7 @@ pub(crate) struct InteractivePrinter<'a> {
 ansi_prefix_sgr: String,
 content_type: Option<ContentType>,
 #[cfg(feature = "git")]
- pub line_changes: Option<LineChanges>,
+ pub line_changes: &'a Option<LineChanges>,
 highlighter: Option<HighlightLines<'a>>,
 syntax_set: &'a SyntaxSet,
 background_color_highlight: Option<Color>,
@@ -101,6 +101,7 @@ impl<'a> InteractivePrinter<'a> {
 config: &'a Config,
 assets: &'a HighlightingAssets,
 input: &mut OpenedInput,
+ #[cfg(feature = "git")] line_changes: &'a Option<LineChanges>,
 ) -> Self {
 let theme = assets.get_theme(&config.theme);
 
@@ -145,9 +146,6 @@ impl<'a> InteractivePrinter<'a> {
 panel_width = 0;
 }
 
- #[cfg(feature = "git")]
- let mut line_changes = None;
-
 let highlighter = if input
 .reader
 .content_type
@@ -155,18 +153,6 @@ impl<'a> InteractivePrinter<'a> {
 {
 None
 } else {
- // Get the Git modifications
- #[cfg(feature = "git")]
- {
- use crate::input::OpenedInputKind;
-
- if config.style_components.changes() {
- if let OpenedInputKind::OrdinaryFile(ref path) = input.kind {
- line_changes = get_git_diff(path);
- }
- }
- }
-
 // Determine the type of syntax for highlighting
 let syntax = assets.get_syntax(config.language, input, &config.syntax_mapping);
 Some(HighlightLines::new(syntax, theme))

View File

@@ -0,0 +1,19 @@
ARG architecture=amd64
FROM $architecture/centos:7
LABEL com.example.version="0.2.1-beta"
ARG architecture
ENV INTERESTING_PATH /usr/bin/interesting-software
COPY entrypoint.sh /usr/bin/entrypoint.sh
RUN if [ "$architecture" = "i386" ]; then echo "Building i386 docker image" && \
 linux32 yum update -y && linux32 yum install -y mysql ; \
 else yum update -y && yum install -y mysql
EXPOSE 80/tcp
VOLUME [/var/lib/mysql/data]
ENTRYPOINT ["/usr/bin/entrypoint.sh"]

View File

@@ -0,0 +1,57 @@
# Keyword
export TEST_KEYWORD="bar"
export TEST_KEYWORD=12345
export TEST_KEYWORD=TRUE
# Variable
TEST_VARIABLE="Hello"
# String interpolation
TEST_INTERPOLATION_VARIABLE="$VAR1 test test$VAR2test test"
TEST_INTERPOLATION_SYNTAX_ONE="test test{$NVAR1}test{$NVAR2}test test"
TEST_INTERPOLATION_SYNTAX_TWO="test test${NVAR1}test${NVAR2}test test"
TEST_INTERPOLATION_SYNTAX_ALL="test$VAR1test test {VAR2}test test${VAR3}test"
# Unquoted
TEST_UNQUOTED=bar
TEST_UNQUOTED_NO_VALUE=
# White spaced
TEST_WHITE_SPACE =
TEST_WHITE_SPACE_STRING = "Hello"
TEST_WHITE_SPACE_UNQUOTED = bar
TEST_WHITE_SPACE_UNQUOTED_BOOL = false
TEST_WHITE_SPACE_UNQUOTED_NUM = 20
# language constants
TEST_TRUE=true
TEST_FALSE=false
TEST_NULL=null
TEST_TRUE_CAPITAL=TRUE
TEST_FALSE_CAPITAL=FALSE
TEST_NULL_CAPITAL=NULL
# Numerical values
TEST_NUM_DECIMAL=54
TEST_NUM_FLOAT=5.3
TEST_NUM=1e10
TEST_NUM_NEGATIVE=-42
TEST_NUM_OCTAL=057
TEST_NUM_HEX=0x1A
# Comments
#TEST_ONE=foobar
# TEST_TWO='foobar'
# TEST_THREE="foobar" # a comment on a commented row
TEST_FOUR="test test test" # this is a comment
TEST_FIVE="comment symbol # inside string" # this is a comment
TEST_SIX="comment symbol # and quotes \" \' inside quotes" # " this is a comment
# Escape sequences
TEST_ESCAPE="escaped characters \n \t \r \" \' \$ or maybe a backslash \\..."
# Double Quotes
TEST_DOUBLE="Lorem {$VAR1} ${VAR2} $VAR3 ipsum dolor sit amet\n\r\t\\"
# Single Quotes
TEST_SINGLE='Lorem {$VAR1} ${VAR2} $VAR3 ipsum dolor sit amet\n\r\t\\'

View File

@@ -0,0 +1,72 @@
-module(bat_erlang).
-export([main/0]).
-record(test, {
 name :: list(),
 data :: binary()
}).
-define(TESTMACRO, "testmacro").
-spec main() -> ok.
main() ->
 %% Handling Lists and Numbers
 List = [1, 2, 3, 4, $6, 2#00111],
 _Sum = lists:sum(List),
 _ = [(N * N) + N / N - N || N <- List, N > 2],
 [_Head, _SecondHead | _Tail] = List,
 _ = [1, atom, [list], <<"binary">>, {tuple, tuple}, #{map => key}, #test{name = "record"}],
 %% Handling Binaries 
 BinHelloWorld = <<"Hello World">>,
 <<X || <<X:1/binary>> <= BinHelloWorld >>,
 <<0,0,0,0,0,0,0,151>> = <<151:64/signed-integer>>,
 %% Handling Boolean and Atoms
 true = true andalso true,
 true = false orelse true,
 _ = true =:= true,
 _ = false =/= true,
 _ = 'HELLO' /= hello,
 _ = hello == world,
 %% Handling Maps and Records
 TestMap = #{a => 1, b => 2, c => 3},
 #{a := _Value, c := _} = TestMap,
 _ = TestMap#{d => 4},
 Record = #test{name = ?TESTMACRO},
 _ = Record#test.name,
 %% Conditionals
 case TestMap of
 #{b := B} ->
 B;
 _ ->
 ok
 end,
 if
 erlang:is_map(TestMap) ->
 map;
 true ->
 test_function(1)
 end,
 %% Messaging
 Self = erlang:self(),
 Self ! hello_world,
 receive
 hello_world ->
 ok;
 _ ->
 io:format("unknown message")
 after 1000 ->
 timeout
 end,
 ok.
test_function(N) when erlang:is_integer(N) -> integer;
test_function([_|_]) -> list;
test_function(<<_/binary>>) -> binary;
test_function(_) ->
 undefined.

View File

@@ -0,0 +1,67 @@
root:x:0:root
sys:x:3:bin
mem:x:8:
ftp:x:11:
mail:x:12:
log:x:19:
smmsp:x:25:
proc:x:26:polkitd
games:x:50:
lock:x:54:
network:x:90:
floppy:x:94:
scanner:x:96:
power:x:98:
adm:x:999:daemon
wheel:x:998:username
kmem:x:997:
tty:x:5:
utmp:x:996:
audio:x:995:mpd,username
disk:x:994:
input:x:993:
kvm:x:992:
lp:x:991:
optical:x:990:username
render:x:989:
storage:x:988:username
uucp:x:987:
video:x:986:username
users:x:985:
systemd-journal:x:984:
rfkill:x:983:
bin:x:1:daemon
daemon:x:2:bin
http:x:33:
nobody:x:65534:
dbus:x:81:
systemd-journal-remote:x:982:
systemd-network:x:981:
systemd-resolve:x:980:
systemd-timesync:x:979:
systemd-coredump:x:978:
uuidd:x:68:
username:x:1000:
git:x:977:
avahi:x:976:
colord:x:975:
polkitd:x:102:
mpd:x:45:
rtkit:x:133:
transmission:x:169:
wireshark:x:150:username
lightdm:x:974:
geoclue:x:973:
usbmux:x:140:
dhcpcd:x:972:
brlapi:x:971:
gdm:x:120:
libvirt:x:970:
flatpak:x:969:
gluster:x:968:
rpc:x:32:
tor:x:43:
rslsync:x:967:
docker:x:966:username
sambashare:x:1002:username
named:x:40:

View File

@@ -0,0 +1,77 @@
set fish_greeting ""
begin
 set --local AUTOJUMP_PATH $XDG_CONFIG_HOME/fish/functions/autojump.fish
 if test -e $AUTOJUMP_PATH
 source $AUTOJUMP_PATH
 end
end
fish_vi_key_bindings
function fish_prompt
 set_color brblack
 echo -n "["(date "+%H:%M")"] "
 set_color blue
 echo -n (hostname)
 if [ $PWD != $HOME ]
 set_color brblack
 echo -n ':'
 set_color yellow
 echo -n (basename $PWD)
 end
 set_color green
 printf '%s ' (__fish_git_prompt)
 set_color red
 echo -n '| '
 set_color normal
end
function fish_greeting
 echo
 echo -e (uname -ro | awk '{print " \\\\e[1mOS: \\\\e[0;32m"$0"\\\\e[0m"}')
 echo -e (uptime -p | sed 's/^up //' | awk '{print " \\\\e[1mUptime: \\\\e[0;32m"$0"\\\\e[0m"}')
 echo -e (uname -n | awk '{print " \\\\e[1mHostname: \\\\e[0;32m"$0"\\\\e[0m"}')
 echo -e " \\e[1mDisk usage:\\e[0m"
 echo
 echo -ne (\
 df -l -h | grep -E 'dev/(xvda|sd|mapper)' | \
 awk '{printf "\\\\t%s\\\\t%4s / %4s %s\\\\n\n", $6, $3, $2, $5}' | \
 sed -e 's/^\(.*\([8][5-9]\|[9][0-9]\)%.*\)$/\\\\e[0;31m\1\\\\e[0m/' -e 's/^\(.*\([7][5-9]\|[8][0-4]\)%.*\)$/\\\\e[0;33m\1\\\\e[0m/' | \
 paste -sd ''\
 )
 echo
 echo -e " \\e[1mNetwork:\\e[0m"
 echo
 # http://tdt.rocks/linux_network_interface_naming.html
 echo -ne (\
 ip addr show up scope global | \
 grep -E ': <|inet' | \
 sed \
 -e 's/^[[:digit:]]\+: //' \
 -e 's/: <.*//' \
 -e 's/.*inet[[:digit:]]* //' \
 -e 's/\/.*//'| \
 awk 'BEGIN {i=""} /\.|:/ {print i" "$0"\\\n"; next} // {i = $0}' | \
 sort | \
 column -t -R1 | \
 # public addresses are underlined for visibility \
 sed 's/ \([^ ]\+\)$/ \\\e[4m\1/' | \
 # private addresses are not \
 sed 's/m\(\(10\.\|172\.\(1[6-9]\|2[0-9]\|3[01]\)\|192\.168\.\).*\)/m\\\e[24m\1/' | \
 # unknown interfaces are cyan \
 sed 's/^\( *[^ ]\+\)/\\\e[36m\1/' | \
 # ethernet interfaces are normal \
 sed 's/\(\(en\|em\|eth\)[^ ]* .*\)/\\\e[39m\1/' | \
 # wireless interfaces are purple \
 sed 's/\(wl[^ ]* .*\)/\\\e[35m\1/' | \
 # wwan interfaces are yellow \
 sed 's/\(ww[^ ]* .*\).*/\\\e[33m\1/' | \
 sed 's/$/\\\e[0m/' | \
 sed 's/^/\t/' \
 )
 echo
 set_color normal
end

View File

@@ -0,0 +1,42 @@
#version 330 core
#ifdef TEST
layout (location = 0) in vec4 vertex;
#else
layout (location = 6) in vec4 vertex;
#endif
out vec2 p_textureVertex;
/*
 * This stores offsets
 */
struct Data
{
 double offsetX;
 double offsetY;
}
uniform mat4 projectionMatrix;
uniform bool test;
uniform Data data;
double calc()
{
 if (test)
 {
 return 1.0;
 }
 else
 {
 return 0.0;
 }
}
void main()
{
 // This GLSL code serves the purpose of bat syntax highlighting tests
 double x = data.offsetX + calc();
 gl_Position = projectionMatrix * vec4(vertex.xy, data.offsetX, data.offsetY);
 p_textureVertex = vertex.zw;
}

View File

@@ -0,0 +1,16 @@
#
# Comment
[attr]binary -diff -merge -text
* text=auto
*.c diff=c
*.cc text diff=cpp
*.o binary
*.bat text eol=crlf
*.lock text -diff
*.*ignore text
*.patch -text
.gitattributes linguist-language=gitattributes
.gitkeep export-ignore

View File

@@ -0,0 +1,107 @@
[alias]
 br = branch
 branch = branch -a
 c = clone --recursive
 ci = commit
 cl = clone
 co = checkout
 contributors = shortlog --summary --numbered
 lg = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)'
 remote = remote -v
 st = status
 tag = tag -l
[apply]
 whitespace = fix
[color]
 ui = true
[color "branch"]
 current = yellow
 local = yellow
 remote = green
[color "diff"]
 commit = yellow bold
 frag = magenta bold
 meta = yellow
 new = green bold
 old = red bold
 whitespace = red reverse
[color "diff-highlight"]
 newHighlight = green bold 22
 newNormal = green bold
 oldHighlight = red bold 52
 oldNormal = red bold
[color "status"]
 added = green
 changed = yellow
 untracked = cyan
[commit]
 gpgsign = true
[core]
 editor = /usr/bin/vim
 # global exclude
 excludesfile = /home/frank/.config/git/ignore
 pager = delta
 ; broken on old machines
 untrackedCache = true
[credential]
 helper = store
[delta]
 features = line-numbers decorations
 max-line-length = 1024
 whitespace-error-style = 22 reverse
[delta "decorations"]
 commit-decoration-style = bold yellow box ul
 file-decoration-style = none
 file-style = bold yellow
 syntax-theme = gruvbox
[diff]
 submodule = diff
 algorithm = histogram
 renames = copies
[difftool]
 prompt = false
[difftool "wrapper"]
 binary = true
 cmd = git-difftool-wrapper \"$LOCAL\" \"$REMOTE\"
[diff "pdfconv"]
 textconv = pdftohtml -stdout
[fetch]
 negotiationAlgorithm = skipping
 parallel = 0
[help]
 autocorrect = 1
[index]
 version = 4
[interactive]
 diffFilter = delta --color-only
[merge]
 log = true
[protocol]
 version = 2
[pull]
 rebase = true
[push]
 default = current
 recurseSubmodules = on-demand
[rebase]
 autoStash = true
[rerere]
 autoUpdate = true
 enabled = true
[sequence]
 editor = interactive-rebase-tool
[submodule]
 fetchJobs = 0
[tag]
 gpgSign = true
 sort = -version:refname
[url "git@gist.github.com:"]
 insteadOf = gist:
 pushInsteadOf = https://gist.github.com/
[url "git@github.com:"]
 insteadOf = gh:
 pushInsteadOf = https://github.com/
[user]
 email = f.nord@example.com
 name = Frank Nord
 signingkey = AAAAAAAAAAAAAAAA

View File

@@ -0,0 +1,145 @@
# Token::
# Punctuator
# Name
# IntValue
# FloatValue
# StringValue
# Punctuator:: one of
# ! $ ( ) ... : = @ [ ] { | }
# Name::
# /[_A-Za-z][_0-9A-Za-z]*/
# Document :
# Definition (list)
# Definition :
# ExecutableDefinition
# TypeSystemDefinition
# TypeSystemExtension
# ExecutableDefinition :
# FragmentDefinition
# OperationDefintion
# FragmentDefinition
type someType {
 id: ID
}
fragment subsriberFields on someType {
 id
 name
 fooInt(int: 1234, negInt: -56789, zero: 0)
 fooFloat(
 float: 1.1
 floatExp: 1.4e10
 floatExpSign1: 1.4e+10
 floatExpSign2: 1.5e-40
 floatExpBigE: 1.5E10
 )
 fooBool(x: true, y: false)
 fooString(str: "hello", strUni: "\u2116", strEscWs: "\t")
 fooLongStr(
 lStr: """
 Hello Reader,
 This is a long string block.
 Best,
 Writer
 """
 )
 fooNull(nullThing: null)
 fooList(numList: [1, 2, 3], strList: ["a", "b", "c"])
 fooObj(someObj: { str: "hi", int: 2 })
}
# OperationDefintion
query _A1 {
 getThings(strArg: "string") {
 id # commas here are ignored but valid
 name
 }
}
query _A2($x: String) {
 someFn(episode: $x) {
 name
 }
}
mutation B1 {
 changeThings(intArg: 123) {
 parent {
 nestedField1
 nestedField2
 }
 }
}
subscription C1_Hello {
 subsribePlease(floatArg: 1.4) {
 id
 ...subsriberFields
 }
}
# TypeSystemDefinition :
# SchemaDefinition
# TypeDefinition
schema {
 query: Query
 mutation: Mutation
}
type Query {
 """
 Can provide documentation this way.
 """
 scalars: Scalars
 someList: SomeLists
 fooBar: FooBar
}
interface Thing {
 id: ID!
}
type Scalars implements Thing {
 id: ID!
 int: Int!
 float: Float!
 str: String! @deprecated(reason: "Need to test a directive")
 bool: Boolean
 type: StringTypes
}
type SomeLists {
 ints: [Int!]!
}
type Foo {
 fooVal: String
}
type Bar {
 barVal: String
}
union FooBar = Foo | Bar
enum StringTypes {
 ONE
 TWO
}
input Xyz {
 id: ID!
}
type Mutation {
 createXyz(input: xyz!): Xyz!
}

View File

@@ -0,0 +1,41 @@
digraph {
 label = <Label <font color='red'><b>formating</b></font>,<br/> test <font point-size='20'>is</font> done<br/> here <i>now.</i>>;
 node [shape=box]
 rankdir=LR
 margin=0.1
 a->b
 // http://www.graphviz.org/doc/info/colors.html
 // note: style=filled!
 node [shape=box colorscheme=paired12 style=filled]
 margin=0.1
 a2[fillcolor=1]
 b2[fillcolor=3]
 a2->b2->x2
 // http://www.graphviz.org/doc/info/colors.html
 // note: style=filled!
 node [shape=box colorscheme=paired12 style=filled]
 rankdir=LR
 margin=0.1
 c1[fillcolor=1]
 c2[fillcolor=2]
 c3[fillcolor=3]
 c4[fillcolor=4]
 c5[fillcolor=5]
 c6[fillcolor=6]
 c7[fillcolor=7]
 c8[fillcolor=8]
 c9[fillcolor=9]
 c10[fillcolor=10]
 c11[fillcolor=11]
 c12[fillcolor=12]
 c->{c1 c3 c5 c7 c9 c11}
 c1->c2
 c3->c4
 c5->c6
 c7->c8
 c9->c10
 c11->c12
}

View File

@@ -0,0 +1,3 @@
graph {
 a--b
}

View File

@@ -0,0 +1,77 @@
interface Display {
 String asText()
}
trait Entity {
 Integer id
}
class Product implements Entity, Display {
 public String name
 public Boolean available
 public Float price
 private String key
 protected String data
 /**
 * Creates a new product instance.
 * @param id Product ID.
 * @param name Product name.
 * @param available Product availability.
 * @param price Product price.
 * @param key Product key.
 * @param data Product internal data.
 */
 Product(id, name, available, price, key = "key", data = "internal") {
 this.id = id
 this.name = name
 this.available = available
 this.price = price
 this.key = key
 this.data = data
 }
 /**@
 * Returns product data as text.
 * @return Data string.
 */
 String asText() {
 return """ID [${id}] Name [${name}] Available [${available}] Price [${price}]"""
 }
}
/* Creates a new product instance */
def product = new Product(1, "T-Shirt", true, 15.00)
println(product.asText())
product.available = false
product.price = 0.0
// Check values
assert product.asText() == "ID [1] Name [T-Shirt] Available [false] Price [0.0]"
def factorial(Integer value) {
 if (value <= 1) {
 return 1
 } else {
 return value * factorial(value - 1)
 }
}
assert factorial(5) == 120
static String join(List<String> list, String separator) {
 String data = ""
 list.each { item ->
 data += item + separator
 }
 data = data.substring(0, data.length() - 1)
 return data
}
assert join(["g", "r", "o", "o", "v", "y"], " ") == "g r o o v y"

View File

@@ -0,0 +1,115 @@
<!DOCTYPE html SYSTEM "about:legacy-compat">
<html>
 <!-- Behold my erudite commentary -->
 <head>
 <title>Bat Syntax Test</title>
 <meta charset="utf-8"> 
 <script>
 const x = 'world';
 function logGreeting() {
 console.log(`Hello, ${x}`);
 }
 </script>
 </head>
 <body>
 <div>
 <h1>Here find some simple tags</h1>
 <br />
 <p center style="color: rebeccapurple;">
 Lorem <strong>ipsum</strong> dolor sit amet consectetur adipisicing
 elit. A quo, autem quaerat explicabo impedit mollitia amet molestiae
 nulla cum architecto ducimus itaque sit blanditiis quasi animi optio ab
 facilis nihil?
 </p>
 <p>
 Here are some escaped characters: &amp; (ampersand), &agrave; (a with grave), &#8470; (numero sign).
 </p>
 </div>
 <div>
 <h1>This is a form that demonstrates loose attribute formatting</h1>
 <form action="POST">
 <input
 disabled
 type="text"
 name="text input"
 id="specificTextInput"
 value="yes"
 />
 </form>
 </div>
 <div>
 <h1>A table with normal closing tags</h1>
 <table>
 <caption>
 Pet Features
 </caption>
 <colgroup>
 <col />
 <col />
 <col />
 </colgroup>
 <thead>
 <tr>
 <th>Feature</th>
 <th>Cat</th>
 <th>Dog</th>
 </tr>
 </thead>
 <tbody>
 <tr>
 <td>Tail</td>
 <td>✔</td>
 <td>✔</td>
 </tr>
 <tr>
 <td>Eyes</td>
 <td>✔</td>
 <td>✔</td>
 </tr>
 <tr>
 <td>Ears</td>
 <td>✔</td>
 <td>✔</td>
 </tr>
 <tr>
 <td>Barking</td>
 <td></td>
 <td>✔</td>
 </tr>
 <tr>
 <td>Litter Box</td>
 <td>✔</td>
 <td></td>
 </tr>
 </tbody>
 </table>
 </div>
 <div>
 <h1>A table without closing tags</h1>
 <table>
 <caption>Pet Features
 <colgroup><col><col><col>
 <thead>
 <tr> <th>Feature <th>Cat <th>Dog
 <tbody>
 <tr> <td>Tail <td>✔ <td>✔
 <tr> <td>Eyes <td>✔ <td>✔
 <tr> <td>Ears <td>✔ <td>✔
 <tr> <td>Barking <td> <td>✔
 <tr> <td>Litter Box <td>✔ <td>
 </tbody>
 </table>
 </div>
 <div>
 <h1>A math section with CDATA</h1>
 <p>You can add a string to a number, but this stringifies the number:</p>
 <math>
 <ms><![CDATA[a / b]]></ms>
 <mo>-</mo>
 <mn>7</mn>
 <mo>=</mo>
 <ms><![CDATA[a / b - 7]]></ms>
 </math>
 </div>
 </body>
</html>

View File

@@ -0,0 +1,8 @@
#this is a comment in the hosts file
127.0.0.1  localhost
192.168.0.1 sample.test #a comment
192.160.0.200 try.sample.test try #another comment
216.58.223.238 google.com
::1 localhost.try ip6-localhost

View File

@@ -0,0 +1,68 @@
import data.matrix.notation
import data.vector2
/-!
Helpers that don't currently fit elsewhere...
-/
lemma split_eq {m n : Type*} (x : m × n) (p p' : m × n) :
 p = x p' = x (x p x p') := by tauto
-- For `playfield`s, the piece type and/or piece index type.
variables (X : Type*)
variables [has_repr X]
namespace chess.utils
section repr
/--
An auxiliary wrapper for `option X` that allows for overriding the `has_repr` instance
for `option`, and rather, output just the value in the `some` and a custom provided
`string` for `none`.
-/
structure option_wrapper :=
(val : option X)
(none_s : string)
instance wrapped_option_repr : has_repr (option_wrapper X) :=
λ val, s, (option.map has_repr.repr val).get_or_else s
variables {X}
/--
Construct an `option_wrapper` term from a provided `option X` and the `string`
that will override the `has_repr.repr` for `none`.
-/
def option_wrap (val : option X) (none_s : string) : option_wrapper X := val, none_s
-- The size of the "vectors" for a `fin n' → X`, for `has_repr` definitions
variables {m' n' : }
/--
For a "vector" `X^n'` represented by the type `Π n' : , fin n' → X`, where
the `X` has a `has_repr` instance itself, we can provide a `has_repr` for the "vector".
This definition is used for displaying rows of the playfield, when it is defined
via a `matrix`, likely through notation.
-/
def vec_repr : Π {n' : }, (fin n' X) string :=
λ _ v, string.intercalate ", " ((vector.of_fn v).to_list.map repr)
instance vec_repr_instance : has_repr (fin n' X) := vec_repr
/--
For a `matrix` `X^(m' × n')` where the `X` has a `has_repr` instance itself,
we can provide a `has_repr` for the matrix, using `vec_repr` for each of the rows of the matrix.
This definition is used for displaying the playfield, when it is defined
via a `matrix`, likely through notation.
-/
def matrix_repr : Π {m' n'}, matrix (fin m') (fin n') X string :=
λ _ _ M, string.intercalate ";\n" ((vector.of_fn M).to_list.map repr)
instance matrix_repr_instance :
 has_repr (matrix (fin n') (fin m') X) := matrix_repr
end repr
end chess.utils

View File

@@ -0,0 +1,80 @@
(cl:defpackage :chillax.utils
 (:use :cl :alexandria)
 (:export
 :fun :mkhash :hashget :strcat :dequote :at))
(in-package :chillax.utils)
;;; Functions
(defmacro fun (&body body)
 "This macro puts the FUN back in FUNCTION."
 `(lambda (&optional _) (declare (ignorable _)) ,@body))
;;; Hash tables
(defun mkhash (&rest keys-and-values &aux (table (make-hash-table :test #'equal)))
 "Convenience function for `literal' hash table definition."
 (loop for (key val) on keys-and-values by #'cddr do (setf (gethash key table) val)
 finally (return table)))
(defun hashget (hash &rest keys)
 "Convenience function for recursively accessing hash tables."
 (reduce (lambda (h k) (gethash k h)) keys :initial-value hash))
(define-compiler-macro hashget (hash &rest keys)
 (if (null keys) hash
 (let ((hash-sym (make-symbol "HASH"))
 (key-syms (loop for i below (length keys)
 collect (make-symbol (format nil "~:@(~:R~)-KEY" i)))))
 `(let ((,hash-sym ,hash)
 ,@(loop for key in keys for sym in key-syms
 collect `(,sym ,key)))
 ,(reduce (lambda (hash key) `(gethash ,key ,hash))
 key-syms :initial-value hash-sym)))))
(defun (setf hashget) (new-value hash key &rest more-keys)
 "Uses the last key given to hashget to insert NEW-VALUE into the hash table
returned by the second-to-last key.
tl;dr: DWIM SETF function for HASHGET."
 (if more-keys
 (setf (gethash (car (last more-keys))
 (apply #'hashget hash key (butlast more-keys)))
 new-value)
 (setf (gethash key hash) new-value)))
;;; Strings
(defun strcat (string &rest more-strings)
 (apply #'concatenate 'string string more-strings))
(defun dequote (string)
 (let ((len (length string)))
 (if (and (> len 1) (starts-with #\" string) (ends-with #\" string))
 (subseq string 1 (- len 1))
 string)))
;;;
;;; At
;;;
(defgeneric at (doc &rest keys))
(defgeneric (setf at) (new-value doc key &rest more-keys))
(defmethod at ((doc hash-table) &rest keys)
 (apply #'hashget doc keys))
(defmethod (setf at) (new-value (doc hash-table) key &rest more-keys)
 (apply #'(setf hashget) new-value doc key more-keys))
(defmethod at ((doc list) &rest keys)
 (reduce (lambda (alist key)
 (cdr (assoc key alist :test #'equal)))
 keys :initial-value doc))
(defmethod (setf at) (new-value (doc list) key &rest more-keys)
 (if more-keys
 (setf (cdr (assoc (car (last more-keys))
 (apply #'at doc key (butlast more-keys))
 :test #'equal))
 new-value)
 (setf (cdr (assoc key doc :test #'equal)) new-value)))
;; A playful alias.
(defun @ (doc &rest keys)
 (apply #'at doc keys))
(defun (setf @) (new-value doc key &rest more-keys)
 (apply #'(setf at) new-value doc key more-keys))

View File

@@ -0,0 +1,34 @@
--- Finds factorial of a number.
-- @param value Number to find factorial.
-- @return Factorial of number.
local function factorial(value)
 if value <= 1 then
 return 1
 else
 return value * factorial(value - 1)
 end
end
--- Joins a table of strings into a new string.
-- @param table Table of strings.
-- @param separator Separator character.
-- @return Joined string.
local function join(table, separator)
 local data = ""
 
 for index, value in ipairs(table) do
 data = data .. value .. separator
 end
 
 data = data:sub(1, data:len() - 1)
 
 return data
end
local a = factorial(5)
print(a)
local b = join({ "l", "u", "a" }, ",")
print(b)

View File

@@ -0,0 +1,34 @@
function zz=sample(aa)
%%%%%%%%%%%%%%%%%%
% some comments
%%%%%%%%%%%%%%%%%%
x = 'a string'; % some 'ticks' in a comment
y = 'a string with ''interal'' quotes';
for i=1:20
 disp(i);
end
a = rand(30);
b = rand(30);
c = a .* b ./ a \ ... comment at end of line and continuation
 (b .* a + b - a);
c = a' * b'; % note: these ticks are for transpose, not quotes.
disp('a comment symbol, %, in a string');
!echo abc % this isn't a comment - it's passed to system command
function y=myfunc(x)
y = exp(x);
%{
 a block comment
%}
function no_arg_func
fprintf('%s\n', 'function with no args')
end

View File

@@ -0,0 +1,385 @@
# Redis Makefile
# Copyright (C) 2009 Salvatore Sanfilippo <antirez at gmail dot com>
# This file is released under the BSD license, see the COPYING file
#
# The Makefile composes the final FINAL_CFLAGS and FINAL_LDFLAGS using
# what is needed for Redis plus the standard CFLAGS and LDFLAGS passed.
# However when building the dependencies (Jemalloc, Lua, Hiredis, ...)
# CFLAGS and LDFLAGS are propagated to the dependencies, so to pass
# flags only to be used when compiling / linking Redis itself REDIS_CFLAGS
# and REDIS_LDFLAGS are used instead (this is the case of 'make gcov').
#
# Dependencies are stored in the Makefile.dep file. To rebuild this file
# Just use 'make dep', but this is only needed by developers.
release_hdr := $(shell sh -c './mkreleasehdr.sh')
uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
uname_M := $(shell sh -c 'uname -m 2>/dev/null || echo not')
OPTIMIZATION?=-O2
DEPENDENCY_TARGETS=hiredis linenoise lua
NODEPS:=clean distclean
# Default settings
STD=-std=c11 -pedantic -DREDIS_STATIC=''
ifneq (,$(findstring clang,$(CC)))
ifneq (,$(findstring FreeBSD,$(uname_S)))
 STD+=-Wno-c11-extensions
endif
endif
WARN=-Wall -W -Wno-missing-field-initializers
OPT=$(OPTIMIZATION)
PREFIX?=/usr/local
INSTALL_BIN=$(PREFIX)/bin
INSTALL=install
PKG_CONFIG?=pkg-config
# Default allocator defaults to Jemalloc if it's not an ARM
MALLOC=libc
ifneq ($(uname_M),armv6l)
ifneq ($(uname_M),armv7l)
ifeq ($(uname_S),Linux)
 MALLOC=jemalloc
endif
endif
endif
# To get ARM stack traces if Redis crashes we need a special C flag.
ifneq (,$(filter aarch64 armv,$(uname_M)))
 CFLAGS+=-funwind-tables
else
ifneq (,$(findstring armv,$(uname_M)))
 CFLAGS+=-funwind-tables
endif
endif
# Backwards compatibility for selecting an allocator
ifeq ($(USE_TCMALLOC),yes)
 MALLOC=tcmalloc
endif
ifeq ($(USE_TCMALLOC_MINIMAL),yes)
 MALLOC=tcmalloc_minimal
endif
ifeq ($(USE_JEMALLOC),yes)
 MALLOC=jemalloc
endif
ifeq ($(USE_JEMALLOC),no)
 MALLOC=libc
endif
# Override default settings if possible
-include .make-settings
FINAL_CFLAGS=$(STD) $(WARN) $(OPT) $(DEBUG) $(CFLAGS) $(REDIS_CFLAGS)
FINAL_LDFLAGS=$(LDFLAGS) $(REDIS_LDFLAGS) $(DEBUG)
FINAL_LIBS=-lm
DEBUG=-g -ggdb
# Linux ARM needs -latomic at linking time
ifneq (,$(filter aarch64 armv,$(uname_M)))
 FINAL_LIBS+=-latomic
else
ifneq (,$(findstring armv,$(uname_M)))
 FINAL_LIBS+=-latomic
endif
endif
ifeq ($(uname_S),SunOS)
 # SunOS
 ifneq ($(@@),32bit)
 CFLAGS+= -m64
 LDFLAGS+= -m64
 endif
 DEBUG=-g
 DEBUG_FLAGS=-g
 export CFLAGS LDFLAGS DEBUG DEBUG_FLAGS
 INSTALL=cp -pf
 FINAL_CFLAGS+= -D__EXTENSIONS__ -D_XPG6
 FINAL_LIBS+= -ldl -lnsl -lsocket -lresolv -lpthread -lrt
else
ifeq ($(uname_S),Darwin)
 # Darwin
 FINAL_LIBS+= -ldl
 OPENSSL_CFLAGS=-I/usr/local/opt/openssl/include
 OPENSSL_LDFLAGS=-L/usr/local/opt/openssl/lib
else
ifeq ($(uname_S),AIX)
 # AIX
 FINAL_LDFLAGS+= -Wl,-bexpall
 FINAL_LIBS+=-ldl -pthread -lcrypt -lbsd
else
ifeq ($(uname_S),OpenBSD)
 # OpenBSD
 FINAL_LIBS+= -lpthread
 ifeq ($(USE_BACKTRACE),yes)
 FINAL_CFLAGS+= -DUSE_BACKTRACE -I/usr/local/include
 FINAL_LDFLAGS+= -L/usr/local/lib
 FINAL_LIBS+= -lexecinfo
 endif
else
ifeq ($(uname_S),FreeBSD)
 # FreeBSD
 FINAL_LIBS+= -lpthread -lexecinfo
else
ifeq ($(uname_S),DragonFly)
 # FreeBSD
 FINAL_LIBS+= -lpthread -lexecinfo
else
ifeq ($(uname_S),OpenBSD)
 # OpenBSD
 FINAL_LIBS+= -lpthread -lexecinfo
else
ifeq ($(uname_S),NetBSD)
 # NetBSD
 FINAL_LIBS+= -lpthread -lexecinfo
else
 # All the other OSes (notably Linux)
 FINAL_LDFLAGS+= -rdynamic
 FINAL_LIBS+=-ldl -pthread -lrt
endif
endif
endif
endif
endif
endif
endif
endif
# Include paths to dependencies
FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src
# Determine systemd support and/or build preference (defaulting to auto-detection)
BUILD_WITH_SYSTEMD=no
# If 'USE_SYSTEMD' in the environment is neither "no" nor "yes", try to
# auto-detect libsystemd's presence and link accordingly.
ifneq ($(USE_SYSTEMD),no)
 LIBSYSTEMD_PKGCONFIG := $(shell $(PKG_CONFIG) --exists libsystemd && echo $$?)
# If libsystemd cannot be detected, continue building without support for it
# (unless a later check tells us otherwise)
ifeq ($(LIBSYSTEMD_PKGCONFIG),0)
 BUILD_WITH_SYSTEMD=yes
endif
endif
ifeq ($(USE_SYSTEMD),yes)
ifneq ($(LIBSYSTEMD_PKGCONFIG),0)
$(error USE_SYSTEMD is set to "$(USE_SYSTEMD)", but $(PKG_CONFIG) cannot find libsystemd)
endif
# Force building with libsystemd
 BUILD_WITH_SYSTEMD=yes
endif
ifeq ($(BUILD_WITH_SYSTEMD),yes)
 FINAL_LIBS+=$(shell $(PKG_CONFIG) --libs libsystemd)
 FINAL_CFLAGS+= -DHAVE_LIBSYSTEMD
endif
ifeq ($(MALLOC),tcmalloc)
 FINAL_CFLAGS+= -DUSE_TCMALLOC
 FINAL_LIBS+= -ltcmalloc
endif
ifeq ($(MALLOC),tcmalloc_minimal)
 FINAL_CFLAGS+= -DUSE_TCMALLOC
 FINAL_LIBS+= -ltcmalloc_minimal
endif
ifeq ($(MALLOC),jemalloc)
 DEPENDENCY_TARGETS+= jemalloc
 FINAL_CFLAGS+= -DUSE_JEMALLOC -I../deps/jemalloc/include
 FINAL_LIBS := ../deps/jemalloc/lib/libjemalloc.a $(FINAL_LIBS)
endif
ifeq ($(BUILD_TLS),yes)
 FINAL_CFLAGS+=-DUSE_OPENSSL $(OPENSSL_CFLAGS)
 FINAL_LDFLAGS+=$(OPENSSL_LDFLAGS)
 LIBSSL_PKGCONFIG := $(shell $(PKG_CONFIG) --exists libssl && echo $$?)
ifeq ($(LIBSSL_PKGCONFIG),0)
 LIBSSL_LIBS=$(shell $(PKG_CONFIG) --libs libssl)
else
 LIBSSL_LIBS=-lssl
endif
 LIBCRYPTO_PKGCONFIG := $(shell $(PKG_CONFIG) --exists libcrypto && echo $$?)
ifeq ($(LIBCRYPTO_PKGCONFIG),0)
 LIBCRYPTO_LIBS=$(shell $(PKG_CONFIG) --libs libcrypto)
else
 LIBCRYPTO_LIBS=-lcrypto
endif
 FINAL_LIBS += ../deps/hiredis/libhiredis_ssl.a $(LIBSSL_LIBS) $(LIBCRYPTO_LIBS)
endif
REDIS_CC=$(QUIET_CC)$(CC) $(FINAL_CFLAGS)
REDIS_LD=$(QUIET_LINK)$(CC) $(FINAL_LDFLAGS)
REDIS_INSTALL=$(QUIET_INSTALL)$(INSTALL)
CCCOLOR="\033[34m"
LINKCOLOR="\033[34;1m"
SRCCOLOR="\033[33m"
BINCOLOR="\033[37;1m"
MAKECOLOR="\033[32;1m"
ENDCOLOR="\033[0m"
ifndef V
QUIET_CC = @printf ' %b %b\n' $(CCCOLOR)CC$(ENDCOLOR) $(SRCCOLOR)$@$(ENDCOLOR) 1>&2;
QUIET_LINK = @printf ' %b %b\n' $(LINKCOLOR)LINK$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
QUIET_INSTALL = @printf ' %b %b\n' $(LINKCOLOR)INSTALL$(ENDCOLOR) $(BINCOLOR)$@$(ENDCOLOR) 1>&2;
endif
REDIS_SERVER_NAME=redis-server
REDIS_SENTINEL_NAME=redis-sentinel
REDIS_SERVER_OBJ=adlist.o quicklist.o ae.o anet.o dict.o server.o sds.o zmalloc.o lzf_c.o lzf_d.o pqsort.o zipmap.o sha1.o ziplist.o release.o networking.o util.o object.o db.o replication.o rdb.o t_string.o t_list.o t_set.o t_zset.o t_hash.o config.o aof.o pubsub.o multi.o debug.o sort.o intset.o syncio.o cluster.o crc16.o endianconv.o slowlog.o scripting.o bio.o rio.o rand.o memtest.o crcspeed.o crc64.o bitops.o sentinel.o notify.o setproctitle.o blocked.o hyperloglog.o latency.o sparkline.o redis-check-rdb.o redis-check-aof.o geo.o lazyfree.o module.o evict.o expire.o geohash.o geohash_helper.o childinfo.o defrag.o siphash.o rax.o t_stream.o listpack.o localtime.o lolwut.o lolwut5.o lolwut6.o acl.o gopher.o tracking.o connection.o tls.o sha256.o timeout.o setcpuaffinity.o
REDIS_CLI_NAME=redis-cli
REDIS_CLI_OBJ=anet.o adlist.o dict.o redis-cli.o zmalloc.o release.o ae.o crcspeed.o crc64.o siphash.o crc16.o
REDIS_BENCHMARK_NAME=redis-benchmark
REDIS_BENCHMARK_OBJ=ae.o anet.o redis-benchmark.o adlist.o dict.o zmalloc.o siphash.o
REDIS_CHECK_RDB_NAME=redis-check-rdb
REDIS_CHECK_AOF_NAME=redis-check-aof
all: $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_RDB_NAME) $(REDIS_CHECK_AOF_NAME)
 @echo ""
 @echo "Hint: It's a good idea to run 'make test' ;)"
 @echo ""
Makefile.dep:
 -$(REDIS_CC) -MM *.c > Makefile.dep 2> /dev/null || true
ifeq (0, $(words $(findstring $(MAKECMDGOALS), $(NODEPS))))
-include Makefile.dep
endif
.PHONY: all
persist-settings: distclean
 echo STD=$(STD) >> .make-settings
 echo WARN=$(WARN) >> .make-settings
 echo OPT=$(OPT) >> .make-settings
 echo MALLOC=$(MALLOC) >> .make-settings
 echo BUILD_TLS=$(BUILD_TLS) >> .make-settings
 echo USE_SYSTEMD=$(USE_SYSTEMD) >> .make-settings
 echo CFLAGS=$(CFLAGS) >> .make-settings
 echo LDFLAGS=$(LDFLAGS) >> .make-settings
 echo REDIS_CFLAGS=$(REDIS_CFLAGS) >> .make-settings
 echo REDIS_LDFLAGS=$(REDIS_LDFLAGS) >> .make-settings
 echo PREV_FINAL_CFLAGS=$(FINAL_CFLAGS) >> .make-settings
 echo PREV_FINAL_LDFLAGS=$(FINAL_LDFLAGS) >> .make-settings
 -(cd ../deps && $(MAKE) $(DEPENDENCY_TARGETS))
.PHONY: persist-settings
# Prerequisites target
.make-prerequisites:
 @touch $@
# Clean everything, persist settings and build dependencies if anything changed
ifneq ($(strip $(PREV_FINAL_CFLAGS)), $(strip $(FINAL_CFLAGS)))
.make-prerequisites: persist-settings
endif
ifneq ($(strip $(PREV_FINAL_LDFLAGS)), $(strip $(FINAL_LDFLAGS)))
.make-prerequisites: persist-settings
endif
# redis-server
$(REDIS_SERVER_NAME): $(REDIS_SERVER_OBJ)
 $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a $(FINAL_LIBS)
# redis-sentinel
$(REDIS_SENTINEL_NAME): $(REDIS_SERVER_NAME)
 $(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME)
# redis-check-rdb
$(REDIS_CHECK_RDB_NAME): $(REDIS_SERVER_NAME)
 $(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(REDIS_CHECK_RDB_NAME)
# redis-check-aof
$(REDIS_CHECK_AOF_NAME): $(REDIS_SERVER_NAME)
 $(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(REDIS_CHECK_AOF_NAME)
# redis-cli
$(REDIS_CLI_NAME): $(REDIS_CLI_OBJ)
 $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/linenoise/linenoise.o $(FINAL_LIBS)
# redis-benchmark
$(REDIS_BENCHMARK_NAME): $(REDIS_BENCHMARK_OBJ)
 $(REDIS_LD) -o $@ $^ ../deps/hiredis/libhiredis.a $(FINAL_LIBS)
dict-benchmark: dict.c zmalloc.c sds.c siphash.c
 $(REDIS_CC) $(FINAL_CFLAGS) $^ -D DICT_BENCHMARK_MAIN -o $@ $(FINAL_LIBS)
DEP = $(REDIS_SERVER_OBJ:%.o=%.d) $(REDIS_CLI_OBJ:%.o=%.d) $(REDIS_BENCHMARK_OBJ:%.o=%.d)
-include $(DEP)
# Because the jemalloc.h header is generated as a part of the jemalloc build,
# building it should complete before building any other object. Instead of
# depending on a single artifact, build all dependencies first.
%.o: %.c .make-prerequisites
 $(REDIS_CC) -MMD -o $@ -c $<
clean:
 rm -rf $(REDIS_SERVER_NAME) $(REDIS_SENTINEL_NAME) $(REDIS_CLI_NAME) $(REDIS_BENCHMARK_NAME) $(REDIS_CHECK_RDB_NAME) $(REDIS_CHECK_AOF_NAME) *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep dict-benchmark
 rm -f $(DEP)
.PHONY: clean
distclean: clean
 -(cd ../deps && $(MAKE) distclean)
 -(rm -f .make-*)
.PHONY: distclean
test: $(REDIS_SERVER_NAME) $(REDIS_CHECK_AOF_NAME)
 @(cd ..; ./runtest)
test-sentinel: $(REDIS_SENTINEL_NAME)
 @(cd ..; ./runtest-sentinel)
check: test
lcov:
 $(MAKE) gcov
 @(set -e; cd ..; ./runtest --clients 1)
 @geninfo -o redis.info .
 @genhtml --legend -o lcov-html redis.info
test-sds: sds.c sds.h
 $(REDIS_CC) sds.c zmalloc.c -DSDS_TEST_MAIN $(FINAL_LIBS) -o /tmp/sds_test
 /tmp/sds_test
.PHONY: lcov
bench: $(REDIS_BENCHMARK_NAME)
 ./$(REDIS_BENCHMARK_NAME)
32bit:
 @echo ""
 @echo "WARNING: if it fails under Linux you probably need to install libc6-dev-i386"
 @echo ""
 $(MAKE) CFLAGS="-m32" LDFLAGS="-m32"
gcov:
 $(MAKE) REDIS_CFLAGS="-fprofile-arcs -ftest-coverage -DCOVERAGE_TEST" REDIS_LDFLAGS="-fprofile-arcs -ftest-coverage"
noopt:
 $(MAKE) OPTIMIZATION="-O0"
valgrind:
 $(MAKE) OPTIMIZATION="-O0" MALLOC="libc"
helgrind:
 $(MAKE) OPTIMIZATION="-O0" MALLOC="libc" CFLAGS="-D__ATOMIC_VAR_FORCE_SYNC_MACROS"
src/help.h:
 @../utils/generate-command-help.rb > help.h
install: all
 @mkdir -p $(INSTALL_BIN)
 $(REDIS_INSTALL) $(REDIS_SERVER_NAME) $(INSTALL_BIN)
 $(REDIS_INSTALL) $(REDIS_BENCHMARK_NAME) $(INSTALL_BIN)
 $(REDIS_INSTALL) $(REDIS_CLI_NAME) $(INSTALL_BIN)
 $(REDIS_INSTALL) $(REDIS_CHECK_RDB_NAME) $(INSTALL_BIN)
 $(REDIS_INSTALL) $(REDIS_CHECK_AOF_NAME) $(INSTALL_BIN)
 @ln -sf $(REDIS_SERVER_NAME) $(INSTALL_BIN)/$(REDIS_SENTINEL_NAME)
uninstall:
 rm -f $(INSTALL_BIN)/{$(REDIS_SERVER_NAME),$(REDIS_BENCHMARK_NAME),$(REDIS_CLI_NAME),$(REDIS_CHECK_RDB_NAME),$(REDIS_CHECK_AOF_NAME),$(REDIS_SENTINEL_NAME)}

View File

@@ -0,0 +1,243 @@
BAT(1) General Commands Manual BAT(1)
NAME
 bat - a cat(1) clone with syntax highlighting and Git integration.
USAGE
 bat [OPTIONS] [FILE]...
 bat cache [CACHE-OPTIONS] [--build|--clear]
DESCRIPTION
 bat prints the syntax-highlighted content of a collection of FILEs to
 the terminal. If no FILE is specified, or when FILE is '-', it reads
 from standard input.
 bat supports a large number of programming and markup languages. It
 also communicates with git(1) to show modifications with respect to the
 git index. bat automatically pipes its output through a pager (by de
 fault: less).
 Whenever the output of bat goes to a non-interactive terminal, i.e.
 when the output is piped into another process or into a file, bat will
 act as a drop-in replacement for cat(1) and fall back to printing the
 plain file contents.
OPTIONS
 General remarks: Command-line options like '-l'/'--language' that take
 values can be specified as either '--language value', '--lan
 guage=value', '-l value' or '-lvalue'.
 -A, --show-all
 Show non-printable characters like space, tab or newline. Use
 '--tabs' to control the width of the tab-placeholders.
 -p, --plain
 Only show plain style, no decorations. This is an alias for
 '--style=plain'. When '-p' is used twice ('-pp'), it also dis
 ables automatic paging (alias for '--style=plain
 --pager=never').
 -l, --language <language>
 Explicitly set the language for syntax highlighting. The lan
 guage can be specified as a name (like 'C++' or 'LaTeX') or pos
 sible file extension (like 'cpp', 'hpp' or 'md'). Use
 '--list-languages' to show all supported language names and file
 extensions.
 -H, --highlight-line <N:M>...
 Highlight the specified line ranges with a different background
 color For example:
 --highlight-line 40
 highlights line 40
 --highlight-line 30:40
 highlights lines 30 to 40
 --highlight-line :40
 highlights lines 1 to 40
 --highlight-line 40:
 highlights lines 40 to the end of the file
 --tabs <T>
 Set the tab width to T spaces. Use a width of 0 to pass tabs
 through directly
 --wrap <mode>
 Specify the text-wrapping mode (*auto*, never, character). The
 '--terminal-width' option can be used in addition to control the
 output width.
 --terminal-width <width>
 Explicitly set the width of the terminal instead of determining
 it automatically. If prefixed with '+' or '-', the value will be
 treated as an offset to the actual terminal width. See also:
 '--wrap'.
 -n, --number
 Only show line numbers, no other decorations. This is an alias
 for '--style=numbers'
 --color <when>
 Specify when to use colored output. The automatic mode only en
 ables colors if an interactive terminal is detected. Possible
 values: *auto*, never, always.
 --italic-text <when>
 Specify when to use ANSI sequences for italic text in the out
 put. Possible values: always, *never*.
 --decorations <when>
 Specify when to use the decorations that have been specified via
 '--style'. The automatic mode only enables decorations if an in
 teractive terminal is detected. Possible values: *auto*, never,
 always.
 -f, --force-colorization
 Alias for '--decorations=always --color=always'. This is useful
 if the output of bat is piped to another program, but you want
 to keep the colorization/decorations.
 --paging <when>
 Specify when to use the pager. To disable the pager, use '--pag
 ing=never' or its alias, -P. To disable the pager permanently,
 set BAT_PAGER to an empty string. To control which pager is
 used, see the '--pager' option. Possible values: *auto*, never,
 always.
 --pager <command>
 Determine which pager is used. This option will override the
 PAGER and BAT_PAGER environment variables. The default pager is
 'less'. To control when the pager is used, see the '--paging'
 option. Example: '--pager "less -RF"'.
 -m, --map-syntax <glob-pattern:syntax-name>...
 Map a glob pattern to an existing syntax name. The glob pattern
 is matched on the full path and the filename. For example, to
 highlight *.build files with the Python syntax, use -m
 '*.build:Python'. To highlight files named '.myignore' with the
 Git Ignore syntax, use -m '.myignore:Git Ignore'.
 --theme <theme>
 Set the theme for syntax highlighting. Use '--list-themes' to
 see all available themes. To set a default theme, add the
 '--theme="..."' option to the configuration file or export the
 BAT_THEME environment variable (e.g.: export BAT_THEME="...").
 --list-themes
 Display a list of supported themes for syntax highlighting.
 --style <style-components>
 Configure which elements (line numbers, file headers, grid bor
 ders, Git modifications, ..) to display in addition to the file
 contents. The argument is a comma-separated list of components
 to display (e.g. 'numbers,changes,grid') or a pre-defined style
 ('full'). To set a default style, add the '--style=".."' option
 to the configuration file or export the BAT_STYLE environment
 variable (e.g.: export BAT_STYLE=".."). Possible values: *auto*,
 full, plain, changes, header, grid, numbers, snip.
 -r, --line-range <N:M>...
 Only print the specified range of lines for each file. For exam
 ple:
 --line-range 30:40
 prints lines 30 to 40
 --line-range :40
 prints lines 1 to 40
 --line-range 40:
 prints lines 40 to the end of the file
 -L, --list-languages
 Display a list of supported languages for syntax highlighting.
 -u, --unbuffered
 This option exists for POSIX-compliance reasons ('u' is for 'un
 buffered'). The output is always unbuffered - this option is
 simply ignored.
 -h, --help
 Print this help message.
 -V, --version
 Show version information.
POSITIONAL ARGUMENTS
 <FILE>...
 Files to print and concatenate. Use a dash ('-') or no argument
 at all to read from standard input.
SUBCOMMANDS
 cache - Modify the syntax-definition and theme cache.
FILES
 bat can also be customized with a configuration file. The location of
 the file is dependent on your operating system. To get the default path
 for your system, call:
 bat --config-file
 Alternatively, you can use the BAT_CONFIG_PATH environment variable to
 point bat to a non-default location of the configuration file.
ADDING CUSTOM LANGUAGES
 bat supports Sublime Text .sublime-syntax language files, and can be
 customized to add additional languages to your local installation. To
 do this, add the .sublime-snytax language files to `$(bat --config-
 dir)/syntaxes` and run `bat cache --build`.
 Example:
 mkdir -p "$(bat --config-dir)/syntaxes"
 cd "$(bat --config-dir)/syntaxes"
 # Put new '.sublime-syntax' language definition files
 # in this folder (or its subdirectories), for example:
 git clone https://github.com/tellnobody1/sublime-purescript-syntax
 # And then build the cache.
 bat cache --build
 Once the cache is built, the new language will be visible in `bat
 --list-languages`.
 If you ever want to remove the custom languages, you can clear the
 cache with `bat cache --clear`.
ADDING CUSTOM THEMES
 Similarly to custom languages, bat supports Sublime Text .tmTheme
 themes. These can be installed to `$(bat --config-dir)/themes`, and
 are added to the cache with `bat cache --build`.
MORE INFORMATION
 For more information and up-to-date documentation, visit the bat repo:
 https://github.com/sharkdp/bat
 BAT(1)

View File

@@ -0,0 +1,330 @@
SELECT(2) Linux Programmer's Manual SELECT(2)
NAME
 select, pselect, FD_CLR, FD_ISSET, FD_SET, FD_ZERO - synchronous I/O multiplexing
SYNOPSIS
 #include <sys/select.h>
 int select(int nfds, fd_set *readfds, fd_set *writefds,
 fd_set *exceptfds, struct timeval *timeout);
 void FD_CLR(int fd, fd_set *set);
 int FD_ISSET(int fd, fd_set *set);
 void FD_SET(int fd, fd_set *set);
 void FD_ZERO(fd_set *set);
 int pselect(int nfds, fd_set *readfds, fd_set *writefds,
 fd_set *exceptfds, const struct timespec *timeout,
 const sigset_t *sigmask);
 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
 pselect(): _POSIX_C_SOURCE >= 200112L
DESCRIPTION
 select() allows a program to monitor multiple file descriptors, waiting until one or more of the file descriptors become
 "ready" for some class of I/O operation (e.g., input possible). A file descriptor is considered ready if it is possible to
 perform a corresponding I/O operation (e.g., read(2), or a sufficiently small write(2)) without blocking.
 select() can monitor only file descriptors numbers that are less than FD_SETSIZE; poll(2) and epoll(7) do not have this limi
 tation. See BUGS.
 File descriptor sets
 The principal arguments of select() are three "sets" of file descriptors (declared with the type fd_set), which allow the
 caller to wait for three classes of events on the specified set of file descriptors. Each of the fd_set arguments may be
 specified as NULL if no file descriptors are to be watched for the corresponding class of events.
 Note well: Upon return, each of the file descriptor sets is modified in place to indicate which file descriptors are currently
 "ready". Thus, if using select() within a loop, the sets must be reinitialized before each call. The implementation of the
 fd_set arguments as value-result arguments is a design error that is avoided in poll(2) and epoll(7).
 The contents of a file descriptor set can be manipulated using the following macros:
 FD_ZERO()
 This macro clears (removes all file descriptors from) set. It should be employed as the first step in initializing a
 file descriptor set.
 FD_SET()
 This macro adds the file descriptor fd to set. Adding a file descriptor that is already present in the set is a no-op,
 and does not produce an error.
 FD_CLR()
 This macro removes the file descriptor fd from set. Removing a file descriptor that is not present in the set is a no-
 op, and does not produce an error.
 FD_ISSET()
 select() modifies the contents of the sets according to the rules described below. After calling select(), the FD_IS
 SET() macro can be used to test if a file descriptor is still present in a set. FD_ISSET() returns nonzero if the file
 descriptor fd is present in set, and zero if it is not.
 Arguments
 The arguments of select() are as follows:
 readfds
 The file descriptors in this set are watched to see if they are ready for reading. A file descriptor is ready for
 reading if a read operation will not block; in particular, a file descriptor is also ready on end-of-file.
 After select() has returned, readfds will be cleared of all file descriptors except for those that are ready for read
 ing.
 writefds
 The file descriptors in this set are watched to see if they are ready for writing. A file descriptor is ready for
 writing if a write operation will not block. However, even if a file descriptor indicates as writable, a large write
 may still block.
 After select() has returned, writefds will be cleared of all file descriptors except for those that are ready for writ
 ing.
 exceptfds
 The file descriptors in this set are watched for "exceptional conditions". For examples of some exceptional condi
 tions, see the discussion of POLLPRI in poll(2).
 After select() has returned, exceptfds will be cleared of all file descriptors except for those for which an excep
 tional condition has occurred.
 nfds This argument should be set to the highest-numbered file descriptor in any of the three sets, plus 1. The indicated
 file descriptors in each set are checked, up to this limit (but see BUGS).
 timeout
 The timeout argument is a timeval structure (shown below) that specifies the interval that select() should block wait
 ing for a file descriptor to become ready. The call will block until either:
 • a file descriptor becomes ready;
 • the call is interrupted by a signal handler; or
 • the timeout expires.
 Note that the timeout interval will be rounded up to the system clock granularity, and kernel scheduling delays mean
 that the blocking interval may overrun by a small amount.
 If both fields of the timeval structure are zero, then select() returns immediately. (This is useful for polling.)
 If timeout is specified as NULL, select() blocks indefinitely waiting for a file descriptor to become ready.
 pselect()
 The pselect() system call allows an application to safely wait until either a file descriptor becomes ready or until a signal
 is caught.
 The operation of select() and pselect() is identical, other than these three differences:
 • select() uses a timeout that is a struct timeval (with seconds and microseconds), while pselect() uses a struct timespec
 (with seconds and nanoseconds).
 • select() may update the timeout argument to indicate how much time was left. pselect() does not change this argument.
 • select() has no sigmask argument, and behaves as pselect() called with NULL sigmask.
 sigmask is a pointer to a signal mask (see sigprocmask(2)); if it is not NULL, then pselect() first replaces the current sig
 nal mask by the one pointed to by sigmask, then does the "select" function, and then restores the original signal mask. (If
 sigmask is NULL, the signal mask is not modified during the pselect() call.)
 Other than the difference in the precision of the timeout argument, the following pselect() call:
 ready = pselect(nfds, &readfds, &writefds, &exceptfds,
 timeout, &sigmask);
 is equivalent to atomically executing the following calls:
 sigset_t origmask;
 pthread_sigmask(SIG_SETMASK, &sigmask, &origmask);
 ready = select(nfds, &readfds, &writefds, &exceptfds, timeout);
 pthread_sigmask(SIG_SETMASK, &origmask, NULL);
 The reason that pselect() is needed is that if one wants to wait for either a signal or for a file descriptor to become ready,
 then an atomic test is needed to prevent race conditions. (Suppose the signal handler sets a global flag and returns. Then a
 test of this global flag followed by a call of select() could hang indefinitely if the signal arrived just after the test but
 just before the call. By contrast, pselect() allows one to first block signals, handle the signals that have come in, then
 call pselect() with the desired sigmask, avoiding the race.)
 The timeout
 The timeout argument for select() is a structure of the following type:
 struct timeval {
 time_t tv_sec; /* seconds */
 suseconds_t tv_usec; /* microseconds */
 };
 The corresponding argument for pselect() has the following type:
 struct timespec {
 time_t tv_sec; /* seconds */
 long tv_nsec; /* nanoseconds */
 };
 On Linux, select() modifies timeout to reflect the amount of time not slept; most other implementations do not do this.
 (POSIX.1 permits either behavior.) This causes problems both when Linux code which reads timeout is ported to other operating
 systems, and when code is ported to Linux that reuses a struct timeval for multiple select()s in a loop without reinitializing
 it. Consider timeout to be undefined after select() returns.
RETURN VALUE
 On success, select() and pselect() return the number of file descriptors contained in the three returned descriptor sets (that
 is, the total number of bits that are set in readfds, writefds, exceptfds). The return value may be zero if the timeout ex
 pired before any file descriptors became ready.
 On error, -1 is returned, and errno is set to indicate the error; the file descriptor sets are unmodified, and timeout becomes
 undefined.
ERRORS
 EBADF An invalid file descriptor was given in one of the sets. (Perhaps a file descriptor that was already closed, or one on
 which an error has occurred.) However, see BUGS.
 EINTR A signal was caught; see signal(7).
 EINVAL nfds is negative or exceeds the RLIMIT_NOFILE resource limit (see getrlimit(2)).
 EINVAL The value contained within timeout is invalid.
 ENOMEM Unable to allocate memory for internal tables.
VERSIONS
 pselect() was added to Linux in kernel 2.6.16. Prior to this, pselect() was emulated in glibc (but see BUGS).
CONFORMING TO
 select() conforms to POSIX.1-2001, POSIX.1-2008, and 4.4BSD (select() first appeared in 4.2BSD). Generally portable to/from
 non-BSD systems supporting clones of the BSD socket layer (including System V variants). However, note that the System V
 variant typically sets the timeout variable before returning, but the BSD variant does not.
 pselect() is defined in POSIX.1g, and in POSIX.1-2001 and POSIX.1-2008.
NOTES
 An fd_set is a fixed size buffer. Executing FD_CLR() or FD_SET() with a value of fd that is negative or is equal to or larger
 than FD_SETSIZE will result in undefined behavior. Moreover, POSIX requires fd to be a valid file descriptor.
 The operation of select() and pselect() is not affected by the O_NONBLOCK flag.
 On some other UNIX systems, select() can fail with the error EAGAIN if the system fails to allocate kernel-internal resources,
 rather than ENOMEM as Linux does. POSIX specifies this error for poll(2), but not for select(). Portable programs may wish
 to check for EAGAIN and loop, just as with EINTR.
 The self-pipe trick
 On systems that lack pselect(), reliable (and more portable) signal trapping can be achieved using the self-pipe trick. In
 this technique, a signal handler writes a byte to a pipe whose other end is monitored by select() in the main program. (To
 avoid possibly blocking when writing to a pipe that may be full or reading from a pipe that may be empty, nonblocking I/O is
 used when reading from and writing to the pipe.)
 Emulating usleep(3)
 Before the advent of usleep(3), some code employed a call to select() with all three sets empty, nfds zero, and a non-NULL
 timeout as a fairly portable way to sleep with subsecond precision.
 Correspondence between select() and poll() notifications
 Within the Linux kernel source, we find the following definitions which show the correspondence between the readable,
 writable, and exceptional condition notifications of select() and the event notifications provided by poll(2) and epoll(7):
 #define POLLIN_SET (EPOLLRDNORM | EPOLLRDBAND | EPOLLIN |
 EPOLLHUP | EPOLLERR)
 /* Ready for reading */
 #define POLLOUT_SET (EPOLLWRBAND | EPOLLWRNORM | EPOLLOUT |
 EPOLLERR)
 /* Ready for writing */
 #define POLLEX_SET (EPOLLPRI)
 /* Exceptional condition */
 Multithreaded applications
 If a file descriptor being monitored by select() is closed in another thread, the result is unspecified. On some UNIX sys
 tems, select() unblocks and returns, with an indication that the file descriptor is ready (a subsequent I/O operation will
 likely fail with an error, unless another process reopens file descriptor between the time select() returned and the I/O oper
 ation is performed). On Linux (and some other systems), closing the file descriptor in another thread has no effect on se
 lect(). In summary, any application that relies on a particular behavior in this scenario must be considered buggy.
 C library/kernel differences
 The Linux kernel allows file descriptor sets of arbitrary size, determining the length of the sets to be checked from the
 value of nfds. However, in the glibc implementation, the fd_set type is fixed in size. See also BUGS.
 The pselect() interface described in this page is implemented by glibc. The underlying Linux system call is named pselect6().
 This system call has somewhat different behavior from the glibc wrapper function.
 The Linux pselect6() system call modifies its timeout argument. However, the glibc wrapper function hides this behavior by
 using a local variable for the timeout argument that is passed to the system call. Thus, the glibc pselect() function does
 not modify its timeout argument; this is the behavior required by POSIX.1-2001.
 The final argument of the pselect6() system call is not a sigset_t * pointer, but is instead a structure of the form:
 struct {
 const kernel_sigset_t *ss; /* Pointer to signal set */
 size_t ss_len; /* Size (in bytes) of object
 pointed to by 'ss' */
 };
 This allows the system call to obtain both a pointer to the signal set and its size, while allowing for the fact that most ar
 chitectures support a maximum of 6 arguments to a system call. See sigprocmask(2) for a discussion of the difference between
 the kernel and libc notion of the signal set.
 Historical glibc details
 Glibc 2.0 provided an incorrect version of pselect() that did not take a sigmask argument.
 In glibc versions 2.1 to 2.2.1, one must define _GNU_SOURCE in order to obtain the declaration of pselect() from <sys/se
 lect.h>.
BUGS
 POSIX allows an implementation to define an upper limit, advertised via the constant FD_SETSIZE, on the range of file descrip
 tors that can be specified in a file descriptor set. The Linux kernel imposes no fixed limit, but the glibc implementation
 makes fd_set a fixed-size type, with FD_SETSIZE defined as 1024, and the FD_*() macros operating according to that limit. To
 monitor file descriptors greater than 1023, use poll(2) or epoll(7) instead.
 According to POSIX, select() should check all specified file descriptors in the three file descriptor sets, up to the limit
 nfds-1. However, the current implementation ignores any file descriptor in these sets that is greater than the maximum file
 descriptor number that the process currently has open. According to POSIX, any such file descriptor that is specified in one
 of the sets should result in the error EBADF.
 Starting with version 2.1, glibc provided an emulation of pselect() that was implemented using sigprocmask(2) and select().
 This implementation remained vulnerable to the very race condition that pselect() was designed to prevent. Modern versions of
 glibc use the (race-free) pselect() system call on kernels where it is provided.
 On Linux, select() may report a socket file descriptor as "ready for reading", while nevertheless a subsequent read blocks.
 This could for example happen when data has arrived but upon examination has the wrong checksum and is discarded. There may
 be other circumstances in which a file descriptor is spuriously reported as ready. Thus it may be safer to use O_NONBLOCK on
 sockets that should not block.
 On Linux, select() also modifies timeout if the call is interrupted by a signal handler (i.e., the EINTR error return). This
 is not permitted by POSIX.1. The Linux pselect() system call has the same behavior, but the glibc wrapper hides this behavior
 by internally copying the timeout to a local variable and passing that variable to the system call.
EXAMPLES
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/select.h>
 int
 main(void)
 {
 fd_set rfds;
 struct timeval tv;
 int retval;
 /* Watch stdin (fd 0) to see when it has input. */
 FD_ZERO(&rfds);
 FD_SET(0, &rfds);
 /* Wait up to five seconds. */
 tv.tv_sec = 5;
 tv.tv_usec = 0;
 retval = select(1, &rfds, NULL, NULL, &tv);
 /* Don't rely on the value of tv now! */
 if (retval == -1)
 perror("select()");
 else if (retval)
 printf("Data is available now.\n");
 /* FD_ISSET(0, &rfds) will be true. */
 else
 printf("No data within five seconds.\n");
 exit(EXIT_SUCCESS);
 }
SEE ALSO
 accept(2), connect(2), poll(2), read(2), recv(2), restart_syscall(2), send(2), sigprocmask(2), write(2), epoll(7), time(7)
 For a tutorial with discussion and examples, see select_tut(2).
COLOPHON
 This page is part of release 5.08 of the Linux man-pages project. A description of the project, information about reporting
 bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.
Linux 2020-04-11 SELECT(2)

View File

@@ -0,0 +1,53 @@
MemTotal: 1004892 kB
MemFree: 109424 kB
MemAvailable: 498032 kB
Buffers: 66360 kB
Cached: 448344 kB
SwapCached: 0 kB
Active: 547076 kB
Inactive: 196864 kB
Active(anon): 249956 kB
Inactive(anon): 7328 kB
Active(file): 297120 kB
Inactive(file): 189536 kB
Unevictable: 18516 kB
Mlocked: 18516 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 276 kB
Writeback: 0 kB
AnonPages: 247780 kB
Mapped: 168472 kB
Shmem: 19860 kB
KReclaimable: 59128 kB
Slab: 108616 kB
SReclaimable: 59128 kB
SUnreclaim: 49488 kB
KernelStack: 2060 kB
PageTables: 4232 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 502444 kB
Committed_AS: 678300 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 10756 kB
VmallocChunk: 0 kB
Percpu: 784 kB
HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
ShmemHugePages: 0 kB
ShmemPmdMapped: 0 kB
FileHugePages: 0 kB
FilePmdMapped: 0 kB
CmaTotal: 0 kB
CmaFree: 0 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
Hugetlb: 0 kB
DirectMap4k: 118764 kB
DirectMap2M: 929792 kB
DirectMap1G: 0 kB

View File

@@ -0,0 +1,6 @@
cflags = -Wall
rule cc
 command = gcc $cflags -c $in -o $out
build foo.o: cc foo.c

View File

@@ -0,0 +1,68 @@
#import <Foundation/Foundation.h>
class Hello {
 private:
 id greeting_text;
 public:
 Hello() {
 greeting_text = @"Hello, world!";
 }
 Hello(const char* initial_greeting_text) {
 greeting_text = [[NSString alloc] initWithUTF8String:initial_greeting_text];
 }
 void say_hello() {
 printf("%s\n", [greeting_text UTF8String]);
 }
};
@interface Greeting : NSObject {
 @private
 Hello *hello;
}
- (id)init;
- (void)dealloc;
- (void)sayGreeting;
- (void)sayGreeting:(Hello*)greeting;
@end
@implementation Greeting
- (id)init {
 self = [super init];
 if (self) {
 hello = new Hello();
 }
 return self;
}
- (void)dealloc {
 delete hello;
 [super dealloc];
}
- (void)sayGreeting {
 hello->say_hello();
}
- (void)sayGreeting:(Hello*)greeting {
 greeting->say_hello();
}
@end
int main() {
 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
 Greeting *greeting = [[Greeting alloc] init];
 [greeting sayGreeting];
 Hello *hello = new Hello("Bonjour, monde!");
 [greeting sayGreeting:hello];
 delete hello;
 [greeting release];
 [pool release];
 return 0;
}

View File

@@ -0,0 +1,32 @@
#import <myClass.h>
@import Foundation
// Single line comments
/*
 * Multi line comment
 */
int main (int argc, const char * argv[]) {
 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
 NSLog(@"Storage size for int : %d \n", sizeof(int));
 NSLog (@"hello world");
 if (NO)
 {
 NSLog(@"I am never run");
 } else if (0)
 {
 NSLog(@"I am also never run");
 } else
 {
 NSLog(@"I print");
 }
 [pool drain];
 return 0;
}
@implementation MyClass {
 long distance;
 NSNumber height;
}

View File

@@ -0,0 +1,111 @@
<?php
#if this was md, i'll be a title
define("CONSTANT", 3.14);
echo CONSTANT;
//am i a comment
/*
 yes, and so am I too
*/
//variable declaration
$variable = "welcome";
$number = 2;
$float = 1.23;
$nothing = null;
$truth = true;
$lies = false;
$numberone = 2;
$numbertwo = 3;
//operators
$third = $numberone + $numbertwo;
$third = $numberone - $numbertwo;
$third = $numberone * $numbertwo;
$third = $numberone / $numbertwo;
$third = $numberone % $numbertwo;
$third = $numberone ** $numbertwo;
$numberone += $numbertwo;
echo $variable;
echo "You are $variable!";
echo "We are " . $variable ."s!";
if(($numberone >= 3 || $numberone <=2) && $numberone != 2.5){
 echo "what a number!!!";
}
if($numberone >= 3 and $numberone <=2 and $numberone != 2.5){
 echo "something is wrong, this is supposed to be impossible";
}
if ($number < 3){
 $languages = array("HTML", "CSS", "JS");
 print_r($languages);
 echo $languages[2];
 print $languages[$number];
}
elseif ($number == 3 ){
 function favMovie() {
 echo "JUMAJI";
 return true;
 }
 favMovie();
}
else {
 switch ($number) {
 case 4:
 echo "fours";
 break;
 default:
 echo "I dont know you";
 }
}
while($number <= 6 ){
 echo $number;
 $number++;
 $number += 1;
}
do {
 $number++;
} while ($number < 10);
for ($houses = 0; $houses <= 5; $housees++){
 break;
 echo "getting more houses";
}
class Person {
 public $name;
 public $age;
 
 function __construct($name){
 $this->name = $name;
 }
 
 function __destruct(){
 echo "On my way out";
 }
 
 function setName($name) {
 $this->name = $name;
 }
}
$doe = new Person("John Do");
$doe->setName('John Doe');
$ending = 2 > 3 ? "yep" : "nah";
?>

View File

@@ -0,0 +1,42 @@
program Hello;
uses crt;
type str = string[1];
 arr = array[1..20, 1..60] of char;
var x, y:integer;
 carr:arr;
 c:char;
Procedure start;
{comment here}
begin write (' Press enter to begin. ');
readln;
end;
Function Valid (var choice:char): boolean;
begin 
 valid:= false;
 case choice of 
 '1':valid:= true;
 '2': valid:= true;
 '3': valid:= true;
 '4': valid:= true;
 '5': valid:= true;
 '6': valid:= true;
 end;
end;
begin
 for y:=1 to 3 do
 begin
 writeln (y);
 end;
 
 repeat
 writeln(y);
 y := y + 1;
 until y > 5;
 writeln ('Hello World');
end.

View File

@@ -0,0 +1,157 @@
# Perl Test
# By saul-bt
# PUBLIC DOMAIN
use strict;
use warnings;
## REFERENCES ##
my @colors = ("red", "green", "blue");
# '\' can be used to get a reference
my $colorsRef = \@colors;
my %superHash = (
 "colors" => $colorsRef,
 # Also you can create an anonymous
 # array with '[]' ({} for hashes)
 # that returns the reference
 "numbers" => [1, 2, 3]
);
# Now the hash stores something like
# this: ("colors", ARRAY(0x...),
# "numbers", ARRAY(0x...))
# And you can access these arrays with:
print qq(@{$superHash{"colors"}}\n);
# To print an element:
print qq(${$superHash{"numbers"}}[0]\n);
print $superHash{"colors"} -> [0], "\n";
# Size of array:
print scalar @{$superHash{"colors"}};
## ARRAYS ##
%meh1 = (num => 0, val => 4);
%meh2 = (
 num => 1,
 val => 3
);
@mehs = (\%meh1, \%meh2);
print $mehs[0]{val};
## HANDLERS & HEREDOC ##
print "What's your name? ";
$name = <STDIN>;
chomp($name);
print <<WELCOME;
Hi $name, Where are you from?
WELCOME
$place = <STDIN>;
chomp($place);
print <<GOODBYE;
Oh, you are $name from $place...
I hear that $place is a beautiful place.
It's nice meet people like you $name.
I hope to see you soon :)
Bye $name.
GOODBYE
open (content, "<", "file.txt");
for $line (<content>) {
 print $line;
}
print "What are you looking for? ";
$numResults = 0;
$word = <STDIN>;
chomp($word);
for $line (<>) {
 if ($line =~ m/\b$word\b/i) {
 $numResults += 1;
 print "[$word FOUND]> $line\n";
 next;
 }
 print $line;
}
print "\n\n=== There are $numResults coincidences ===";
## SCRIPT ARGUMENTS ##
$nargs = $#ARGV + 1;
print "There are $nargs arguments:\n";
for $arg (@ARGV) {
 print "- $arg\n";
}
## REGEX STUFF ##
$string = "Perl is cool";
if ($string =~ m/[Pp]erl/) {
 print "Yeah";
}
elsif ($string =~ m(perl)i) {
 print "Sad";
}
else {
 print "MEH";
}
# From my dummy recreation of printf
sub checkTypes {
 my @percents = @{scalar(shift)};
 my @args = @{scalar(shift)};
 my $size = scalar(@percents);
 foreach my $n (0..$size - 1) {
 my $currArg = $args[$n];
 my $currFormat = substr($percents[$n],-1);
 
 $currFormat eq 's' && $currArg =~ m/^\D+$/ ||
 $currFormat =~ m/[dx]/ && $currArg =~ m/^\d+$/ ||
 $currFormat eq 'f' && $currArg =~ m/^\d+(?:\.\d+)?$/ or
 die "'$currArg' can't be formatted as '$currFormat'";
 }
}
## WEIRD STUFF (JAPH) ##
# VMS <3
not exp log srand xor s qq qx xor
s x x length uc ord and print chr
ord for qw q join use sub tied qx
xor eval xor print qq q q xor int
eval lc q m cos and print chr ord
for qw y abs ne open tied hex exp
ref y m xor scalar srand print qq
q q xor int eval lc qq y sqrt cos
and print chr ord for qw x printf
each return local x y or print qq
s s and eval q s undef or oct xor
time xor ref print chr int ord lc
foreach qw y hex alarm chdir kill
exec return y s gt sin sort split
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
''=~('(?{'.('-)@.)@_*([]@!@/)(@)@-@),@(@@+@)'
^'][)@]`}`]()`@.@]@%[`}%[@`@!#@%[').',"})')

View File

@@ -0,0 +1,178 @@
␀␊
\u{1}␊
\u{2}␊
\u{3}␊
\u{4}␊
\u{5}␊
\u{6}␊
␇␊
␈␊
├──┤␊
␊
␊
\u{b}␊
\u{c}␊
␊
\u{e}␊
\u{f}␊
\u{10}␊
\u{11}␊
\u{12}␊
\u{13}␊
\u{14}␊
\u{15}␊
\u{16}␊
\u{17}␊
\u{18}␊
\u{19}␊
\u{1a}␊
␛␊
\u{1c}␊
\u{1d}␊
\u{1e}␊
\u{1f}␊
·␊
!␊
"␊
#␊
$␊
%␊
&␊
'␊
(␊
)␊
*␊
+␊
,␊
-␊
.␊
/␊
0␊
1␊
2␊
3␊
4␊
5␊
6␊
7␊
8␊
9␊
:␊
;␊
<␊
=␊
>␊
?␊
@␊
A␊
B␊
C␊
D␊
E␊
F␊
G␊
H␊
I␊
J␊
K␊
L␊
M␊
N␊
O␊
P␊
Q␊
R␊
S␊
T␊
U␊
V␊
W␊
X␊
Y␊
Z␊
[␊
\␊
]␊
^␊
_␊
`␊
a␊
b␊
c␊
d␊
e␊
f␊
g␊
h␊
i␊
j␊
k␊
l␊
m␊
n␊
o␊
p␊
q␊
r␊
s␊
t␊
u␊
v␊
w␊
x␊
y␊
z␊
{␊
|␊
}␊
~␊
\u{7f}␊
\u{80}␊
\u{81}␊
\u{82}␊
\u{83}␊
\u{84}␊
\u{85}␊
\u{86}␊
\u{87}␊
\u{88}␊
\u{89}␊
\u{8a}␊
\u{8b}␊
\u{8c}␊
\u{8d}␊
\u{8e}␊
\u{8f}␊
\u{90}␊
\u{91}␊
\u{92}␊
\u{93}␊
\u{94}␊
\u{95}␊
\u{96}␊
\u{97}␊
\u{98}␊
\u{99}␊
\u{9a}␊
\u{9b}␊
\u{9c}␊
\u{9d}␊
\u{9e}␊
\u{9f}␊
\u{a0}␊
\u{a1}␊
\u{a2}␊
\u{a3}␊
\u{a4}␊
\u{a5}␊
\u{a6}␊
\u{a7}␊
\u{a8}␊
\u{a9}␊
\u{aa}␊
\u{ab}␊
\u{ac}␊
\u{ad}␊
\u{ae}␊
␊
Here's·a·line·with·multiple·characters.␊

View File

@@ -0,0 +1,25 @@
# PowerShell script for testing syntax highlighting
function Get-FutureTime {
 param (
 [Int32] $Minutes
 )
 
 $time = Get-Date | % { $_.AddMinutes($Minutes) }
 "{0:d2}:{1:d2}:{2:d2}" -f @($time.hour, $time.minute, $time.second)
}
if ($env:PATH -match '.*rust.*') {
 'Path contains Rust'
 try {
 & "cargo" "--version"
 } catch {
 Write-Error "Failed to run cargo"
 }
} else {
 'Path does not contain Rust'
}
(5..30) | ? { $_ % (2 * 2 + 1) -eq 0 } | % {"In {0} minutes, the time will be {1}." -f $_, $( Get-FutureTime $_ )}
$later = Get-FutureTime -Minutes $( Get-Random -Minimum 60 -Maximum 120 )
"The time will be " + $later + " later."

View File

@@ -0,0 +1,89 @@
-- | This module defines a datatype `Pair` together with a few useful instances
-- | and helper functions. Note that this is not just `Tuple a a` but rather a
-- | list with exactly two elements. Specifically, the `Functor` instance maps
-- | over both values (in contrast to the `Functor` instance for `Tuple a`).
module Data.Pair
 ( Pair(..)
 , (~)
 , fst
 , snd
 , curry
 , uncurry
 , swap
 ) where
import Prelude
import Data.Foldable (class Foldable)
import Data.Traversable (class Traversable)
import Data.Distributive (class Distributive)
import Test.QuickCheck.Arbitrary (class Arbitrary, arbitrary)
-- | A pair simply consists of two values of the same type.
data Pair a = Pair a a
infixl 6 Pair as ~
-- | Returns the first component of a pair.
fst ∷ ∀ a. Pair a → a
fst (x ~ _) = x
-- | Returns the second component of a pair.
snd ∷ ∀ a. Pair a → a
snd (_ ~ y) = y
-- | Turn a function that expects a pair into a function of two arguments.
curry ∷ ∀ a b. (Pair a → b) → a → a → b
curry f x y = f (x ~ y)
-- | Turn a function of two arguments into a function that expects a pair.
uncurry ∷ ∀ a b. (a → a → b) → Pair a → b
uncurry f (x ~ y) = f x y
-- | Exchange the two components of the pair
swap ∷ ∀ a. Pair a → Pair a
swap (x ~ y) = y ~ x
derive instance eqPair ∷ Eq a ⇒ Eq (Pair a)
derive instance ordPair ∷ Ord a ⇒ Ord (Pair a)
instance showPair ∷ Show a ⇒ Show (Pair a) where
 show (x ~ y) = "(" <> show x <> " ~ " <> show y <> ")"
instance functorPair ∷ Functor Pair where
 map f (x ~ y) = f x ~ f y
instance applyPair ∷ Apply Pair where
 apply (f ~ g) (x ~ y) = f x ~ g y
instance applicativePair ∷ Applicative Pair where
 pure x = x ~ x
instance bindPair ∷ Bind Pair where
 bind (x ~ y) f = fst (f x) ~ snd (f y)
instance monadPair ∷ Monad Pair
instance semigroupPair ∷ Semigroup a ⇒ Semigroup (Pair a) where
 append (x1 ~ y1) (x2 ~ y2) = (x1 <> x2) ~ (y1 <> y2)
instance monoidPair ∷ Monoid a ⇒ Monoid (Pair a) where
 mempty = mempty ~ mempty
instance foldablePair ∷ Foldable Pair where
 foldr f z (Pair x y) = x `f` (y `f` z)
 foldl f z (Pair x y) = (z `f` x) `f` y
 foldMap f (Pair x y) = f x <> f y
instance traversablePair ∷ Traversable Pair where
 traverse f (Pair x y) = Pair <$> f x <*> f y
 sequence (Pair mx my) = Pair <$> mx <*> my
instance distributivePair ∷ Distributive Pair where
 distribute xs = map fst xs ~ map snd xs
 collect f xs = map (fst <<< f) xs ~ map (snd <<< f) xs
instance arbitraryPair ∷ Arbitrary a ⇒ Arbitrary (Pair a) where
 arbitrary = Pair <$> arbitrary <*> arbitrary

View File

@@ -0,0 +1,219 @@
import QtQuick 2.0
import "../components"
Page {
 id: page
 // properties
 property bool startup: true
 readonly property var var1: null
 readonly property QtObject var2: null
 allowedOrientations: Orientation.All
 /* components */
 DBusServiceWatcher {
 id: dbusService
 service: "org.bat.service"
 onRegisteredChanged: {
 if (dbusService.registered) {
 announcedNameField.text = daemon.announcedName()
 }
 }
 }
 Component.onCompleted: {
 console.debug("completed")
 }
 Flickable {
 anchors.fill: parent
 contentHeight: column.height
 visible: dbusService.registered
 ViewPlaceholder {
 enabled: !startup
 && trustedDevices.count == 0
 && nearDevices.count == 0
 text: qsTr("Install Bat.")
 }
 Column {
 id: column
 width: page.width
 spacing: Theme.paddingLarge
 PageHeader {
 title: qsTr("Syntax Test")
 }
 TextField {
 id: announcedNameField
 width: parent.width
 label: qsTr("Device Name")
 text: dbusService.registered ? daemon.announcedName() : ""
 onActiveFocusChanged: {
 if (activeFocus)
 return
 if (text.length === 0) {
 text = daemon.announcedName()
 } else {
 daemon.setAnnouncedName(text)
 placeholderText = text
 }
 }
 EnterKey.onClicked: announcedNameField.focus = false
 EnterKey.iconSource: "image://theme/icon-m-enter-close"
 }
 Component {
 id: deviceDelegate
 ListItem {
 id: listItem
 property bool showStatus: deviceStatusLabel.text.length
 width: page.width
 height: Theme.itemSizeMedium
 Image {
 id: icon
 source: iconUrl
 x: Theme.horizontalPageMargin
 anchors.verticalCenter: parent.verticalCenter
 sourceSize.width: Theme.iconSizeMedium
 sourceSize.height: Theme.iconSizeMedium
 }
 Label {
 id: deviceNameLabel
 anchors {
 left: icon.right
 leftMargin: Theme.paddingLarge
 right: parent.right
 rightMargin: Theme.horizontalPageMargin
 }
 y: listItem.contentHeight / 2 - implicitHeight / 2
 - showStatus * (deviceStatusLabel.implicitHeight / 2)
 text: name
 color: listItem.highlighted
 ? Theme.highlightColor
 : Theme.primaryColor
 truncationMode: TruncationMode.Fade
 textFormat: Text.PlainText
 Behavior on y { NumberAnimation {} }
 }
 Label {
 id: deviceStatusLabel
 anchors {
 left: deviceNameLabel.left
 top: deviceNameLabel.bottom
 right: parent.right
 rightMargin: Theme.horizontalPageMargin
 }
 text: (trusted && reachable)
 ? qsTr("Connected")
 : (hasPairingRequests || waitsForPairing
 ? qsTr("Pending pairing request ...") : "")
 color: listItem.highlighted
 ? Theme.secondaryHighlightColor
 : Theme.secondaryColor
 truncationMode: TruncationMode.Fade
 font.pixelSize: Theme.fontSizeExtraSmall
 opacity: showStatus ? 1.0 : 0.0
 width: parent.width
 textFormat: Text.PlainText
 Behavior on opacity { FadeAnimation {} }
 }
 onClicked: {
 pageStack.push(
 Qt.resolvedUrl("DevicePage.qml"),
 { deviceId: id })
 }
 }
 }
 DeviceListModel {
 id: devicelistModel
 }
 ColumnView {
 id: devicesView
 width: page.width
 itemHeight: Theme.itemSizeMedium
 model: trustedDevicesModel
 delegate: deviceDelegate
 visible: devicesView.count > 0
 }
 }
 PullDownMenu {
// MenuItem {
// text: qsTr("About ...")
// onClicked: pageStack.push(Qt.resolvedUrl("AboutPage.qml"))
// }
 MenuItem {
 text: qsTr("Settings ...")
 onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
 }
 }
 VerticalScrollDecorator {}
 }
 /*
 Connections {
 target: ui
 onOpeningDevicePage: openDevicePage(deviceId)
 }*/
 Timer {
 interval: 1000
 running: true
 repeat: false
 onTriggered: startup = false
 }
 function openDevicePage(deviceId) {
 if (typeof pageStack === "undefined")
 return;
 console.log("opening device " + deviceId)
 window.activate()
 var devicePage = pageStack.find(function(page) {
 return page.objectName === "DevicePage"
 })
 if (devicePage !== null && devicePage.deviceId === deviceId) {
 pageStack.pop(devicePage)
 ui.showMainWindow()
 return
 }
 pageStack.pop(page, PageStackAction.Immediate)
 pageStack.push(
 Qt.resolvedUrl("DevicePage.qml"),
 { deviceId: deviceId },
 PageStackAction.Immediate)
 }
}

View File

@@ -0,0 +1,170 @@
# take input from the user
num = as.integer(readline(prompt="Enter a number: "))
factorial = 1
# check is the number is negative, positive or zero
if(num < 0) {
print("Sorry, factorial does not exist for negative numbers")
} else if(num == 0) {
print("The factorial of 0 is 1")
} else {
for(i in 1:num) {
factorial = factorial * i
}
print(paste("The factorial of", num ,"is",factorial))
}
x <- 0
if (x < 0) {
print("Negative number")
} else if (x > 0) {
print("Positive number")
} else
print("Zero")
x <- 1:5
for (val in x) {
if (val == 3){
next
}
print(val)
}
x <- 1
repeat {
print(x)
x = x+1
if (x == 6){
break
}
}
`%divisible%` <- function(x,y)
{
if (x%%y ==0) return (TRUE)
else return (FALSE)
}
switch("length", "color" = "red", "shape" = "square", "length" = 5)
[1] 5
recursive.factorial <- function(x) {
if (x == 0) return (1)
else return (x * recursive.factorial(x-1))
}
pow <- function(x, y) {
# function to print x raised to the power y
result <- x^y
print(paste(x,"raised to the power", y, "is", result))
}
A <- read.table("x.data", sep=",",
 col.names=c("year", "my1", "my2"))
nrow(A) # Count the rows in A
summary(A$year) 
A$newcol <- A$my1 + A$my2 # Makes a new
newvar <- A$my1 - A$my2 # Makes a 
A$my1 <- NULL # Removes 
str(A)
summary(A)
library(Hmisc) 
contents(A)
describe(A)
set.seed(102) # This yields a good illustration.
x <- sample(1:3, 15, replace=TRUE)
education <- factor(x, labels=c("None", "School", "College"))
x <- sample(1:2, 15, replace=TRUE)
gender <- factor(x, labels=c("Male", "Female"))
age <- runif(15, min=20,max=60)
D <- data.frame(age, gender, education)
rm(x,age,gender,education)
print(D)
# Table about education
table(D$education)
# Table about education and gender --
table(D$gender, D$education)
# Joint distribution of education and gender --
table(D$gender, D$education)/nrow(D)
# Add in the marginal distributions also
addmargins(table(D$gender, D$education))
addmargins(table(D$gender, D$education))/nrow(D)
# Generate a good LaTeX table out of it --
library(xtable)
xtable(addmargins(table(D$gender, D$education))/nrow(D),
 digits=c(0,2,2,2,2)) 
by(D$age, D$gender, mean)
by(D$age, D$gender, sd)
by(D$age, D$gender, summary)
a <- matrix(by(D$age, list(D$gender, D$education), mean), nrow=2)
rownames(a) <- levels(D$gender)
colnames(a) <- levels(D$education)
print(a)
print(xtable(a))
dat <- read.csv(file = "files/dataset-2013-01.csv", header = TRUE)
interim_object <- data.frame(rep(1:100, 10),
 rep(101:200, 10),
 rep(201:300, 10))
object.size(interim_object) 
rm("interim_object") 
ls() 
rm(list = ls())
vector1 <- c(5,9,3)
vector2 <- c(10,11,12,13,14,15)
array1 <- array(c(vector1,vector2),dim = c(3,3,2))
vector3 <- c(9,1,0)
vector4 <- c(6,0,11,3,14,1,2,6,9)
array2 <- array(c(vector1,vector2),dim = c(3,3,2))
matrix1 <- array1[,,2]
matrix2 <- array2[,,2]
result <- matrix1+matrix2
print(result)
column.names <- c("COL1","COL2","COL3")
row.names <- c("ROW1","ROW2","ROW3")
matrix.names <- c("Matrix1","Matrix2")
result <- array(c(vector1,vector2),dim = c(3,3,2),dimnames = list(row.names,
 column.names, matrix.names))
print(result[3,,2])
print(result[1,3,1])
print(result[,,2])
# Load the package required to read JSON files.
library("rjson")
result <- fromJSON(file = "input.json")
print(result)
x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)
y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)
relation <- lm(y~x)
print(relation)
relation <- lm(y~x)
png(file = "linearregression.png")
plot(y,x,col = "blue",main = "Height & Weight Regression",
abline(lm(x~y)),cex = 1.3,pch = 16,xlab = "Weight in Kg",ylab = "Height in cm")
dev.off()
data <- c("East","West","East","North","North","East","West","West","West","East","North")
print(data)
print(is.factor(data))
factor_data <- factor(data)
print(factor_data)
print(is.factor(factor_data))
v <- c(7,12,28,3,41)
# Give the chart file a name.
png(file = "line_chart_label_colored.jpg")
plot(v,type = "o", col = "red", xlab = "Month", ylab = "Rain fall", main = "Rain fall chart")

View File

@@ -0,0 +1 @@
^\[START\]\d\D\h\H\s\S[a-z]\v\V\w\W.([a-z]){3,5}\[END\]$

View File

@@ -0,0 +1,8 @@
#this is a sample requirements.txt file
django==11.2.0
pywheels>=12.4 #a whitespace followed by comments
Nuitka<0.6.8.4
wxPython>=1.0, <=2.1
#this is another comment

View File

@@ -0,0 +1,15 @@
%html
 %head
 %title Test Title
 %body
 %navigation
 = render :partial => "navigation_top"
 %h1= page.title
 %p
 Here is a point to emphasize:
 %strong.highlighted#search_item_found= item1.text
 %span{:class => "fancy", :id => "fancy1"}= item2.text
 .special= special.text
 %ol
 %li First
 %li Second

View File

@@ -0,0 +1,22 @@
class ContactsController < ApplicationController
 def new
 @contact = Contact.new
 end
 def create
 @contact = Contact.new(secure_params)
 if @contact.valid?
 UserMailer.contact_email(@contact).deliver_now
 flash[:notice] = "Message sent from #{@contact.name}."
 redirect_to root_path
 else
 render :new
 end
 end
 private
 def secure_params
 params.require(:contact).permit(:name, :email, :content)
 end
end

View File

@@ -1,19 +0,0 @@
@mixin button-base() {
 @include typography(button);
 @include ripple-surface;
 @include ripple-radius-bounded;
 display: inline-flex;
 position: relative;
 height: $button-height;
 border: none;
 vertical-align: middle;
 &:hover { cursor: pointer; }
 &:disabled {
 color: $mdc-button-disabled-ink-color;
 cursor: default;
 pointer-events: none;
 }
}

View File

@@ -0,0 +1,82 @@
@import 'fonts';
$theme_dark: (
 "background-color": null,
);
$theme_main: (
 "text-size": 3em,
 "text-color": black,
 "text-shadow": #36ad 0px 0px 3px,
 "card-background": #d6f,
 "card-shadow": #11121212 0px 0px 2px 1px,
 "card-padding": 1rem,
 "card-margin": 0.5in,
 "image-width": 600px,
 "image-height": 100vh,
 "background-color": #dedbef,
 "i-ran-out-of-placeholders-for-units": (1vw 100% 60pt),
);
$current_theme: $theme_main;
@mixin themed() {
 $current_theme: $theme_main !global;
 @content;
 @media (prefers-color-scheme: dark) {
 $current_theme: $theme_dark !global;
 @content;
 }
 
 .#{"dark"} & {
 $current_theme: $theme_dark !global;
 @content;
 }
}
@function theme($variable) {
 @if map-has_key($current_theme, $variable) {
 @return map-get($current_theme, $variable);
 } @else {
 @error "Unknown theme variable: #{$variable}";
 }
}
body {
 @include themed {
 background-color: theme('background-color');
 background-image: url("https://github.com/sharkdp/bat/raw/master/doc/logo-header.svg");
 }
 
 header[data-selectable="false"] {
 -webkit-user-select: none;
 -moz-user-select: none;
 -ms-user-select: /* CSS comment */ none;
 cursor: default !important; // SCSS comment
 }
 
 > div {
 border: #04f 1px solid;
 
 &::after {
 content: 'Pseudo';
 color: #2F5F7F;
 box-sizing: border-box;
 }
 }
}
@keyframes rotate {
 0% {
 transform: rotate(0deg);
 }
 50% {
 transform: rotate(180deg)}
 100% {transform: rotate(0rad);}
}
@font-face {
 font-family: 'Example Font';
 src: url(example.ttf) format('ttf');
 src: local('Comic Sans MS');
}

View File

@@ -0,0 +1,57 @@
required_packages:
 pkg.installed:
 - pkgs:
 - git
 - perl
 - fortune
cowsay_source:
 git.latest:
 - name: https://github.com/jasonm23/cowsay.git
 - target: /root/cowsay
run_installer:
 cmd.run:
 - name: ./install.sh /usr/local
 - cwd: /root/cowsay
 - onchanges:
 - git: cowsay_source
{% set cowfiles = salt.cmd.run('cowsay -l').split('\n')[1:] %}
{% set ascii_arts = cowfiles | join(' ') %}
{% for ascii_art in ascii_arts.split(' ') %}
run_cowsay_{{ ascii_art }}: # name must be unique
 cmd.run:
 {% if ascii_art is in ['head-in', 'sodomized', 'telebears'] %}
 - name: echo cowsay -f {{ ascii_art }} should not be used
 {% else %}
 - name: fortune | cowsay -f {{ ascii_art }}
 {% endif %}
{% endfor %}
echo_pillar_demo_1:
 cmd.run:
 - name: "echo {{ pillar.demo_text | default('pillar not defined') }}"
echo_pillar_demo_2:
 cmd.run:
 - name: "echo {{ pillar.demo.text | default('pillar not defined') }}"
# Comment
{% set rand = salt['random.get_str'](20) %}
{% set IP_Address = pillar['IP_Address'] %}
wait:
 cmd.run:
 - name: sleep 210 # another comment
create_roster_file:
 file.managed:
 - name: /tmp/salt-roster-{{ rand }}
 - contents:
 - 'switch:'
 - ' host: {{ IP_Address }}'
 - " user: test"
 - " passwd: {{ passwd }}"

View File

@@ -0,0 +1,36 @@
# This test sshd config file is intended for syntax testing
# purposes only.
#
# Definitely do not use this in production for sshd.
Port 22
# Here's a directive commented out:
#ListenAddress 0.0.0.0
ListenAddress 127.0.0.1
HostKey /etc/ssh/ssh_host_rsa_key
IgnoreRhosts yes
PrintMotd yes
X11Forwarding no
AllowAgentForwarding no
PermitRootLogin forced-commands-only
SyslogFacility AUTH
LogLevel VERBOSE
AuthorizedKeysFile /etc/ssh/authorized-keys/%u
PasswordAuthentication yes
PermitEmptyPasswords no
AllowUsers alice
# pass locale information
AcceptEnv LANG LC_*
Banner /etc/sshd_banner
AllowTcpForwarding yes
PermitTunnel no
PermitTTY yes

View File

@@ -0,0 +1,76 @@
@import "fonts"
$theme_dark: (
 "background-color": null
)
$theme_main: (
 "text-size": 3em
 "text-color": black
 "text-shadow": #36ad 0px 0px 3px
 "card-background": #d6f
 "card-shadow": #11121212 0px 0px 2px 1px
 "card-padding": 1rem
 "card-margin": 0.5in
 "image-width": 600px
 "image-height": 100vh
 "background-color": #dedbef
 "i-ran-out-of-placeholders-for-units": (
 1vw 100% 60pt
 )
)
$current_theme: $theme_main
@mixin themed()
 $current_theme: $theme_main !global
 @content
 @media (prefers-color-scheme: dark)
 $current_theme: $theme_dark !global
 @content
 .#{"dark"} &
 $current_theme: $theme_dark !global
 @content
@function theme($variable)
 @if map-has_key($current_theme, $variable)
 @return map-get($current_theme, $variable)
 @else
 @error "Unknown theme variable: #{$variable}"
body
 @include themed
 background-color: theme("background-color")
 background-image: url("https://github.com/sharkdp/bat/raw/master/doc/logo-header.svg")
 header[data-selectable="false"]
 -webkit-user-select: none
 -moz-user-select: none
 -ms-user-select: /* CSS comment */ none
 cursor: default !important // Sass comment
 > div
 border: #04f 1px solid
 &::after
 content: "Pseudo"
 color: #2f5f7f
 box-sizing: border-box
@keyframes rotate
 0%
 transform: rotate(0deg)
 50%
 transform: rotate(180deg)
 100%
 transform: rotate(0rad)
@font-face
 font-family: "Example Font"
 src: url(example.ttf) format("ttf")
 src: local("Comic Sans MS")

View File

@@ -0,0 +1,57 @@
<script>
 import { onMount } from 'svelte';
 import List from './List.svelte';
 import Item from './Item.svelte';
 let item;
 let page;
 async function hashchange() {
 // the poor man's router!
 const path = window.location.hash.slice(1);
 if (path.startsWith('/item')) {
 const id = path.slice(6);
 item = await fetch(`https://node-hnapi.herokuapp.com/item/${id}`).then(r => r.json());
 window.scrollTo(0,0);
 } else if (path.startsWith('/top')) {
 page = +path.slice(5);
 item = null;
 } else {
 window.location.hash = '/top/1';
 }
 }
 onMount(hashchange);
</script>
<style>
 main {
 position: relative;
 max-width: 800px;
 margin: 0 auto;
 min-height: 101vh;
 padding: 1em;
 }
 main :global(.meta) {
 color: #999;
 font-size: 12px;
 margin: 0 0 1em 0;
 }
 main :global(a) {
 color: rgb(0,0,150);
 }
</style>
<svelte:window on:hashchange={hashchange}/>
<main>
 {#if item}
 <Item {item} returnTo="#/top/{page}"/>
 {:else if page}
 <List {page}/>
 {/if}
</main>

View File

@@ -0,0 +1,268 @@
class Person {
// We can define class property here
var age = 25
// Implement Class initializer. Initializers are called when a new object of this class is created
init() { 
 print(A new instance of this class Person is created.) 
 } 
} 
// We can now create an instance of class Person - an object - by putting parentheses after the class name
let personObj = Person()
// Once an instance of Person class is created we can access its properties using the dot . syntax.
print(This person age is \(personObj.age))
import Foundation
class Friend : Comparable {
 let name : String
 let age : Int
 
 init(name : String, age: Int) {
 self.name = name
 self.age = age
 }
}
func < (lhs: Friend, rhs: Friend) -> Bool {
 return lhs.age < rhs.age }; func > (lhs: Friend, rhs: Friend) -> Bool {
 return lhs.age > rhs.age
}
func == (lhs: Friend, rhs: Friend) -> Bool {
 var returnValue = false
 if (lhs.name == rhs.name) && (lhs.age == rhs.age)
 {
 returnValue = true
 }
 return returnValue
}
 let friend1 = Friend(name: "Sergey", age: 35)
 let friend2 = Friend(name: "Sergey", age: 30)
 
 print("Compare Friend object. Same person? (friend1 == friend2)")
func sayHelloWorld() {
 print("Hello World")
}
// Call function
sayHelloWorld()
func printOutFriendNames(names: String...) {
 
 for name in names {
 
 print(name)
 }
 
}
// Call the printOutFriendNames with two parameters
printOutFriendNames("Sergey", "Bill")
// Call the function with more parameters
printOutFriendNames("Sergey", "Bill", "Max")
let simpleClosure = {
 print("From a simpleClosure")
}
// Call closure
simpleClosure() 
let fullName = { (firstName:String, lastName:String)->String in
 return firstName + " " + lastName
}
// Call Closure
let myFullName = fullName("Sergey", "Kargopolov")
print("My full name is \(myFullName)")
let myDictionary = [String:String]()
// Another way to create an empty dictionary
let myDictionary2:[String:String] = [:]
// Keys in dictionary can also be of type Int
let myDictionary3 = [Int:String]()
var myDictionary = ["first_name": "Sergey", "last_name": "Kargopolov"]
// print to preview
print(myDictionary)
// Add a new key with a value
myDictionary["user_id"] = "f5h7ru0tJurY8f7g5s6fd"
// We should now have 3 key value pairs printed
print(myDictionary)
var myDictionary = ["first_name": "Sergey", "last_name": "Kargopolov"]
// Loop through dictionary keys and print values
for (key,value) in myDictionary {
 print("\(key) = \(value)")
}
 class Friend {
 let name : String
 let age : Int
 
 init(name : String, age: Int) {
 self.name = name
 self.age = age
 }
}
 var friends:[Friend] = []
 
 let friend1 = Friend(name: "Sergey", age: 30)
 let friend2 = Friend(name: "Bill", age: 35)
 let friend3 = Friend(name: "Michael", age: 21)
 
 friends.append(friend1)
 friends.append(friend2)
 friends.append(friend3)
 
 printFriends(friends: friends)
 
 // Get sorted array in descending order (largest to the smallest number)
 let sortedFriends = friends.sorted(by: { $0.age > $1.age })
 printFriends(friends: sortedFriends)
 
 // Get sorted array in ascending order (smallest to the largest number)
 let sortedFriendsAscendingOrder = friends.sorted(by: { $0.age < $1.age })
 printFriends(friends: sortedFriendsAscendingOrder)
 func printFriends(friends: [Friend])
 {
 for friendEntry in friends {
 print("Name: \(friendEntry.name), age: \(friendEntry.age)")
 }
 }
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
 super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
 super.viewWillAppear(animated)
 
 // Create destination URL 
 let documentsUrl:URL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first as URL!
 let destinationFileUrl = documentsUrl.appendingPathComponent("downloadedFile.jpg")
 
 //Create URL to the source file you want to download
 let fileURL = URL(string: "https://s3.amazonaws.com/learn-swift/IMG_0001.JPG")
 
 let sessionConfig = URLSessionConfiguration.default
 let session = URLSession(configuration: sessionConfig)
 
 let request = URLRequest(url:fileURL!)
 
 let task = session.downloadTask(with: request) { (tempLocalUrl, response, error) in
 if let tempLocalUrl = tempLocalUrl, error == nil {
 // Success
 if let statusCode = (response as? HTTPURLResponse)?.statusCode {
 print("Successfully downloaded. Status code: \(statusCode)")
 }
 
 do {
 try FileManager.default.copyItem(at: tempLocalUrl, to: destinationFileUrl)
 } catch (let writeError) {
 print("Error creating a file \(destinationFileUrl) : \(writeError)")
 }
 
 } else {
 print("Error took place while downloading a file. Error description: %@", error?.localizedDescription);
 }
 }
 task.resume()
 
 }
}
 do {
 
 // Convert JSON Object received from server side into Swift NSArray.
 // Note the use "try"
 if let convertedJsonIntoArray = try JSONSerialization.JSONObjectWithData(data!, options: []) as? NSArray {
 }
 
 } catch let error as NSError {
 print(error.localizedDescription)
 }
DispatchQueue.global(qos: .userInitiated).async {
 // Do some time consuming task in this background thread
 // Mobile app will remain to be responsive to user actions
 
 print("Performing time consuming task in this background thread")
 
 DispatchQueue.main.async {
 // Task consuming task has completed
 // Update UI from this block of code
 print("Time consuming task has completed. From here we are allowed to update user interface.")
 }
 }
import UIKit
class ViewController: UIViewController {
 
 override func viewDidLoad() {
 super.viewDidLoad()
 // Do any additional setup after loading the view, typically from a nib.
 
 let button = UIButton(type: UIButtonType.system) as UIButton
 
 let xPostion:CGFloat = 50
 let yPostion:CGFloat = 100
 let buttonWidth:CGFloat = 150
 let buttonHeight:CGFloat = 45
 
 button.frame = CGRect(x:xPostion, y:yPostion, width:buttonWidth, height:buttonHeight)
 
 button.backgroundColor = UIColor.lightGray
 button.setTitle("Tap me", for: UIControlState.normal)
 button.tintColor = UIColor.black
 button.addTarget(self, action: #selector(ViewController.buttonAction(_:)), for: .touchUpInside)
 
 self.view.addSubview(button)
 }
 
 func buttonAction(_ sender:UIButton!)
 {
 print("Button tapped")
 }
 
 override func didReceiveMemoryWarning() {
 super.didReceiveMemoryWarning()
 // Dispose of any resources that can be recreated.
 }
 
 
}
import UIKit
class ViewController: UIViewController {
 
 override func viewDidLoad() {
 super.viewDidLoad()
 
 //Create Activity Indicator
 let myActivityIndicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray)
 
 // Position Activity Indicator in the center of the main view
 myActivityIndicator.center = view.center
 
 // If needed, you can prevent Acivity Indicator from hiding when stopAnimating() is called
 myActivityIndicator.hidesWhenStopped = false
 
 // Start Activity Indicator
 myActivityIndicator.startAnimating()
 
 // Call stopAnimating() when need to stop activity indicator
 //myActivityIndicator.stopAnimating()
 
 
 view.addSubview(myActivityIndicator)
 }
 
 override func didReceiveMemoryWarning() {
 super.didReceiveMemoryWarning()
 }
 
}

View File

@@ -0,0 +1,22 @@
set part1 hello
set part2 how; set part3 are
set part4 you
set part2;
set greeting $part1$part2$part3$part4
set somevar {
 This is a literal $ sign, and this \} escaped
 brace remains uninterpreted
}
set name Neo
set greeting "Hello, $name"
variable name NotNeo
namespace eval people {
 set name NeoAgain
}

View File

@@ -0,0 +1,48 @@
provider "github" {
 organization = var.github_organization
}
resource "tls_private_key" "deploy_key" {
 algorithm = "RSA"
 rsa_bits = "4096"
}
resource "null_resource" "private_key_file" {
 triggers = {
 deploy_key = tls_private_key.deploy_key.private_key_pem
 }
 provisioner "file" {
 content = tls_private_key.deploy_key.private_key_pem
 destination = "~/${var.repo_name}_deploy_key.pem"
 connection {
 type = "ssh"
 user = "centos"
 private_key = var.terraform_ssh_key
 host = var.server_ip
 }
 }
 provisioner "remote-exec" {
 inline = [
 "sudo mv ~/${var.repo_name}_deploy_key.pem /app/ssh_keys/",
 "sudo chmod 0400 /app/ssh_keys/${var.repo_name}_deploy_key.pem",
 "sudo chown app:app /app/ssh_keys/${var.repo_name}_deploy_key.pem",
 ]
 connection {
 type = "ssh"
 user = "centos"
 private_key = var.terraform_ssh_key
 host = var.server_ip
 }
 }
}
resource "github_repository_deploy_key" "repo_deploy_key" {
 title = "${var.env_name} Deploy Key"
 repository = var.repo_name
 key = tls_private_key.deploy_key.public_key_openssh
 read_only = var.read_only
}

View File

@@ -0,0 +1,40 @@
###. Single line comment
###..
Multi line comment.
This line is also part of comment.
Continues till next block element
p. This is not a comment, but I am a paragraph.
<!-- HTML comments can also be used -->
h1. This is an <h1>
h2. This is an <h2>
h3. This is an <h3>
h4. This is an <h4>
h5. This is an <h5>
h6. This is an <h6>
--
* Item
** Sub-Item
* Another item
** Another sub-item
** Yet another sub-item
*** Three levels deep
p{color:red}. This line will be red.
%span% are enclosed in percent symbols.
div. This is a new div element

View File

@@ -0,0 +1,92 @@
if &compatible
 set nocompatible
endif
if has('win32') || has ('win64')
 let $VIMHOME = $HOME . "/vimfiles"
elseif v:false && v:true
 echo "Can't get here"
else
 let $VIMHOME = $HOME . "/.vim"
endif
" show existing tab with 2 spaces width
set tabstop=2
" when indenting with '>', use 2 spaces width
set shiftwidth=2
" always set autoindenting on
set autoindent
autocmd VimEnter * echo "Hello Vim"
" Allow :W and :Wq to save too
command! Wq :wq
command! W :w
augroup vimrc
 autocmd!
 autocmd FileType * echo "New filetype"
augroup END
function! s:echo(what)
 return a:what
endfunction
function! HelloWorld(name)
 let l:function_local = "function_local_var"
 let l:parts = split(l:function_local, "_")
 let l:greeting = "Hello " . a:name
 return s:echo(l:greeting)
endfunction
function! source#Hello()
 return "Hello from namespace"
endfunction
function! EchoFunc(...)
 for s in a:000
 echon ' ' . s
 endfor
endfunction
imap <C-h> <C-r>=HelloWorld("World")<CR>
command! -nargs=? Echo :call EchoFunc(<args>)
" TODO test stuff
let g:global = "global var"
let s:script_var = "script var"
let w:window_var = "window war"
let b:buffer_var = "buffer war"
let t:tab_var = "tab war"
echo v:false
3 + 5
echo "Hello" ==# "Hello2"
echo "Hello" ==? "Hello2"
echo "Hello" == "Hello2"
echo "Hello" is "Hello2"
echo "Hello" isnot "Hello2"
echo "Hello" =~ 'xx*'
echo "Hello" !~ "Hello2"
echo "Hello" !~ "Hello2"
echo "/This/should/not/be/a/regex"
" Error case from issue #1604 (https://github.com/sharkdp/bat/issues/1064)
set runtimepath=~/foo/bar
silent g/Aap/p
let g:dict = {}
let g:dict.item = ['l1', 'l2']
let g:dict2 = {'dict_item': ['l1', 'l2'], 'di2': 'x'}
silent g/regex/
silent v/regex/
silent %s/regex/not_regex/
filetype plugin indent on
syntax enable

View File

@@ -0,0 +1,55 @@
<template>
 <div id="app" class="container-fluid">
 <AppHeader></AppHeader>
 <transition name="page" mode="out-in" v-if="!isLoading">
 <router-view></router-view>
 </transition>
 <AppLoadingIndicator></AppLoadingIndicator>
 </div>
</template>
<script>
import AppHeader from "@/components/AppHeader";
import AppLoadingIndicator from "@/components/AppLoadingIndicator";
import { mapGetters } from "vuex";
export default {
 name: "App",
 components: {
 AppHeader,
 AppLoadingIndicator,
 },
 beforeCreate() {
 this.$store.dispatch("fetchData");
 },
 data: {
 message: "Hello!"
 },
 computed: {
 ...mapGetters({
 isLoading: "isLoading",
 }),
 },
};
</script>
<style>
body {
 background-color: rgba(72, 163, 184, 0.05) !important;
}
.page-enter-active,
.page-leave-active {
 transition: opacity 0.2s;
}
.page-enter,
.page-leave-active {
 opacity: 0;
}
.page-enter:hover {
 opacity: 1;
}
</style>

View File

@@ -4,6 +4,9 @@
name: Test User
username: "testuser"
other_names: ['Bob', 'Bill', 'George']
hexa: 0x11c3 #inline comment
octa: 021131
lastseen: .NAN
enabled: true
locked: false
groups: 
@@ -13,6 +16,19 @@
address: >
 123 Alphabet Way
 San Francisco, CA
bio: |
 I am a hardworking person
 and a member of the
 executive staff
phone: null
email: ~
building_access: yes
secure_access: no
bulb: On
fans: Off
emails:
 executives:
 - bob@example.com
 - bill@example.com
 supervisors:
 - george@example.com

View File

@@ -0,0 +1,107 @@
//! this is a top level doc, starts with "//!"
const std = @import("std");
pub fn main() anyerror!void {
 const stdout = std.io.getStdOut().writer();
 try stdout.print("Hello, {}!\n", .{"world"});
}
const expect = std.testing.expect;
test "comments" {
 // comments start with "//" until newline
 // foo bar baz
 const x = true; // another comment
 expect(x);
}
/// a doc comment starts with "///"
/// multiple lines are merged together
const Timestamp = struct {
 /// number of seconds since epoch
 seconds: i64,
 /// number of nanoseconds past the second
 nano: u32,
 const Self = @This();
 pub fn unixEpoch() Self {
 return Self{
 .seconds = 0,
 .nanos = 0,
 };
 }
};
const my_val = switch (std.Target.current.os.tag) {
 .linux => "Linux",
 else => "not Linux",
};
const Book = enum {
 paperback,
 hardcover,
 ebook,
 pdf,
};
const TokenType = union(enum) {
 int: isize,
 float: f64,
 string: []const u8,
};
const array_lit: [4]u8 = .{ 11, 22, 33, 44 };
const sentinal_lit = [_:0]u8{ 1, 2, 3, 4 };
test "address of syntax" {
 // Get the address of a variable:
 const x: i32 = 1234;
 const x_ptr = &x;
 // Dereference a pointer:
 expect(x_ptr.* == 1234);
 // When you get the address of a const variable, you get a const pointer to a single item.
 expect(@TypeOf(x_ptr) == *const i32);
 // If you want to mutate the value, you'd need an address of a mutable variable:
 var y: i32 = 5678;
 const y_ptr = &y;
 expect(@TypeOf(y_ptr) == *i32);
 y_ptr.* += 1;
 expect(y_ptr.* == 5679);
}
// integer literals
const decimal_int = 98222;
const hex_int = 0xff;
const another_hex_int = 0xFF;
const octal_int = 0o755;
const binary_int = 0b11110000;
// underscores may be placed between two digits as a visual separator
const one_billion = 1_000_000_000;
const binary_mask = 0b1_1111_1111;
const permissions = 0o7_5_5;
const big_address = 0xFF80_0000_0000_0000;
// float literals
const floating_point = 123.0E+77;
const another_float = 123.0;
const yet_another = 123.0e+77;
const hex_floating_point = 0x103.70p-5;
const another_hex_float = 0x103.70;
const yet_another_hex_float = 0x103.70P-5;
// underscores may be placed between two digits as a visual separator
const lightspeed = 299_792_458.000_000;
const nanosecond = 0.000_000_001;
const more_hex = 0x1234_5678.9ABC_CDEFp-10;
fn max(comptime T: type, a: T, b: T) T {
 return if (a > b) a else b;
}

View File

@@ -0,0 +1,140 @@
#user nobody;
worker_processes 1;
#pid logs/nginx.pid;
load_module "/usr/local/libexec/nginx/ngx_http_xslt_filter_module.so";
load_module "/usr/local/libexec/nginx/ngx_rtmp_module.so";
events {
 worker_connections 1024;
}
http {
 include mime.types;
 default_type application/octet-stream;
 sendfile  on;
 keepalive_timeout 65;
 gzip  on;
 gzip_disable "msie6";
 include /usr/local/etc/nginx/sites.d/*;
}
rtmp {
 server {
 listen 1935;
 max_message 10M;
 application wnob {
 live on;
 record off;
 }
 application strim {
 live on;
 hls on;
 hls_path /usr/local/www/hls/;
 hls_variant _low BANDWIDTH=250000;
 hls_variant _mid BANDWIDTH=500000;
 hls_variant _high BANDWIDTH=1000000;
 hls_variant _hd720 BANDWIDTH=1500000;
 hls_variant _src BANDWIDTH=2000000;
 }
 }
}
server {
 listen 443 ssl;
 server_name host.example.com
 root /usr/local/www/host.example.com/;
 error_page 404 /404.html;
 index index.html;
 autoindex on;
 autoindex_localtime off;
 autoindex_format xml;
 location / {
 xslt_stylesheet /usr/local/www/host.example.com/index.xslt;
 }
 location ~ /\..* {
 return 404;
 }
 location ~ /.+/ {
 xslt_stylesheet /usr/local/www/host.example.com/project.xslt;
 }
 location ~ /.*\.xslt/ {
 return 404;
 }
 location ~ \.thumb\.png$ {
 error_page 404 /404.thumb.png;
 }
 ssl_certificate /usr/local/etc/letsencrypt/live/host.example.com/fullchain.pem; # managed by Certbot
 ssl_certificate_key /usr/local/etc/letsencrypt/live/host.example.com/privkey.pem; # managed by Certbot
 include /usr/local/etc/letsencrypt/options-ssl-nginx.conf;
 ssl_dhparam /usr/local/etc/letsencrypt/ssl-dhparams.pem;
 add_header Strict-Transport-Security "max-age=31536000" always;
}
server {
 listen 80;
 server_name host.example.com;
 if ($host = host.example.com) {
 return 301 https://$host$request_uri;
 }
 return 404;
}
server {
 listen 443 ssl;
 server_name other.example.com;
 ssl_certificate /usr/local/etc/letsencrypt/live/other.example.com/fullchain.pem;
 ssl_certificate_key /usr/local/etc/letsencrypt/live/other.example.com/privkey.pem;
 include /usr/local/etc/letsencrypt/options-ssl-nginx.conf;
 ssl_dhparam /usr/local/etc/letsencrypt/ssl-dhparams.pem;
 add_header Strict-Transport-Security "max-age=31536000" always;
 access_log /home/otherapp/logs/access.log;
 error_log /home/otherapp/logs/error.log;
 client_max_body_size 5M;
 location / {
 root /home/otherapp/app/static;
 index man.txt;
 try_files $uri @proxy;
 }
 location @proxy {
 proxy_set_header Host $http_host;
 proxy_set_header X-Forwarded-Host $host;
 proxy_set_header X-Real-IP $remote_addr;
 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 proxy_pass http://unix:/var/run/otherapp/sock:;
 }
}
server {
 listen 80;
 server_name other.example.com;
 if ($host = other.example.com) {
 return 301 https://$host$request_uri;
 }
 return 404;
}

View File

@@ -0,0 +1,41 @@
import json
const
 message = "hello world"
 multiLine = """
 foo
 bar
 """
 numbers = @[1, 2, 3]
type Options = enum
 A,
 B,
 C
## Top-level comment
type
 SomeStruct* = ref object
 value*: string
proc someFunc*(): string =
 ## Function docs
 ##
 ## More docs
 result = message
proc someOtherFunc(startingValue: int): (string, int) =
 var num = startingValue
 num += 1
 if num > 10 * 10 * 10:
 echo "Encountered an error"
 raise newException(ValueError, "Value was over 1000")
 ("Fizz", num)
proc `+=`(a: var SomeStruct, b: SomeStruct): string =
 a.value.add(b.value)
 return a.value
echo someFunc()
echo(someOtherFunc(123))
discard someFunc()

View File

@@ -0,0 +1,15 @@
{ nixpkgs ? <nixpkgs>
, nixpkgs' ? import nixpkgs {}}: with nixpkgs';
# some comment
stdenv.mkDerivation rec {
 pname = "test";
 version = "0.2.3";
 name = "${pname}-${version}";
 buildInputs = [
 gzip
 bzip2
 python27
 ];
}

View File

@@ -0,0 +1,38 @@
* This is header
** sub header
*** sub sub header
**** sub sub sub header
* Table representation
| Name | Age |
|---------+-----|
| Milli | 23 |
| Vanilli | 22 |
* Spreadsheets
| n | n + 2 | n ^ 2 |
|---+-------+-------|
| 1 | 3 | 1 |
| 2 | 4 | 4 |
| 3 | 5 | 9 |
#+TBLFM: $2=$1+2::$3=$1*$1
* Source Code
#+BEGIN_SRC rust
 # recursive fibonacci
 fn fib(n: u32) -> u32 {
 match n {
 0 | 1 => 1,
 _ => fib(n - 1) + fib(n - 2),
 }
 }
#+END_SRC
* ToDo and Checkboxes Example
** DONE Write source example
** TODO Generate highlighted example [1/3]
 - [X] run update script
 - [-] get code review
 - [ ] merge into master

View File

@@ -0,0 +1,320 @@
=====
Title
=====
Subtitle
--------
Titles are underlined (or over-
and underlined) with a printing
nonalphanumeric 7-bit ASCII
character. Recommended choices
are "``= - ` : ' " ~ ^ _ * + # < >``".
The underline/overline must be at
least as long as the title text.
A lone top-level (sub)section
is lifted up to be the document's
(sub)title.
Inline syntaxes
---------------
*emphasis* 
**strong emphasis**
`interpreted text`
``inline literal``
http://docutils.sf.net/
Bullet lists
------------
- This is item 1
- This is item 2
- Bullets are "-", "*" or "+".
 Continuing text must be aligned
 after the bullet and whitespace.
Note that a blank line is required
before the first item and after the
last, but is optional between items.
Enumerated lists
----------------
3. This is the first item
4. This is the second item
5. Enumerators are arabic numbers,
 single letters, or roman numerals
6. List items should be sequentially
 numbered, but need not start at 1
 (although not all formatters will
 honour the first index).
#. This item is auto-enumerated
Definition lists
----------------
what
 Definition lists associate a term with
 a definition.
how
 The term is a one-line phrase, and the
 definition is one or more paragraphs or
 body elements, indented relative to the
 term. Blank lines are not allowed
 between term and definition.
Field lists
-----------
:Authors:
 Tony J. (Tibs) Ibbs,
 David Goodger
 (and sundry other good-natured folks)
:Version: 1.0 of 2001/08/08
:Dedication: To my father.
Options lists
-------------
-a command-line option "a"
-b file options can have arguments
 and long descriptions
--long options can be long also
--input=file long options can also have
 arguments
/V DOS/VMS-style options too
Literal Blocks
--------------
A paragraph containing only two colons
indicates that the following indented
or quoted text is a literal block.
::
 Whitespace, newlines, blank lines, and
 all kinds of markup (like *this* or
 \this) is preserved by literal blocks.
 The paragraph containing only '::'
 will be omitted from the result.
The ``::`` may be tacked onto the very
end of any paragraph. The ``::`` will be
omitted if it is preceded by whitespace.
The ``::`` will be converted to a single
colon if preceded by text, like this::
 It's very convenient to use this form.
Literal blocks end when text returns to
the preceding paragraph's indentation.
This means that something like this
is possible::
 We start here
 and continue here
 and end here.
Per-line quoting can also be used on
unindented literal blocks::
> Useful for quotes from email and
> for Haskell literate programming.
Line blocks
-----------
A paragraph containing only two colons
indicates that the following indented
or quoted text is a literal block.
::
 Whitespace, newlines, blank lines, and
 all kinds of markup (like *this* or
 \this) is preserved by literal blocks.
 The paragraph containing only '::'
 will be omitted from the result.
The ``::`` may be tacked onto the very
end of any paragraph. The ``::`` will be
omitted if it is preceded by whitespace.
The ``::`` will be converted to a single
colon if preceded by text, like this::
 It's very convenient to use this form.
Literal blocks end when text returns to
the preceding paragraph's indentation.
This means that something like this
is possible::
 We start here
 and continue here
 and end here.
Per-line quoting can also be used on
unindented literal blocks::
> Useful for quotes from email and
> for Haskell literate programming.
Block quotes
------------
Block quotes are just:
 Indented paragraphs,
 and they may nest.
Doctest blocks
--------------
Doctest blocks are interactive
Python sessions. They begin with
"``>>>``" and end with a blank line.
>>> print "This is a doctest block."
This is a doctest block.
Tables
------
Grid table:
+------------+------------+-----------+
| Header 1 | Header 2 | Header 3 |
+============+============+===========+
| body row 1 | column 2 | column 3 |
+------------+------------+-----------+
| body row 2 | Cells may span columns.|
+------------+------------+-----------+
| body row 3 | Cells may | - Cells |
+------------+ span rows. | - contain |
| body row 4 | | - blocks. |
+------------+------------+-----------+
Simple table:
===== ===== ======
 Inputs Output
------------ ------
 A B A or B
===== ===== ======
False False False
True False True
False True True
True True True
===== ===== ======
Transitions
-----------
A transition marker is a horizontal line
of 4 or more repeated punctuation
characters.
------------
A transition should not begin or end a
section or document, nor should two
transitions be immediately adjacent.
Footnotes
---------
Footnote references, like [5]_.
Note that footnotes may get
rearranged, e.g., to the bottom of
the "page".
.. [5] A numerical footnote. Note there's no colon after the ``]``.
Autonumbered footnotes are
possible, like using [#]_ and [#]_.
.. [#] This is the first one.
.. [#] This is the second one.
They may be assigned 'autonumber
labels' - for instance,
[#fourth]_ and [#third]_.
.. [#third] a.k.a. third_
.. [#fourth] a.k.a. fourth_
Auto-symbol footnotes are also
possible, like this: [*]_ and [*]_.
.. [*] This is the first one.
.. [*] This is the second one.
Citations
---------
Citation references, like [CIT2002]_.
Note that citations may get
rearranged, e.g., to the bottom of
the "page".
.. [CIT2002] A citation (as often used in journals).
Citation labels contain alphanumerics,
underlines, hyphens and fullstops.
Case is not significant.
Given a citation like [this]_, one
can also refer to it like this_.
.. [this] here.
Hyperlink Targets
-----------------
External hyperlinks, like Python_.
.. _Python: http://www.python.org/
External hyperlinks, like `Python
<http://www.python.org/>`_.
Internal crossreferences, like example_.
.. _example:
This is an example crossreference target.
Python_ is `my favourite
programming language`__.
.. _Python: http://www.python.org/
__ Python_
Titles are targets, too
=======================
Implict references, like `Titles are
targets, too`_.
Directives
----------
For instance:
.. image:: images/ball1.gif
The |biohazard| symbol must be used on containers used to dispose of medical waste.
.. |biohazard| image:: biohazard.png
Comments
--------
.. This text will not be shown
 (but, for instance, in HTML might be
 rendered as an HTML comment)
An "empty comment" does not
consume following blocks.
(An empty comment is ".." with
blank lines before and after.)
..
 So this block is not "lost",
 despite its indentation.

View File

@@ -4,7 +4,7 @@ set -eou pipefail
script_directory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
output_directory=$(mktemp -d --suffix=.bat-syntax-regression-test)
output_directory=$(mktemp -d)
"$script_directory"/create_highlighted_versions.py --output="$output_directory"

View File

@@ -0,0 +1,36 @@
<html>
<body>
<!-- #include file ="headers\header.inc" -->
<%
For i = 0 To 5
Response.Write("The number is " & i & "<br />")
Next
%>
<%
Response.Write("Hello World!")
%>
<%
Dim x(2,2)
x(0,0)="Volvo"
x(0,1)="BMW"
x(0,2)="Ford"
x(1,0)="Apple"
x(1,1)="Orange"
x(1,2)="Banana"
x(2,0)="Coke"
x(2,1)="Pepsi"
x(2,2)="Sprite"
for i=0 to 2
response.write("<p>")
for j=0 to 2
response.write(x(i,j) & "<br />")
next
response.write("</p>")
next
%>
</body>
</html>

View File

@@ -0,0 +1,75 @@
import flash.events.*;
import flash.events.MouseEvent;
package TestSyntax {
public class TestSyntax extends flash.display.Sprite {
public static const TEST_CONSTANT:Number = 33.333;
var testAttribute:int = 1;
public namespace TestNamespace;
TestNamespace function Method2():void { }
/**
* Multi-line comment
*/
override public function set x(value:Number):void
{
super.x = Math.round(value);
}
/**
* Actual multi-line comment
* Takes up multiple lines
*/
override public function set y(value:Number):void
{
super.y = 0;
}
public function testFunction() {
var test:String = 'hello';
// arrays
var testArray:Array = ["a", "b", "c", "d"];
for (var i:uint = 0; i < testArray.length; i++)
trace(testArray[i]);
// objects
var testObject:Object = {foo: 20, bar: 40};
for (var key:String in testObject) {
trace(testObject[key]);
}
for each (var objectValue:int in testObject) {
trace(objectValue);
}
// dynamic variables
var testDynamic:*;
testDynamic = 75;
testDynamic = "Seventy-five";
// regex
var testRegExp:RegExp = /foo-\d+/i;
// XML
var testXML:XML =
<employee>
<firstName>Harold</firstName>
<lastName>Webster</lastName>
</employee>;
}
private function anotherFunc(a:int, arg2:uint, arg3:Function, ... args) {
}
[Embed(source="sound1.mp3")] public var soundCls:Class;
public function SoundAssetExample()
{
var mySound:SoundAsset = new soundCls() as SoundAsset;
var sndChannel:SoundChannel = mySound.play();
}
}
}

View File

@@ -0,0 +1,42 @@
# This is a comment
#
ServerRoot ""
Listen 80
LoadModule mpm_event_module /usr/lib/apache2/modules/mod_mpm_event.so
<IfModule unixd_module>
User daemon
Group daemon
</IfModule>
ServerAdmin you@example.com
<Directory />
AllowOverride none
Require all denied
</Directory>
DocumentRoot "/usr/share/apache2/default-site/htdocs"
<Directory "/usr/share/apache2/default-site/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "/var/log/apache2/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
CustomLog "/var/log/apache2/access_log" common
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/usr/lib/cgi-bin/"
</IfModule>
<IfModule mime_module>
TypesConfig /etc/apache2/mime.types
AddType application/x-compress .Z
AddOutputFilter INCLUDES .shtml
</IfModule>
<IfModule proxy_html_module>
Include /etc/apache2/extra/proxy-html.conf
</IfModule>

View File

@@ -0,0 +1,25 @@
-- This is a comment
property defaultClientName : "Mary Smith"
on greetClient(nameOfClient)
display dialog ("Hello " & nameOfClient & "!")
end greetClient
script testGreet
greetClient(defaultClientName)
end script
run testGreet
greetClient("Joe Jones")
set myList to {1, "what", 3}
set beginning of myList to 0
set end of myList to "four"
myList
tell application "TextEdit"
paragraph 1 of document 1
end tell

Some files were not shown because too many files have changed in this diff Show More