chubin / cheat.sh

the only cheat sheet you need
https://cheat.sh/
MIT License
38.47k stars 1.8k forks source link

GNU Octave support. #121

Open sentientmachine opened 5 years ago

sentientmachine commented 5 years ago

Love your cht tool, many of your daily api calls you receive over the last 3 months are from me.

I've been writing some GNU Octave code recently and the closest language you have is matlab. Octave is a popular alternative to the proprietary matlab and Andrew NG uses it for his machine learning coursera class.

I can search cht.sh for matlab, and sometimes I get something useful, but it's not as good as others like Java or whatever.

Are you going to add it or is there a way I can build it for you so that it just works for octave? Octave is a much more popular language than many of the esoteric and "joke style languages" you do support.

chubin commented 5 years ago

It is possible to add support for GNU Octave.

I have several questions from my side:

  1. Is the difference between Matlab and GNU Octave so big? Should we use a separate namespace for GNU Octave or should be redirect Octave related calls to Matlab?

  2. What question type from the following standard (2 of them are not yet published) should be supported for GNU Octave?

  1. Is it a good idea to integrate cheat.sh into GNU Octave shell, so it would be possible to make cheat queries without leaving the GNU Octave shell at all? Soon we will publish a python module (with additional ipython support), that allows to make queries like that in ipython:
    
    %how to reverse a list
    ``
sentientmachine commented 5 years ago

Is the difference between Matlab and GNU Octave so big?

I guess not, Octave seems to be an extension and open source evolution of the propitiatory Matlab. Matlab code will more or less run in Octave without substantial changes, but not the other way around.

Some notable differences:

  1. GNU Octave supports the use of both single and double quotes wheras MATLAB only supports single quotes.
  2. Octave supports C-style i++; ++i; i+=1; etc. wheras MatLab does not.
  3. MATLAB always requires triple dot ... for line continuation wheras octave does not require it.

And many more: https://en.wikibooks.org/wiki/MATLAB_Programming/Differences_between_Octave_and_MATLAB

Should we use a separate namespace for GNU Octave or should be redirect Octave related calls to Matlab?

The core itch behind this issue is I'm hacking away on octave code in vim and I press my keystroke to send a query to cheat.sh and your service comes back with this:

