diff --git a/cool_oneliners/dict.nu b/cool_oneliners/dict.nu index d890e84..3678ffd 100644 --- a/cool_oneliners/dict.nu +++ b/cool_oneliners/dict.nu @@ -1,16 +1,13 @@ -#As the name suggests, the function returns you the definition and example of the sought English word -#(or breaks if it can't find the word because the API uses different columns for successful and invalid searches) - -#usage: dict word -#usage: dict "word with space" - -def dict [word: string] { - let link = (build-string 'https://api.dictionaryapi.dev/api/v2/entries/en/' ($word|str find-replace ' ' '%20')) +# Function querying free online English dictionary API for definition of given word(s) +def dict [...word #word(s) to query the dictionary API but they have to make sense together like "martial law", not "cats dogs" +] { + let query = ($word | str collect %20) + let link = (build-string 'https://api.dictionaryapi.dev/api/v2/entries/en/' ($query|str find-replace ' ' '%20')) let output = (fetch $link | rename word) - let w = ($output.word | first) + let w = ($output.word | first) - if $w == "No Definitions Found" {echo $output.word} {echo $output | + if $w == "No Definitions Found" {echo $output.word} {echo $output | get meanings.definitions | select definition example } diff --git a/data_extraction/ultimate_extractor.nu b/data_extraction/ultimate_extractor.nu index e7f5312..d7383e2 100644 --- a/data_extraction/ultimate_extractor.nu +++ b/data_extraction/ultimate_extractor.nu @@ -1,25 +1,23 @@ -#As in the file name, the script is designed to conveniently handle any archive format - -#usage: extract archive_name - -def extract [name:string] { +#Function to extract archives with different extensions +def extract [name:string #name of the archive to extract +] { let exten = [ [ex com]; - ['.tar.bz2' 'tar xjf'] - ['.tar.gz' 'tar xzf'] - ['.bz2' 'bunzip2'] - ['.rar' 'unrar x'] - ['.tbz2' 'tar xjf'] - ['.tgz' 'tar xzf'] - ['.zip' 'unzip'] - ['.7z' '/usr/bin/7z x'] - ['.deb' 'ar x'] - ['.tar.xz' 'tar xvf'] - ['.tar.zst' 'tar xvf'] - ['.tar' 'tar xvf'] - ['.gz' 'gunzip'] - ['.Z' 'uncompress'] - ] - + ['.tar.bz2' 'tar xjf'] + ['.tar.gz' 'tar xzf'] + ['.bz2' 'bunzip2'] + ['.rar' 'unrar x'] + ['.tbz2' 'tar xjf'] + ['.tgz' 'tar xzf'] + ['.zip' 'unzip'] + ['.7z' '/usr/bin/7z x'] + ['.deb' 'ar x'] + ['.tar.xz' 'tar xvf'] + ['.tar.zst' 'tar xvf'] + ['.tar' 'tar xvf'] + ['.gz' 'gunzip'] + ['.Z' 'uncompress'] + ] + let command = ($exten|where $name =~ $it.ex|first) if ($command|empty?) { echo 'Error! Unsupported file extension' diff --git a/maths/math_functions.nu b/maths/math_functions.nu index de3434e..9249f82 100644 --- a/maths/math_functions.nu +++ b/maths/math_functions.nu @@ -1,37 +1,33 @@ #!/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. # 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] { $num ** ( 1 / 3 ) | math round -p 10 } -# root with custom denominator, e.g. 2 ** 1/4 -def root [ denominator: number, num: number ] { - $num ** ( 1 / $denominator ) | math round -p 10 -} - -# totally custom root, e.g. 2 ** 3/8 +#Root with a custom scaler and denominator def aroot [ scaler: number, denominator: number, num: number ] { $num ** ($scaler / $denominator) | math round -p 10 } -#discriminant of a quadratic equation -def delta [ a: number, b: number, c: number ] { +#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 a given number, works fine only for n<21 (integer range) -def fact [num:number] { +#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'} } -#TODO: -# -sin, cos, tan table for 0-90 degrees -# -radians to degrees and reversed -# -sin, cos, tan, ctg, sec, cosec functions