From 5a48992cb0e12fb9f3873a6d06e82f9c2899a55e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Fri, 4 Oct 2019 14:33:19 +0200 Subject: [PATCH] Small fixes --- README.md | 50 +++++++++++++++++++------------------- index.html | 64 ++++++++++++++++++++++++------------------------- parse.js | 34 +++++++++++++++++++------- web/script_2.js | 15 +++++++++++- 4 files changed, 95 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 8e2005b..80935aa 100644 --- a/README.md +++ b/README.md @@ -401,40 +401,40 @@ Format ### General Options ```python -{:<10} # ' ' -{:^10} # ' ' -{:>10} # ' ' +{:<10} # ' ' +{:^10} # ' ' +{:>10} # ' ' ``` ```python -{:.<10} # '......' -{:<0} # '' +{:.<10} # '......' +{:<0} # '' ``` ### Strings **`'!r'` calls object's repr() method, instead of str(), to get a string.** ```python -{'abcde'!r:<10} # "'abcde' " -{'abcde':.3} # 'abc' -{'abcde':10.3} # 'abc ' +{'abcde'!r:<10} # "'abcde' " +{'abcde':.3} # 'abc' +{'abcde':10.3} # 'abc ' ``` ### Numbers ```python -{ 123456:10,} # ' 123,456' -{ 123456:10_} # ' 123_456' -{ 123456:+10} # ' +123456' -{-123456:=10} # '- 123456' -{ 123456: } # ' 123456' -{-123456: } # '-123456' +{ 123456:10,} # ' 123,456' +{ 123456:10_} # ' 123_456' +{ 123456:+10} # ' +123456' +{-123456:=10} # '- 123456' +{ 123456: } # ' 123456' +{-123456: } # '-123456' ``` ### Floats ```python -{1.23456:10.3} # ' 1.23' -{1.23456:10.3f} # ' 1.235' -{1.23456:10.3e} # ' 1.235e+00' -{1.23456:10.3%} # ' 123.456%' +{1.23456:10.3} # ' 1.23' +{1.23456:10.3f} # ' 1.235' +{1.23456:10.3e} # ' 1.235e+00' +{1.23456:10.3%} # ' 123.456%' ``` #### Comparison of float presentation types: @@ -469,9 +469,9 @@ Format ### Ints ```python -{90:c} # 'Z' -{90:X} # '5A' -{90:b} # '1011010' +{90:c} # 'Z' +{90:X} # '5A' +{90:b} # '1011010' ``` @@ -1499,7 +1499,7 @@ Open = open('', mode='r', encoding=None, newline=None) ``` * **`'encoding=None'` means default encoding is used, which is platform dependent. Best practice is to use `'encoding="utf-8"'` whenever possible.** -* **`'newline=None'` means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to the system's default line separator.** +* **`'newline=None'` means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to system's default line separator.** * **`'newline=""'` means no conversions take place, but input is still broken into chunks by readline() and readlines() on either '\n', '\r' or '\r\n'.** ### Modes @@ -1800,13 +1800,13 @@ SQLite **Server-less database engine that stores each database into separate file.** ### Connect +**Opens a connection to the database file. Creates a new file if path doesn't exist.** ```python import sqlite3 db = sqlite3.connect('') # Also ':memory:'. ... db.close() ``` -* **New database will be created if path doesn't exist.** ### Read **Returned values can be of type str, int, float, bytes or None.** @@ -1963,12 +1963,12 @@ Memory View = memoryview() = [] # Returns an int or a float. = [] # Mview with rearranged elements. - = .cast('') # Casts a memoryview to a new format. + = .cast('') # Casts memoryview to the new format. .release() # Releases the object's memory buffer. ``` ```python -.write() # Writes mview to a binary file. +.write() # Appends mview to the binary file. = bytes() # Creates a new bytes object. = .join() # Joins mviews using bytes object as sep. = list() # Returns list of ints or floats. diff --git a/index.html b/index.html index 66efced..638ee86 100644 --- a/index.html +++ b/index.html @@ -496,32 +496,32 @@ to_exclusive = <range>.stop '187' -

General Options

{<el>:<10}                    # '<el>      '
-{<el>:^10}                    # '   <el>   '
-{<el>:>10}                    # '      <el>'
+

General Options

{<el>:<10}                                     # '<el>      '
+{<el>:^10}                                     # '   <el>   '
+{<el>:>10}                                     # '      <el>'
 
-
{<el>:.<10}                   # '<el>......'
-{<el>:<0}                     # '<el>'
+
{<el>:.<10}                                    # '<el>......'
+{<el>:<0}                                      # '<el>'
 
-

Strings

'!r' calls object's repr() method, instead of str(), to get a string.

{'abcde'!r:<10}               # "'abcde'   "
-{'abcde':.3}                  # 'abc'
-{'abcde':10.3}                # 'abc       '
+

