mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-07-30 13:47:46 +00:00
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`
This commit is contained in:
parent
429126f3d8
commit
15cb7179e2
7 changed files with 9 additions and 46 deletions
|
@ -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 }
|
|
@ -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'}
|
||||
}
|
||||
|
|
@ -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
|
|
@ -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
|
||||
print (look_for "leather" | to json --indent 4)
|
||||
print (look_for "low-top" | to json --indent 4)
|
Loading…
Add table
Add a link
Reference in a new issue