From 15cb7179e2667e41c33f058f87ab4f5c1e45fadd Mon Sep 17 00:00:00 2001 From: Igor Date: Sat, 25 May 2024 19:18:21 +0400 Subject: [PATCH] Port `before_v0.60/math`, `before_v0.60/parsing` and `before_v0.60/git` (#844) This PR is part of porting all old scripts #221 and includes a set of small modules: - `math` - `parsing` - `git` --- before_v0.60/git/git_branch_cleanup.nu | 4 --- before_v0.60/maths/math_functions.nu | 33 ------------------- {before_v0.60 => modules}/git/README.md | 0 .../git/git_branch_age.nu | 6 ++-- {before_v0.60 => modules}/parsing/README.md | 0 .../parsing/sample_andres.json | 0 .../parsing/sample_andres.nu | 12 +++---- 7 files changed, 9 insertions(+), 46 deletions(-) delete mode 100644 before_v0.60/git/git_branch_cleanup.nu delete mode 100644 before_v0.60/maths/math_functions.nu rename {before_v0.60 => modules}/git/README.md (100%) rename {before_v0.60 => modules}/git/git_branch_age.nu (67%) rename {before_v0.60 => modules}/parsing/README.md (100%) rename {before_v0.60 => modules}/parsing/sample_andres.json (100%) rename {before_v0.60 => modules}/parsing/sample_andres.nu (54%) diff --git a/before_v0.60/git/git_branch_cleanup.nu b/before_v0.60/git/git_branch_cleanup.nu deleted file mode 100644 index b87d7ba6e..000000000 --- a/before_v0.60/git/git_branch_cleanup.nu +++ /dev/null @@ -1,4 +0,0 @@ -# Script that remove outdated local branches from a git repo -# More information on this article https://www.techwatching.dev/posts/cleaning-git-branches - -git branch -vl '*/*' | lines | split column " " BranchName Hash Status --collapse-empty | where Status == '[gone]' | each { git branch -D $it.BranchName } \ No newline at end of file diff --git a/before_v0.60/maths/math_functions.nu b/before_v0.60/maths/math_functions.nu deleted file mode 100644 index 9249f821b..000000000 --- a/before_v0.60/maths/math_functions.nu +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/nu -# -# BE CAREFUL WITH ROOTS MADE ON BIG NUMBERS (10 digits and more) — the result is rounded so you may get wrong result. -# just modify the round -p or calculate it manually - -#Root with a custom denominator -def root [ denominator: number, num: number ] { - $num ** ( 1 / $denominator ) | math round -p 10 -} - -#Cube root -def croot [num: number] { - $num ** ( 1 / 3 ) | math round -p 10 -} - -#Root with a custom scaler and denominator -def aroot [ scaler: number, denominator: number, num: number ] { - $num ** ($scaler / $denominator) | math round -p 10 -} - -#calculate delta of the quadratic function -def delta [ a: number,#x^2 factor -b: number, #x factor -c: number #the rest -] { - ( $b ** 2 ) - ( 4 * $a * $c) -} - -#Factorial of the given number -def fact [num: int] { - if $num >= 0 { if $num < 2 {$num} {seq 2 $num | math product} } { echo 'Error: can only calculate non-negative integers'} -} - diff --git a/before_v0.60/git/README.md b/modules/git/README.md similarity index 100% rename from before_v0.60/git/README.md rename to modules/git/README.md diff --git a/before_v0.60/git/git_branch_age.nu b/modules/git/git_branch_age.nu similarity index 67% rename from before_v0.60/git/git_branch_age.nu rename to modules/git/git_branch_age.nu index 9e30bf6e6..8b3674758 100644 --- a/before_v0.60/git/git_branch_age.nu +++ b/modules/git/git_branch_age.nu @@ -1,13 +1,13 @@ # Creates a table listing the branches of a git repository and the day of the last commit -def "git age" [] { +export def "git age" [] { git branch | lines | - str substring 2, | + str substring 2.. | wrap name | insert last_commit { get name | each { - git show $it --no-patch --format=%as | str to-datetime + git show $in --no-patch --format=%as | into datetime } } | sort-by last_commit diff --git a/before_v0.60/parsing/README.md b/modules/parsing/README.md similarity index 100% rename from before_v0.60/parsing/README.md rename to modules/parsing/README.md diff --git a/before_v0.60/parsing/sample_andres.json b/modules/parsing/sample_andres.json similarity index 100% rename from before_v0.60/parsing/sample_andres.json rename to modules/parsing/sample_andres.json diff --git a/before_v0.60/parsing/sample_andres.nu b/modules/parsing/sample_andres.nu similarity index 54% rename from before_v0.60/parsing/sample_andres.nu rename to modules/parsing/sample_andres.nu index edbb43f27..122fe79be 100644 --- a/before_v0.60/parsing/sample_andres.nu +++ b/modules/parsing/sample_andres.nu @@ -5,17 +5,17 @@ def look_for [word] { insert comp { get shoes_name | split row " " | - each --numbered { - [[idx, loc]; [$it.index, ($it.item | str index-of $word)]] - } + enumerate | each { + [[idx, loc]; [$in.index, ($in.item | str index-of $word)]] + } | flatten } | flatten | where comp.loc >= 0 | flatten | - update idx { $it.idx + 1 } | + update idx { $in + 1 } | reject name price loc | rename nameWords targetWordIndex } -look_for "leather" | to json --pretty 4 -look_for "low-top" | to json --pretty 4 \ No newline at end of file +print (look_for "leather" | to json --indent 4) +print (look_for "low-top" | to json --indent 4)