cheat.sh icon indicating copy to clipboard operation
cheat.sh copied to clipboard

[Suggestion] Add Rosettacode as source

Open lf-araujo opened this issue 5 years ago • 8 comments

Rosettacode.org has content that is in line with your app's structure, perhaps this can be added as a repository in the future too?

lf-araujo avatar Oct 11 '18 19:10 lf-araujo

@lf-araujo We are already working on it, and it will be available soon! (I am really happy to see this your feature request)

chubin avatar Oct 11 '18 19:10 chubin

@lf-araujo We have added initial support of Rosetta-Code. To access an example from rosetta code:

$ curl cht.sh/python/rosetta/Sorting-algorithms-Merge-sort
from heapq import merge

def merge_sort(m):
    if len(m) <= 1:
        return m

    middle = len(m) // 2
    left = m[:middle]
    right = m[middle:]

    left = merge_sort(left)
    right = merge_sort(right)
    return list(merge(left, right))

Other examples (if there are several examples of one algorithm) can be accessed with additional number (e.g. /2) at the end.

To get a list of the algorithms:

curl cht.sh/python/rosetta/:list

It works very well with fzf:

curl cht.sh/js/rosetta/$(curl -ks cht.sh/js/rosetta/:list | fzf)

fzf support as well as roseta code support will be integrated soon in the console client cht.sh.

Could you please take a look? Does it work as it should? What could be added from your point of view?

chubin avatar Feb 07 '19 22:02 chubin

Sorry for the late reply.

Thank you for this improvement, it seems feature complete to me. Ready, perhaps, to release. I can't, however, access Nim language examples with this, using:

curl cht.sh/Nim/rosetta/$(curl -ks cht.sh/Nim/rosetta/:list | fzf)

But I am sure is something I am doing wrong.

lf-araujo avatar Mar 23 '19 18:03 lf-araujo

@lf-araujo Hi!

Thank you for the answer. The problem is that Rosetta Code supports much more languages, then cheat.sh (currently). At the moment we have support only for 57 languages, and Rosetta Code covers more than 100 (and Nim is one of the languages that is covered by Rosetta Code but not by cheat.sh).

I think we should extend coverage, and add all languages from Rosetta Code (at least the ones that can be supported).

chubin avatar Mar 23 '19 18:03 chubin

Shouldn't this issue be closed?

I have been using this successfully for some time now:

image

Best, luis

P.S.: Any news on that pesky Nim support?

lf-araujo avatar Jul 02 '19 12:07 lf-araujo

@lf-araujo Yes, it works somehow, I know, but it is just an initial support, it does not yet work as it should. There are basically three features that are not still implemented:

  1. Text on the pages is thrown away completely, and it should stay there (at least when it was not said explicitly to do it) but be commented out (as it is being done for the StackOverflow answers);
  2. There should be some search mode/aliases mode for the Rosetta Code pages, because the page names are not really to everybody;
  3. Updates should be real-time or semi real-time at least, currently they happen quite seldom.

Nim support was added, sorry for the delay. It was not hard to add, but I've just forgotten about it. Thank you very much for reminding me

$ curl cht.sh/nim/:learn | less -R

$ curl cht.sh/nim/rosetta/Substring
import strutils

let
  s = "abcdefgh"
  n = 2
  m = 3
  c = 'd'
  cs = "cd"
var i = 0

# starting from n=2 characters in and m=3 in length
echo s[n-1 .. n+m-2]

# starting from n characters in, up to the end of the string
echo s[n-1 .. s.high]

# whole string minus last character:
echo s[0 .. <s.high]

# starting from a known character c='d'within the string and of m length
i = s.find(c)
echo s[i .. <i+m]

# starting from a known substring cs="cd" within the string and of m length
i = s.find(cs)
echo s[i .. <i+m]

$ curl cht.sh/nim/enumerate+list
# Nim enumerate function like Python
# 
# I'm a newbie with nim, and I'm not really sure what you want, but...
# If you use two variables in a for statement, you will get the index
# and the value:

for x, y in [11,22,33]:
  echo x, " ", y

# Gives:

0 11
1 22
2 33

# HTH.
# 
# [aMike] [so/q/48120733] [cc by-sa 3.0]

Could you please check that everything works as you expected?

PS. What do you thank about binding of nim-by-example (https://nim-by-example.github.io) to cheat.sh via the cheat.sh adapters mechanism?

chubin avatar Jul 06 '19 19:07 chubin

Ok, thank you very much!

I tested your Nim implementation in a current project and it looks like it is flawless.

PS. What do you thank about binding of nim-by-example (https://nim-by-example.github.io) to cheat.sh via the cheat.sh adapters mechanism?

This would be excellent, however I cannot help out on this (again) due to requirements of my job for the following months. I pinged people over Nim's IRC channel for visibility.

Thank you again.

lf-araujo avatar Jul 08 '19 12:07 lf-araujo

@lf-araujo Sure, it is not a problem! I just wanted to hear your opinion on it. As soon as nim-by-example is bound to cheat.sh, I will ping you

chubin avatar Jul 23 '19 22:07 chubin