Browse Source

rebased to current master

pull/23/head
s-weigand 5 years ago
committed by Sebastian Weigand
parent
commit
68c58db5aa
3 changed files with 79 additions and 58 deletions
  1. 20
      README.md
  2. 70
      web/script.js
  3. 47
      web/style.css

20
README.md

@ -8,13 +8,13 @@ Comprehensive Python Cheatsheet
Contents
--------
**   ** **1. Collections:** ** ** **[`List`](#list)**__,__ **[`Dict`](#dictionary)**__,__ **[`Set`](#set)**__,__ **[`Range`](#range)**__,__ **[`Enumerate`](#enumerate)**__,__ **[`Namedtuple`](#named-tuple)**__,__ **[`Iterator`](#iterator)**__,__ **[`Generator`](#generator)**__.__
**   ** **2. Types:** **          ** **[`Type`](#type)**__,__ **[`String`](#string)**__,__ **[`Regex`](#regex)**__,__ **[`Format`](#format)**__,__ **[`Numbers`](#numbers)**__,__ **[`Combinatorics`](#combinatorics)**__,__ **[`Datetime`](#datetime)**__.__
**   ** **3. Syntax:** **         ** **[`Arguments`](#arguments)**__,__ **[`Splat`](#splat-operator)**__,__ **[`Inline`](#inline)**__,__ **[`Closure`](#closure)**__,__ **[`Decorator`](#decorator)**__,__ **[`Class`](#class)**__,__ **[`Enum`](#enum)**__,__ **[`Exceptions`](#exceptions)**__.__
**   ** **4. System:** **        ** **[`Print`](#print)**__,__ **[`Input`](#input)**__,__ **[`Command_Line_Arguments`](#command-line-arguments)**__,__ **[`Open`](#open)**__,__ **[`Path`](#path)**__,__ **[`Command_Execution`](#command-execution)**__.__
**   ** **5. Data:** **             ** **[`CSV`](#csv)**__,__ **[`JSON`](#json)**__,__ **[`Pickle`](#pickle)**__,__ **[`SQLite`](#sqlite)**__,__ **[`Bytes`](#bytes)**__,__ **[`Struct`](#struct)**__,__ **[`Array`](#array)**__,__ **[`MemoryView`](#memory-view)**__,__ **[`Deque`](#deque)**__.__
**   ** **6. Advanced:** **   ** **[`Threading`](#threading)**__,__ **[`Introspection`](#introspection)**__,__ **[`Metaprograming`](#metaprograming)**__,__ **[`Operator`](#operator)**__,__ **[`Eval`](#eval)**__,__ **[`Coroutine`](#coroutine)**__.__
**   ** **7. Libraries:** **      ** **[`Progress_Bar`](#progress-bar)**__,__ **[`Plot`](#plot)**__,__ **[`Table`](#table)**__,__ **[`Curses`](#curses)**__,__ **[`Logging`](#logging)**__,__ **[`Scraping`](#scraping)**__,__ **[`Web`](#web)**__,__ **[`Profile`](#profile)**__,__
**   ** **1. Collections:** ** ** **[`List`](#list)**__,__ **[`Dict`](#dictionary)**__,__ **[`Set`](#set)**__,__ **[`Range`](#range)**__,__ **[`Enumerate`](#enumerate)**__,__ **[`Namedtuple`](#named-tuple)**__,__ **[`Iterator`](#iterator)**__,__ **[`Generator`](#generator)**__.__
**   ** **2. Types:** **          ** **[`Type`](#type)**__,__ **[`String`](#string)**__,__ **[`Regex`](#regex)**__,__ **[`Format`](#format)**__,__ **[`Numbers`](#numbers)**__,__ **[`Combinatorics`](#combinatorics)**__,__ **[`Datetime`](#datetime)**__.__
**   ** **3. Syntax:** **         ** **[`Arguments`](#arguments)**__,__ **[`Splat`](#splat-operator)**__,__ **[`Inline`](#inline)**__,__ **[`Closure`](#closure)**__,__ **[`Decorator`](#decorator)**__,__ **[`Class`](#class)**__,__ **[`Enum`](#enum)**__,__ **[`Exceptions`](#exceptions)**__.__
**   ** **4. System:** **        ** **[`Print`](#print)**__,__ **[`Input`](#input)**__,__ **[`Command_Line_Arguments`](#command-line-arguments)**__,__ **[`Open`](#open)**__,__ **[`Path`](#path)**__,__ **[`Command_Execution`](#command-execution)**__.__
**   ** **5. Data:** **             ** **[`CSV`](#csv)**__,__ **[`JSON`](#json)**__,__ **[`Pickle`](#pickle)**__,__ **[`SQLite`](#sqlite)**__,__ **[`Bytes`](#bytes)**__,__ **[`Struct`](#struct)**__,__ **[`Array`](#array)**__,__ **[`MemoryView`](#memory-view)**__,__ **[`Deque`](#deque)**__.__
**   ** **6. Advanced:** **   ** **[`Threading`](#threading)**__,__ **[`Introspection`](#introspection)**__,__ **[`Metaprograming`](#metaprograming)**__,__ **[`Operator`](#operator)**__,__ **[`Eval`](#eval)**__,__ **[`Coroutine`](#coroutine)**__.__
**   ** **7. Libraries:** **      ** **[`Progress_Bar`](#progress-bar)**__,__ **[`Plot`](#plot)**__,__ **[`Table`](#table)**__,__ **[`Curses`](#curses)**__,__ **[`Logging`](#logging)**__,__ **[`Scraping`](#scraping)**__,__ **[`Web`](#web)**__,__ **[`Profile`](#profile)**__,__
**                                 ** **[`NumPy`](#numpy)**__,__ **[`Image`](#image)**__,__ **[`Audio`](#audio)**__.__
@ -467,7 +467,7 @@ from dateutil.tz import UTC, tzlocal, gettz
<D> = date(year, month, day)
<T> = time(hour=0, minute=0, second=0, microsecond=0, tzinfo=None, fold=0)
<DT> = datetime(year, month, day, hour=0, minute=0, second=0, ...)
<TD> = timedelta(days=0, seconds=0, microseconds=0, milliseconds=0,
<TD> = timedelta(days=0, seconds=0, microseconds=0, milliseconds=0,
minutes=0, hours=0, weeks=0)
```
* **Use `'<D/DT>.weekday()'` to get the day of the week (Mon == 0).**
@ -1834,7 +1834,7 @@ duration = pc() - start_time
### Timing a Snippet
```python
>>> from timeit import timeit
>>> timeit('"-".join(str(a) for a in range(100))',
>>> timeit('"-".join(str(a) for a in range(100))',
... number=10000, globals=globals(), setup='pass')
0.34986
```
@ -2082,7 +2082,7 @@ Basic Script Template
#!/usr/bin/env python3
#
# Usage: .py
#
#
from collections import namedtuple
from enum import Enum

70
web/script.js

@ -3,25 +3,42 @@ $(document).ready(function() {
});
function parseMd() {
var GITHUB = 'https://raw.githubusercontent.com/gto76/python-cheatsheet/master/README.md';
var GITHUB =
"https://raw.githubusercontent.com/gto76/python-cheatsheet/master/README.md";
jQuery.get(GITHUB, function(text) {
console.log(text);
text = removeMdToc(text);
console.log(text);
var converter = new showdown.Converter();
html = converter.makeHtml(text);
aDiv = $('#main_container');
aDiv = $("#main_container");
nodes = $.parseHTML(html);
aDiv.after(nodes);
removeOrigToc();
insertLinks();
d3.selectAll("code").each(function() { hljs.highlightBlock(this); });
addImgParentClass();
d3.selectAll("code").each(function() {
hljs.highlightBlock(this);
});
addToc();
});
}
function removeOrigToc() {
headerContents = $('#contents')
contentsList = headerContents.next()
headerContents.remove()
contentsList.remove()
function removeMdToc(text) {
var out = [];
lines = text.match(/[^\r\n]+/g);
insideContents = false;
for (line of lines) {
if (line.trim() === "Contents") {
insideContents = true;
} else if (line.trim() === "Main") {
insideContents = false;
}
if (!insideContents) {
out.push(line);
}
}
return out.join("\n");
}
function insertLinks() {
@ -32,29 +49,28 @@ function insertLinks() {
});
}
function addImgParentClass() {
$("img").each(function() {
$(this)
.parent()
.addClass("img_parent");
});
let monty_img = $("img").first();
monty_img.parent().addClass("img_parent");
monty_img.before("<br>");
}
function addToc() {
headerMain = $('#main');
headerMain = $("#main");
nodes = $.parseHTML(TOC);
headerMain.before(nodes);
}
var TOC = '<br>' +
'<h2 id="toc">Contents<a href="#toc" name="toc">#</a></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';
var TOC =
"<br>" +
'<h2 id="toc">Contents<a href="#toc" name="toc">#</a></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";

47
web/style.css

@ -1,9 +1,7 @@
/* Copyright 2013 Michael Bostock. All rights reserved. Do not copy. */
@import url(https://fonts.googleapis.com/css?family=PT+Serif|PT+Serif:b|PT+Serif:i|PT+Sans|PT+Sans:b);
.ocks-org body {
background: #fcfcfa;
color: #333;
@ -11,6 +9,7 @@
margin: 1em auto 4em auto;
position: relative;
width: 960px;
padding: 1rem;
}
.ocks-org header,
@ -39,21 +38,22 @@ h1 {
font-size: 64px;
font-weight: 300;
letter-spacing: -2px;
margin: .3em 0 .1em 0;
margin: 0.3em 0 0.1em 0;
}
h2 {
margin-top: 2em;
}
h1, h2 {
h1,
h2 {
text-rendering: optimizeLegibility;
}
h2 a[name],
h2 a[id] {
color: #ccc;
padding: 0 .3em;
padding-right: 0.3em;
}
header,
@ -64,12 +64,12 @@ footer {
.ocks-org header aside,
.ocks-org footer aside {
float: left;
margin-right: .5em;
margin-right: 0.5em;
}
.ocks-org header aside:after,
.ocks-org footer aside:after {
padding-left: .5em;
padding-left: 0.5em;
content: "/";
}
@ -89,7 +89,8 @@ h1 ~ aside {
margin-bottom: 2em;
}
body > p, li > p {
body > p,
li > p {
line-height: 1.5em;
}
@ -123,7 +124,9 @@ a:not(:hover) {
text-decoration: none;
}
pre, code, textarea {
pre,
code,
textarea {
font-family: "Menlo", monospace;
}
@ -187,13 +190,15 @@ svg {
font: 10px sans-serif;
}
.axis path, .axis line {
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
sup, sub {
sup,
sub {
line-height: 0;
}
@ -214,23 +219,23 @@ blockquote q:before,
blockquote q:after {
content: "";
}
h3,h4,p, ul{
h3,
h4,
p,
ul {
padding-left: 2rem;
}
.img_parent{
.img_parent {
padding: 0;
}
@media only screen
and (max-device-width : 1024px){
.ocks-org body {
margin: 1rem;
}
h1{
@media only screen and (max-device-width: 1024px) {
h1 {
font-size: 3rem;
}
.img_parent, h1, img{
.img_parent,
h1,
img {
max-width: calc(100vw - 2em);
min-width: calc(100vw - 2em);
}

Loading…
Cancel
Save