Browse Source

Created the pdf dir and cleaned the web dir

pull/52/head
Jure Šorn 4 years ago
parent
commit
6358d27b56
23 changed files with 63 additions and 231 deletions
  1. 4
      index.html
  2. 9
      parse.js
  3. 0
      pdf/Acrobat/Chapter_1.xml
  4. 0
      pdf/Acrobat/bottom_line.xml
  5. 0
      pdf/Acrobat/chapter_2.xml
  6. 0
      pdf/Acrobat/chapter_3.xml
  7. 0
      pdf/Acrobat/chapter_4.xml
  8. 0
      pdf/Acrobat/chapter_5.xml
  9. 0
      pdf/Acrobat/chapter_6.xml
  10. 0
      pdf/Acrobat/chapter_7.xml
  11. 0
      pdf/Acrobat/even_pages.xml
  12. 0
      pdf/Acrobat/odd_pages.xml
  13. 0
      pdf/create_index.py
  14. BIN
      pdf/descripitive image_final-01.png
  15. 0
      pdf/descripitive image_final.png
  16. 55
      pdf/how_to_create_pdf.md
  17. 2
      pdf/index_for_pdf.html
  18. 6
      pdf/index_for_pdf_print.html
  19. BIN
      web/button.png
  20. BIN
      web/external_link.png
  21. 149
      web/index_tmp.txt
  22. 65
      web/script.js
  23. 4
      web/template.html

4
index.html

