Python’s howdoi package to query easy programming stuff you keep forgetting



Nowadays programmers use variety of tools, whether programming languages, cloud, IDEs, frameworks, etc. Each and everyone of them is a rabbit hole you can spend your lifetime in. It requires extraordinary memory to memorize everything. Still, no one is perfect and to forget is a human thing. So what do you do when forgetting happens? Normally you open your browser, type in the question, hit the first stack overflow link, scroll down. What if you could do it faster? What if you could do it in your terminal? Presenting: howdoi

howdoi is a Python package to query common programming questions. Let's take a look

$ howdoi convert string to number javascript
>> var x = Number("1000")

Btw. that's actually a thing I keep forgetting. howdoi comes with couple options, here is how to list them

howdoi howdoi

Here are a few popular howdoi commands
>>> howdoi print hello world in python (default query)
>>> howdoi print hello world in python -a (read entire answer)
>>> howdoi print hello world in python -n [number] (retrieve n number of answers)
>>> howdoi print hello world in python -l (display only a link to where the answer is from
>>> howdoi print hello world in python -c (Add colors to the output)
>>> howdoi print hello world in python -e (Specify the search engine you want to use e.g google,bing)

Let's ask again same question with -a option. The awesome thing is, it also gives the url to SO if you want to go more into details.

★  Answer from ★
The simplest way would be to use the native Number function:
var x = Number("1000")
If that doesn't work for you, then there are the parseInt , unary plus , parseFloat with floor , and Math.round methods.
var x = parseInt("1000", 10); // you want to use radix 10
    // so you get a decimal number even with a leading 0 and an old browser ([IE8, Firefox 20, Chrome 22 and older][1])
unary plus
if your string is already in the form of an integer:
var x = +"1000";
if your string is or might be a float and you want an integer:
var x = Math.floor("1000.01"); //floor automatically converts string to number
or, if you're going to be using Math.floor several times:
var floor = Math.floor;
var x = floor("1000.01");
If you're the type who forgets to put the radix in when you call parseInt, you can use parseFloat and round it however you like. Here I use floor.
var floor = Math.floor;
var x = floor(parseFloat("1000.01"));
Interestingly, Math.round (like Math.floor) will do a string to number conversion, so if you want the number rounded (or if you have an integer in the string), this is a great way, maybe my favorite:
var round = Math.round;
var x = round("1000"); //equivalent to round("1000",0)

To list multiple answers supply -n option with number

$ howdoi convert string to number javascript -n 3

★  Answer from ★
var x = Number("1000")


★  Answer from ★
var votevalue = parseInt($(".btn").data('votevalue'), 10);


★  Answer from ★

I recommend playing around with all the options. Combination of -a and -c gives you more readable code.

Now, the serious question we all want to the answer to.

$ howdoi expect Spanish inquisition
Sorry, couldn't find any help with that topic