Strings

'!r' calls object's repr() method, instead of str(), to get a string.

{'abcde'!r:<10}                                # "'abcde'   "
+{'abcde':.3}                                   # 'abc'
+{'abcde':10.3}                                 # 'abc       '
 
-

Numbers

{ 123456:10,}                 # '   123,456'
-{ 123456:10_}                 # '   123_456'
-{ 123456:+10}                 # '   +123456'
-{-123456:=10}                 # '-   123456'
-{ 123456: }                   # ' 123456'
-{-123456: }                   # '-123456'
+

Numbers

{ 123456:10,}                                  # '   123,456'
+{ 123456:10_}                                  # '   123_456'
+{ 123456:+10}                                  # '   +123456'
+{-123456:=10}                                  # '-   123456'
+{ 123456: }                                    # ' 123456'
+{-123456: }                                    # '-123456'
 
-

Floats

{1.23456:10.3}                # '      1.23'
-{1.23456:10.3f}               # '     1.235'
-{1.23456:10.3e}               # ' 1.235e+00'
-{1.23456:10.3%}               # '  123.456%'
+

Floats

{1.23456:10.3}                                 # '      1.23'
+{1.23456:10.3f}                                # '     1.235'
+{1.23456:10.3e}                                # ' 1.235e+00'
+{1.23456:10.3%}                                # '  123.456%'
 

Comparison of float presentation types:

+----------------+----------------+---------------+----------------+-----------------+
@@ -551,9 +551,9 @@ to_exclusive   = <range>.stop
 |  567.89        |   '5.7e+02'    |    '567.89'   |   '5.68e+02'   |   '56789.00%'   |
 +----------------+----------------+---------------+----------------+-----------------+
 
-

Ints

{90:c}                        # 'Z'
-{90:X}                        # '5A'
-{90:b}                        # '1011010'
+

Ints

{90:c}                                # 'Z'
+{90:X}                                # '5A'
+{90:b}                                # '1011010'
 

#Numbers

Types

