Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9d92be4

Browse files
authored
Merge pull request #1 from gto76/master
Pull in upstream
2 parents a25708b + a59cb90 commit 9d92be4

File tree

9 files changed

+576
-246
lines changed

9 files changed

+576
-246
lines changed

README.md

Lines changed: 175 additions & 81 deletions
Large diffs are not rendered by default.

index.html

Lines changed: 206 additions & 81 deletions
Large diffs are not rendered by default.

parse.js

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,50 @@ const TOC =
3030
'}\n' +
3131
'</code></pre>\n';
3232

33-
const MRO =
34-
'<pre><code class="python language-python hljs"><span class="hljs-meta">&gt;&gt;&gt; </span>C.mro()\n[&lt;<span class="hljs-class"><span class="hljs-title">class</span> \'<span class="hljs-title">C</span>\'&gt;, &lt;<span class="hljs-title">class</span> \'<span class="hljs-title">A</span>\'&gt;, &lt;<span class="hljs-title">class</span> \'<span class="hljs-title">B</span>\'&gt;, &lt;<span class="hljs-title">class</span> \'<span class="hljs-title">object</span>\'&gt;]</span></code>\n</pre>\n'
33+
const DIAGRAM_1_A =
34+
'+---------+-------------+\n' +
35+
'| Classes | Metaclasses |\n' +
36+
'+---------+-------------|\n' +
37+
'| MyClass > MyMetaClass |\n' +
38+
'| | v |\n' +
39+
'| object ---> type <+ |\n' +
40+
'| | ^ +---+ |\n' +
41+
'| str -------+ |\n' +
42+
'+---------+-------------+\n';
43+
44+
const DIAGRAM_1_B =
45+
'┏━━━━━━━━━┯━━━━━━━━━━━━━┓\n' +
46+
'┃ Classes │ Metaclasses ┃\n' +
47+
'┠─────────┼─────────────┨\n' +
48+
'┃ MyClass → MyMetaClass ┃\n' +
49+
'┃ │ ↓ ┃\n' +
50+
'┃ object ───→ type ←╮ ┃\n' +
51+
'┃ │ ↑ ╰───╯ ┃\n' +
52+
'┃ str ───────╯ ┃\n' +
53+
'┗━━━━━━━━━┷━━━━━━━━━━━━━┛\n';
54+
55+
const DIAGRAM_2_A =
56+
'+---------+-------------+\n' +
57+
'| Classes | Metaclasses |\n' +
58+
'+---------+-------------|\n' +
59+
'| MyClass | MyMetaClass |\n' +
60+
'| v | v |\n' +
61+
'| object <--- type |\n' +
62+
'| ^ | |\n' +
63+
'| str | |\n' +
64+
'+---------+-------------+\n';
65+
66+
const DIAGRAM_2_B =
67+
'┏━━━━━━━━━┯━━━━━━━━━━━━━┓\n' +
68+
'┃ Classes │ Metaclasses ┃\n' +
69+
'┠─────────┼─────────────┨\n' +
70+
'┃ MyClass │ MyMetaClass ┃\n' +
71+
'┃ ↓ │ ↓ ┃\n' +
72+
'┃ object ←─── type ┃\n' +
73+
'┃ ↑ │ ┃\n' +
74+
'┃ str │ ┃\n' +
75+
'┗━━━━━━━━━┷━━━━━━━━━━━━━┛\n';
76+
3577

