Browse Source

Cython highlights

pull/187/head
Jure Šorn 6 months ago
parent
commit
34629b2592
2 changed files with 25 additions and 8 deletions
  1. 12
      index.html
  2. 21
      parse.js

12
index.html

@ -2877,18 +2877,18 @@ ex.line(df, x=<span class="hljs-string">'Date'</span>, y=<span class="hljs-strin
<div><h4 id="definitions">Definitions:</h4><ul>
<li><strong>All <code class="python hljs"><span class="hljs-string">'cdef'</span></code> definitions are optional, but they contribute to the speed-up.</strong></li>
<li><strong>Script needs to be saved with a <code class="python hljs"><span class="hljs-string">'pyx'</span></code> extension.</strong></li>
</ul><pre><code class="python language-python hljs">cdef &lt;ctype&gt; &lt;var_name&gt; = &lt;el&gt;
cdef &lt;ctype&gt;[n_elements] &lt;var_name&gt; = [&lt;el&gt;, &lt;el&gt;, ...]
cdef &lt;ctype/void&gt; &lt;func_name&gt;(&lt;ctype&gt; &lt;arg_name&gt;): ...
</ul><pre><code class="python language-python hljs"><span class="hljs-keyword">cdef</span> &lt;ctype&gt; &lt;var_name&gt; = &lt;el&gt;
<span class="hljs-keyword">cdef</span> &lt;ctype&gt;[n_elements] &lt;var_name&gt; = [&lt;el&gt;, &lt;el&gt;, ...]
<span class="hljs-keyword">cdef</span> &lt;ctype/void&gt; &lt;func_name&gt;(&lt;ctype&gt; &lt;arg_name&gt;): ...
</code></pre></div>
<pre><code class="python language-python hljs">cdef <span class="hljs-class"><span class="hljs-keyword">class</span> &lt;<span class="hljs-title">class_name</span>&gt;:</span>
cdef public &lt;ctype&gt; &lt;attr_name&gt;
<pre><code class="python language-python hljs"><span class="hljs-keyword">cdef</span> <span class="hljs-class"><span class="hljs-keyword">class</span> &lt;<span class="hljs-title">class_name</span>&gt;:</span>
<span class="hljs-keyword">cdef</span> <span class="hljs-keyword">public</span> &lt;ctype&gt; &lt;attr_name&gt;
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, &lt;ctype&gt; &lt;arg_name&gt;)</span>:</span>
self.&lt;attr_name&gt; = &lt;arg_name&gt;
</code></pre>
<pre><code class="python language-python hljs">cdef enum &lt;enum_name&gt;: &lt;member_name&gt;, &lt;member_name&gt;, ...
<pre><code class="python language-python hljs"><span class="hljs-keyword">cdef</span> <span class="hljs-keyword">enum</span> &lt;enum_name&gt;: &lt;member_name&gt;, &lt;member_name&gt;, ...
</code></pre>
<div><h3 id="virtualenvironments">Virtual Environments</h3><p><strong>System for installing libraries directly into project's directory.</strong></p><pre><code class="bash language-bash hljs">$ python3 -m venv &lt;name&gt; <span class="hljs-comment"># Creates virtual environment in current directory.</span>
$ <span class="hljs-built_in">source</span> &lt;name&gt;/bin/activate <span class="hljs-comment"># Activates venv. On Windows run `&lt;name&gt;\Scripts\activate`.</span>

21
parse.js

@ -300,7 +300,7 @@ const MARIO =
'<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">\'__main__\'</span>:\n' +
' main()\n';
const PLOTLY =
const GROUPBY =
'<span class="hljs-meta">&gt;&gt;&gt; </span>gb = df.groupby(<span class="hljs-string">\'z\'</span>); gb.apply(print)\n' +
' x y z\n' +
'a <span class="hljs-number">1</span> <span class="hljs-number">2</span> <span class="hljs-number">3</span>\n' +
@ -308,6 +308,20 @@ const PLOTLY =
'b <span class="hljs-number">4</span> <span class="hljs-number">5</span> <span class="hljs-number">6</span>\n' +
'c <span class="hljs-number">7</span> <span class="hljs-number">8</span> <span class="hljs-number">6</span>';
const CYTHON_1 =
'<span class="hljs-keyword">cdef</span> &lt;ctype&gt; &lt;var_name&gt; = &lt;el&gt;\n' +
'<span class="hljs-keyword">cdef</span> &lt;ctype&gt;[n_elements] &lt;var_name&gt; = [&lt;el&gt;, &lt;el&gt;, ...]\n' +
'<span class="hljs-keyword">cdef</span> &lt;ctype/void&gt; &lt;func_name&gt;(&lt;ctype&gt; &lt;arg_name&gt;): ...\n';
const CYTHON_2 =
'<span class="hljs-keyword">cdef</span> <span class="hljs-class"><span class="hljs-keyword">class</span> &lt;<span class="hljs-title">class_name</span>&gt;:</span>\n' +
' <span class="hljs-keyword">cdef</span> <span class="hljs-keyword">public</span> &lt;ctype&gt; &lt;attr_name&gt;\n' +
' <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span><span class="hljs-params">(self, &lt;ctype&gt; &lt;arg_name&gt;)</span>:</span>\n' +
' self.&lt;attr_name&gt; = &lt;arg_name&gt;\n';
const CYTHON_3 =
'<span class="hljs-keyword">cdef</span> <span class="hljs-keyword">enum</span> &lt;enum_name&gt;: &lt;member_name&gt;, &lt;member_name&gt;, ...\n';
const INDEX =
'<li><strong>Only available in the <a href="https://transactions.sendowl.com/products/78175486/4422834F/view">PDF</a>.</strong></li>\n' +
'<li><strong>Ctrl+F / ⌘F is usually sufficient.</strong></li>\n' +
@ -827,7 +841,10 @@ function fixHighlights() {
$(`code:contains(>>> logging.basicConfig()`).html(LOGGING_EXAMPLE);
$(`code:contains(samples_f = (sin(i *)`).html(AUDIO);
$(`code:contains(collections, dataclasses, enum, io, itertools)`).html(MARIO);
$(`code:contains(>>> gb = df.groupby)`).html(PLOTLY);
$(`code:contains(>>> gb = df.groupby)`).html(GROUPBY);
$(`code:contains(cdef <ctype> <var_name> = <el>)`).html(CYTHON_1);
$(`code:contains(cdef class <class_name>:)`).html(CYTHON_2);
$(`code:contains(cdef enum <enum_name>: <member_name>, <member_name>, ...)`).html(CYTHON_3);
$(`ul:contains(Only available in)`).html(INDEX);
}

Loading…
Cancel
Save