From 37036861e05b4a771d0d62d16d3ac676186d6a54 Mon Sep 17 00:00:00 2001 From: Idan Pazi Date: Wed, 3 Jul 2024 12:05:54 +0300 Subject: [PATCH] static demo on readme --- README.md | 112 ++++++++++++- docs/demo/asciinario.py | 20 ++- docs/demo/demo_dark.svg | 303 ------------------------------------ docs/demo/demo_html.sh | 16 ++ docs/demo/demo_light.svg | 303 ------------------------------------ docs/demo/demo_scenario.txt | 18 ++- docs/examples.md | 118 -------------- 7 files changed, 150 insertions(+), 740 deletions(-) delete mode 100644 docs/demo/demo_dark.svg create mode 100644 docs/demo/demo_html.sh delete mode 100644 docs/demo/demo_light.svg delete mode 100644 docs/examples.md diff --git a/README.md b/README.md index 8cf81ea..7d372c6 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,111 @@ Terminal calculator and advanced math solver using Python, IPython and SymPy. ## Usage -

- - - - demo - -

+
$ calcpy +In [1]: 4*2 + 3/4 + sqrt(2) +Out[1]: √2 + 35/4 ≈ 10.1642135623731 +In [2]: _/2 +Out[2]: +√2 35 +── + ── ≈ 5.08210678118655 +2 8 +In [3]: 3MB - 200KB +Out[3]: 2940928 0x002ce000 0000 0000 0010 1100 1110 0000 0000 0000 +In [4]: 45EUR +Out[4]: 48.2805000000000⋅USD +In [5]: diff(sin(x**y), y) +Out[5]: + y ⎛ y⎞ +x ⋅log(x)⋅cos⎝x ⎠ +In [6]: ((1,2),(2,4))*((5,6),(7,8)) +Out[6]: +⎡19 22⎤ +⎢ ⎥ +⎣38 44⎦ +In [7]: ((1,0),(a,b))^-1 +Out[7]: +⎡ 1 0⎤ +⎢ ⎥ +⎢-a 1⎥ +⎢─── ─⎥ +⎣ b b⎦ +In [8]: x^2+3x-1=0 +Out[8]: +⎡ 3 √13 √13 3⎤ +⎢- ─ + ───, - ─── - ─⎥ ≈ [0.302775637731995, -3.30277563773199] +⎣ 2 2 2 2⎦ +In [9]: tan(x)? +Out[9]: tan(x) + 2 +tan (x) + 1 = diff(_) +  +-log(cos(x)) = integrate(_) +  +π = periodicity(_, x) +  + 3 5 + x 2⋅x ⎛ 6⎞ +x + ── + ──── + O⎝x ⎠ + 3 15 = series(_) +  +[0] = solve(_) +In [10]: ((1,2),(2,3))? +Out[10]: +⎡1 2⎤ +⎢ ⎥ +⎣2 3⎦ +  +-1 = det(_) +4 = trace(_) +  +⎡-3 2 ⎤ +⎢ ⎥ +⎣2 -1⎦ = _**-1 +  + 2 +λ - 4⋅λ - 1 = _.charpoly().as_expr() +  +⎡⎛ ⎡⎡ √5 1⎤⎤⎞ ⎛ ⎡⎡ 1 √5⎤⎤⎞⎤ +⎢⎜ ⎢⎢- ── - ─⎥⎥⎟ ⎜ ⎢⎢- ─ + ──⎥⎥⎟⎥ +⎢⎜2 - √5, 1, ⎢⎢ 2 2⎥⎥⎟, ⎜2 + √5, 1, ⎢⎢ 2 2 ⎥⎥⎟⎥ +⎢⎜ ⎢⎢ ⎥⎥⎟ ⎜ ⎢⎢ ⎥⎥⎟⎥ +⎣⎝ ⎣⎣ 1 ⎦⎦⎠ ⎝ ⎣⎣ 1 ⎦⎦⎠⎦ = _.eigenvects() # ((eval, mult, evec),... +  -[Examples](docs/examples.md) · [Try online](http://calcpy.duckdns.org) +⎛⎡ √5 1 1 √5⎤ ⎞ +⎜⎢- ── - ─ - ─ + ──⎥ ⎡2 - √5 0 ⎤⎟ +⎜⎢ 2 2 2 2 ⎥, ⎢ ⎥⎟ +⎜⎢ ⎥ ⎣ 0 2 + √5⎦⎟ +⎝⎣ 1 1 ⎦ ⎠ = _.diagonalize() # (P,D) so _=PDP^-1 +In [11]: \$\frac{1}{x}$ * $\sin{x}$ +Out[11]: +sin(x) +────── + x +In [12]: diff(_) +Out[12]: +cos(x) sin(x) +────── - ────── + x 2 + x +In [13]: latex(_) +Out[13]: \frac{\cos{\left(x \right)}}{x} - \frac{\sin{\left(x \right)}}{x^{2}} +In [14]: +
+
+ +[Try online](http://calcpy.duckdns.org) ## Installation Prerequisites - [Python](https://www.python.org/downloads/) diff --git a/docs/demo/asciinario.py b/docs/demo/asciinario.py index 5fc6400..1cf8dc2 100644 --- a/docs/demo/asciinario.py +++ b/docs/demo/asciinario.py @@ -49,7 +49,7 @@ def do_status_type(self, match): time.sleep(self.type_wait) def do_type(self, match): - need_escape = "^" + need_escape = "^\\" flags = set(match[1]) message = match[2] for c in message: @@ -118,14 +118,21 @@ def play_inscript(text, screen_id): player.do(line) parser = ArgumentParser() +parser.add_argument('-t', '--type', default='asciinema', help="type of recorder") +parser.add_argument("--keep", action="store_true", help="don't kill session") parser.add_argument("scenario") parser.add_argument("output") args, args_reminder = parser.parse_known_args() instructions = Path(args.scenario).read_text() screen_id = str(uuid4()) -cmd = f"screen -S {screen_id}" -recorder_proc = subprocess.Popen(["asciinema", "rec", "--overwrite", "--cols", "80", "--rows", "20", "-c", cmd, args.output]) +if args.type == 'asciinema': + cmd = f"screen -S {screen_id}" + recorder_proc = subprocess.Popen(["asciinema", "rec", "--overwrite", "--cols", "80", "--rows", "20", "-c", cmd, args.output]) +elif args.type == 'screen': + recorder_proc = subprocess.Popen(["screen", "-L", "-Logfile", args.output, "-S", screen_id]) +elif args.type == 'script': + recorder_proc = subprocess.Popen(["screen", "-S", screen_id]) # give some time for screen to start for _ in range(10): @@ -140,6 +147,11 @@ def play_inscript(text, screen_id): else: sys.exit(f"screen session {screen_id} could not be found") +if args.type == 'script': + subprocess.check_output(["screen", "-S", screen_id, "-X", "stuff", rf"script {args.output}\n"]) + time.sleep(.5) + play_inscript(instructions, screen_id) -subprocess.check_output(["screen", "-S", screen_id, "-X", "quit"]) +if not args.keep: + subprocess.check_output(["screen", "-S", screen_id, "-X", "quit"]) recorder_proc.wait() diff --git a/docs/demo/demo_dark.svg b/docs/demo/demo_dark.svg deleted file mode 100644 index 35eb6ca..0000000 --- a/docs/demo/demo_dark.svg +++ /dev/null @@ -1,303 +0,0 @@ - - - - - - - - - - - $ $ c $ ca $ cal $ calc $ calcp $ calcpy $ calcpyIn [1]: In [1]: 4 4In [1]: 4* In [1]: 4*2 8In [1]: 4*2 In [1]: 4*2 + In [1]: 4*2 + In [1]: 4*2 + 3 11In [1]: 4*2 + 3/ In [1]: 4*2 + 3/4 8.75 In [1]: 4*2 + 3/4 In [1]: 4*2 + 3/4 + In [1]: 4*2 + 3/4 + In [1]: 4*2 + 3/4 + s In [1]: 4*2 + 3/4 + sq In [1]: 4*2 + 3/4 + sqr In [1]: 4*2 + 3/4 + sqrt s + 8.75 In [1]: 4*2 + 3/4 + sqrt( In [1]: 4*2 + 3/4 + sqrt(2 In [1]: 4*2 + 3/4 + sqrt(2) 10.1642 In [1]: 4*2 + 3/4 + sqrt(2) Out[1]: Out[1]: √2 + 35/4 ≈ 10.1642 In [2]: In [2]: _ In [2]: _/ In [2]: _/2 5.08211 In [2]: _/2 Out[2]: Out[2]: √2 35 ── + ── ≈ 5.082112 8 In [3]: In [3]: 3 3 In [3]: 3M 3⋅M In [3]: 3MB 3.14573e+06 In [3]: 3MB In [3]: 3MB - In [3]: 3MB - In [3]: 3MB - 2 In [3]: 3MB - 20 3.14571e+06 In [3]: 3MB - 200 3.14553e+06 In [3]: 3MB - 200K 3.14573e+06 - 200⋅K In [3]: 3MB - 200KB 2.94093e+06 In [3]: 3MB - 200KB Out[3]: Out[3]: 2940928 0x002ce000 0000 0000 0010 1100 1110 0000 0000 0000 In [4]: In [4]: 4*2 + 3/4 + sqrt(2) 4 In [4]: 45 45 In [4]: 45E In [4]: 45EU In [4]: 45EUR 50.0535⋅USD In [4]: 45EUR Out[4]: Out[4]: 50.0535⋅USD In [5]: In [5]: d d In [5]: di In [5]: dif In [5]: diff <function sympy.core.function.diff(f, *symbols, **kwargs)> In [5]: diff( In [5]: diff(s In [5]: diff(si In [5]: diff(sin In [5]: diff(sin( In [5]: diff(sin(x In [5]: diff(sin(x* In [5]: diff(sin(x** In [5]: diff(sin(x**y In [5]: diff(sin(x**y) In [5]: diff(sin(x**y), In [5]: diff(sin(x**y), In [5]: diff(sin(x**y), y In [5]: diff(sin(x**y), y) x**y*log(x)*cos(x**y) In [5]: diff(sin(x**y), y) Out[5]: Out[5]: y ⎛ y⎞x ⋅log(x)⋅cos⎝x ⎠In [6]: In [6]: ( In [6]: (( In [6]: ((1 In [6]: ((1, In [6]: ((1,0 In [6]: ((1,0) In [6]: ((1,0), In [6]: ((1,0),( In [6]: ((1,0),(a In [6]: ((1,0),(a, In [6]: ((1,0),(a,b In [6]: ((1,0),(a,b) In [6]: ((1,0),(a,b)) ((1, 0), (a, b)) In [6]: ((1,0),(a,b))^ In [6]: ((1,0),(a,b))^- In [6]: ((1,0),(a,b))^-1 ((1, 0), (-a/b, 1/b)) In [6]: ((1,0),(a,b))^-1 Out[6]: Out[6]: ⎡ 1 0⎤⎢ ⎥ ⎢-a 1⎥⎢─── ─⎥⎣ b b⎦In [7]: In [7]: _/2 ((1, 0), (-a/b, 1/b))In [7]: _^ In [7]: _^2 ((1, 0), (-a/b - a/b**2, b**(-2))) In [7]: _^2 Out[7]: Out[7]: ⎡ 1 0 ⎤ ⎡ 1 0 ⎤⎢ ⎥ ⎢ ⎥⎢ a a 1 ⎥ ⎢a⋅(-b - 1) 1 ⎥⎢- ─ - ── ──⎥ = ⎢────────── ──⎥⎢ b 2 2⎥ ⎢ 2 2⎥⎣ b b ⎦ ⎣ b b ⎦In [8]: In [8]: x xIn [8]: x^ In [8]: x^2 x**2In [8]: x^2+ In [8]: x^2+3 x**2 + 3.0 In [8]: x^2+3x x**2 + 3.0*x In [8]: x^2+3x- In [8]: x^2+3x-1 x**2 + 3.0*x - 1.0 In [8]: x^2+3x-1= In [8]: x^2+3x-1=0 In [8]: x^2+3x-1=0 Out[8]: Out[8]: ⎡ 3 √13 √13 3⎤ ⎢- ─ + ───, - ─── - ─⎥ ≈ [0.302776, -3.30278]⎣ 2 2 2 2⎦ In [9]: In [9]: ? In [9]: ?t tIn [9]: ?ta In [9]: ?tan tanIn [9]: ?tan( In [9]: ?tan(x In [9]: ?tan(x) tan(x) In [9]: ?tan(x) Out[9]: Out[9]: tan(x) 2 tan (x) + 1 = diff(_)-log(cos(x)) = integrate(_)π = periodicity(_, x) 3 5 x 2⋅x ⎛ 6⎞x + ── + ──── + O⎝x ⎠ 3 15 = series(_)[0] = solve(_)In [10]: In [10]: - \ No newline at end of file diff --git a/docs/demo/demo_html.sh b/docs/demo/demo_html.sh new file mode 100644 index 0000000..2e8fe1b --- /dev/null +++ b/docs/demo/demo_html.sh @@ -0,0 +1,16 @@ +echo "export PS1=\"$ \"" >> ~/.bashrc +calcpy -c 'calcpy.reset(False)' +calcpy -c 'calcpy.base_currency="usd"' +calcpy -c 'calcpy.previewer=False' +cp -f $(dirname "$0")/demo_config.py $(ipython locate)/profile_calcpy/ipython_config.py +rm -f $(ipython locate)/profile_calcpy/history.sqlite +rm -f demo_out +python asciinario.py --type screen demo_scenario.txt demo_out + +# using https://github.com/theZiz/aha +# cat demo_out | aha > demo_out.html + +cat demo_out | $(dirname "$0")/terminal-to-html -preview > demo_out.html + +# remove the export from bashrc +head -n -1 ~/.bashrc > temp.txt ; mv temp.txt ~/.bashrc diff --git a/docs/demo/demo_light.svg b/docs/demo/demo_light.svg deleted file mode 100644 index 82a39c7..0000000 --- a/docs/demo/demo_light.svg +++ /dev/null @@ -1,303 +0,0 @@ - - - - - - - - - - - $ $ c $ ca $ cal $ calc $ calcp $ calcpy $ calcpyIn [1]: In [1]: 4 4In [1]: 4* In [1]: 4*2 8In [1]: 4*2 In [1]: 4*2 + In [1]: 4*2 + In [1]: 4*2 + 3 11In [1]: 4*2 + 3/ In [1]: 4*2 + 3/4 8.75 In [1]: 4*2 + 3/4 In [1]: 4*2 + 3/4 + In [1]: 4*2 + 3/4 + In [1]: 4*2 + 3/4 + s In [1]: 4*2 + 3/4 + sq In [1]: 4*2 + 3/4 + sqr In [1]: 4*2 + 3/4 + sqrt s + 8.75 In [1]: 4*2 + 3/4 + sqrt( In [1]: 4*2 + 3/4 + sqrt(2 In [1]: 4*2 + 3/4 + sqrt(2) 10.1642 In [1]: 4*2 + 3/4 + sqrt(2) Out[1]: Out[1]: √2 + 35/4 ≈ 10.1642 In [2]: In [2]: _ In [2]: _/ In [2]: _/2 5.08211 In [2]: _/2 Out[2]: Out[2]: √2 35 ── + ── ≈ 5.082112 8 In [3]: In [3]: 3 3 In [3]: 3M 3⋅M In [3]: 3MB 3.14573e+06 In [3]: 3MB In [3]: 3MB - In [3]: 3MB - In [3]: 3MB - 2 In [3]: 3MB - 20 3.14571e+06 In [3]: 3MB - 200 3.14553e+06 In [3]: 3MB - 200K 3.14573e+06 - 200⋅K In [3]: 3MB - 200KB 2.94093e+06 In [3]: 3MB - 200KB Out[3]: Out[3]: 2940928 0x002ce000 0000 0000 0010 1100 1110 0000 0000 0000 In [4]: In [4]: 4*2 + 3/4 + sqrt(2) 4 In [4]: 45 45 In [4]: 45E In [4]: 45EU In [4]: 45EUR 50.0535⋅USD In [4]: 45EUR Out[4]: Out[4]: 50.0535⋅USD In [5]: In [5]: d d In [5]: di In [5]: dif In [5]: diff <function sympy.core.function.diff(f, *symbols, **kwargs)> In [5]: diff( In [5]: diff(s In [5]: diff(si In [5]: diff(sin In [5]: diff(sin( In [5]: diff(sin(x In [5]: diff(sin(x* In [5]: diff(sin(x** In [5]: diff(sin(x**y In [5]: diff(sin(x**y) In [5]: diff(sin(x**y), In [5]: diff(sin(x**y), In [5]: diff(sin(x**y), y In [5]: diff(sin(x**y), y) x**y*log(x)*cos(x**y) In [5]: diff(sin(x**y), y) Out[5]: Out[5]: y ⎛ y⎞x ⋅log(x)⋅cos⎝x ⎠In [6]: In [6]: ( In [6]: (( In [6]: ((1 In [6]: ((1, In [6]: ((1,0 In [6]: ((1,0) In [6]: ((1,0), In [6]: ((1,0),( In [6]: ((1,0),(a In [6]: ((1,0),(a, In [6]: ((1,0),(a,b In [6]: ((1,0),(a,b) In [6]: ((1,0),(a,b)) ((1, 0), (a, b)) In [6]: ((1,0),(a,b))^ In [6]: ((1,0),(a,b))^- In [6]: ((1,0),(a,b))^-1 ((1, 0), (-a/b, 1/b)) In [6]: ((1,0),(a,b))^-1 Out[6]: Out[6]: ⎡ 1 0⎤⎢ ⎥ ⎢-a 1⎥⎢─── ─⎥⎣ b b⎦In [7]: In [7]: _/2 ((1, 0), (-a/b, 1/b))In [7]: _^ In [7]: _^2 ((1, 0), (-a/b - a/b**2, b**(-2))) In [7]: _^2 Out[7]: Out[7]: ⎡ 1 0 ⎤ ⎡ 1 0 ⎤⎢ ⎥ ⎢ ⎥⎢ a a 1 ⎥ ⎢a⋅(-b - 1) 1 ⎥⎢- ─ - ── ──⎥ = ⎢────────── ──⎥⎢ b 2 2⎥ ⎢ 2 2⎥⎣ b b ⎦ ⎣ b b ⎦In [8]: In [8]: x xIn [8]: x^ In [8]: x^2 x**2In [8]: x^2+ In [8]: x^2+3 x**2 + 3.0 In [8]: x^2+3x x**2 + 3.0*x In [8]: x^2+3x- In [8]: x^2+3x-1 x**2 + 3.0*x - 1.0 In [8]: x^2+3x-1= In [8]: x^2+3x-1=0 In [8]: x^2+3x-1=0 Out[8]: Out[8]: ⎡ 3 √13 √13 3⎤ ⎢- ─ + ───, - ─── - ─⎥ ≈ [0.302776, -3.30278]⎣ 2 2 2 2⎦ In [9]: In [9]: ? In [9]: ?t tIn [9]: ?ta In [9]: ?tan tanIn [9]: ?tan( In [9]: ?tan(x In [9]: ?tan(x) tan(x) In [9]: ?tan(x) Out[9]: Out[9]: tan(x) 2 tan (x) + 1 = diff(_)-log(cos(x)) = integrate(_)π = periodicity(_, x) 3 5 x 2⋅x ⎛ 6⎞x + ── + ──── + O⎝x ⎠ 3 15 = series(_)[0] = solve(_)In [10]: In [10]: - \ No newline at end of file diff --git a/docs/demo/demo_scenario.txt b/docs/demo/demo_scenario.txt index 0b6045f..f84a9ec 100644 --- a/docs/demo/demo_scenario.txt +++ b/docs/demo/demo_scenario.txt @@ -4,7 +4,7 @@ set enter_wait = 2 wait .5 $>> calcpy -wait 5.5 +wait 6 $> 4*2 + 3/4 + sqrt(2) @@ -16,11 +16,21 @@ $> 45EUR $> diff(sin(x**y), y) -$> ((1,0),(a,b))^-1 +$> ((1,2),(2,4))*((5,6),(7,8)) -$> _^2 +$> ((1,0),(a,b))^-1 $> x^2+3x-1=0 -$> ?tan(x) +$> tan(x)? +wait 6 + +$> ((1,2),(2,3))? wait 6 + +$> $\frac{1}{x}$ * $\sin{x}$ + +$> diff(_) + +$> latex(_) +wait 5 diff --git a/docs/examples.md b/docs/examples.md deleted file mode 100644 index 842d434..0000000 --- a/docs/examples.md +++ /dev/null @@ -1,118 +0,0 @@ -## Algebra -Matrices: - -``` -In [1]: ((1,2),(2,4))*((5,6),(7,8)) -Out[1]: -⎡19 22⎤ -⎢ ⎥ -⎣38 44⎦ -``` - -``` -In [1]: ((a,b),(c,d))**-1 -Out[1]: -⎡ d -b ⎤ -⎢───────── ─────────⎥ -⎢a*d - b*c a*d - b*c⎥ -⎢ ⎥ -⎢ -c a ⎥ -⎢───────── ─────────⎥ -⎣a*d - b*c a*d - b*c⎦ -``` - -``` -In [1]: ((1,2),(2,4))*((x,y),).T -Out[1]: -⎡ x + 2*y ⎤ -⎢ ⎥ -⎣2*x + 4*y⎦ -``` -Detailed information about matrix: -``` -In [1]: ?((1,2),(2,3)) -``` - -## Calculus - -``` -In [1]: diff(sin(x)) -Out[1]: cos(x) -``` - -Detailed information about function: -``` -In [1]: ?e**(x**2) -``` - -This is equivalent to `solve(Eq(8x**2+2x-10,0))` -``` -In [1]: 8x**2+2x-10 = 0 -Out[1]: [-5/4, 1] ≈ [-1.25, 1] -``` - -## Plotting -``` -In [1]: plot(sin(x)) -``` - -save the last figure with -``` -In [1]: plt.savefig('fig.png') -``` - -## Programmer -``` -In [1]: (34MB - 7000KB)/2MB -Out[1]: -3477 -──── ≈ 13.582 -256 -``` - -``` -In [1]: (0xab00 >> 8) & 0xff -Out[1]: 171 0xab 1010 1011 -``` - -## Currency - -``` -In [1]: 400EUR -Out[1]: 428.88⋅USD -In [2]: 100USD -Out[2]: [93.2662⋅EUR 79.1597⋅GBP 669.94⋅CNY 12688.9⋅JPY] -``` -base_currency and common_currencies are set automatically. -Setting different base currency and the common currencies: -``` -In [1]: calcpy.base_currency = 'EUR' -In [2]: calcpy.common_currencies = ["USD", "ILS"] -``` -## Latex -``` -In [1]: $\frac{1}{x}$ * $\sin{x}$ -Out[1]: -sin(x) -────── - x -In [2]: diff(_) -Out[2]: -cos(x) sin(x) x⋅cos(x) - sin(x) -────── - ────── ───────────────── - x 2 = 2 - x x -In [3]: latex(_) -Out[3]: \frac{\cos{\left(x \right)}}{x} - \frac{\sin{\left(x \right)}}{x^{2}} -``` - -## Misc - -``` -In [1]: sin(60deg) -Out[1]: -√3 -── -2 ≈ 0.866025 -``` -