9 ms·
Howdoi – Instant Coding Answers via the Command Line
- kwang88 14y agoLooks like an awesome tool for the little things that nobody bothers to memorize -- very cool!
- udfalkso 14y agoVery nice, I'm going to use this. Thanks!
- roryokane 14y agoAccording to the source code (https://github.com/gleitz/howdoi/blob/master/howdoi/howdoi.py https://github.com/gleitz/howdoi/blob/master/howdoi/howdoi.p...), 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.
- gleitz 14y agoPrecisely! You can pass the "-a" flag to print the entire answer or "-l" to get the link itself. "-p2" will give the second answer. I find myself using the following command quite a bit: open `howdoi print stack trace python -l`
- pests 14y ago-p2 gives the second search result's answer, not the second answer from the first result. Or so it seems from other replies.
- gleitz 14y agoAlthough not user facing, there is also a DuckDuckGo search endpoint if you don't want to use Google for one reason or another.
- kanzure 14y agoIt should probably use symbolhound.com instead, which does exact symbol queries on stackoverflow content. Google, alas, thinks we are all terrible people for wanting our precious bytes.
- gleitz 14y agoThat's a nice search tool. I found that the relevance is not quite as good as Google (for example "howdoi get referrer url php") but this could be used when you enter a query that contains symbols.
- lambda 14y agoThat is exactly what I would have guessed. It's basically "I'm feeling lucky" for coding questions.
- nerdfiles 14y agoBrilliant. 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. $ howdoi mvp pattern $ howdoi wittgenstein $ howdoi hopfield network $ howdoi feed forward network $ howdoi artificial heart It's like an overly precocious child that got trapped in a library, and is now set to aid you in your research/development.
- gleitz 14y ago"howdoi wittgenstein" is the search of the day. Well done!
- nerdfiles 14y agoI'm sure there's tons of academic literature riddled with ad hoc <code> block usage and strange deviations from standard markup. This thing is great.
- mtraven 14y ago$ howdoi turing $ howdoi solve the halting problem $ howdoi find the holy grail I could do this all day.
- spencerb 14y agoThanks for sharing, very useful in the few sample queries that I ran
- davej 14y agoSuper useful, love it. Some queries I tried (results were not perfect but pretty decent): 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 <?php session_start(); if (!isset($_SESSION["origURL"])) $_SESSION["origURL"] = $_SERVER["HTTP_REFERER"]; ?>
- gleitz 14y agoAn enhancement I've been considering is noticing when users ask for a second or third answer with "-p2" or "-p3". If it happens often and the user never queries again after reading the second answer you can assume it is probably correct and display it to all users as the default response.
- nicpottier 14y agoThat's not a bad idea, kind of meta level answer tracking. What about making it even easier by just prompting as to whether it answered their question? (perhaps defaulting to 'y' so you can just hit enter if so)
- davej 14y agoThat sounds smart but it also means that you'd need to keep track of and store user actions centrally. I don't know if I'd like that. You could always make it an opt-in feature I suppose.
- nicpottier 14y agoAlso.. don't you think the more common case is not that the top answer is incorrect but rather you picked the wrong question from the search results? Seems to me that would be more common.
- cllns 14y agoVery cool! You might want to change 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" to something a little more honest though, unless you have a good reason for keeping it.
- tluyben2 14y agoHe scrapes from Google right? Google doesn't like automated queries so it makes sense.
- nicpottier 14y agoI really like the idea of this, I'm getting some good results and some not so good. One that fails rather badly: format dates django templates Returns simply "date", despite StackOverflow having lots of hits: http://stackoverflow.com/search?q=format+dates+django+templates http://stackoverflow.com/search?q=format+dates+django+templa... But some others are super cool: create datetime from epoch >>> datetime.datetime.fromtimestamp(1284286794) One suggestion is that by default I would include the link to the stackoverflow page. Some color might be nice to make it extra sexy, look at the colorama package to do it easily cross platform.
- gleitz 14y agoThanks for playing with it. Sometimes the first answer isn't the greatest but -p2 or -p3 will get it. In this case the following command gets you closer: howdoi format dates django templates -p3 Excellent idea for colorization! I've already got that suggestion on the github page -> https://github.com/gleitz/howdoi/issues/4 https://github.com/gleitz/howdoi/issues/4
- niggler 14y agoIs 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.
- gleitz 14y agoNo way to currently contribute answers. Another commenter mentioned cheat.errtheblog.com that uses a wiki system. The downside is that when the wiki fails (like right now) the application breaks. You may want to just submit a good answer to StackOverflow and make sure it is well written and gets lots of votes.
- roryokane 14y agoA similar program is `cheat`, from http://cheat.errtheblog.com/ http://cheat.errtheblog.com/. 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.
- robertskmiles 14y agoHuh, I wrote a little tool to keep track of my own command line snippets ages ago, also called `cheat`. I guess that's the natural name for it.
- tathagatadg 14y agoWhoa! 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
- ajanuary 14y agoIt was my understanding it's easy to run a terminal command from vim.
- jgeralnik 14y agoYes, it's just :r!howdoi python regex :r! executes a command and inserts its standard output below the cursor
- tathagatadg 14y agoCool! ... that solves it! One less unfinished side project
- coldpie 14y agoBe 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.
- gleitz 14y agoI'm not familiar with the proper way to annotate that. How would I change the hashbang? #!/usr/bin/env python
- coldpie 14y agoI'm not an expert, but I believe just s/python/python2/. Also put it in the documentation as a requirement. Edit: Hee hee [aeikum@aeikum howdoi]$ howdoi use python2 on default python3 /usr/bin/env python2.7
- gleitz 14y agoMy worry is that not everyone will have python2.7 so I'd rather stick to "#!/usr/bin/env python". It would be great if this works but it doesn't #!/usr/bin/env python2
- geofft 14y agoIsn't that an Arch bug? Last I heard, there was consensus in the upstream Python community that /usr/bin/python should not be Python 3, which makes sense because Python 3 is deliberately incompatible with Python 2. Of course, that viewpoint might have changed. But still, even if upstream disagrees, I think it is the responsibility of the packagers not to break ABI compatibility in this way (just as they wouldn't ship OpenSSL 1.0 as libopenssl0.9.8.so). I'm pretty sure every script that uses Python 3 uses python3 in the shebang.
- coldpie 14y agoYou're talking about PEP 394[1]. It suggests that "python" point to either "python2" or "python3", depending on what ships with the distro by default or on the distro's stated goals. Arch tries to be as cutting edge as possible, even putting out new kernels within weeks after their release. It makes sense for Arch to begin pushing the boundaries here. There was a discussion on the arch-dev-public mailing list[2] recently that you might be interested in. In any case, I think it's clearly beneficial for every new Python application to make their version requirements explicit in the hashbang. [1] http://www.python.org/dev/peps/pep-0394/ http://www.python.org/dev/peps/pep-0394/ [2] https://mailman.archlinux.org/pipermail/arch-dev-public/2012-September/023558.html https://mailman.archlinux.org/pipermail/arch-dev-public/2012...
- darkarmani 14y agoIt took a minute to realize that it requires an internet connection. Maybe you should spell that out? I thought at first you had compiled a corpus of knowledge, but this is much better, but with the requirement of internet access.
- gleitz 14y agoDoes SO provide data dumps like Wikipedia?
- ygra 14y agoThey did monthly or bi-monthly data dumps. Not sure whether they still do. A few gibibytes of zipped XML would be a bit hard to ship, though :P
- ajanuary 14y agoYou could allow people to download a tag for offline use. Would be more data to store though.
- yread 14y agoYes, but the last I could find is from 2011 http://blog.stackexchange.com/category/cc-wiki-dump/ http://blog.stackexchange.com/category/cc-wiki-dump/
- a3_nm 14y agoAugust 2012 : http://www.clearbits.net/creators/146-stack-exchange-data-dump http://www.clearbits.net/creators/146-stack-exchange-data-du...
- sheckel 14y agoIt looks like they are trying to make the dumps available on S3: http://meta.stackoverflow.com/questions/158050/regular-stack-exchange-data-dumps http://meta.stackoverflow.com/questions/158050/regular-stack... They also have odata endpoints so you should be able to get at the data (updated weekly) that way. It looks like there is a problem with it at the moment, though (I get 'server error'): http://data.stackexchange.com/stackoverflow/atom http://data.stackexchange.com/stackoverflow/atom
- madethemcry 14y agoI 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. "Have I ever had this problem ?" "Did I save the answer ? (In evernote or whatever)" 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.
- dirkk0 14y agohttps://twitter.com/dirkk/status/255941043189583872 https://twitter.com/dirkk/status/255941043189583872 What I meant with that - post your solution not locally but somewhere useful (Stackoverflow?). You'll do yourself a favor and others can benefit from that.
- madethemcry 14y agoGreat tweet! :) Maybe it`s my fear of finding my own post on stackoverflow. Anyway I`ll try to follow your advice. I have a bad ratio giving back knowledge to the community- mostly due to my even worse time management.
- travisby 14y agoThis is awesome! I'm going to create some issues (and hopefully pull requests!) later with some feature ideas. I'm thinking seeing the question, and listing all questions so I know which -pX I want ;)
- decktech 14y ago$ howdoi program 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'll figure it out one of these days.
- tom68 14y agoreset your password using iForgot
- mtraven 14y agoVery 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.
- andrewljohnson 14y agoThis is pretty cool, but it doesn't really feel a need for me. 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. 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.
- bnegreve 14y ago> so popping over to the browser is no more work for me than showing the terminal. But parsing a web page to find an precise answer usually takes a while.
- notJim 14y agoI think the appeal of this for me would be that it feels less flow breaking to use my command-line (all work things) than using the browser (mix of work things and distractions.)
- alexkus 14y agoExcellent, I can give it to a friend who seems to use me (via Skype) as a proxy for StackOverflow. He hasn't got the hint with lmgtfy links so I'll try a different tack...
- Hawkee 14y agoI 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.
- gleitz 14y agoThanks!
- lightyrs 14y agoThis is amazing. Thank you so very much! I was very impressed by responses to queries like this: howdoi retrieve the keys from an array of hashes in ruby hash = {"apple" => "fruit", "carrot" => "vegetable"} array = hash.keys #=> ["apple", "carrot"]
- slajax 14y agoCan't seem to get it installed either via brew, pip or python setup.py install on osx 10.8.2 Bummer. It looks really cool.
- junkblocker 14y agoInstalls just fine here on OSX 10.8.2 % uname -a Darwin xxx 12.2.1 Darwin Kernel Version 12.2.1: Thu Oct 18 16:32:48 PDT 2012; root:xnu-2050.20.9~2/RELEASE_X86_64 x86_64 % sudo pip install howdoi Password: Downloading/unpacking howdoi Downloading howdoi-0.2.tar.gz Running setup.py egg_info for package howdoi Requirement already satisfied (use --upgrade to upgrade): pyquery in /Library/Python/2.7/site-packages (from howdoi) Requirement already satisfied (use --upgrade to upgrade): lxml>=2.1 in /Library/Python/2.7/site-packages (from pyquery->howdoi) Requirement already satisfied (use --upgrade to upgrade): cssselect in /Library/Python/2.7/site-packages (from pyquery->howdoi) Installing collected packages: howdoi Running setup.py install for howdoi Installing howdoi script to /usr/local/bin Successfully installed howdoi Cleaning up... Maybe file a bug with what happens when you try?
- slajax 14y agoIt works now. Had to run: sudo chmod -R go+w /Library/Python/2.7/site-packages/ which is noted at the bottom of the readme and I missed it.
- SonicSoul 14y agothis is incredible! thanks so much for creating this. now i just need to figure out how to port it to Alfred :)
- crazydiamond 14y agobtw, 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). Tried "howdoi split string zsh" and it gave me a good answer.
- a2i 14y agoThanks for the tip, I was just figuring out what changes I should make, when run into your post.
- nnq 14y agoIt even has a good sense of humor: $ howdoi kill someone ps aux ...yeah, first I must find out if "he"'s alive and how can I find "him", so it's a good first step :) $ howdoi clean up blood stains No, you cannot achieve that with PHP [...] ...indeed, PHP has never been my fav language :)
- thiderman 14y agoI enjoy this, since it's a very clever and well executed idea. Cheers! However, something bugs me a little; Is there any reason for not mentioning Stack Overflow in the README?
- cpa 14y agoWould be cool if one could directly call howdoi from the python shell. >>> howdoi foo bar Or as a magic function for ipython.
- firesofmay 14y agoWould 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.
- gleitz 14y agoNice suggestions! We've got a whole list going on at https://github.com/gleitz/howdoi/issues https://github.com/gleitz/howdoi/issues
- hughdbrown 14y agoClassic Stackoverflow moment: howdoi -a parse HTML with regex