Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
maxim-uvarov committed Nov 30, 2024
1 parent f3068ec commit 4ba577e
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ Output:
╰──────────────────name───────────────────┴─type─╯
> sys host | get boot_time
Sat, 23 Nov 2024 18:43:06 -0300 (6 days ago)
Sat, 23 Nov 2024 18:43:07 -0300 (a week ago)
> 2 + 2
4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ Output:
// ```
// ```output-numd
// foo/baz/bar
//
// ```
// #code-block-marker-open-6
// ```nu
Expand All @@ -215,7 +214,6 @@ Output:
//
// > 2 + 2
// 4
//
// ```
```

Expand All @@ -233,9 +231,9 @@ Output:
// ╭──────────────────┬────────────────────╮
// │ filename │ simple_markdown.md │
// │ nushell_blocks │ 3 │
// │ levenshtein_dist │ 157
// │ diff_lines │ -7 (-23.3%)
// │ levenshtein_dist │ 155
// │ diff_lines │ -9 (-30%)
// │ diff_words │ -11 (-17.5%) │
// │ diff_chars │ -72 (-18.8%) │
// │ diff_chars │ -74 (-19.3%) │
// ╰──────────────────┴────────────────────╯
```
5 changes: 5 additions & 0 deletions z_examples/99_strip_markdown/numd_commands_explanations.nu
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ $env.config.table.abbreviated_row_count = 100
# We use `path join` here to construct working paths for both Windows and Unix
use ($init_numd_pwd_const | path join numd commands.nu) *


# ```nu indent-output
# Here we set the `$file` variable (which will be used in several commands throughout this script) to point to `z_examples/1_simple_markdown/simple_markdown.md`.
let $file = $init_numd_pwd_const | path join z_examples 1_simple_markdown simple_markdown.md
Expand All @@ -16,6 +17,7 @@ let $md_orig = open -r $file | toggle-output-fences
let $original_md_table = $md_orig | find-code-blocks
$original_md_table | table -e


# ```nu indent-output
# Here we emulate that the `$intermed_script_path` options is not set
let $intermediate_script_path = $file
Expand All @@ -27,6 +29,7 @@ decortate-original-code-blocks $original_md_table

open $intermediate_script_path


# ```nu indent-output
# the flag `$no_fail_on_error` is set to false
let $no_fail_on_error = false
Expand All @@ -35,12 +38,14 @@ let $nu_res_stdout_lines = execute-intermediate-script $intermediate_script_path
rm $intermediate_script_path
$nu_res_stdout_lines


# ```nu indent-output
let $md_res = $nu_res_stdout_lines
| str join (char nl)
| clean-markdown

$md_res


# ```nu indent-output
compute-change-stats $file $md_orig $md_res
1 change: 1 addition & 0 deletions z_examples/99_strip_markdown/raw_strings_test.nu
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
let $two_single_lines_text = r#'"High up in the mountains, a Snake crawled and lay in a damp gorge, coiled
into a knot, staring out at the sea.'#
# ```nu
$two_single_lines_text
2 changes: 2 additions & 0 deletions z_examples/99_strip_markdown/simple_markdown.nu
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
# ```nu
let $var1 = 'foo'


# ```nu
# This block will produce some output in a separate block
$var1 | path join 'baz' 'bar'


# ```nu
# This block will output results inline
whoami
Expand Down
2 changes: 2 additions & 0 deletions z_examples/99_strip_markdown/simple_markdown_first_block.nu
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
# ```nu
let $var1 = 'foo'


# ```nu
# This block will produce some output in a separate block
$var1 | path join 'baz' 'bar'


# ```nu
# This block will output results inline
whoami
Expand Down
2 changes: 2 additions & 0 deletions z_examples/99_strip_markdown/simple_nu_table.nu
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# ```nushell
$env.numd?


# ```nushell
[[a b c]; [1 2 3]]


