Skip to content

Commit 68c58db

Browse files
committed
rebased to current master
1 parent e73f8d4 commit 68c58db

File tree

3 files changed

+79
-58
lines changed

3 files changed

+79
-58
lines changed

README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ Comprehensive Python Cheatsheet
88

99
Contents
1010
--------
11-
**   ** **1. Collections:** ** ** **[`List`](#list)**__,__ **[`Dict`](#dictionary)**__,__ **[`Set`](#set)**__,__ **[`Range`](#range)**__,__ **[`Enumerate`](#enumerate)**__,__ **[`Namedtuple`](#named-tuple)**__,__ **[`Iterator`](#iterator)**__,__ **[`Generator`](#generator)**__.__
12-
**   ** **2. Types:** **          ** **[`Type`](#type)**__,__ **[`String`](#string)**__,__ **[`Regex`](#regex)**__,__ **[`Format`](#format)**__,__ **[`Numbers`](#numbers)**__,__ **[`Combinatorics`](#combinatorics)**__,__ **[`Datetime`](#datetime)**__.__
13-
**   ** **3. Syntax:** **         ** **[`Arguments`](#arguments)**__,__ **[`Splat`](#splat-operator)**__,__ **[`Inline`](#inline)**__,__ **[`Closure`](#closure)**__,__ **[`Decorator`](#decorator)**__,__ **[`Class`](#class)**__,__ **[`Enum`](#enum)**__,__ **[`Exceptions`](#exceptions)**__.__
14-
**   ** **4. System:** **        ** **[`Print`](#print)**__,__ **[`Input`](#input)**__,__ **[`Command_Line_Arguments`](#command-line-arguments)**__,__ **[`Open`](#open)**__,__ **[`Path`](#path)**__,__ **[`Command_Execution`](#command-execution)**__.__
15-
**   ** **5. Data:** **             ** **[`CSV`](#csv)**__,__ **[`JSON`](#json)**__,__ **[`Pickle`](#pickle)**__,__ **[`SQLite`](#sqlite)**__,__ **[`Bytes`](#bytes)**__,__ **[`Struct`](#struct)**__,__ **[`Array`](#array)**__,__ **[`MemoryView`](#memory-view)**__,__ **[`Deque`](#deque)**__.__
16-
**   ** **6. Advanced:** **   ** **[`Threading`](#threading)**__,__ **[`Introspection`](#introspection)**__,__ **[`Metaprograming`](#metaprograming)**__,__ **[`Operator`](#operator)**__,__ **[`Eval`](#eval)**__,__ **[`Coroutine`](#coroutine)**__.__
17-
**   ** **7. Libraries:** **      ** **[`Progress_Bar`](#progress-bar)**__,__ **[`Plot`](#plot)**__,__ **[`Table`](#table)**__,__ **[`Curses`](#curses)**__,__ **[`Logging`](#logging)**__,__ **[`Scraping`](#scraping)**__,__ **[`Web`](#web)**__,__ **[`Profile`](#profile)**__,__
11+
**   ** **1. Collections:** ** ** **[`List`](#list)**__,__ **[`Dict`](#dictionary)**__,__ **[`Set`](#set)**__,__ **[`Range`](#range)**__,__ **[`Enumerate`](#enumerate)**__,__ **[`Namedtuple`](#named-tuple)**__,__ **[`Iterator`](#iterator)**__,__ **[`Generator`](#generator)**__.__
12+
**   ** **2. Types:** **          ** **[`Type`](#type)**__,__ **[`String`](#string)**__,__ **[`Regex`](#regex)**__,__ **[`Format`](#format)**__,__ **[`Numbers`](#numbers)**__,__ **[`Combinatorics`](#combinatorics)**__,__ **[`Datetime`](#datetime)**__.__
13+
**   ** **3. Syntax:** **         ** **[`Arguments`](#arguments)**__,__ **[`Splat`](#splat-operator)**__,__ **[`Inline`](#inline)**__,__ **[`Closure`](#closure)**__,__ **[`Decorator`](#decorator)**__,__ **[`Class`](#class)**__,__ **[`Enum`](#enum)**__,__ **[`Exceptions`](#exceptions)**__.__
14+
**   ** **4. System:** **        ** **[`Print`](#print)**__,__ **[`Input`](#input)**__,__ **[`Command_Line_Arguments`](#command-line-arguments)**__,__ **[`Open`](#open)**__,__ **[`Path`](#path)**__,__ **[`Command_Execution`](#command-execution)**__.__
15+
**   ** **5. Data:** **             ** **[`CSV`](#csv)**__,__ **[`JSON`](#json)**__,__ **[`Pickle`](#pickle)**__,__ **[`SQLite`](#sqlite)**__,__ **[`Bytes`](#bytes)**__,__ **[`Struct`](#struct)**__,__ **[`Array`](#array)**__,__ **[`MemoryView`](#memory-view)**__,__ **[`Deque`](#deque)**__.__
16+
**   ** **6. Advanced:** **   ** **[`Threading`](#threading)**__,__ **[`Introspection`](#introspection)**__,__ **[`Metaprograming`](#metaprograming)**__,__ **[`Operator`](#operator)**__,__ **[`Eval`](#eval)**__,__ **[`Coroutine`](#coroutine)**__.__
17+
**   ** **7. Libraries:** **      ** **[`Progress_Bar`](#progress-bar)**__,__ **[`Plot`](#plot)**__,__ **[`Table`](#table)**__,__ **[`Curses`](#curses)**__,__ **[`Logging`](#logging)**__,__ **[`Scraping`](#scraping)**__,__ **[`Web`](#web)**__,__ **[`Profile`](#profile)**__,__
1818
**                                 ** **[`NumPy`](#numpy)**__,__ **[`Image`](#image)**__,__ **[`Audio`](#audio)**__.__
1919

2020

@@ -467,7 +467,7 @@ from dateutil.tz import UTC, tzlocal, gettz
467467
<D> = date(year, month, day)
468468
<T> = time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, fold=0)
469469
<DT> = datetime(year, month, day, hour=0, minute=0, second=0, ...)
470-
<TD> = timedelta(days=0, seconds=0, microseconds=0, milliseconds=0,
470+
<TD> = timedelta(days=0, seconds=0, microseconds=0, milliseconds=0,
471471
minutes=0, hours=0, weeks=0)
472472
```
473473
* **Use `'<D/DT>.weekday()'` to get the day of the week (Mon == 0).**
@@ -1834,7 +1834,7 @@ duration = pc() - start_time
18341834
### Timing a Snippet
18351835
```python
18361836
>>> from timeit import timeit
1837-
>>> timeit('"-".join(str(a) for a in range(100))',
1837+
>>> timeit('"-".join(str(a) for a in range(100))',
18381838
... number=10000, globals=globals(), setup='pass')
18391839
0.34986
18401840
```
@@ -2082,7 +2082,7 @@ Basic Script Template
20822082
#!/usr/bin/env python3
20832083
#
20842084
# Usage: .py
2085-
#
2085+
#
20862086

20872087
from collections import namedtuple
20882088
from enum import Enum

web/script.js

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,42 @@ $(document).ready(function() {
33
});
44

55
function parseMd() {
6-
var GITHUB = 'https://raw.githubusercontent.com/gto76/python-cheatsheet/master/README.md';
6+
var GITHUB =
7+
"https://raw.githubusercontent.com/gto76/python-cheatsheet/master/README.md";
78
jQuery.get(GITHUB, function(text) {
9+
console.log(text);
10+
text = removeMdToc(text);
11+
console.log(text);
812
var converter = new showdown.Converter();
913
html = converter.makeHtml(text);
10-
aDiv = $('#main_container');
14+
aDiv = $("#main_container");
1115
nodes = $.parseHTML(html);
1216
aDiv.after(nodes);
1317
removeOrigToc();
1418
insertLinks();
15-
d3.selectAll("code").each(function() { hljs.highlightBlock(this); });
19+
addImgParentClass();
20+
d3.selectAll("code").each(function() {
21+
hljs.highlightBlock(this);
22+
});
1623
addToc();
1724
});
1825
}
1926

20-
function removeOrigToc() {
21-
headerContents = $('#contents')
22-
contentsList = headerContents.next()
23-
headerContents.remove()
24-
contentsList.remove()
27+
function removeMdToc(text) {
28+
var out = [];
29+
lines = text.match(/[^\r\n]+/g);
30+
insideContents = false;
31+
for (line of lines) {
32+
if (line.trim() === "Contents") {
33+
insideContents = true;
34+
} else if (line.trim() === "Main") {
35+
insideContents = false;
36+
}
37+
if (!insideContents) {
38+
out.push(line);
39+
}
40+
}
41+
return out.join("\n");
2542
}
2643

2744
function insertLinks() {
@@ -32,29 +49,28 @@ function insertLinks() {
3249
});
3350
}
3451
function addImgParentClass() {
35-
$("img").each(function() {
36-
$(this)
37-
.parent()
38-
.addClass("img_parent");
39-
});
52+
let monty_img = $("img").first();
53+
monty_img.parent().addClass("img_parent");
54+
monty_img.before("<br>");
4055
}
4156

4257
function addToc() {
43-
headerMain = $('#main');
58+
headerMain = $("#main");
4459
nodes = $.parseHTML(TOC);
4560
headerMain.before(nodes);
4661
}
4762

48-
var TOC = '<br>' +
49-
'<h2 id="toc">Contents<a href="#toc" name="toc">#</a></h2>\n' +
50-
'<pre><code class="hljs bash"><strong>ToC</strong> = {\n' +
51-
' <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' +
52-
' <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' +
53-
' <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' +
54-
' <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' +
55-
' <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' +
56-
' <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' +
57-
' <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' +
58-
' <a href="#numpy">NumPy</a>, <a href="#image">Image</a>, <a href="#audio">Audio</a>]\n' +
59-
'}\n' +
60-
'</code></pre>\n';
63+
var TOC =
64+
"<br>" +
65+
'<h2 id="toc">Contents<a href="#toc" name="toc">#</a></h2>\n' +
66+
'<pre><code class="hljs bash"><strong>ToC</strong> = {\n' +
67+
' <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' +
68+
' <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' +
69+
' <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' +
70+
' <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' +
71+
' <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' +
72+
' <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' +
73+
' <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' +
74+
' <a href="#numpy">NumPy</a>, <a href="#image">Image</a>, <a href="#audio">Audio</a>]\n' +
75+
"}\n" +
76+
"</code></pre>\n";

web/style.css

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
21
/* Copyright 2013 Michael Bostock. All rights reserved. Do not copy. */
32

43
@import url(https://fonts.googleapis.com/css?family=PT+Serif|PT+Serif:b|PT+Serif:i|PT+Sans|PT+Sans:b);
54

6-
75
.ocks-org body {
86
background: #fcfcfa;
97
color: #333;
108
font-family: "PT Serif", serif;
119
margin: 1em auto 4em auto;
1210
position: relative;
1311
width: 960px;
12+
padding: 1rem;
1413
}
1514

1615
.ocks-org header,
@@ -39,21 +38,22 @@ h1 {
3938
font-size: 64px;
4039
font-weight: 300;
4140
letter-spacing: -2px;
42-
margin: .3em 0 .1em 0;
41+
margin: 0.3em 0 0.1em 0;
4342
}
4443

4544
h2 {
4645
margin-top: 2em;
4746
}
4847

49-
h1, h2 {
48+
h1,
49+
h2 {
5050
text-rendering: optimizeLegibility;
5151
}
5252

5353
h2 a[name],
5454
h2 a[id] {
5555
color: #ccc;
56-
padding: 0 .3em;
56+
padding-right: 0.3em;
5757
}
5858

5959
header,
@@ -64,12 +64,12 @@ footer {
6464
.ocks-org header aside,
6565
.ocks-org footer aside {
6666
float: left;
67-
margin-right: .5em;
67+
margin-right: 0.5em;
6868
}
6969

7070
.ocks-org header aside:after,
7171
.ocks-org footer aside:after {
72-
padding-left: .5em;
72+
padding-left: 0.5em;
7373
content: "/";
7474
}
7575

@@ -89,7 +89,8 @@ h1 ~ aside {
8989
margin-bottom: 2em;
9090
}
9191

92-
body > p, li > p {
92+
body > p,
93+
li > p {
9394
line-height: 1.5em;
9495
}
9596

@@ -123,7 +124,9 @@ a:not(:hover) {
123124
text-decoration: none;
124125
}
125126

126-
pre, code, textarea {
127+
pre,
128+
code,
129+
textarea {
127130
font-family: "Menlo", monospace;
128131
}
129132

@@ -187,13 +190,15 @@ svg {
187190
font: 10px sans-serif;
188191
}
189192

190-
.axis path, .axis line {
193+
.axis path,
194+
.axis line {
191195
fill: none;
192196
stroke: #000;
193197
shape-rendering: crispEdges;
194198
}
195199

196-
sup, sub {
200+
sup,
201+
sub {
197202
line-height: 0;
198203
}
199204

@@ -214,23 +219,23 @@ blockquote q:before,
214219
blockquote q:after {
215220
content: "";
216221
}
217-
h3,h4,p, ul{
222+
h3,
223+
h4,
224+
p,
225+
ul {
218226
padding-left: 2rem;
219227
}
220-
.img_parent{
228+
.img_parent {
221229
padding: 0;
222230
}
223231

224-
@media only screen
225-
and (max-device-width : 1024px){
226-
.ocks-org body {
227-
margin: 1rem;
228-
}
229-
230-
h1{
232+
@media only screen and (max-device-width: 1024px) {
233+
h1 {
231234
font-size: 3rem;
232235
}
233-
.img_parent, h1, img{
236+
.img_parent,
237+
h1,
238+
img {
234239
max-width: calc(100vw - 2em);
235240
min-width: calc(100vw - 2em);
236241
}

0 commit comments

Comments
 (0)