@ -203,7 +203,7 @@ pre.prettyprint {
<body>
<header>
<aside>December 15, 2019</aside>
<aside>March 7, 2020</aside>
<a href="../" rel="author">Jure Šorn</a>
</header>
@ -2507,7 +2507,7 @@ simpleaudio.play_buffer(samples_b, <span class="hljs-number">1</span>, <span cla
<footer>
<aside>December 15, 2019</aside>
<aside>March 7, 2020</aside>
<a href="../" rel="author">Jure Šorn</a>
</footer>

9
parse.js

@ -15,9 +15,6 @@ const showdown = require('showdown');
const hljs = require('highlightjs');
const PDF_BUTTON =
'<a href="https://transactions.sendowl.com/products/78175486/4422834F/view" rel="nofollow"><img src="web/button.png" style="max-width: none; min-width: 0;"/></a>\n';
const TOC =
'<br>' +
'<h2 id="toc">Contents</h2>\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();

web/Acrobat/DC/HeaderFooter/Chapter_1.xml → pdf/Acrobat/Chapter_1.xml

web/Acrobat/DC/HeaderFooter/bottom_line.xml → pdf/Acrobat/bottom_line.xml

web/Acrobat/DC/HeaderFooter/chapter_2.xml → pdf/Acrobat/chapter_2.xml

web/Acrobat/DC/HeaderFooter/chapter_3.xml → pdf/Acrobat/chapter_3.xml

web/Acrobat/DC/HeaderFooter/chapter_4.xml → pdf/Acrobat/chapter_4.xml

web/Acrobat/DC/HeaderFooter/chapter_5.xml → pdf/Acrobat/chapter_5.xml

web/Acrobat/DC/HeaderFooter/chapter_6.xml → pdf/Acrobat/chapter_6.xml

web/Acrobat/DC/HeaderFooter/chapter_7.xml → pdf/Acrobat/chapter_7.xml

web/Acrobat/DC/HeaderFooter/even_pages.xml → pdf/Acrobat/even_pages.xml

web/Acrobat/DC/HeaderFooter/odd_pages.xml → pdf/Acrobat/odd_pages.xml

web/create_index.py → pdf/create_index.py

BIN
pdf/descripitive image_final-01.png

Before After
Width: 2517  |  Height: 625  |  Size: 167 KiB

web/descripitive image_final.png → pdf/descripitive image_final.png

55
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 'web/Adobe/' folder to '/Users/<username>/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 '<p><br></p>' before the '<h1>Libraries</h1>'.
* Then replace the footer and last three '<br>' elements with contents of 'web/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 '<p><br></p>' before the '<h1>Libraries</h1>'.
* Then replace the footer and last three '<br>' elements with contents of 'web/index_for_pdf_print.html' file and save.
* Change all links in text to normal text. They can be found with this regex: '<strong>.*a href.*</strong>'.
* 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.

web/index_for_pdf.html → pdf/index_for_pdf.html

@ -1,4 +1,6 @@
<div class="pagebreak"></div>
<br>
<div class="pagebreak"></div>
<h2 id="index"><a href="#index" name="index">#</a>Index</h2>

web/index_for_pdf_print.html → pdf/index_for_pdf_print.html

@ -1,8 +1,6 @@
<!-- Brightnesses: sideline: 87, hash_symbol: 89, red: 37, blue: 60, comments: 58, pip_install_comments: 57 / scale-when-saving: 100%, scale-when-printing: 98% -->
<!-- Change page size: fixed sizes: A4, XOffset: 0.1 in-->
<!-- 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 -->
<div class="pagebreak"></div>
<br>
<div class="pagebreak"></div>
<h2 id="index"><a href="#index" name="index">#</a>Index</h2>

BIN
web/button.png

Before After
Width: 170  |  Height: 36  |  Size: 2.4 KiB

BIN
web/external_link.png

Before After
Width: 512  |  Height: 512  |  Size: 3.3 KiB

149
web/index_tmp.txt

@ -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)**

65
web/script.js

@ -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('<a href="#' + aId + '" name="' + aId + '">#</a>' + 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 =
"<br>" +
'<h2 id="toc">Contents</h2>\n' +
'<pre><code class="hljs bash"><strong>ToC</strong> = {\n' +
' <strong><span class="hljs-string">\'1. Collections\'</span></strong>: [<a href="#list">List</a>, <a href="#dictionary">Dict</a>, <a href="#set">Set</a>, <a href="#range">Range</a>, <a href="#enumerate">Enumerate</a>, <a href="#namedtuple">Namedtuple</a>, <a href="#iterator">Iterator</a>, <a href="#generator">Generator</a>],\n' +
' <strong><span class="hljs-string">\'2. Types\'</span></strong>: [<a href="#type">Type</a>, <a href="#string">String</a>, <a href="#regex">Regex</a>, <a href="#format">Format</a>, <a href="#numbers">Numbers</a>, <a href="#combinatorics">Combinatorics</a>, <a href="#datetime">Datetime</a>ᴺᴱᵂ],\n' +
' <strong><span class="hljs-string">\'3. Syntax\'</span></strong>: [<a href="#arguments">Arguments</a>, <a href="#splatoperator">Splat</a>, <a href="#inline">Inline</a>, <a href="#closure">Closure</a>, <a href="#decorator">Decorator</a>, <a href="#class">Class</a>, <a href="#enum">Enum</a>, <a href="#exceptions">Exceptions</a>],\n' +
' <strong><span class="hljs-string">\'4. System\'</span></strong>: [<a href="#print">Print</a>, <a href="#input">Input</a>, <a href="#commandlinearguments">Command_Line_Arguments</a>, <a href="#open">Open</a>, <a href="#path">Path</a>ᴺᴱᵂ, <a href="#commandexecution">Command_Execution</a>],\n' +
' <strong><span class="hljs-string">\'5. Data\'</span></strong>: [<a href="#csv">CSV</a>, <a href="#json">JSON</a>, <a href="#pickle">Pickle</a>, <a href="#sqlite">SQLite</a>, <a href="#bytes">Bytes</a>, <a href="#struct">Struct</a>, <a href="#array">Array</a>, <a href="#memoryview">MemoryView</a>, <a href="#deque">Deque</a>],\n' +
' <strong><span class="hljs-string">\'6. Advanced\'</span></strong>: [<a href="#threading">Threading</a>, <a href="#introspection">Introspection</a>, <a href="#metaprograming">Metaprograming</a>, <a href="#operator">Operator</a>, <a href="#eval">Eval</a>, <a href="#coroutine">Coroutine</a>],\n' +
' <strong><span class="hljs-string">\'7. Libraries\'</span></strong>: [<a href="#progressbar">Progress_Bar</a>, <a href="#plot">Plot</a>, <a href="#table">Table</a>, <a href="#curses">Curses</a>, <a href="#logging">Logging</a>ᴺᴱᵂ, <a href="#scraping">Scraping</a>, <a href="#web">Web</a>, <a href="#profile">Profile</a>,\n' +
' <a href="#numpy">NumPy</a>, <a href="#image">Image</a>, <a href="#audio">Audio</a>]\n' +
"}\n" +
"</code></pre>\n";

4
web/template.html

@ -203,7 +203,7 @@ pre.prettyprint {
<body>
<header>
<aside>December 15, 2019</aside>
<aside>March 7, 2020</aside>
<a href="../" rel="author">Jure Šorn</a>
</header>
@ -211,7 +211,7 @@ pre.prettyprint {
<div id=main_container></div>
<footer>
<aside>December 15, 2019</aside>
<aside>March 7, 2020</aside>
<a href="../" rel="author">Jure Šorn</a>
</footer>

Loading…
Cancel
Save