3678
function main() {
3779
const html = getMd();
@@ -52,11 +94,17 @@ function initDom(html) {
5294
}
5395

5496
function getMd() {
55-
const readme = readFile('README.md');
97+
var readme = readFile('README.md');
98+
readme = switchClassDiagrams(readme);
5699
const converter = new showdown.Converter();
57100
return converter.makeHtml(readme);
58101
}
59102

103+
function switchClassDiagrams(readme) {
104+
readme = readme.replace(DIAGRAM_1_A, DIAGRAM_1_B)
105+
return readme.replace(DIAGRAM_2_A, DIAGRAM_2_B)
106+
}
107+
60108
function modifyPage() {
61109
removeOrigToc();
62110
addToc();
@@ -94,23 +142,23 @@ function unindentBanner() {
94142
}
95143

96144
function highlightCode() {
97-
setApache('<D>')
98-
setApache('<T>')
99-
setApache('<DT>')
100-
setApache('<TD>')
101-
setApache('<a>')
102-
setApache('<n>')
145+
setApaches(['<D>', '<T>', '<DT>', '<TD>', '<a>', '<n>']);
103146
$('code').not('.python').not('.text').not('.bash').not('.apache').addClass('python');
104147
$('code').each(function(index) {
105148
hljs.highlightBlock(this);
106149
});
107-
$('#copy').prev().remove()
108-
const nodes = $.parseHTML(MRO);
109-
$('#copy').before(nodes);
150+
fixClasses()
151+
}
152+
153+
function setApaches(elements) {
154+
for (el of elements) {
155+
$(`code:contains(${el})`).addClass('apache');
156+
}
110157
}
111158

112-
function setApache(codeContents) {
113-
$(`code:contains(${codeContents})`).addClass('apache');
159+
function fixClasses() {
160+
// Changes class="hljs-keyword" to class="hljs-title" of 'class' keyword.
161+
$('.hljs-class').filter(':contains(class \')').find(':first-child').removeClass('hljs-keyword').addClass('hljs-title')
114162
}
115163

116164
function readFile(filename) {

web/default.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/empty_script.py

Lines changed: 4 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# This is an empty Python script.
22
# It is here, so it tricks GitHub into thinking that this is a Python project.
33
# But because GitHub counts characters, we have to fill it with something.
4-
54
# How about:
5+
66
from math import sin, pi
7+
78
LEN = 40
8-
wave = ['#' * (1 + round(amp * (1+sin(i/resolution*2*pi))))
9-
for resolution, amp in zip(range(10, 10+LEN, 2), range(2, 2+LEN, 2))
9+
wave = ['#' * (1 + round(amp * (1+sin(i/resolution*2*pi))))
10+
for resolution, amp in zip(range(10, 10+LEN, 2), range(2, 2+LEN, 2))
1011
for i in range(resolution)]
1112
print('\n'.join(wave))
1213

@@ -1210,44 +1211,6 @@
12101211
#
12111212
#
12121213
#
1213-
#
1214-
#
1215-
#
1216-
#
1217-
#
1218-
#
1219-
#
1220-
#
1221-
#
1222-
#
1223-
#
1224-
#
1225-
#
1226-
#
1227-
#
1228-
#
1229-
#
1230-
#
1231-
#
1232-
#
1233-
#
1234-
#
1235-
#
1236-
#
1237-
#
1238-
#
1239-
#
1240-
#
1241-
#
1242-
#
1243-
#
1244-
#
1245-
#
1246-
#
1247-
#
1248-
#
1249-
#
1250-
#
12511214
##
12521215
####
12531216
#######
@@ -3458,34 +3421,6 @@
34583421
###
34593422
##
34603423
#
3461-
#
3462-
#
3463-
#
3464-
#
3465-
#
3466-
#
3467-
#
3468-
#
3469-
#
3470-
#
3471-
#
3472-
#
3473-
#
3474-
#
3475-
#
3476-
#
3477-
#
3478-
#
3479-
#
3480-
#
3481-
#
3482-
#
3483-
#
3484-
#
3485-
#
3486-
#
3487-
#
3488-
#
34893424
##
34903425
####
34913426
#######

web/jquery-3.4.0.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/jquery-3.4.0.slim.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/script_2.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const DIAGRAM_1_A =
2+
'+---------+-------------+\n' +
3+
'| Classes | Metaclasses |\n' +
4+
'+---------+-------------|\n' +
5+
'| MyClass > MyMetaClass |\n' +
6+
'| | v |\n' +
7+
'| object ---> type <+ |\n' +
8+
'| | ^ +---+ |\n' +
9+
'| str -------+ |\n' +
10+
'+---------+-------------+\n';
11+
12+
const DIAGRAM_1_B =
13+
'┏━━━━━━━━━┯━━━━━━━━━━━━━┓\n' +
14+
'┃ Classes │ Metaclasses ┃\n' +
15+
'┠─────────┼─────────────┨\n' +
16+
'┃ MyClass → MyMetaClass ┃\n' +
17+
'┃ │ ↓ ┃\n' +
18+
'┃ object ───→ type ←╮ ┃\n' +
19+
'┃ │ ↑ ╰───╯ ┃\n' +
20+
'┃ str ───────╯ ┃\n' +
21+
'┗━━━━━━━━━┷━━━━━━━━━━━━━┛\n';
22+
23+
const DIAGRAM_2_A =
24+
'+---------+-------------+\n' +
25+
'| Classes | Metaclasses |\n' +
26+
'+---------+-------------|\n' +
27+
'| MyClass | MyMetaClass |\n' +
28+
'| v | v |\n' +
29+
'| object <--- type |\n' +
30+
'| ^ | |\n' +
31+
'| str | |\n' +
32+
'+---------+-------------+\n';
33+
34+
const DIAGRAM_2_B =
35+
'┏━━━━━━━━━┯━━━━━━━━━━━━━┓\n' +
36+
'┃ Classes │ Metaclasses ┃\n' +
37+
'┠─────────┼─────────────┨\n' +
38+
'┃ MyClass │ MyMetaClass ┃\n' +
39+
'┃ ↓ │ ↓ ┃\n' +
40+
'┃ object ←─── type ┃\n' +
41+
'┃ ↑ │ ┃\n' +
42+
'┃ str │ ┃\n' +
43+
'┗━━━━━━━━━┷━━━━━━━━━━━━━┛\n';
44+
45+
46+
(function(d){function c(c){b.style.fontFamily=c;e.appendChild(b);f=b.clientWidth;e.removeChild(b);return f}var f,e=d.body,b=d.createElement("span");b.innerHTML=Array(100).join("wi");b.style.cssText=["position:absolute","width:auto","font-size:128px","left:-99999px"].join(" !important;");var g=c("monospace"),h=c("serif"),k=c("sans-serif");window.isFontAvailable=function(b){return g!==c(b+",monospace")||k!==c(b+",sans-serif")||h!==c(b+",serif")}})(document);
47+
48+
if (!isFontAvailable('Menlo')) {
49+
$(`code:contains(${DIAGRAM_1_B})`).html(DIAGRAM_1_A);
50+
$(`code:contains(${DIAGRAM_2_B})`).html(DIAGRAM_2_A);
51+
var htmlString = $('code:contains(ᴺᴱᵂ)').html().replace(//g, '');
52+
$('code:contains(ᴺᴱᵂ)').html(htmlString);
53+
}
54+
55+
var isMobile = false; //initiate as false
56+
// device detection
57+
if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|ipad|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent)
58+
|| /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0,4))) {
59+
isMobile = true;
60+
}
61+
62+
// ===== Scroll to Top ====
63+
$(window).scroll(function() {
64+
if (isMobile && $(this).scrollTop() >= 480) { // If mobile device and page is scrolled more than 520px.
65+
$('#return-to-top').fadeIn(200); // Fade in the arrow
66+
} else {
67+
$('#return-to-top').fadeOut(200); // Else fade out the arrow
68+
}
69+
});
70+
71+
$('#return-to-top').click(function() { // When arrow is clicked
72+
$('body,html').animate({
73+
scrollTop : 0 // Scroll to top of body
74+
}, 500);
75+
});

web/template.html

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
<meta charset="utf-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
77
<title>Comprehensive Python Cheatsheet</title>
8+
<meta name="description" content="Exhaustive, simple, beautiful and concise. A truly pythonic cheat sheet about Python programming language.">
89
<link rel="icon" href="web/favicon.png">
910
<link rel="stylesheet" href="web/default.min.css">
11+
<link href="https://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
1012
<meta name="twitter:card" content="summary">
1113
<meta name="twitter:title" content="Comprehensive Python Cheatsheet">
1214
<meta name="twitter:description" content="Exhaustive, simple, beautiful and concise. A truly pythonic cheat sheet about Python programming language.">
1315
<meta name="twitter:image" content="https://gto76.github.io/python-cheatsheet/web/image_twitter_card_2.jpeg">
16+
<meta name="google-site-verification" content="w3rvuG0D1kUm_w20qsJecSEZh59Am8jK4eSPVU83e_M" />
1417
</head>
1518

1619
<style>
@@ -141,6 +144,49 @@
141144
padding: 1em;
142145
white-space: pre-wrap;
143146
}
147+
148+
#return-to-top {
149+
position: fixed;
150+
bottom: 20px;
151+
right: 20px;
152+
background: rgb(0, 0, 0);
153+
background: rgba(0, 0, 0, 0.2);
154+
width: 50px;
155+
height: 50px;
156+
display: block;
157+
text-decoration: none;
158+
-webkit-border-radius: 35px;
159+
-moz-border-radius: 35px;
160+
border-radius: 35px;
161+
display: none;
162+
-webkit-transition: all 0.3s linear;
163+
-moz-transition: all 0.3s ease;
164+
-ms-transition: all 0.3s ease;
165+
-o-transition: all 0.3s ease;
166+
transition: all 0.3s ease;
167+
}
168+
169+
#return-to-top i {
170+
color: #fff;
171+
margin: 0;
172+
position: relative;
173+
left: 16px;
174+
top: 13px;
175+
font-size: 19px;
176+
-webkit-transition: all 0.3s ease;
177+
-moz-transition: all 0.3s ease;
178+
-ms-transition: all 0.3s ease;
179+
-o-transition: all 0.3s ease;
180+
transition: all 0.3s ease;
181+
}
182+
183+
#return-to-top:hover {
184+
background: rgba(0, 0, 0, 0.35);
185+
}
186+
187+
#return-to-top:hover i {
188+
color: #f0f0f0;
189+
}
144190
</style>
145191

146192
<body>
@@ -149,6 +195,7 @@
149195
<a href="../" rel="author">Jure Šorn</a>
150196
</header>
151197

198+
<a href="javascript:" id="return-to-top"><i class="icon-chevron-up"></i></a>
152199
<div id=main_container></div>
153200

154201
<footer>
@@ -159,5 +206,7 @@
159206
<br>
160207
<br>
161208
<br>
209+
<script src="web/jquery-3.4.0.min.js"></script>
210+
<script src="web/script_2.js"></script>
162211
</body>
163212
</html>

0 commit comments

Comments
 (0)