diff --git a/README.md b/README.md index 34b1a49..07d0715 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ flatter_list = list(itertools.chain.from_iterable()) product_of_elems = functools.reduce(lambda out, x: out * x, ) list_of_chars = list() ``` -* **Check out module [operator](#operator) for alternative versions of examples.** +* **Module [operator](#operator) provides functions itemgetter() and mul() that offer the same functionality as lambda expressions above.** ```python = .count() # Returns number of occurrences. Also works on strings. @@ -2294,7 +2294,8 @@ async def random_controller(id_, moves): await asyncio.sleep(random.random() / 2) async def human_controller(screen, moves): - while (ch := screen.getch()) != 27: + while True: + ch = screen.getch() key_mappings = {259: D.n, 261: D.e, 258: D.s, 260: D.w} if ch in key_mappings: moves.put_nowait(('*', key_mappings[ch])) diff --git a/index.html b/index.html index 5c88d97..cb59815 100644 --- a/index.html +++ b/index.html @@ -203,7 +203,7 @@ pre.prettyprint {
- +
@@ -250,7 +250,7 @@ product_of_elems = functools.reduce(lambda out list_of_chars = list(<str>)
    -
  • Check out module operator for alternative versions of examples.
  • +
  • Module operator provides functions itemgetter() and mul() that offer the same functionality as lambda expressions above.
<int> = <list>.count(<el>)     # Returns number of occurrences. Also works on strings.
 index = <list>.index(<el>)     # Returns index of first occurrence or raises ValueError.
@@ -1990,7 +1990,8 @@ D = enum.Enum('D', 'n
         await asyncio.sleep(random.random() / 2)
 
 async def human_controller(screen, moves):
-    while (ch := screen.getch()) != 27:
+    while True:
+        ch = screen.getch()
         key_mappings = {259: D.n, 261: D.e, 258: D.s, 260: D.w}
         if ch in key_mappings:
             moves.put_nowait(('*', key_mappings[ch]))
@@ -2721,7 +2722,7 @@ urlpatterns = [
  
 
   
 
diff --git a/parse.js b/parse.js
index ba4ea83..55fdaab 100755
--- a/parse.js
+++ b/parse.js
@@ -15,9 +15,6 @@ const showdown  = require('showdown');
 const hljs = require('highlightjs');
 
 
-const PDF_BUTTON =
-  '\n';
-
 const TOC =
   '
' + '

Contents

\n' + @@ -96,7 +93,6 @@ function getMd() { } function modifyPage() { - // addPdfButton() removeOrigToc(); addToc(); insertLinks(); @@ -104,11 +100,6 @@ function modifyPage() { highlightCode(); } -function addPdfButton() { - const nodes = $.parseHTML(PDF_BUTTON); - $('img').first().parent().before(nodes); -} - function removeOrigToc() { const headerContents = $('#contents'); const contentsList = headerContents.next(); diff --git a/web/Acrobat/DC/HeaderFooter/Chapter_1.xml b/pdf/Acrobat/Chapter_1.xml similarity index 100% rename from web/Acrobat/DC/HeaderFooter/Chapter_1.xml rename to pdf/Acrobat/Chapter_1.xml diff --git a/web/Acrobat/DC/HeaderFooter/bottom_line.xml b/pdf/Acrobat/bottom_line.xml similarity index 100% rename from web/Acrobat/DC/HeaderFooter/bottom_line.xml rename to pdf/Acrobat/bottom_line.xml diff --git a/web/Acrobat/DC/HeaderFooter/chapter_2.xml b/pdf/Acrobat/chapter_2.xml similarity index 100% rename from web/Acrobat/DC/HeaderFooter/chapter_2.xml rename to pdf/Acrobat/chapter_2.xml diff --git a/web/Acrobat/DC/HeaderFooter/chapter_3.xml b/pdf/Acrobat/chapter_3.xml similarity index 100% rename from web/Acrobat/DC/HeaderFooter/chapter_3.xml rename to pdf/Acrobat/chapter_3.xml diff --git a/web/Acrobat/DC/HeaderFooter/chapter_4.xml b/pdf/Acrobat/chapter_4.xml similarity index 100% rename from web/Acrobat/DC/HeaderFooter/chapter_4.xml rename to pdf/Acrobat/chapter_4.xml diff --git a/web/Acrobat/DC/HeaderFooter/chapter_5.xml b/pdf/Acrobat/chapter_5.xml similarity index 100% rename from web/Acrobat/DC/HeaderFooter/chapter_5.xml rename to pdf/Acrobat/chapter_5.xml diff --git a/web/Acrobat/DC/HeaderFooter/chapter_6.xml b/pdf/Acrobat/chapter_6.xml similarity index 100% rename from web/Acrobat/DC/HeaderFooter/chapter_6.xml rename to pdf/Acrobat/chapter_6.xml diff --git a/web/Acrobat/DC/HeaderFooter/chapter_7.xml b/pdf/Acrobat/chapter_7.xml similarity index 100% rename from web/Acrobat/DC/HeaderFooter/chapter_7.xml rename to pdf/Acrobat/chapter_7.xml diff --git a/web/Acrobat/DC/HeaderFooter/even_pages.xml b/pdf/Acrobat/even_pages.xml similarity index 100% rename from web/Acrobat/DC/HeaderFooter/even_pages.xml rename to pdf/Acrobat/even_pages.xml diff --git a/web/Acrobat/DC/HeaderFooter/odd_pages.xml b/pdf/Acrobat/odd_pages.xml similarity index 100% rename from web/Acrobat/DC/HeaderFooter/odd_pages.xml rename to pdf/Acrobat/odd_pages.xml diff --git a/web/create_index.py b/pdf/create_index.py similarity index 100% rename from web/create_index.py rename to pdf/create_index.py diff --git a/pdf/descripitive image_final-01.png b/pdf/descripitive image_final-01.png new file mode 100755 index 0000000..6841172 Binary files /dev/null and b/pdf/descripitive image_final-01.png differ diff --git a/web/descripitive image_final.png b/pdf/descripitive image_final.png similarity index 100% rename from web/descripitive image_final.png rename to pdf/descripitive image_final.png diff --git a/pdf/how_to_create_pdf.md b/pdf/how_to_create_pdf.md new file mode 100644 index 0000000..64f2d7d --- /dev/null +++ b/pdf/how_to_create_pdf.md @@ -0,0 +1,55 @@ +How To Create PDF (on macOS) +============================ +PDF file can also be purchased here: https://transactions.sendowl.com/products/78175486/4422834F/view + +Setup +----- +* Install Adobe Acrobat Pro DC. +* Copy headers and footers from `pdf/Adobe/` folder to `/Users//Library/Preferences/Adobe/Acrobat/DC/HeaderFooter/`. +* Change date in header and footer element of `web/template.html`. +* Run `./parse.js` and commit changes. + +Printing to PDF +--------------- +### Normal PDF +* Open `index.html` in text editor and first remove element `


` before the `

Libraries

`. +* Then replace the footer and last three `
` elements with contents of `pdf/index_for_pdf.html` file and save. +* Open `index.html` in Chrome and select 'Print...'. +* Select destination 'Save as PDF', paper size 'A4', margins and scale 'Default' and no headers and footers and save. + +### PDF optimized for laser color printing +* Run `./parse.js` again. +* Open `index.html` in text editor and first remove element `


` before the `

Libraries

`. +* Then replace the footer and last three `
` elements with contents of `pdf/index_for_pdf_print.html` file and save. +* Change all links in text to normal text. They can be found with this regex: `.*a href.*`. +* Open `index.html` in Chrome. +* Change brightness of elements by right clicking on them and selecting inspect. Then click on the rectangle that represents color and toggle the color space to HSLA by clicking on the button with two vertical arrows. +* Change lightness (L) percentage to: +* 0% for the text. +* 87% for the gray line on the left side of the code. +* 89% for the gray hash characters by the titles +* 37% for the red text and function names (they use their own red). +* 60% for the blue text and the text in the contents (it uses its own blue), but leave color of decorators and the `>>>` intact. +* 58% for the comments. +* Individually change brightness of every comment line that starts with: `# $ pip3 install + ...` and of comments in basic script template to 57%, by adding `color: hsla(0, 0%, 57%, 1);` to their element.style. +* Select 'Print...' and destination 'Save as PDF', paper size 'A4', margins and scale 'Default' and no headers and footers and save. + +Adding headers and footers to PDF (the same for both files) +----------------------------------------------------------- +* Open the PDF file in Adobe Acrobat Pro DC. +* Select 'Organize Pages' tab and remove last empty page. +* Right click on one of the pages and select 'Crop Pages...'. +* In 'Change page size' section select 'A4' for 'Page Sizes' set 'XOffset' to '0.1 in' and select page range All. +* Select 'Edit PDF' tab and add headers and footers by clicking 'Header & Footer' button, selecting a preset from 'Saved Settings' dropdown menu and clicking ok. Repeat the process for each preset. +* If presets get lost, the font and the margins are as follow: Borders: left-line: 0.6, left-text: 0.8, top-line: 11.4, bottom-text: 0.27, right-text-odd: 0.57, font-name: menlo, font-size: 8. +* Set title and author by selecting 'File/Propertiess...'. +* Save. + +Printing the PDF +---------------- +* Open a PDF that was optimized for printing in Chrome and print on A4 on both sides with default margins, scale 98% and no headers and footers. + + + + diff --git a/web/index_for_pdf.html b/pdf/index_for_pdf.html similarity index 99% rename from web/index_for_pdf.html rename to pdf/index_for_pdf.html index b41662f..baa8d36 100644 --- a/web/index_for_pdf.html +++ b/pdf/index_for_pdf.html @@ -1,4 +1,6 @@ +
+

#Index

diff --git a/web/index_for_pdf_print.html b/pdf/index_for_pdf_print.html similarity index 93% rename from web/index_for_pdf_print.html rename to pdf/index_for_pdf_print.html index 2d96707..e5e7024 100644 --- a/web/index_for_pdf_print.html +++ b/pdf/index_for_pdf_print.html @@ -1,8 +1,6 @@ - - - - +
+

#Index

diff --git a/web/button.png b/web/button.png deleted file mode 100755 index 53b0eeb..0000000 Binary files a/web/button.png and /dev/null differ diff --git a/web/external_link.png b/web/external_link.png deleted file mode 100644 index 4d5ee40..0000000 Binary files a/web/external_link.png and /dev/null differ diff --git a/web/index_tmp.txt b/web/index_tmp.txt deleted file mode 100644 index 29cb472..0000000 --- a/web/index_tmp.txt +++ /dev/null @@ -1,149 +0,0 @@ - -Index ------ -### A -**abstract base classes, [4](#abc), [19](#collectionsabcsequence)** -**all function, [11](#anyall)** -**animation, [39](#animation)** -**any function, [11](#anyall)** -**argparse module, [22](#argparse)** -**arguments, [10](#arguments)** -**arrays, [28](#array)** -**audio, [39](#audio)-[40](#writefloatsamplestowavfile)** - -### B -**basic script template, [41](#basicscripttemplate)** -**beautifulsoup4 library, [34](#scraping)** -**binary representation, [8](#binhex)** -**bitwise operators, [8](#bitwiseoperators)** -**bottle library, [35](#web)** -**bytes, [27](#bytes)-[28](#readbytesfromfile)** - -### C -**cache, [13](#lrucache)** -**csv module, [25](#csv), [33](#printsacsvfileasanasciitable)** -**callable, [17](#callable)** -**chars, [5](#char)** -**class, [14](#class)-[15](#property)** -**closure, [12](#closure)** -**collection, [18](#collection)** -**combinatorics, [8](#combinatorics)** -**command line arguments, [22](#commandlinearguments)** -**comprehension, [11](#comprehension)** -**context manager, [17](#contextmanager)** -**copy function, [15](#copy)** -**coroutine, [32](#coroutine)** -**curses module, [33](#curses)** - -### D -**dataclass decorator, [15](#dataclass)** -**datetime module, [8](#datetime)-9** -**decorator, [13](#decorator)** -**deques, [29](#deque)** -**dictionaries, [2](#dictionary)** -**duck types, [16](#ducktypes)-[19](#collectionsabcsequence)** - -### E -**enum module, [19](#enum)-[20](#inline-2)** -**enumerate function, [3](#enumerate)** -**eval function, [32](#eval)** -**exceptions, [20](#exceptions)-[21](#reraisingcaughtexception), [22](#exceptions-1)** - -### F -**files, [23](#file)** -**filter function, [11](#mapfilterreduce)** -**floats, [4](#abc), [6](#floats), [7](#types)** -**format function, [6](#format)-[7](#comparisonoffloatpresentationtypes)** -**futures, [30](#threadpool)** - -### G -**generator, [4](#generator)** - -### H -**hash function, [16](#hashable)** -**hexadecimal representation, [8](#binhex)** - -### I -**image, [38](#image)** -**inline, [11](#inline)-12** -**input function, [22](#input)** -**introspection, [30](#introspection)** -**ints, [4](#abc), [7](#types), [8](#binhex)** -**iterable, [18](#iterable)** -**iterator, [3](#iterator), [17](#iterator-1)** - -### J -**json module, [27](#json)** - -### L -**lambda, [11](#lambda)** -**list comprehension, [11](#comprehension)** -**lists, [1](#list)-2** -**locks, [29](#lock)** -**logging, [34](#logging)** -**lru_cache decorator, [13](#lrucache)** - -### M -**main function, [1](#main), [41](#basicscripttemplate)** -**map function, [11](#mapfilterreduce)** -**math module, [7](#math)** -**matplotlib library, [33](#plot)** -**memoryviews, [29](#memoryview)** -**metaprograming, [31](#metaprograming)** -**mysql library, [26](#mysql)** - -### N -**namedtuples, [3](#namedtuple)** -**nonlocal keyword, [12](#nonlocal)** -**numpy module, [36](#numpy)-[37](#indexing)** - -### O -**open function, [22](#open)-[23](#file)** -**operator module, [30](#operator)** -**OS commands, [24](#oscommands)** - -### P -**parameters, [10](#arguments)** -**partial function, [12](#partial)** -**paths, [23](#path)-24** -**pickle module, [27](#pickle)** -**PIL library, [38](#image)** -**plotting, [33](#plot)** -**print function, [21](#print)** -**profiling, [35](#profiling)-[36](#timingasnippet)** -**progress bar, [33](#progressbar)** - -### Q -**queues, [30](#queue)** - -### R -**random module, [8](#random)** -**ranges, [3](#range)** -**recursion, [13](#lrucache)** -**reduce function, [11](#mapfilterreduce)** -**regular expressions, [5](#regex)-[6](#specialsequences)** -**requests library, [34](#scraping), [35](#test)** - -### S -**sqlite3 module, [26](#sqlite)** -**scraping, [34](#scraping)** -**sequence, [18](#sequence), [19](#collectionsabcsequence)** -**sets, [2](#set)** -**shell commands, [24](#shellcommands)** -**sleep function, [33](#progressbar)** -**splat operator, [10](#splatoperator)-[11](#otheruses)** -**statistics module, [7](#statistics)** -**strings, [5](#string)** -**struct module, [28](#struct)** -**synthesizer, [40](#synthesizer)** - -### T -**table, [33](#table)** -**threading module, [29](#threading)-[30](#threadpool)** -**time module, [33](#progressbar), [35](#stopwatch)** -**tqdm library, [33](#progressbar)** -**tuples, [3](#tuple)** -**type, [4](#type), [31](#type-1)** - -### W -**web, [35](#web)** diff --git a/web/mario_bros.png b/web/mario_bros.png index 41051b3..d583f0e 100644 Binary files a/web/mario_bros.png and b/web/mario_bros.png differ diff --git a/web/script.js b/web/script.js deleted file mode 100644 index e43c385..0000000 --- a/web/script.js +++ /dev/null @@ -1,65 +0,0 @@ -$(document).ready(function() { - parseMd(); -}); - -function parseMd() { - var GITHUB = - "https://raw.githubusercontent.com/gto76/python-cheatsheet/master/README.md"; - jQuery.get(GITHUB, function(text) { - var converter = new showdown.Converter(); - html = converter.makeHtml(text); - aDiv = $("#main_container"); - nodes = $.parseHTML(html); - aDiv.after(nodes); - removeOrigToc(); - addToc(); - insertLinks(); - unindentBanner(); - d3.selectAll("code").each(function() { - hljs.highlightBlock(this); - }); - }); -} - -function removeOrigToc() { - headerContents = $("#contents"); - contentsList = headerContents.next(); - headerContents.remove(); - contentsList.remove(); -} - -function insertLinks() { - $("h2").each(function() { - aId = $(this).attr("id"); - text = $(this).text(); - $(this).html('#' + text); - }); -} - -function unindentBanner() { - let montyImg = $("img").first(); - montyImg.parent().addClass("banner"); - let downloadPraragrapth = $("p").first(); - downloadPraragrapth.addClass("banner"); -} - -function addToc() { - headerMain = $("#main"); - nodes = $.parseHTML(TOC); - headerMain.before(nodes); -} - -var TOC = - "
" + - '

Contents

\n' + - '
ToC = {\n' +
-  '    \'1. Collections\': [List, Dict, Set, Range, Enumerate, Namedtuple, Iterator, Generator],\n' +
-  '    \'2. Types\':       [Type, String, Regex, Format, Numbers, Combinatorics, Datetimeᴺᴱᵂ],\n' +
-  '    \'3. Syntax\':      [Arguments, Splat, Inline, Closure, Decorator, Class, Enum, Exceptions],\n' +
-  '    \'4. System\':      [Print, Input, Command_Line_Arguments, Open, Pathᴺᴱᵂ, Command_Execution],\n' +
-  '    \'5. Data\':        [CSV, JSON, Pickle, SQLite, Bytes, Struct, Array, MemoryView, Deque],\n' +
-  '    \'6. Advanced\':    [Threading, Introspection, Metaprograming, Operator, Eval, Coroutine],\n' +
-  '    \'7. Libraries\':   [Progress_Bar, Plot, Table, Curses, Loggingᴺᴱᵂ, Scraping, Web, Profile,\n' +
-  '                       NumPy, Image, Audio]\n' +
-  "}\n" +
-  "
\n"; diff --git a/web/sprite.png b/web/sprite.png deleted file mode 100644 index 54ec2fe..0000000 Binary files a/web/sprite.png and /dev/null differ diff --git a/web/template.html b/web/template.html index 5d8af37..628573d 100644 --- a/web/template.html +++ b/web/template.html @@ -203,7 +203,7 @@ pre.prettyprint {
- +
@@ -211,7 +211,7 @@ pre.prettyprint {