Skip to content

Commit

Permalink
static demo on readme
Browse files Browse the repository at this point in the history
  • Loading branch information
idanpa committed Jul 3, 2024
1 parent 4985467 commit 3703686
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 740 deletions.
112 changes: 104 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,111 @@
Terminal calculator and advanced math solver using Python, IPython and SymPy.

## Usage
<p align="center">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="docs/demo/demo_dark.svg">
<source media="(prefers-color-scheme: light)" srcset="docs/demo/demo_light.svg">
<img alt="demo" width="640" height="340" src="docs/demo/demo_light.svg">
</picture>
</p>
<div style='background: #171717;
border-radius: 5px;
color: white;
word-break: break-word;
overflow-wrap: break-word;
font-family: "SFMono-Regular", Monaco, Menlo, Consolas, "Liberation Mono", Courier, monospace;
font-size: 12px;
line-height: 20px;
padding: 14px 18px;
white-space: pre-wrap;
overflow-y: scroll;
height:400px;'>$ calcpy
<span style='color: #b0f986;'>In [</span><span style='color: #00FF00;'>1</span><span style='color: #b0f986;'>]: 4</span>*<span style='color: #b0f986;'>2</span> + <span style='color: #b0f986;'>3</span>&#47;<span style='color: #b0f986;'>4</span> + sqrt(<span style='color: #b0f986;'>2</span>)
<span style='color: #ff7070;'>Out[</span><span style='color: #ff3333;'>1</span><span style='color: #ff7070;'>]: </span>√2 + 35&#47;4 ≈ 10.1642135623731
<span style='color: #b0f986;'>In [</span><span style='color: #00FF00;'>2</span><span style='color: #b0f986;'>]: </span>_&#47;<span style='color: #b0f986;'>2</span>
<span style='color: #ff7070;'>Out[</span><span style='color: #ff3333;'>2</span><span style='color: #ff7070;'>]: </span>
√2 35
── + ── ≈ 5.08210678118655
2 8
<span style='color: #b0f986;'>In [</span><span style='color: #00FF00;'>3</span><span style='color: #b0f986;'>]: 3</span>MB - <span style='color: #b0f986;'>200</span>KB
<span style='color: #ff7070;'>Out[</span><span style='color: #ff3333;'>3</span><span style='color: #ff7070;'>]: </span>2940928 0x002ce000 0000 0000 0010 1100 1110 0000 0000 0000
<span style='color: #b0f986;'>In [</span><span style='color: #00FF00;'>4</span><span style='color: #b0f986;'>]: 45</span>EUR
<span style='color: #ff7070;'>Out[</span><span style='color: #ff3333;'>4</span><span style='color: #ff7070;'>]: </span>48.2805000000000⋅USD
<span style='color: #b0f986;'>In [</span><span style='color: #00FF00;'>5</span><span style='color: #b0f986;'>]: </span>diff(sin(x**y), y)
<span style='color: #ff7070;'>Out[</span><span style='color: #ff3333;'>5</span><span style='color: #ff7070;'>]: </span>
y ⎛ y⎞
x ⋅log(x)⋅cos⎝x ⎠
<span style='color: #b0f986;'>In [</span><span style='color: #00FF00;'>6</span><span style='color: #b0f986;'>]: </span>((<span style='color: #b0f986;'>1</span>,<span style='color: #b0f986;'>2</span>),(<span style='color: #b0f986;'>2</span>,<span style='color: #b0f986;'>4</span>))*((<span style='color: #b0f986;'>5</span>,<span style='color: #b0f986;'>6</span>),(<span style='color: #b0f986;'>7</span>,<span style='color: #b0f986;'>8</span>))
<span style='color: #ff7070;'>Out[</span><span style='color: #ff3333;'>6</span><span style='color: #ff7070;'>]: </span>
⎡19 22⎤
⎢ ⎥
⎣38 44⎦
<span style='color: #b0f986;'>In [</span><span style='color: #00FF00;'>7</span><span style='color: #b0f986;'>]: </span>((<span style='color: #b0f986;'>1</span>,<span style='color: #b0f986;'>0</span>),(a,b))^-<span style='color: #b0f986;'>1</span>
<span style='color: #ff7070;'>Out[</span><span style='color: #ff3333;'>7</span><span style='color: #ff7070;'>]: </span>
⎡ 1 0⎤
⎢ ⎥
⎢-a 1⎥
⎢─── ─⎥
⎣ b b⎦
<span style='color: #b0f986;'>In [</span><span style='color: #00FF00;'>8</span><span style='color: #b0f986;'>]: </span>x^<span style='color: #b0f986;'>2</span>+<span style='color: #b0f986;'>3</span>x-<span style='color: #b0f986;'>1</span>=<span style='color: #b0f986;'>0</span>
<span style='color: #ff7070;'>Out[</span><span style='color: #ff3333;'>8</span><span style='color: #ff7070;'>]: </span>
⎡ 3 √13 √13 3⎤
⎢- ─ + ───, - ─── - ─⎥ ≈ [0.302775637731995, -3.30277563773199]
⎣ 2 2 2 2⎦
<span style='color: #b0f986;'>In [</span><span style='color: #00FF00;'>9</span><span style='color: #b0f986;'>]: </span>tan(x)?
<span style='color: #ff7070;'>Out[</span><span style='color: #ff3333;'>9</span><span style='color: #ff7070;'>]: </span>tan(x)
2
tan (x) + 1 = diff(_)
&nbsp;
-log(cos(x)) = integrate(_)
&nbsp;
π = periodicity(_, x)
&nbsp;
3 5
x 2⋅x ⎛ 6⎞
x + ── + ──── + O⎝x ⎠
3 15 = series(_)
&nbsp;
[0] = solve(_)
<span style='color: #b0f986;'>In [</span><span style='color: #00FF00;'>10</span><span style='color: #b0f986;'>]: </span>((<span style='color: #b0f986;'>1</span>,<span style='color: #b0f986;'>2</span>),(<span style='color: #b0f986;'>2</span>,<span style='color: #b0f986;'>3</span>))?
<span style='color: #ff7070;'>Out[</span><span style='color: #ff3333;'>10</span><span style='color: #ff7070;'>]: </span>
⎡1 2⎤
⎢ ⎥
⎣2 3⎦
&nbsp;
-1 = det(_)
4 = trace(_)
&nbsp;
⎡-3 2 ⎤
⎢ ⎥
⎣2 -1⎦ = _**-1
&nbsp;
2
λ - 4⋅λ - 1 = _.charpoly().as_expr()
&nbsp;
⎡⎛ ⎡⎡ √5 1⎤⎤⎞ ⎛ ⎡⎡ 1 √5⎤⎤⎞⎤
⎢⎜ ⎢⎢- ── - ─⎥⎥⎟ ⎜ ⎢⎢- ─ + ──⎥⎥⎟⎥
⎢⎜2 - √5, 1, ⎢⎢ 2 2⎥⎥⎟, ⎜2 + √5, 1, ⎢⎢ 2 2 ⎥⎥⎟⎥
⎢⎜ ⎢⎢ ⎥⎥⎟ ⎜ ⎢⎢ ⎥⎥⎟⎥
⎣⎝ ⎣⎣ 1 ⎦⎦⎠ ⎝ ⎣⎣ 1 ⎦⎦⎠⎦ = _.eigenvects() # ((eval, mult, evec),...
&nbsp;

