diff --git a/README.md b/README.md index ddccaa5..139d9dc 100644 --- a/README.md +++ b/README.md @@ -201,20 +201,22 @@ Some languages has the one-liners-cheat sheet, `1line`: * `:list` shows all topics related to the language * `:learn` shows a learn-x-in-minutes language cheat sheet perfect for getting started with the language. * `1line` is a collection of one-liners in this language +* `weirdness` is a collection of examples of weird things in this language ![cheat.sh usage](http://cheat.sh/files/supported-languages.png) -At the moment, cheat.sh covers the 7 following programming languages (alphabetically sorted): +At the moment, cheat.sh covers the 8 following programming languages (alphabetically sorted): -|Prefix |Language|Basics|One-liners| -|-----------|--------|------|----------| -|`go/` |Go |✓ | | -|`lua/` |Lua |✓ | | -|`perl/` |Perl |✓ |✓ | -|`php/` |PHP |✓ | | -|`python/` |Python |✓ | | -|`rust/` |Rust |✓ | | -|`scala/` |Scala |✓ | | +|Prefix |Language |Basics|One-liners|Weirdness| +|-----------|----------|------|----------|---------| +|`go/` |Go |✓ | | | +|`js/` |JavaScript|✓ |✓ |✓ | +|`lua/` |Lua |✓ | | | +|`perl/` |Perl |✓ |✓ | | +|`php/` |PHP |✓ | | | +|`python/` |Python |✓ | | | +|`rust/` |Rust |✓ | | | +|`scala/` |Scala |✓ | | | ## Cheat sheets sources diff --git a/lib/adapter_learnxiny.py b/lib/adapter_learnxiny.py index d234e01..317807d 100644 --- a/lib/adapter_learnxiny.py +++ b/lib/adapter_learnxiny.py @@ -121,28 +121,39 @@ class LearnLuaAdapter(LearnXYAdapter): answer = answer[:1] return answer -class LearnPHPAdapter(LearnXYAdapter): - _prefix = "php" - _filename = "php.html.markdown" +class LearnJavaScriptAdapter(LearnXYAdapter): + _prefix = "js" + _filename = "javascript.html.markdown" def _is_block_separator(self, before, now, after): - if (re.match(r'/\*\*\*\*\*+', before) - and re.match(r'\s*\*/', after) - and re.match(r'\s*\*\s*', now)): - block_name = re.sub(r'\s*\*\s*', '', now) - block_name = re.sub(r'&', '', block_name) - block_name = '_'.join(block_name.strip().split()) + if ( re.match('//////+', before) + and re.match('//+\s+[0-9]+\.', now) + and re.match('\s*', after)): + block_name = re.sub('//+\s+[0-9]+\.\s*', '', now) + block_name = '_'.join(block_name.strip(", ").split()) + replace_with = { + 'More_about_Objects': + 'Prototypes', + } + for k in replace_with: + if k in block_name: + block_name = replace_with[k] return block_name else: return None @staticmethod def _cut_block(block): - return block[2:] + answer = block[2:-1] + if answer[0].split() == '': + answer = answer[1:] + if answer[-1].split() == '': + answer = answer[:1] + return answer -class LearnPythonAdapter(LearnXYAdapter): - _prefix = "python" - _filename = "python.html.markdown" +class LearnKotlinAdapter(LearnXYAdapter): + _prefix = "kotlin" + _filename = "kotlin.html.markdown" def _is_block_separator(self, before, now, after): if (re.match('#######+', before) @@ -198,15 +209,84 @@ class LearnPerlAdapter(LearnXYAdapter): answer = answer[:1] return answer +class LearnPHPAdapter(LearnXYAdapter): + _prefix = "php" + _filename = "php.html.markdown" + + def _is_block_separator(self, before, now, after): + if (re.match(r'/\*\*\*\*\*+', before) + and re.match(r'\s*\*/', after) + and re.match(r'\s*\*\s*', now)): + block_name = re.sub(r'\s*\*\s*', '', now) + block_name = re.sub(r'&', '', block_name) + block_name = '_'.join(block_name.strip().split()) + return block_name + else: + return None + + @staticmethod + def _cut_block(block): + return block[2:] + +class LearnPythonAdapter(LearnXYAdapter): + _prefix = "python" + _filename = "python.html.markdown" + + def _is_block_separator(self, before, now, after): + if (re.match('#######+', before) + and re.match('#######+', after) + and re.match('#+\s+[0-9]+\.', now)): + block_name = re.sub('#+\s+[0-9]+\.\s*', '', now) + block_name = '_'.join(block_name.strip().split()) + return block_name + else: + return None + + @staticmethod + def _cut_block(block): + answer = block[2:-1] + if answer[0].split() == '': + answer = answer[1:] + if answer[-1].split() == '': + answer = answer[:1] + return answer + +class LearnRubyAdapter(LearnXYAdapter): + _prefix = "ruby" + _filename = "ruby.html.markdown" + + def _is_block_separator(self, before, now, after): + if (re.match('#######+', before) + and re.match('#######+', after) + and re.match('#+\s+[0-9]+\.', now)): + block_name = re.sub('#+\s+[0-9]+\.\s*', '', now) + block_name = '_'.join(block_name.strip().split()) + return block_name + else: + return None + + @staticmethod + def _cut_block(block): + answer = block[2:-1] + if answer[0].split() == '': + answer = answer[1:] + if answer[-1].split() == '': + answer = answer[:1] + return answer + + # # Exported functions # ADAPTERS = { + 'js' : LearnJavaScriptAdapter(), + 'kotlin' : LearnKotlinAdapter(), 'lua' : LearnLuaAdapter(), 'python' : LearnPythonAdapter(), 'php' : LearnPHPAdapter(), 'perl' : LearnPerlAdapter(), + 'ruby' : LearnRubyAdapter(), } def get_learnxiny(topic): diff --git a/lib/cheat_wrapper.py b/lib/cheat_wrapper.py index b3937ee..2e21c5a 100644 --- a/lib/cheat_wrapper.py +++ b/lib/cheat_wrapper.py @@ -11,6 +11,7 @@ import glob import re import random import string +import collections from fuzzywuzzy import process, fuzz @@ -35,17 +36,19 @@ from buttons import TWITTER_BUTTON, GITHUB_BUTTON, GITHUB_BUTTON_2, GITHUB_BUTTO from adapter_learnxiny import get_learnxiny, get_learnxiny_list, is_valid_learnxy # globals -INTERNAL_TOPICS = [":list", ":firstpage", ':post', ':bash_completion', ':help', ':styles', ':styles-demo', ':emacs', ':fish', ':bash', ':zsh'] +INTERNAL_TOPICS = [":list", ":firstpage", ':post', ':bash_completion', ':help', ':styles', ':styles-demo', ':emacs', ':emacs-ivy', ':fish', ':bash', ':zsh'] LEXER = { - "go" : pygments.lexers.GoLexer, "elixir": pygments.lexers.ElixirLexer, + "go" : pygments.lexers.GoLexer, "js" : pygments.lexers.JavascriptLexer, + "kotlin": pygments.lexers.KotlinLexer, "lua" : pygments.lexers.LuaLexer, - "scala" : pygments.lexers.ScalaLexer, - "rust" : pygments.lexers.RustLexer, "perl" : pygments.lexers.PerlLexer, "python": pygments.lexers.PythonLexer, "php" : pygments.lexers.PhpLexer, + "ruby" : pygments.lexers.RubyLexer, + "rust" : pygments.lexers.RustLexer, + "scala" : pygments.lexers.ScalaLexer, } REDIS = redis.StrictRedis(host='localhost', port=6379, db=0) @@ -132,6 +135,16 @@ def get_topics_list(skip_dirs=False, skip_internal=False): def get_topics_dirs(): return set([x.split('/', 1)[0] for x in get_topics_list() if '/' in x]) + +def get_stat(): + stat = collections.Counter([ + get_topic_type(topic) for topic in get_topics_list() + ]) + + answer = "" + for k,v in stat.items(): + answer += "%s %s\n" % (k,v) + return answer # # # @@ -177,6 +190,9 @@ def get_internal(topic): if topic == ':styles': return "\n".join(COLOR_STYLES) + "\n" + if topic == ":stat": + return get_stat()+"\n" + if topic in INTERNAL_TOPICS: return open(os.path.join(MYDIR, "share", topic[1:]+".txt"), "r").read() diff --git a/share/firstpage.txt b/share/firstpage.txt index a7295db..153518c 100644 --- a/share/firstpage.txt +++ b/share/firstpage.txt @@ -11,10 +11,11 @@ d88' `"Y8 888P"Y88b d88' `88b `P )88b 888 d88( "8 888P"Y88b * the fastest way to find | you need * provides access to community driven cheat sheets repositories - * delivers <783> cheat sheets in <8> areas and growing + * delivers <822> cheat sheets in <9> areas and growing * covers UNIX/Linux commands and programming languages * programming languages cheat sheets are under: - + + * supports bash completion (add {/:bash_completion} to your {~/.bashrc})