<int>      = int(<float/str/bool>)    # Or: math.floor(<float>)
@@ -1337,7 +1337,7 @@ LogicOp = Enum('LogicOp', {pass
 
-

#Print

print(<el_1>, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
+

#Print

print(<el_1>, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
 
    @@ -1387,7 +1387,7 @@ value = args.<name>
    • 'encoding=None' means default encoding is used, which is platform dependent. Best practice is to use 'encoding="utf-8"' whenever possible.
    • -
    • 'newline=None' means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to the system's default line separator.
    • +
    • 'newline=None' means all different end of line combinations are converted to '\n' on read, while on write all '\n' characters are converted to system's default line separator.
    • 'newline=""' means no conversions take place, but input is still broken into chunks by readline() and readlines() on either '\n', '\r' or '\r\n'.

    Modes

      @@ -1605,7 +1605,7 @@ shutil.copytree(from, to) # Copies the enti writer.writerows(rows)
-

#SQLite

Server-less database engine that stores each database into separate file.

Connect

import sqlite3
+

#SQLite

Server-less database engine that stores each database into separate file.

Connect

Opens a connection to the database file. Creates a new file if path doesn't exist.

import sqlite3
 db = sqlite3.connect('<path>')                  # Also ':memory:'.
 ...
 db.close()
@@ -1613,9 +1613,7 @@ db.close()
 
 
 
-
    -
  • New database will be created if path doesn't exist.
  • -
+

Read

Returned values can be of type str, int, float, bytes or None.

<cursor> = db.execute('<query>')                # Can raise sqlite3.OperationalError.
 <tuple>  = <cursor>.fetchone()                  # Returns next row. Also next(<cursor>).
 <list>   = <cursor>.fetchall()                  # Returns remaining rows.
@@ -1702,21 +1700,21 @@ db = connector.connect(host=<str>, user=<str>, password=<str>,
 (1, 2, 3)
 
-

Format

For standard sizes start format string with:

    +

    Format

    For standard sizes start format string with:

    • '=' - native byte order
    • '<' - little-endian
    • '>' - big-endian
    • -

    Integer types. Use capital letter for unsigned type. Standard sizes are in brackets:

      +

    Integer types. Use capital letter for unsigned type. Standard sizes are in brackets:

    • 'x' - pad byte
    • 'b' - char (1)
    • 'h' - short (2)
    • 'i' - int (4)
    • 'l' - long (4)
    • 'q' - long long (8)
    • -

    Floating point types:

      +

    Floating point types:

    • 'f' - float (4)
    • 'd' - double (8)
    • -
+
@@ -1737,12 +1735,12 @@ db = connector.connect(host=<str>, user=<str>, password=<str>,
<mview> = memoryview(<bytes/bytearray/array>)
 <num>   = <mview>[<index>]                     # Returns an int or a float.
 <mview> = <mview>[<slice>]                     # Mview with rearranged elements.
-<mview> = <mview>.cast('<typecode>')           # Casts a memoryview to a new format.
+<mview> = <mview>.cast('<typecode>')           # Casts memoryview to the new format.
 <mview>.release()                              # Releases the object's memory buffer.
 
-
<bin_file>.write(<mview>)                      # Writes mview to a binary file.
+
<bin_file>.write(<mview>)                      # Appends mview to the binary file.
 <bytes> = bytes(<mview>)                       # Creates a new bytes object.
 <bytes> = <bytes>.join(<coll_of_mviews>)       # Joins mviews using bytes object as sep.
 <list>  = list(<mview>)                        # Returns list of ints or floats.
diff --git a/parse.js b/parse.js
index 8cee01c..1f7da29 100755
--- a/parse.js
+++ b/parse.js
@@ -309,8 +309,9 @@ function highlightCode() {
   fixClasses();
   fixHighlights();
   preventPageBreaks();
-  fixPageBreaks();
-  // insertPageBreak();
+  fixPageBreaksFile();
+  fixPageBreaksStruct();
+  insertPageBreaks();
 }
 
 function setApaches(elements) {
@@ -346,16 +347,31 @@ function preventPageBreaks() {
   });
 }
 
-function fixPageBreaks() {
-  const fileDiv = $('#file').parent()
+function fixPageBreaksFile() {
   const modesDiv = $('#file').parent().parent().parent()
-  modesDiv.after(fileDiv)
-  const exceptDiv = $('#exceptions-1').parent()
-  modesDiv.after(exceptDiv)
+  move(modesDiv, 'file')
+  move(modesDiv, 'exceptions-1')
 }
 
-function insertPageBreak() {
-  $('
').insertBefore($('#libraries').parent()) +function fixPageBreaksStruct() { + const formatDiv = $('#floatingpointtypes').parent().parent().parent().parent() + move(formatDiv, 'floatingpointtypes') + move(formatDiv, 'integertypesusecapitalletterforunsignedtypestandardsizesareinbrackets') + move(formatDiv, 'forstandardsizesstartformatstringwith') +} + +function move(anchor_el, el_id) { + const el = $('#'+el_id).parent() + anchor_el.after(el) +} + +function insertPageBreaks() { + // insertPageBreakBefore('#libraries') + insertPageBreakBefore('#print') +} + +function insertPageBreakBefore(an_id) { + $('
').insertBefore($(an_id).parent()) } function readFile(filename) { diff --git a/web/script_2.js b/web/script_2.js index 00fcafd..ab9da5e 100644 --- a/web/script_2.js +++ b/web/script_2.js @@ -118,6 +118,19 @@ const DIAGRAM_7_B = '┃ count() │ │ │ │ ✓ ┃\n' + '┗━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┷━━━━━━━━━━━━━━┛\n'; +const DIAGRAM_7_C = + '┏━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━┯━━━━━━━━━━━━━━┓\n' + + '┃ │ Iterable │ Collection │ Sequence │ abc.Sequence ┃\n' + + '┠────────────┼────────────┼────────────┼────────────┼──────────────┨\n' + + '┃ iter() │ ! │ ! │ ✓ │ ✓ ┃\n' + + '┃ contains() │ ✓ │ ✓ │ ✓ │ ✓ ┃\n' + + '┃ len() │ │ ! │ ! │ ! ┃\n' + + '┃ getitem() │ │ │ ! │ ! ┃\n' + + '┃ reversed() │ │ │ ✓ │ ✓ ┃\n' + + '┃ index() │ │ │ │ ✓ ┃\n' + + '┃ count() │ │ │ │ ✓ ┃\n' + + '┗━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━┷━━━━━━━━━━━━━━┛\n'; + const DIAGRAM_8_A = 'BaseException\n' + ' +-- SystemExit'; @@ -203,7 +216,7 @@ if (isFontAvailable('Menlo')) { $(`code:contains(${DIAGRAM_4_A})`).html(DIAGRAM_4_B); $(`code:contains(${DIAGRAM_5_A})`).html(DIAGRAM_5_B); $(`code:contains(${DIAGRAM_6_A})`).html(DIAGRAM_6_B); - $(`code:contains(${DIAGRAM_7_A})`).html(DIAGRAM_7_B); + $(`code:contains(${DIAGRAM_7_A})`).html(DIAGRAM_7_C); $(`code:contains(${DIAGRAM_8_A})`).html(DIAGRAM_8_B); $(`code:contains(${DIAGRAM_9_A})`).html(DIAGRAM_9_B); $(`code:contains(${DIAGRAM_10_A})`).html(DIAGRAM_10_B);