mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 07:07:46 +00:00
Merge pull request #107 from skelly37/main
Documented + minor enchancement
This commit is contained in:
commit
6d7fc9fe16
3 changed files with 40 additions and 49 deletions
|
@ -1,11 +1,8 @@
|
||||||
#As the name suggests, the function returns you the definition and example of the sought English word
|
# Function querying free online English dictionary API for definition of given word(s)
|
||||||
#(or breaks if it can't find the word because the API uses different columns for successful and invalid searches)
|
def dict [...word #word(s) to query the dictionary API but they have to make sense together like "martial law", not "cats dogs"
|
||||||
|
] {
|
||||||
#usage: dict word
|
let query = ($word | str collect %20)
|
||||||
#usage: dict "word with space"
|
let link = (build-string 'https://api.dictionaryapi.dev/api/v2/entries/en/' ($query|str find-replace ' ' '%20'))
|
||||||
|
|
||||||
def dict [word: string] {
|
|
||||||
let link = (build-string 'https://api.dictionaryapi.dev/api/v2/entries/en/' ($word|str find-replace ' ' '%20'))
|
|
||||||
let output = (fetch $link |
|
let output = (fetch $link |
|
||||||
rename word)
|
rename word)
|
||||||
let w = ($output.word | first)
|
let w = ($output.word | first)
|
||||||
|
|
|
@ -1,24 +1,22 @@
|
||||||
#As in the file name, the script is designed to conveniently handle any archive format
|
#Function to extract archives with different extensions
|
||||||
|
def extract [name:string #name of the archive to extract
|
||||||
#usage: extract archive_name
|
] {
|
||||||
|
|
||||||
def extract [name:string] {
|
|
||||||
let exten = [ [ex com];
|
let exten = [ [ex com];
|
||||||
['.tar.bz2' 'tar xjf']
|
['.tar.bz2' 'tar xjf']
|
||||||
['.tar.gz' 'tar xzf']
|
['.tar.gz' 'tar xzf']
|
||||||
['.bz2' 'bunzip2']
|
['.bz2' 'bunzip2']
|
||||||
['.rar' 'unrar x']
|
['.rar' 'unrar x']
|
||||||
['.tbz2' 'tar xjf']
|
['.tbz2' 'tar xjf']
|
||||||
['.tgz' 'tar xzf']
|
['.tgz' 'tar xzf']
|
||||||
['.zip' 'unzip']
|
['.zip' 'unzip']
|
||||||
['.7z' '/usr/bin/7z x']
|
['.7z' '/usr/bin/7z x']
|
||||||
['.deb' 'ar x']
|
['.deb' 'ar x']
|
||||||
['.tar.xz' 'tar xvf']
|
['.tar.xz' 'tar xvf']
|
||||||
['.tar.zst' 'tar xvf']
|
['.tar.zst' 'tar xvf']
|
||||||
['.tar' 'tar xvf']
|
['.tar' 'tar xvf']
|
||||||
['.gz' 'gunzip']
|
['.gz' 'gunzip']
|
||||||
['.Z' 'uncompress']
|
['.Z' 'uncompress']
|
||||||
]
|
]
|
||||||
|
|
||||||
let command = ($exten|where $name =~ $it.ex|first)
|
let command = ($exten|where $name =~ $it.ex|first)
|
||||||
if ($command|empty?) {
|
if ($command|empty?) {
|
||||||
|
|
|
@ -1,37 +1,33 @@
|
||||||
#!/usr/bin/nu
|
#!/usr/bin/nu
|
||||||
# made by @skelly37 for everyone :)
|
|
||||||
#
|
|
||||||
# (sqrt skipped because of math module from nushell)
|
|
||||||
#
|
#
|
||||||
# BE CAREFUL WITH ROOTS MADE ON BIG NUMBERS (10 digits and more) — the result is rounded so you may get wrong result.
|
# 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
|
# just modify the round -p or calculate it manually
|
||||||
|
|
||||||
# cube root
|
#Root with a custom denominator
|
||||||
|
def root [ denominator: number, num: number ] {
|
||||||
|
$num ** ( 1 / $denominator ) | math round -p 10
|
||||||
|
}
|
||||||
|
|
||||||
|
#Cube root
|
||||||
def croot [num: number] {
|
def croot [num: number] {
|
||||||
$num ** ( 1 / 3 ) | math round -p 10
|
$num ** ( 1 / 3 ) | math round -p 10
|
||||||
}
|
}
|
||||||
|
|
||||||
# root with custom denominator, e.g. 2 ** 1/4
|
#Root with a custom scaler and denominator
|
||||||
def root [ denominator: number, num: number ] {
|
|
||||||
$num ** ( 1 / $denominator ) | math round -p 10
|
|
||||||
}
|
|
||||||
|
|
||||||
# totally custom root, e.g. 2 ** 3/8
|
|
||||||
def aroot [ scaler: number, denominator: number, num: number ] {
|
def aroot [ scaler: number, denominator: number, num: number ] {
|
||||||
$num ** ($scaler / $denominator) | math round -p 10
|
$num ** ($scaler / $denominator) | math round -p 10
|
||||||
}
|
}
|
||||||
|
|
||||||
#discriminant of a quadratic equation
|
#calculate delta of the quadratic function
|
||||||
def delta [ a: number, b: number, c: number ] {
|
def delta [ a: number,#x^2 factor
|
||||||
|
b: number, #x factor
|
||||||
|
c: number #the rest
|
||||||
|
] {
|
||||||
( $b ** 2 ) - ( 4 * $a * $c)
|
( $b ** 2 ) - ( 4 * $a * $c)
|
||||||
}
|
}
|
||||||
|
|
||||||
#factorial of a given number, works fine only for n<21 (integer range)
|
#Factorial of the given number
|
||||||
def fact [num: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'}
|
if $num >= 0 { if $num < 2 {$num} {seq 2 $num | math product} } { echo 'Error: can only calculate non-negative integers'}
|
||||||
}
|
}
|
||||||
|
|
||||||
#TODO:
|
|
||||||
# -sin, cos, tan table for 0-90 degrees
|
|
||||||
# -radians to degrees and reversed
|
|
||||||
# -sin, cos, tan, ctg, sec, cosec functions
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue