9 ms·
$ coinmon() { > curl "https://api.coinmarketcap.com/v1/ticker/?convert=$1" | jq ".[0] .price_$1" > } $ coinmon eur "6988.4723188" In case
by adtac 9y ago
$ coinmon() {
> curl "https://api.coinmarketcap.com/v1/ticker/?convert=$1" | jq ".[0] .price_$1"
> }
$ coinmon eur
"6988.4723188"
In case you don't want to install 61 packages [1] :)
I don't know when/where nodejs development went wrong, but there's definitely something wrong.
[1] http://npm.anvaka.com/#/view/2d/coinmon http://npm.anvaka.com/#/view/2d/coinmon
- progx 9y agoand curl did not have dependencies? The installation of coinmon and all its deps is faster, as i can your post. But you are right, it uses incredible 33 MB of my disk space, so i now have only 300000 MB left. OMG doomed!
- adtac 9y agoYou're missing my point: nodejs is really not a suitable candidate for tiny CLI programs like this. If the author is just learning node, there's nothing wrong with it, of course. In any case, the bash one-liner is just an alternative :) Also, this kind of "it uses just 33 MB" culture is exactly what's wrong with node: 33 MB is small enough, but what about real programs? Would you still freely add trivial dependencies? This would get unwieldy very fast. There's also the security aspect that comes with relying on 61 dependencies. What if one of the dependencies is compromised (as it happened recently)?
- psyc 9y agoAnd if we had exabyte drives, would there be nothing suspect about a CLI utility taking petabytes? Are we not engineers / programmers?
- joshbaptiste 9y agoIndeed.. I'll probably write a Nim version as I prefer a single binary and not rely on having a JVM, Node, Python etc.. VM and associated libraries pre-installed.
- cobookman 9y agoI think its fair to rely on Python for Linux Distros. Ubuntu/Debian/Redhat all bundle python with the distro. Where-as the JVM & Nodejs are generally seperate packages. Java 9 though, allows you to ship zero-dep golang style binaries [1]. https://steveperkins.com/using-java-9-modularization-to-ship-zero-dependency-native-apps/ https://steveperkins.com/using-java-9-modularization-to-ship...
- ddxxgg 9y agoNim beginner here. I wanted to see if I was capable of making an equivalent program in Nim. I'm still a bit confused about some of Nim's conventions and idioms, mostly revolving around when to use objects vs. ref objects, and how to properly construct an object. Care to take a look at my code and give me some pointers (heh)? https://gist.github.com/anonymous/1e3d7045de67f59c676135fead3aa66a https://gist.github.com/anonymous/1e3d7045de67f59c676135fead...
- JepZ 9y agoYou are so right. When I saw the link I thought: "That could be fun, lets take a look how it displays the data". But when I saw that it uses node.js I thought "Oh my god, who had this brilliant idea to write it with node"... Hey guys, please use rust, golang, haskell or whatever you like, but please do not use nodejs to write CLI tools. And I am not one of the guys who is against JS in general. In fact, I like building PWAs and other JS heavy apps/websites a lot. But there are so many tools do a better job at building cli programs.
- Klathmon 9y agoI don't get the hate here, Node works great for CLI tools. Easy and quick install, supports colors and icons in the terminal, has several easy and useful table libraries to choose from, and it runs plenty fast enough for it's use case. What benefits would rust, golang, haskell, or whatever you like provide over node in this situation?
- drinchev 9y agoI'm quite confident that "whatever you like" does not benefit versus NodeJS anyway. And of course you should write cli tools with whatever you feel comfortable. If you want them to be well-received by everyone, well that's a different topic.
- diggan 9y agoAlso a NodeJS fan in general, but prefer to install/develop cli's with golang instead of node just because you get a compiled, static binary that works cross-platform. Faster for users to install, less bloaty and works on all platforms without any dependencies.
- 52-6F-62 9y agoI personally usually use Python, Bash, or C, but there is a utility for packaging NodeJS tools into executables. I think it does some tree-shaking as well. Disclaimer: I haven't used it, so I'm not sure of the results. But it is possible. https://www.npmjs.com/package/pkg https://www.npmjs.com/package/pkg edit: For the curious -- Just tried on a really simple script that just takes one argument and writes it with some text to STDOUT and it still came to 35MB. So it must package a bunch of Node with it. I won't be leaving my go-to's for it anytime soon unless usability and development speed necessitate it. Going to have to go with the, best to not use NodeJS for general cmd-line utils outside of the NodeJS environment. The one perk is that it will, by default, output executables for Linux, macOS, and Windows. Source: (function() { 'use strict'; function main(_string) { console.log(`${_string} was read from STDIN.`); } main(process.argv[2]); }()); Output file: 35088858 Nov 20 11:36 index-linux 35717043 Nov 20 11:36 index-macos 23137020 Nov 20 11:36 index-win.exe
- deadcast 9y agoNow that's what I call a refactor! :D ty
- mallaidh 9y agoI prefer curl -s "https://api.coinmarketcap.com/v1/ticker/?convert=$1" | jq ".[0] .price_$1" | sed 's/\"//g' for silent curl and no quotes in output. Unfortunately, this does add a third dependency to the script.
- lhinds 9y agoThat was my reaction to: npm install Nah, i'm alright mate.
- StavrosK 9y agoWhat's up with that API? Why is it a list of objects rather than an object of {"coin-id": {values}}? The way they return things, you have to walk the entire list to find the currency you're interested in.
- throwaway899 9y agoNot necessarily the whole list though ;)
- StavrosK 9y agoHere's a simple Python script with no dependencies other than the stdlib (adjust to taste): https://www.pastery.net/jnscrh/ https://www.pastery.net/jnscrh/
- krapp 9y ago>I don't know when/where nodejs development went wrong, but there's definitely something wrong. Probably when they decided that every function and almost every statement and boolean check needed to be its own separate package with its own build system and test framework.
- Fnoord 9y agoVery nice, thank you! I'm not much into APIs or JS (CBA with auth tokens etc either) so I often forget the sheer power of jq. I prefer to output the curl data 2>/dev/null so there's less noise and the data could be parsed further. I also want to default to eur, with the option of say usd. Finally, I want the currency to be shown as $2 and I want it uppercase. I ended up with: coinmon() { local currency=$1 case "$currency" in "") currency="eur";; esac data=`curl "https://api.coinmarketcap.com/v1/ticker/?convert=$currency" 2>/dev/null | jq ".[0] .price_$currency" | cut -d \" -f 2` echo "$data ${currency^^} " } (Sorry for the scrollbar here on HN.) One could also use tosheets [1] to put $data in spreadsheet or perhaps use something like gnuplot. One could also round $data to say 2 numbers behind the comma (or well, dot is being used in this case) to get a more human readable amount. This could also be implemented like df -h creates human readable output (see man df). [1] https://news.ycombinator.com/item?id=15722108 https://news.ycombinator.com/item?id=15722108