TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Howdoi – Instant Coding Answers via the Command Line

245 pointsby gleitzover 12 years ago

28 comments

roryokaneover 12 years ago
According to the source code (<a href="https://github.com/gleitz/howdoi/blob/master/howdoi/howdoi.py" rel="nofollow">https://github.com/gleitz/howdoi/blob/master/howdoi/howdoi.p...</a>), the answers come from Stack Overflow, searched using Google site search. Howdoi scrapes and prints the first code block in the top answer, or the full text of the top answer if it contains no code block.
评论 #5027203 未加载
评论 #5027230 未加载
评论 #5030201 未加载
评论 #5029833 未加载
davejover 12 years ago
Super useful, love it.<p>Some queries I tried (results were not perfect but pretty decent):<p><pre><code> howdoi split string javascript var split = 'john smith~123 Street~Apt 4~New York~NY~12345'.split('~'); var name = split[0]; var street = split[1]; etc... howdoi get day from date javascript var date = new Date(); var day = date.getDay(); howdoi iterate coffeescript ages = [] ages["jim"] = 12 ages["john"] = 7 for k,v of ages console.log k + " is " + v howdoi get referrer url php &#60;?php session_start(); if (!isset($_SESSION["origURL"])) $_SESSION["origURL"] = $_SERVER["HTTP_REFERER"]; ?&#62;</code></pre>
评论 #5027251 未加载
decktechover 12 years ago
<i>$ howdoi program</i><p><i>Why do you need the Apple Developer Program Enrollment ID? I also tried to apply to the iOS Developer Program this weekend. I applied, I paid and I got my activation codes. But then when I tried to activate with my Apple ID I got an error saying (in my case) they "were not able to successfully verify my identity". In that error message there was an Enrollment ID# consisting of both letters and numbers, a total of 10 characters, that I was supposed to include when contacting the support regarding this issue. I have not seen the same Enrollment ID somewhere else in the process and therefore I assume it is some kind of internal ID for my signing up process and you should only see it/use it when you hit some problems during the process.</i><p>I'll figure it out one of these days.
评论 #5028101 未加载
nicpottierover 12 years ago
I really like the idea of this, I'm getting some good results and some not so good.<p>One that fails rather badly:<p><i>format dates django templates</i> Returns simply "date", despite StackOverflow having lots of hits: <a href="http://stackoverflow.com/search?q=format+dates+django+templates" rel="nofollow">http://stackoverflow.com/search?q=format+dates+django+templa...</a><p>But some others are super cool:<p><i>create datetime from epoch</i> &#62;&#62;&#62; datetime.datetime.fromtimestamp(1284286794)<p>One suggestion is that by default I would include the link to the stackoverflow page.<p>Some color might be nice to make it extra sexy, look at the colorama package to do it easily cross platform.
评论 #5027300 未加载
nnqover 12 years ago
It even has a good sense of humor:<p><pre><code> $ howdoi kill someone ps aux </code></pre> ...yeah, first I must find out if "he"'s alive and how can I find "him", so it's a good first step :)<p><pre><code> $ howdoi clean up blood stains No, you cannot achieve that with PHP [...] </code></pre> ...indeed, PHP has never been my fav language :)
评论 #5030885 未加载
alexkusover 12 years ago
Excellent, I can give it to a friend who seems to use me (via Skype) as a proxy for StackOverflow.<p>He hasn't got the hint with lmgtfy links so I'll try a different tack...
cllnsover 12 years ago
Very cool! You might want to change<p>USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17"<p>to something a little more honest though, unless you have a good reason for keeping it.
评论 #5027655 未加载
darkarmaniover 12 years ago
It took a minute to realize that it requires an internet connection. Maybe you should spell that out?<p>I thought at first you had compiled a corpus of knowledge, but this is much better, but with the requirement of internet access.
评论 #5029550 未加载
评论 #5027494 未加载
coldpieover 12 years ago
Be nice if you'd make it explicit that it depends on Python 2 (change your hashbang to point to python2, or make it work in either runtime). Arch Linux defaults to Python 3 these days.
评论 #5029525 未加载
评论 #5027490 未加载
andrewljohnsonover 12 years ago
This is pretty cool, but it doesn't really feel a need for me.<p>Google for _split string javascript_ or the other queries, and you'll get basically the same results, just not limited to StackOverflow as howdoi does.<p>Maybe if I were more married to my command line this would be useful, but in general, I'm only there for bash and git. I spend most of my time in an editor, so popping over to the browser is no more work for me than showing the terminal.
评论 #5028511 未加载
评论 #5029926 未加载
roryokaneover 12 years ago
A similar program is `cheat`, from <a href="http://cheat.errtheblog.com/" rel="nofollow">http://cheat.errtheblog.com/</a>. Like howdoi, it prints short help on various topics to the commandline. But rather than searching Stack Overflow, it accesses a much smaller online wiki of cheat sheets. I’d give some examples of cheat sheets it has, but the online wiki seems to be down right now.
评论 #5027739 未加载
travisbyover 12 years ago
This is awesome! I'm going to create some issues (and hopefully pull requests!) later with some feature ideas.<p>I'm thinking seeing the question, and listing all questions so I know which -pX I want ;)
评论 #5027838 未加载
评论 #5031189 未加载
madethemcryover 12 years ago
I can`t use tools like this nor other local knowledge databases like evernote (although I save programming notes in evernote). If I have a pending question I ask myself two questions.<p><i>"Have I ever had this problem ?" "Did I save the answer ? (In evernote or whatever)"</i><p>To think about those two answers I need around 2000ms. After 1000ms I wrote the query and asked google again... Is it only me? I wish I would use my local knowledge database but I only use it when I`m not lucky with google after the first queries.
评论 #5027637 未加载
Hawkeeover 12 years ago
I think the code here is a very good example to get started with Python. It includes some very essential elements for interacting with external websites.
评论 #5028714 未加载
tathagatadgover 12 years ago
Whoa! I was just doing the same thing but with stackoverflow's api and in vim ... instead of making the query from the command line i.e. leave your editor, I'm thinking of writing the query like a comment and highlight it so that I can see the returned search results in a separate buffer. Haven't made much progress due to unfamiliarity with programming vim
评论 #5027711 未加载
lightyrsover 12 years ago
This is amazing. Thank you so very much!<p>I was very impressed by responses to queries like this:<p><pre><code> howdoi retrieve the keys from an array of hashes in ruby hash = {"apple" =&#62; "fruit", "carrot" =&#62; "vegetable"} array = hash.keys #=&#62; ["apple", "carrot"]</code></pre>
firesofmayover 12 years ago
Would be nice if it caches 2-3 answers so it doesn't have to call each time. Also if I could specify like -p123 it shows me first three answers instead of only first and I have to make a new call till I find my answer. Really useful. Thanks for sharing.
评论 #5031836 未加载
kwang88over 12 years ago
Looks like an awesome tool for the little things that nobody bothers to memorize -- very cool!
评论 #5027149 未加载
nigglerover 12 years ago
Is there a way to "contribute answers"? I think a hookup with a wiki-type system would make this useful and essentially replace the text file of commands I discovered.
评论 #5027447 未加载
thidermanover 12 years ago
I enjoy this, since it's a very clever and well executed idea. Cheers!<p>However, something bugs me a little; Is there any reason for not mentioning Stack Overflow in the README?
mtravenover 12 years ago
Very nice. I like the -l feature but wish the link could appear with the normal answer, doesn't seem to be a way to do that.
crazydiamondover 12 years ago
btw, on my system the `brew install` failed giving an error about "make the appropriate changes to your system". When I tried installing pyquery I realized it requires sudo access to write to /Library. I was able to install using "sudo python setup.py install". (pip gave a stack trace).<p>Tried "howdoi split string zsh" and it gave me a good answer.
评论 #5030919 未加载
slajaxover 12 years ago
Can't seem to get it installed either via brew, pip or python setup.py install on osx 10.8.2<p>Bummer. It looks really cool.
评论 #5029784 未加载
cpaover 12 years ago
Would be cool if one could directly call howdoi from the python shell.<p>&#62;&#62;&#62; howdoi foo bar<p>Or as a magic function for ipython.
hughdbrownover 12 years ago
Classic Stackoverflow moment:<p>howdoi -a parse HTML with regex
udfalksoover 12 years ago
Very nice, I'm going to use this. Thanks!
SonicSoulover 12 years ago
this is incredible! thanks so much for creating this. now i just need to figure out how to port it to Alfred :)
nerdfilesover 12 years ago
Brilliant. Given the data set, this appears somewhat intelligent, since more theoretical computer science problems may simply result in something like "advice" rather than code blocks.<p>$ howdoi mvp pattern<p>$ howdoi wittgenstein<p>$ howdoi hopfield network<p>$ howdoi feed forward network<p>$ howdoi artificial heart<p>It's like an overly precocious child that got trapped in a library, and is now set to aid you in your research/development.
评论 #5028166 未加载
评论 #5027392 未加载