# ```nushell
[[column long_text];

Expand Down
29 changes: 29 additions & 0 deletions z_examples/99_strip_markdown/types_of_data.nu
Original file line number Diff line number Diff line change
Expand Up @@ -2,105 +2,134 @@
# ```nushell
42 | describe


# ```nushell
"-5" | into int


# ```nushell
"1.2" | into float


# ```nushell
let mybool = 2 > 1
$mybool
let mybool = ($nu.home-path | path exists)
$mybool


# ```nushell
3.14day


# ```nushell
30day / 1sec # How many seconds in 30 days?


# ```nushell
1Gb / 1b
1Gib / 1b
(1Gib / 1b) == 2 ** 30


# ```nushell
0x[1F FF] # Hexadecimal
0b[1 1010] # Binary
0o[377] # Octal


# ```nushell
{name: sam rank: 10}


# ```nushell
{x:3 y:1} | insert z 0


# ```nushell
{name: sam, rank: 10} | transpose key value


# ```nushell
{x:12 y:4}.x


# ```nushell
{"1":true " ":false}." "


# ```nushell
let data = { name: alice, age: 50 }
{ ...$data, hobby: cricket }


# ```nushell
[sam fred george]


# ```nushell
[bell book candle] | where ($it =~ 'b')


# ```nushell
[a b c].1


# ```nushell
[a b c d e f] | range 1..3


# ```nushell
let x = [1 2]
[...$x 3 ...(4..7 | take 2)]


# ```nushell
[[column1, column2]; [Value1, Value2] [Value3, Value4]]


# ```nushell
[{name: sam, rank: 10}, {name: bob, rank: 7}]


# ```nushell
[{x:12, y:5}, {x:3, y:6}] | get 0


# ```nushell
[[x,y];[12,5],[3,6]] | get 0


# ```nushell
[{x:12 y:5} {x:4 y:7} {x:2 y:2}].x


# ```nushell
[{x:0 y:5 z:1} {x:4 y:7 z:3} {x:2 y:2 z:0}] | select y z


# ```nushell
[{x:0 y:5 z:1} {x:4 y:7 z:3} {x:2 y:2 z:0}] | select 1 2


# ```nushell
[{foo: 123}, {}].foo?


# ```nushell
# Assign a closure to a variable
let greet = { |name| print $"Hello ($name)"}
do $greet "Julian"


# ```nushell
mut x = 1
if true {
$x += 1000
}
print $x


# ```nushell try,new-instance
[{a:1 b:2} {b:1}]
[{a:1 b:2} {b:1}].1.a
16 changes: 16 additions & 0 deletions z_examples/99_strip_markdown/working_with_lists.nu
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
[1, 2, 3, 4] | insert 2 10
# [1, 2, 10, 3, 4]


# ```nu
[1, 2, 3, 4] | update 1 10
# [1, 10, 3, 4]


# ```nu
let colors = [yellow green]
let colors = ($colors | prepend red)
Expand All @@ -15,22 +17,26 @@ let colors = ($colors ++ "blue")
let colors = ("black" ++ $colors)
$colors # [black red yellow green purple blue]


# ```nu
let colors = [red yellow green purple]
let colors = ($colors | skip 1)
let colors = ($colors | drop 2)
$colors # [yellow]


# ```nu
let colors = [red yellow green purple black magenta]
let colors = ($colors | last 3)
$colors # [purple black magenta]


# ```nu
let colors = [yellow green purple]
let colors = ($colors | first 2)
$colors # [yellow green]


# ```nu
let names = [Mark Tami Amanda Jeremy]
$names | each { |it| $"Hello, ($it)!" }
Expand All @@ -39,16 +45,19 @@ $names | each { |it| $"Hello, ($it)!" }
$names | enumerate | each { |it| $"($it.index + 1) - ($it.item)" }
# Outputs "1 - Mark", "2 - Tami", etc.


# ```nu
let colors = [red orange yellow green blue purple]
$colors | where ($it | str ends-with 'e')
# The block passed to `where` must evaluate to a boolean.
# This outputs the list [orange blue purple].


# ```nu
let scores = [7 10 8 6 7]
$scores | where $it > 7 # [10 8]


# ```nu
let scores = [3 8 4]
$"total = ($scores | reduce { |it, acc| $acc + $it })" # total = 15
Expand All @@ -59,28 +68,33 @@ $"product = ($scores | reduce --fold 1 { |it, acc| $acc * $it })" # product = 96

$scores | enumerate | reduce --fold 0 { |it, acc| $acc + $it.index * $it.item } # 0*3 + 1*8 + 2*4 = 16


# ```nu
let names = [Mark Tami Amanda Jeremy]
$names.1 # gives Tami


# ```nu
let names = [Mark Tami Amanda Jeremy]
let index = 1
$names | get $index # gives Tami


# ```nu
let colors = [red green blue]
$colors | is-empty # false

let colors = []
$colors | is-empty # true


# ```nu
let colors = [red green blue]
'blue' in $colors # true
'yellow' in $colors # false
'gold' not-in $colors # true


# ```nu
let colors = [red green blue]
# Do any color names end with "e"?
Expand All @@ -96,6 +110,7 @@ $scores | any {|it| $it > 7 } # true
# Are any scores odd?
$scores | any {|it| $it mod 2 == 1 } # true


# ```nu
let colors = [red green blue]
# Do all color names end with "e"?
Expand All @@ -111,6 +126,7 @@ $scores | all {|it| $it > 7 } # false
# Are all scores even?
$scores | all {|it| $it mod 2 == 0 } # false


# ```nu
[1 [2 3] 4 [5 6]] | flatten # [1 2 3 4 5 6]

Expand Down

0 comments on commit 4ba577e

Please sign in to comment.