1
Fork 0
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:
JT 2021-12-03 07:21:57 +13:00 committed by GitHub
commit 6d7fc9fe16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 49 deletions

View file

@ -1,11 +1,8 @@
#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)

View file

@ -1,24 +1,22 @@
#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?) {

View file

@ -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