From 36f823c8d50272a9a932e1d542cefc54abf3ff65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jure=20=C5=A0orn?= Date: Mon, 2 Jun 2025 09:08:12 +0200 Subject: [PATCH] String, Cython --- README.md | 27 +++++++++++++++------------ index.html | 29 ++++++++++++++--------------- parse.js | 17 +++++++++++------ 3 files changed, 40 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index b385b3f..59939a1 100644 --- a/README.md +++ b/README.md @@ -327,11 +327,11 @@ String = in # Checks if string contains the substring. = .startswith() # Pass tuple of strings for multiple options. = .find() # Returns start index of the first match or -1. - = .index() # Same, but raises ValueError if there's no match. ``` ```python - = .lower() # Changes the case. Also upper/capitalize/title(). + = .lower() # Lowers the case. Also upper/capitalize/title(). + = .casefold() # Same, but converts ẞ/ß to ss, Σ/ς to σ, etc. = .replace(old, new [, count]) # Replaces 'old' with 'new' at most 'count' times. = .translate() # Use `str.maketrans()` to generate table. ``` @@ -2788,7 +2788,7 @@ from PIL import Image ### Modes * **`'L'` - Lightness (greyscale image). Each pixel is an integer between 0 and 255.** * **`'RGB'` - Red, green, blue (true color image). Each pixel is a tuple of three integers.** -* **`'RGBA'` - RGB with alpha. Low alpha (i.e. forth int) makes pixel more transparent.** +* **`'RGBA'` - RGB with alpha. Low alpha (i.e. fourth int) makes pixel more transparent.** * **`'HSV'` - Hue, saturation, value. Three ints representing color in HSV color space.** @@ -3410,7 +3410,7 @@ import plotly.express as px, pandas as pd ```python = px.line( [, y=col_key/s [, x=col_key]]) # Also px.line(y= [, x=]). -.update_layout(paper_bgcolor='rgb(0, 0, 0)') # Also `margin=dict(t=0, r=0, b=0, l=0)`. +.update_layout(paper_bgcolor='#rrggbb') # Also `margin=dict(t=0, r=0, b=0, l=0)`. .write_html/json/image('') # Use .show() to display the plot. ``` @@ -3518,21 +3518,24 @@ import # Script must be saved with '.pyx' extens .main() # Main() isn't automatically executed. ``` -#### Definitions: -* **All `'cdef'` definitions are optional, but they contribute to the speed-up.** -* **Also supports C pointers (via `'*'` and `'&'`), structs, unions and enums.** +#### All `'cdef'` definitions are optional, but they contribute to the speed-up: ```python -cdef [= ] +cdef [*] [= ] cdef [n_elements] [= ] -cdef ( ): ... +cdef ( [*]): ... ``` ```python cdef class : - cdef public - def __init__(self, ): - self. = + cdef public [*] + def __init__(self, [*]): + self. = [&] +``` + +```python +cdef struct : + [*] ``` ### Virtual Environments diff --git a/index.html b/index.html index eec6ff0..3947fff 100644 --- a/index.html +++ b/index.html @@ -56,7 +56,7 @@
- +
@@ -317,9 +317,9 @@ Point(x=1, y=2
<bool> = <sub_str> in <str>                  # Checks if string contains the substring.
 <bool> = <str>.startswith(<sub_str>)         # Pass tuple of strings for multiple options.
 <int>  = <str>.find(<sub_str>)               # Returns start index of the first match or -1.
-<int>  = <str>.index(<sub_str>)              # Same, but raises ValueError if there's no match.
 
-
<str>  = <str>.lower()                       # Changes the case. Also upper/capitalize/title().
+
<str>  = <str>.lower()                       # Lowers the case. Also upper/capitalize/title().
+<str>  = <str>.casefold()                    # Same, but converts ẞ/ß to ss, Σ/ς to σ, etc.
 <str>  = <str>.replace(old, new [, count])   # Replaces 'old' with 'new' at most 'count' times.
 <str>  = <str>.translate(<table>)            # Use `str.maketrans(<dict>)` to generate table.
 
@@ -2288,7 +2288,7 @@ right = np.array([[0.1, Modes
  • 'L' - Lightness (greyscale image). Each pixel is an integer between 0 and 255.
  • 'RGB' - Red, green, blue (true color image). Each pixel is a tuple of three integers.
  • -
  • 'RGBA' - RGB with alpha. Low alpha (i.e. forth int) makes pixel more transparent.
  • +
  • 'RGBA' - RGB with alpha. Low alpha (i.e. fourth int) makes pixel more transparent.
  • 'HSV' - Hue, saturation, value. Three ints representing color in HSV color space.

Examples

Creates a PNG image of a rainbow gradient:

WIDTH, HEIGHT = 100, 100
 n_pixels = WIDTH * HEIGHT
@@ -2789,7 +2789,7 @@ z
 
<Fig> = px.line(<DF> [, y=col_key/s [, x=col_key]])   # Also px.line(y=<list> [, x=<list>]).
-<Fig>.update_layout(paper_bgcolor='rgb(0, 0, 0)')     # Also `margin=dict(t=0, r=0, b=0, l=0)`.
+<Fig>.update_layout(paper_bgcolor='#rrggbb')          # Also `margin=dict(t=0, r=0, b=0, l=0)`.
 <Fig>.write_html/json/image('<path>')                 # Use <Fig>.show() to display the plot.
 
<Fig> = px.area/bar/box(<DF>, x=col_key, y=col_keys)  # Also `color=col_key`. All are optional.
@@ -2881,19 +2881,18 @@ px.line(df, x='Date', y=Definitions:
    -
  • All 'cdef' definitions are optional, but they contribute to the speed-up.
  • -
  • Also supports C pointers (via '*' and '&'), structs, unions and enums.
  • -
cdef <ctype/type> <var_name> [= <obj>]
+

All 'cdef' definitions are optional, but they contribute to the speed-up:

cdef <ctype/type> [*]<var_name> [= <obj>]
 cdef <ctype>[n_elements] <var_name> [= <coll_of_nums>]
-cdef <ctype/type/void> <func_name>(<ctype/type> <arg_name>): ...
+cdef <ctype/type/void> <func_name>(<ctype/type> [*]<arg_name>): ...
 
-
cdef class <class_name>:
-    cdef public <ctype/type> <attr_name>
-    def __init__(self, <ctype/type> <arg_name>):
-        self.<attr_name> = <arg_name>
+    cdef public <ctype/type> [*]<attr_name>
+    def __init__(self, <ctype/type> [*]<arg_name>):
+        self.<attr_name> = [&]<arg_name>
+
+
cdef struct <struct_name>:
+    <ctype> [*]<field_name>
 

Virtual Environments

System for installing libraries directly into project's directory.

$ python3 -m venv NAME      # Creates virtual environment in current directory.
 $ source NAME/bin/activate  # Activates it. On Windows run `NAME\Scripts\activate`.
@@ -2940,7 +2939,7 @@ $ deactivate                # Deactivates the active
  
 
   
 
diff --git a/parse.js b/parse.js
index a54d578..41bfb6b 100755
--- a/parse.js
+++ b/parse.js
@@ -327,15 +327,19 @@ const GROUPBY =
 
 
 const CYTHON_1 =
-  'cdef <ctype/type> <var_name> [= <obj>]\n' +
+  'cdef <ctype/type> [*]<var_name> [= <obj>]\n' +
   'cdef <ctype>[n_elements] <var_name> [= <coll_of_nums>]\n' +
-  'cdef <ctype/type/void> <func_name>(<ctype/type> <arg_name>): ...\n';
+  'cdef <ctype/type/void> <func_name>(<ctype/type> [*]<arg_name>): ...\n';
 
 const CYTHON_2 =
   'cdef class <class_name>:\n' +
-  '    cdef public <ctype/type> <attr_name>\n' +
-  '    def __init__(self, <ctype/type> <arg_name>):\n' +
-  '        self.<attr_name> = <arg_name>\n';
+  '    cdef public <ctype/type> [*]<attr_name>\n' +
+  '    def __init__(self, <ctype/type> [*]<arg_name>):\n' +
+  '        self.<attr_name> = [&]<arg_name>\n';
+
+const CYTHON_3 =
+  'cdef struct <struct_name>:\n' +
+  '    <ctype> [*]<field_name>\n';
 
 const INDEX =
   '
  • Ctrl+F / ⌘F is usually sufficient.
  • \n' + @@ -938,8 +942,9 @@ function fixHighlights() { $(`code:contains(samples_f = (sin(i *)`).html(AUDIO_2); $(`code:contains(collections, dataclasses, enum, io, itertools)`).html(MARIO); $(`code:contains(>>> gb = df.groupby)`).html(GROUPBY); - $(`code:contains(cdef [= ])`).html(CYTHON_1); + $(`code:contains(cdef [*] [= ])`).html(CYTHON_1); $(`code:contains(cdef class :)`).html(CYTHON_2); + $(`code:contains(cdef struct :)`).html(CYTHON_3); $(`ul:contains(Ctrl+F / ⌘F is usually sufficient.)`).html(INDEX); }