%{ 
 { What is the exact value of NaN in matlab? 
 {  
 { According to Mathwork's documentation 
 { (http://www.mathworks.com.au/help/matlab/ref/nan.html), NaN returns 
 { the IEEE arithmetic representation for Not-a-Number.  NaN is always in 
 { floating point representation (float or double) - I don't believe 
 { there is an integer NaN. 
 {  
 { In IEEE 754, NaN's are represented as floating point numbers with all 
 { the exponent bits set to 1 and the fractional part any non-zero value 
 { (so there are actually many ways of representing a general NaN).  See 
 { "Special Values" here 
 { (http://steve.hollasch.net/cgindex/coding/ieeefloat.html). 
 {  
 { The most reliable way to test for NaN by hand is not to look for a 
 { specific value but to test that all the exponent bits are set and the 
 { fractional part is non-zero. 
 {  
 { [Brian L] [so/q/13813195] [cc by-sa 3.0] 
 %} 

That stackoverflow post has 'matlab' as a tag. The information about nan is correct for matlab and also to some extent for Octave, but the manual links are all under the umbrella of matlab. Matlab doesn't like Octave and so the two turfs don't share.

I was hoping for information and links about the open source links and stuff related to octave since I have no intention of ever paying for matlab.

What question type from the following standard (2 of them are not yet published) should be supported for GNU Octave?

What keeps me coming back to your server for queries is that 8 times in 10 your code finds a very relevant StackOverflow post and does it in 2.5 seconds rather than me having to move my hand to the mouse and navigate around a browser, wasting 8 to 15 seconds to do the same thing. I'm only interested in typing "nan" to cheat.sh and getting something where the comments and code are written by octave developers, not matlab.

Is it a good idea to integrate cheat.sh into GNU Octave shell, so it would be possible to make cheat queries without leaving the GNU Octave shell at all?

I don't care about inside gnu octave shell since that's too limited. I do the work in the editor which caches cht hits. see: https://gist.github.com/sentientmachine/e09ea2ffa50bfb6444fdd18deda07053

And a gif: http://www.filedropper.com/chtgetoctaveexample

I think the user should be able to choose which stackoverflow tags your software searches for. It shouldn't be hard to change, just clone the matlab portion, and wherever it says matlab, just swap for octave and then I get answers under an octave umbrella, or not, from octave, and if that's not good enough, I can use matlab.

sentientmachine commented 5 years ago

I just noticed partial redirect support for GNU Octave now, thanks.

Now I do: http://cht.sh/octave/reverse a list

And I get a relevant response from stackoverflow which is better than an not found error. Your stackoverflow search filterer still uses the matlab tag to filter the octave query though.

Is there a way I can tell your code which stackoverflow tag to filter by? Your StackOverflow searcher seems hardcoded to the language. What I want is for your code to do exactly what it does, except use a one of the stackoverflow tags that I want responses from:

https://stackoverflow.com/questions/tagged/octave

and not this tag:

https://stackoverflow.com/questions/tagged/matlab

One partial workaround is to put the word in the query like this: http://cht.sh/octave/octave reverse a list which will bias your searcher to look for the word.

Your code that scans stackoverflow and returns answers that have correct functional code in them is the MVP of this tool, because it:

  1. Lets me keep my fingers on home row when I'm doing a web search. Not demolishing my programming context.
  2. Bypass ads and nonsense that browser websearch tool presents to me, since their angle is to make money selling my eyeball to 3rd parties.

If I could send some flags into your code that scrapes the stackoverflow API, that would be super cool. Or better yet, do you have the code that scrapes Stackoverflow available to fork?

chubin commented 5 years ago

I am working on it, but it is not so easy, as it seems. Do you have a couple of filters that you want to apply? If you want, we can create an experimental subspace (on the server side), where we could experiment with the feature

sentientmachine commented 5 years ago

As for which filters I'd like to apply: The answer is: "The set of all possible filters", you can offload all that to a JSON string or an SQL statement like this:

https://data.stackexchange.com/stackoverflow/query/886/posts-with-many-thank-you-answers

select ParentId as [Post Link], count(id)  
from posts where posttypeid = 2 and len(body) <= 200
and (body like '%hank%') group by parentid having count(id) > 1
order by count(id) desc;

Click 'fork query' at the above link to edit and play around with it. I'd like to do this programatically, but not have to deal with authentication to hit stackoverflow.

https://data.stackexchange.com/stackoverflow/query/fork/886

What I want is this:

cht.sh/octave/suppress+warnings

Except also:

  1. Force the stackoverflow answer from a question that has any given valid stackoverflow tag.
  2. The answer has correct runnable octave code in it, not just a boring wall of comments.
  3. Answer is written by a user with more than 2835 reputation.

I send you a string of SQL, and you return the first hit just like you do, or an error, or a ddos backoff message. You could even get away with monthly stackoverflow data dump, and your server does the filter locally to Stackoverflow isn't inconvenienced.

It's a lot of extra work on your end since you have to ddos stackoverflow, or else download a petabyte of data every month. So I'm just talking out loud.

chubin commented 5 years ago

I've added initial support for GNU/Octave:

The last feature (RosettaCode integration) is new, and not yet documented. To access RosettaCode solutions in Ocatve, use queries like that:

cht.sh/octave/rosetta/Vector-products

To get the full list of available RosettaCode solutions in Octave:

cht.sh/octave/rosetta/:list

Regarding your questions about StackExchange filters: theoretically it is possible, but not so easy. What we could do, we could combine our search engine with StackOverflow filters; i.e. say

  1. you make some query, like suppress warnings
  2. Some set of answers is found
  3. To the found set of answers we apply some additional filters (e.g. code is needed; reputation is more than XXX; etc.)
  4. If something is found (after application of the filter) the answer is returned.
  5. If nothing was found, some error message is returned.

Another option: return a list of possible answers with additional information in the output (i.e. reputation, tags, code lines), so that the user can pick the best answer on its own.