1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 22:57:46 +00:00

Ported my scripts to 0.60 (#189)

* dict.nu ready for 0.60

* wolfram didn't require any changes

* extractor works flawlessy on 0.60

* maths ported to 0.60
This commit is contained in:
Kamil 2022-03-24 19:49:01 +01:00 committed by GitHub
parent 29c96015a0
commit 8b04417a4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 3 deletions

View file

@ -0,0 +1,19 @@
#Fetch simple anwser from WolframAlpha API
def wolfram [...query #Your query
] {
let appID = #YOUR APP_ID
let query_string = ($query | str collect " ")
let result = (fetch ("https://api.wolframalpha.com/v1/result?" + ([[appid i]; [$appID $query_string]] | to url)))
$result + ""
}
#Fetch image with full anwser from WolframAlpha API
def wolframimg [...query #Your query
] {
let appID = #YOUR APP_ID
let query_string = ($query | str collect " ")
let filename = ($query_string + ".png")
let link = ("https://api.wolframalpha.com/v1/simple?" + ([[appid i]; [$appID $query_string]] | to url) + "&background=F5F5F5&fontsize=20")
fetch $link | save $filename
echo ("Query result saved in file: " + $filename)
}

View file

@ -7,8 +7,11 @@ def dict [...word #word(s) to query the dictionary API but they have to make sen
rename word)
let w = ($output.word | first)
if $w == "No Definitions Found" {echo $output.word} else {echo $output |
get meanings.definitions |
select definition example
if $w == "No Definitions Found" {
echo $output.word
} else {
echo $output.meanings.definitions |
flatten | flatten |
select definition example
}
}

View file

@ -0,0 +1,27 @@
#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']
]
let command = ($exten|where $name =~ $it.ex|first)
if ($command|empty?) {
echo 'Error! Unsupported file extension'
} else {
nu -c (build-string $command.com ' ' $name)
}
}

35
maths/math_functions.nu Normal file
View file

@ -0,0 +1,35 @@
#Root with a custom denominator
def root [ denominator, num ] {
$num ** ( 1 / $denominator ) | math round -p 10
}
#Cube root
def croot [num] {
$num ** ( 1 / 3 ) | math round -p 10
}
#Root with a custom scaler and denominator
def aroot [ scaler, denominator, num] {
$num ** ($scaler / $denominator) | math round -p 10
}
#calculate delta of the quadratic function
def delta [ a,#x^2 factor
b, #x factor
c #the rest
] {
( $b ** 2 ) - ( 4 * $a * $c)
}
#Factorial of the given number
def fact [num: int] {
if $num >= 0 {
if $num < 2 {
$num
} else {
seq 2 $num | math product
}
} else {
echo 'Error: can only calculate non-negative integers'
}
}