[Examples](docs/examples.md)&emsp;·&emsp;[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
<span style='color: #b0f986;'>In [</span><span style='color: #00FF00;'>11</span><span style='color: #b0f986;'>]: </span>\$\frac{<span style='color: #b0f986;'>1</span>}{x}$ * $\sin{x}$
<span style='color: #ff7070;'>Out[</span><span style='color: #ff3333;'>11</span><span style='color: #ff7070;'>]: </span>
sin(x)
──────
x
<span style='color: #b0f986;'>In [</span><span style='color: #00FF00;'>12</span><span style='color: #b0f986;'>]: </span>diff(_)
<span style='color: #ff7070;'>Out[</span><span style='color: #ff3333;'>12</span><span style='color: #ff7070;'>]: </span>
cos(x) sin(x)
────── - ──────
x 2
x
<span style='color: #b0f986;'>In [</span><span style='color: #00FF00;'>13</span><span style='color: #b0f986;'>]: </span>latex(_)
<span style='color: #ff7070;'>Out[</span><span style='color: #ff3333;'>13</span><span style='color: #ff7070;'>]: </span>\frac{\cos{\left(x \right)}}{x} - \frac{\sin{\left(x \right)}}{x^{2}}
<span style='color: #b0f986;'>In [</span><span style='color: #00FF00;'>14</span><span style='color: #b0f986;'>]: </span>
</div>
<br>

[Try online](http://calcpy.duckdns.org)

## Installation
Prerequisites - [Python](https://www.python.org/downloads/)
Expand Down
20 changes: 16 additions & 4 deletions docs/demo/asciinario.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -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()
Loading

0 comments on commit 3703686

Please sign in to comment.