Download:
child 1:794840b6d903
0:65366ba5ac77
Anton Shestakov <engored@ya.ru>, Sun, 14 Sep 2014 13:54:37 +0900
Cheating automated.

5 файлов изменено, 342 вставок(+), 0 удалений(-) [+]
Makefile file | annotate | diff | comparison | revisions
html2png.py file | annotate | diff | comparison | revisions
rst2cheatsheet.py file | annotate | diff | comparison | revisions
source.rst file | annotate | diff | comparison | revisions
template.html file | annotate | diff | comparison | revisions
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile Sun Sep 14 13:54:37 2014 +0900
@@ -0,0 +1,7 @@
+all: html png
+
+html:
+ ./rst2cheatsheet.py source.rst > cheatsheet.html
+
+png:
+ ./html2png.py "file://$(realpath cheatsheet.html)" wallcheat.png
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/html2png.py Sun Sep 14 13:54:37 2014 +0900
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+import sys
+
+import glib
+import gtk
+import webkit
+
+
+class SimpleBrowser(object):
+ # http://kmandla.wordpress.com/2010/05/24/the-1-2kb-python-browser-script/
+ # taken from there and adapted to be stupid and take screenshots
+ def __init__(self, url, output_filename):
+ self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
+ self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS)
+ self.window.connect('delete_event', self.close_application)
+ screen = self.window.get_screen()
+ self.webview = webkit.WebView()
+ self.webview.set_size_request(screen.get_width(), screen.get_height())
+ self.window.add(self.webview)
+ self.window.set_title('%s' % url)
+ self.window.show_all()
+ self.webview.connect(
+ 'document-load-finished', self.screenshot, output_filename)
+ self.webview.open(url)
+
+ @staticmethod
+ def screenshot(webview, frame, output_filename):
+ def callback():
+ width, height = webview.window.get_size()
+ pb = gtk.gdk.Pixbuf('rgb', False, 8, width, height)
+ cm = gtk.gdk.colormap_get_system()
+ pb.get_from_drawable(webview.window, cm, 0, 0, 0, 0, width, height)
+ pb.save(output_filename, 'png')
+ gtk.main_quit()
+ glib.timeout_add_seconds(1, callback) # delay until rendering finishes
+
+ def close_application(self, widget, event, data=None):
+ gtk.main_quit()
+
+
+if __name__ == '__main__':
+ if len(sys.argv) == 3:
+ gtk.gdk.threads_init()
+ SimpleBrowser(sys.argv[1], sys.argv[2])
+ gtk.main()
+ else:
+ print 'usage:', sys.argv[0], 'INPUT OUTPUT'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/rst2cheatsheet.py Sun Sep 14 13:54:37 2014 +0900
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+from sys import argv
+
+from docutils.core import publish_parts
+from docutils.writers import html4css1
+
+
+class CheatsheetWriter(html4css1.Writer):
+ def __init__(self):
+ html4css1.Writer.__init__(self)
+ self.translator_class = CheatsheetTranslator
+
+
+class CheatsheetTranslator(html4css1.HTMLTranslator):
+ def visit_section(self, node):
+ if not self.section_level:
+ self.body.append(self.starttag(node, 'div', CLASS='uk-float-left uk-margin-large-right uk-margin-bottom'))
+ self.section_level += 1
+
+ def depart_section(self, node):
+ self.section_level -= 1
+ if not self.section_level:
+ self.body.append('</div>')
+
+ def visit_title(self, node):
+ if self.section_level == 1:
+ self.body.append('<!--h1>')
+ else:
+ self.body.append(self.starttag(node, 'h2', ''))
+
+ def depart_title(self, node):
+ if self.section_level == 1:
+ self.body.append('</h1-->\n')
+ else:
+ self.body.append('</h2>\n')
+
+ def visit_literal(self, node):
+ self.body.append(self.starttag(node, 'code', ''))
+
+ def visit_title_reference(self, node):
+ self.body.append(self.starttag(node, 'kbd', ''))
+
+ def depart_title_reference(self, node):
+ self.body.append('</kbd>')
+
+ def visit_definition_list(self, node):
+ self.body.append(self.starttag(node, 'table', CLASS='table-cheats uk-text-left'))
+ self.body.append('\n')
+
+ def depart_definition_list(self, node):
+ self.body.append('</table>\n')
+
+ def visit_definition_list_item(self, node):
+ self.body.append(self.starttag(node, 'tr', ''))
+
+ def depart_definition_list_item(self, node):
+ self.body.append('</tr>\n')
+
+ def visit_term(self, node):
+ self.body.append(self.starttag(node, 'td', ''))
+
+ def depart_term(self, node):
+ self.body.append('</td>')
+
+ def visit_definition(self, node):
+ self.body.append(self.starttag(node, 'td', ''))
+
+ def depart_definition(self, node):
+ self.body.append('</td>')
+
+
+source_path = argv[1]
+with open(source_path, 'r') as sf:
+ source = sf.read()
+
+parts = publish_parts(source=source, source_path=source_path, writer=CheatsheetWriter())
+
+with open('template.html', 'r') as tf:
+ template = tf.read()
+
+print template.replace('{{ content }}', parts['fragment']).encode('utf-8')
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/source.rst Sun Sep 14 13:54:37 2014 +0900
@@ -0,0 +1,161 @@
+Column 1
+========
+
+
+Moving
+------
+
+`{` `}`
+ beginning of *previous*, *next* paragraph
+
+`(` `)`
+ beginning of *previous*, *next* sentence
+
+`0` `gm`
+ *beginning*, *middle* of line
+
+`^` `$`
+ *first*, *last* character of line
+
+`ngg` `nG`
+ line n, default the *first*, *last*
+
+`n%`
+ percentage n of the file
+
+`n|`
+ column n of current line
+
+`%`
+ match of next brace, bracket, comment, #define
+
+`nH` `nL`
+ line n from *start*, *bottom* of window
+
+`M`
+ middle line of window
+
+
+Editing
+-------
+
+`i` `a`
+ insert *before*, *after* cursor
+
+`I` `A`
+ insert at *beginning*, *end* of line
+
+`gI`
+ insert text in first column
+
+`o` `O`
+ open a new line *below*, *above* the current line
+
+`cc` `S`
+ change current line
+
+`C`
+ change to the end of line
+
+`gum` `gUm`
+ *lowercase*, *uppercase* text of movement m
+
+
+Copying
+-------
+
+`yy` `Y`
+ yank current line into register
+
+`p` `P`
+ put register *after*, *before* cursor position
+
+`]p` `[p`
+ like `p`, `P` with indent adjusted
+
+`gp` `gP`
+ like `p`, `P` leaving cursor after new text
+
+
+Column 2
+========
+
+
+VIM Regex
+---------
+
+``*``
+ 0 or more
+
+``\+``
+ 1 or more
+
+``\=``
+ 0 or 1
+
+``\{n,m}``
+ from n to m
+
+``\{n}``
+ exactly n
+
+``\{n,}``
+ at least n
+
+``\{,m}``
+ at most m
+
+``\{-}``
+ non-greedy ``*``
+
+``\{-n,m}``
+ non-greedy ``\{n,m}``
+
+``\{-n,}``
+ non-greedy ``\{n,}``
+
+``\{-,m}``
+ non-greedy ``\{,m}``
+
+
+Column 3
+========
+
+
+re Extensions
+-------------
+
+``(?iLmsux)``
+ the group matches the empty string; the letters set the corresponding flags
+
+``(?:...)``
+ a non-capturing version of regular parentheses
+
+``(?P<name>...)``
+ the substring matched by the group is accessible via the symbolic group
+ name
+
+``(?P=name)``
+ matches whatever text was matched by the earlier named group named
+ (backreference)
+
+``(?#...)``
+ the contents of the parentheses are simply ignored
+
+``(?=...)``
+ matches next, but doesn't consume any of the string (lookahead assertion)
+
+``(?!...)``
+ negative lookahead assertion
+
+``(?<=...)``
+ matches a preceding string (lookbehind assertion)
+
+``(?<!...)``
+ negative lookbehind assertion, patterns which start with it may match at
+ the beginning of the string being searched
+
+.. break the list
+
+``(?(id/name)yes-pattern|no-pattern)``
+ magic. ``(<)?(\w+@\w+(?:\.\w+)+)(?(1)>)``
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/template.html Sun Sep 14 13:54:37 2014 +0900
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title></title>
+ <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/uikit/2.9.0/css/uikit.min.css">
+ <style>
+ html {
+ font-size: 10pt;
+ margin-top: 30px;
+ }
+ body {
+ background: #1c1c1c;
+ color: white;
+ }
+ h1, h2, h3, h4, h5, h6 {
+ color: #5f5f5f;
+ }
+ .table-cheats {
+ color: #afaf87;
+ }
+ .table-cheats td:first-child {
+ padding-right: 10px;
+ vertical-align: top;
+ }
+ kbd, code {
+ font-weight: bold;
+ }
+ kbd {
+ color: #d7005f;
+ }
+ code {
+ color: #87ff00;
+ }
+ em {
+ color: #e97c02;
+ }
+ </style>
+ </head>
+ <body>
+ <div class="uk-margin-large-top uk-margin-large-right uk-margin-large-bottom uk-margin-large-left">
+{{ content }}
+ </div>
+ </body>
+</html>