<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://milia.dev/blog/feed.xml" rel="self" type="application/atom+xml" /><link href="https://milia.dev/blog/" rel="alternate" type="text/html" /><updated>2026-11-16T23:12:01+00:00</updated><id>https://milia.dev/blog/feed.xml</id><title type="html">Blog</title><subtitle>Notes and writing.</subtitle><author><name>Milia</name></author><entry><title type="html">How to instrument a FastAPI python application with Elastic APM</title><link href="https://milia.dev/blog/2025/07/11/fastapi-elastic-apm/" rel="alternate" type="text/html" title="How to instrument a FastAPI python application with Elastic APM" /><published>2025-07-11T08:40:38+00:00</published><updated>2025-07-11T08:40:38+00:00</updated><id>https://milia.dev/blog/2025/07/11/fastapi-elastic-apm</id><content type="html" xml:base="https://milia.dev/blog/2025/07/11/fastapi-elastic-apm/"><![CDATA[<h2 id="1-create-an-elasticsearch-deployment">1. Create an Elasticsearch deployment</h2>

<p>Either in <a href="https://www.elastic.co/docs/deploy-manage/deploy/elastic-cloud/create-an-elastic-cloud-hosted-deployment">ECH</a> or in other platforms (<a href="https://www.elastic.co/guide/en/cloud-on-k8s/1.0/k8s-apm-server.html">ECK</a>, ECE, etc).</p>

<p>It should have an APM server.</p>

<h2 id="2-go-to-the-apm-page">2. Go to the APM page</h2>

<p>Capture the following information from the Elastic APM page from Kibana:</p>

<pre><code class="language-bash">SERVICE_NAME=&lt;YOUR_SERVICE_NAME&gt;
SERVER_URL=&lt;APM_SERVER_ENDPOINT&gt;
SECRET_TOKEN=&lt;APM_TOKEN&gt;
</code></pre>

<h2 id="3-install-apm-python-library">3. Install apm python library</h2>

<p>In your virtualenv run:</p>

<pre><code class="language-bash">pip install elastic-apm
</code></pre>

<h2 id="4-go-to-your-python-app">4. Go to your python app</h2>

<p>Inside your <code>app.py</code> file add:</p>

<pre><code class="language-python">from elasticapm.contrib.starlette import ElasticAPM
app = FastAPI() # this should already exist
app.add_middleware(ElasticAPM) # APM
</code></pre>

<h2 id="5-set-environment-variables">5. Set environment variables</h2>

<p>In a CLI write:</p>

<pre><code class="language-bash"> export ELASTIC_APM_SERVICE_NAME=&lt;YOUR_SERVICE_NAME&gt;
 export ELASTIC_APM_SERVER_URL=&lt;APM_SERVER_ENDPOINT&gt;
 export ELASTIC_APM_SECRET_TOKEN=&lt;APM_TOKEN&gt;
</code></pre>

<h2 id="6-run-app">6. Run app</h2>

<pre><code class="language-bash">python3 app.py
</code></pre>

<p>And send some responses.</p>

<h2 id="7-check-apm">7. Check APM</h2>

<p>Go to <code>Observability &gt; Aoplications &gt; Service Inventory</code> and see your service.</p>]]></content><author><name>Milia</name></author><summary type="html"><![CDATA[1. Create an Elasticsearch deployment Either in ECH or in other platforms (ECK, ECE, etc). It should have an APM server. 2. Go to the APM page Capture the following information from the Elastic APM page from Kibana: SERVICE_NAME=&lt;YOUR_SERVICE_NAME&gt; SERVER_URL=&lt;APM_SERVER_ENDPOINT&gt; SECRET_TOKEN=&lt;APM_TOKEN&gt; 3. Install apm python library In your virtualenv run: pip install elastic-apm 4. Go to your python app Inside your app.py file add: from elasticapm.contrib.starlette import ElasticAPM app = FastAPI() # this should already exist app.add_middleware(ElasticAPM) # APM 5. Set environment variables In a CLI write: export ELASTIC_APM_SERVICE_NAME=&lt;YOUR_SERVICE_NAME&gt; export ELASTIC_APM_SERVER_URL=&lt;APM_SERVER_ENDPOINT&gt; export ELASTIC_APM_SECRET_TOKEN=&lt;APM_TOKEN&gt; 6. Run app python3 app.py And send some responses. 7. Check APM Go to Observability &gt; Aoplications &gt; Service Inventory and see your service.]]></summary></entry><entry><title type="html">Square free numbers problem (in J)</title><link href="https://milia.dev/blog/2022/09/27/square-free-numbers-j/" rel="alternate" type="text/html" title="Square free numbers problem (in J)" /><published>2022-09-27T06:29:08+00:00</published><updated>2022-09-27T06:29:08+00:00</updated><id>https://milia.dev/blog/2022/09/27/square-free-numbers-j</id><content type="html" xml:base="https://milia.dev/blog/2022/09/27/square-free-numbers-j/"><![CDATA[<pre><code class="language-j">NB. This problem was read in  the blogpost (https://www.glc.us.es/~jalonso/exercitium/numeros-libres-de-cuadrados/) of @Jose_A_Alonso.
NB. Problem statement: given a positive integer N, it's called square-free if no square number (eg 2^2, 11^11) can be created from its prime divisors.
NB. Created using the J903 online playground (https://jsoftware.github.io/j-playground/bin/html2/). 

NB. Let's get the matrix of the prime divisors of an array of integers
q: @&gt;  10 30 40 1000 11 121
NB.  2  5 0 0 0 0
NB.  2  3 5 0 0 0
NB.  2  2 2 5 0 0
NB.  2  2 2 5 5 5
NB. 11  0 0 0 0 0
NB. 11 11 0 0 0 0

NB. First solution
sqfr1 =: {{
    arr=. q: y NB. prime divisor decomposition of y
    max=. &gt;./ arr NB. return biggest prime divisor
    filter=. 1+i.max NB. array from 1 to the maximum prime divisor of arr
    bool_mat=. filter =/ arr NB. boolean matrix of multiples
    transbool=. |: bool_mat NB. transpose bool matrix
    add_ones=. +/ transbool NB. add ones per column
    ge_two =. 2 &lt;: add_ones NB. the elements of res are greater eq to 2
    one_in=. 1 e. ge_two NB. 1 is a member of ge_two array
    -. one_in NB. NOT(one_in)
}}
sqfr1 @&gt;  10 30 40 1000 11 121 NB. 1 1 0 0 1 0

NB. Second solution, adaptation of the 4th solution of Jose from Haskell.
NB. It compares the product of the unique prime divisors of the number N with the number N. 
NB. If there are no multiples (and thus squares) they're the same.
sqfr2 =: {{ y = */ {./.~ q: y }}
sqfr2 @&gt;  10 30 40 1000 11 121 NB. 1 1 0 0 1 0

NB. Third solution. 
NB. Just compare the length of the array with the unique prime divisors of the number N
NB. with the full array of its prime divisors. Not that pretty as the second solution due 
NB. to the use of the parentheses.
sqfr3 =: {{ (# q: y) = (# {./.~ q: y) }}
sqfr3 @&gt;  10 30 40 1000 11 121 NB. 1 1 0 0 1 0

NB. Refactoring
NB. -----------
NB. Both of these solutions are due to moon-child from libera/#jsoftware.
NB.
NB. The first one, sqfr3_tacit is the tacit form of sqfr3 that uses 
NB. a fork (https://code.jsoftware.com/wiki/Help/Primer/Fork), 
NB. compose "&amp;" (https://code.jsoftware.com/wiki/Vocabulary/ampv) and 
NB. at "@:" (https://code.jsoftware.com/wiki/Vocabulary/atco).
NB. The second one, sqfr3_tacit2 is a refactored version of sqfr3_tacit. 
sqfr3_tacit =: q: =&amp;# {./.~@:q:
sqfr3_tacit @&gt;  10 30 40 1000 11 121 NB. 1 1 0 0 1 0

sqfr3_tacit2 =: (=&amp;# {./.~)@:q:
sqfr3_tacit2 @&gt;  10 30 40 1000 11 121 NB. 1 1 0 0 1 0

NB. Automatic tacit form translation
NB. --------------------------------
NB.
NB. Thanks to moon-child and nickspoon from libera/#jsoftware that drew
NB. my attention to https://www.jsoftware.com/help/dictionary/intro19.htm

9!:3 ] 2 5 NB.  to obtain both the boxed and linear displays of verbs

s=: 0 : 0
(# q: y) = (# {./.~ q: y)
)

s2=: 0 : 0
y = */ {./.~ q: y
)

sqfr3 =: 3 : s
SQFR3_tac3 =: 13 : s
sqfr3
NB. +-+-+-------------------------+
NB. |3|:|(# q: y) = (# {./.~ q: y)|
NB. +-+-+-------------------------+
NB. 3 : '(# q: y) = (# {./.~ q: y)'
SQFR3_tac3
NB. +---------+-+--------------------------+
NB. |+--+-+--+|=|+--+-+-------------------+|
NB. ||[:|#|q:|| ||[:|#|+--+-----------+--+||
NB. |+--+-+--+| ||  | ||[:|+-------+-+|q:|||
NB. |         | ||  | ||  ||+--+--+|~||  |||
NB. |         | ||  | ||  |||{.|/.|| ||  |||
NB. |         | ||  | ||  ||+--+--+| ||  |||
NB. |         | ||  | ||  |+-------+-+|  |||
NB. |         | ||  | |+--+-----------+--+||
NB. |         | |+--+-+-------------------+|
NB. +---------+-+--------------------------+
NB. ([: # q:) = [: # [: {./.~ q:

SQFR3_tac3 @&gt; 10 30 40 1000 11 121 NB. 1 1 0 0 1 0

sqfr2 =: 3 : s2
SQFR2_tac =: 13 : s2   
sqfr2
NB. +-+-+-----------------+
NB. |3|:|y = */ {./.~ q: y|
NB. +-+-+-----------------+
NB. 3 : 'y = */ {./.~ q: y'
SQFR2_tac
NB. +-+-+------------------------------+
NB. |]|=|+--+-----+-------------------+|
NB. | | ||[:|+-+-+|+--+-----------+--+||
NB. | | ||  ||*|/|||[:|+-------+-+|q:|||
NB. | | ||  |+-+-+||  ||+--+--+|~||  |||
NB. | | ||  |     ||  |||{.|/.|| ||  |||
NB. | | ||  |     ||  ||+--+--+| ||  |||
NB. | | ||  |     ||  |+-------+-+|  |||
NB. | | ||  |     |+--+-----------+--+||
NB. | | |+--+-----+-------------------+|
NB. +-+-+------------------------------+
NB. ] = [: */ [: {./.~ q:

SQFR2_tac @&gt; 10 30 40 1000 11 121 NB. 1 1 0 0 1 0
</code></pre>]]></content><author><name>Milia</name></author><summary type="html"><![CDATA[NB. This problem was read in the blogpost (https://www.glc.us.es/~jalonso/exercitium/numeros-libres-de-cuadrados/) of @Jose_A_Alonso. NB. Problem statement: given a positive integer N, it's called square-free if no square number (eg 2^2, 11^11) can be created from its prime divisors. NB. Created using the J903 online playground (https://jsoftware.github.io/j-playground/bin/html2/). NB. Let's get the matrix of the prime divisors of an array of integers q: @&gt; 10 30 40 1000 11 121 NB. 2 5 0 0 0 0 NB. 2 3 5 0 0 0 NB. 2 2 2 5 0 0 NB. 2 2 2 5 5 5 NB. 11 0 0 0 0 0 NB. 11 11 0 0 0 0 NB. First solution sqfr1 =: {{ arr=. q: y NB. prime divisor decomposition of y max=. &gt;./ arr NB. return biggest prime divisor filter=. 1+i.max NB. array from 1 to the maximum prime divisor of arr bool_mat=. filter =/ arr NB. boolean matrix of multiples transbool=. |: bool_mat NB. transpose bool matrix add_ones=. +/ transbool NB. add ones per column ge_two =. 2 &lt;: add_ones NB. the elements of res are greater eq to 2 one_in=. 1 e. ge_two NB. 1 is a member of ge_two array -. one_in NB. NOT(one_in) }} sqfr1 @&gt; 10 30 40 1000 11 121 NB. 1 1 0 0 1 0 NB. Second solution, adaptation of the 4th solution of Jose from Haskell. NB. It compares the product of the unique prime divisors of the number N with the number N. NB. If there are no multiples (and thus squares) they're the same. sqfr2 =: {{ y = */ {./.~ q: y }} sqfr2 @&gt; 10 30 40 1000 11 121 NB. 1 1 0 0 1 0 NB. Third solution. NB. Just compare the length of the array with the unique prime divisors of the number N NB. with the full array of its prime divisors. Not that pretty as the second solution due NB. to the use of the parentheses. sqfr3 =: {{ (# q: y) = (# {./.~ q: y) }} sqfr3 @&gt; 10 30 40 1000 11 121 NB. 1 1 0 0 1 0 NB. Refactoring NB. ----------- NB. Both of these solutions are due to moon-child from libera/#jsoftware. NB. NB. The first one, sqfr3_tacit is the tacit form of sqfr3 that uses NB. a fork (https://code.jsoftware.com/wiki/Help/Primer/Fork), NB. compose "&amp;" (https://code.jsoftware.com/wiki/Vocabulary/ampv) and NB. at "@:" (https://code.jsoftware.com/wiki/Vocabulary/atco). NB. The second one, sqfr3_tacit2 is a refactored version of sqfr3_tacit. sqfr3_tacit =: q: =&amp;# {./.~@:q: sqfr3_tacit @&gt; 10 30 40 1000 11 121 NB. 1 1 0 0 1 0 sqfr3_tacit2 =: (=&amp;# {./.~)@:q: sqfr3_tacit2 @&gt; 10 30 40 1000 11 121 NB. 1 1 0 0 1 0 NB. Automatic tacit form translation NB. -------------------------------- NB. NB. Thanks to moon-child and nickspoon from libera/#jsoftware that drew NB. my attention to https://www.jsoftware.com/help/dictionary/intro19.htm 9!:3 ] 2 5 NB. to obtain both the boxed and linear displays of verbs s=: 0 : 0 (# q: y) = (# {./.~ q: y) ) s2=: 0 : 0 y = */ {./.~ q: y ) sqfr3 =: 3 : s SQFR3_tac3 =: 13 : s sqfr3 NB. +-+-+-------------------------+ NB. |3|:|(# q: y) = (# {./.~ q: y)| NB. +-+-+-------------------------+ NB. 3 : '(# q: y) = (# {./.~ q: y)' SQFR3_tac3 NB. +---------+-+--------------------------+ NB. |+--+-+--+|=|+--+-+-------------------+| NB. ||[:|#|q:|| ||[:|#|+--+-----------+--+|| NB. |+--+-+--+| || | ||[:|+-------+-+|q:||| NB. | | || | || ||+--+--+|~|| ||| NB. | | || | || |||{.|/.|| || ||| NB. | | || | || ||+--+--+| || ||| NB. | | || | || |+-------+-+| ||| NB. | | || | |+--+-----------+--+|| NB. | | |+--+-+-------------------+| NB. +---------+-+--------------------------+ NB. ([: # q:) = [: # [: {./.~ q: SQFR3_tac3 @&gt; 10 30 40 1000 11 121 NB. 1 1 0 0 1 0 sqfr2 =: 3 : s2 SQFR2_tac =: 13 : s2 sqfr2 NB. +-+-+-----------------+ NB. |3|:|y = */ {./.~ q: y| NB. +-+-+-----------------+ NB. 3 : 'y = */ {./.~ q: y' SQFR2_tac NB. +-+-+------------------------------+ NB. |]|=|+--+-----+-------------------+| NB. | | ||[:|+-+-+|+--+-----------+--+|| NB. | | || ||*|/|||[:|+-------+-+|q:||| NB. | | || |+-+-+|| ||+--+--+|~|| ||| NB. | | || | || |||{.|/.|| || ||| NB. | | || | || ||+--+--+| || ||| NB. | | || | || |+-------+-+| ||| NB. | | || | |+--+-----------+--+|| NB. | | |+--+-----+-------------------+| NB. +-+-+------------------------------+ NB. ] = [: */ [: {./.~ q: SQFR2_tac @&gt; 10 30 40 1000 11 121 NB. 1 1 0 0 1 0]]></summary></entry><entry><title type="html">Multiple keyboard layouts on RaspberryOS 64 bit, Debian Bullseye</title><link href="https://milia.dev/blog/2022/04/18/multiple-keyboard-layouts-raspberryos/" rel="alternate" type="text/html" title="Multiple keyboard layouts on RaspberryOS 64 bit, Debian Bullseye" /><published>2022-04-18T10:17:44+00:00</published><updated>2022-04-18T10:17:44+00:00</updated><id>https://milia.dev/blog/2022/04/18/multiple-keyboard-layouts-raspberryos</id><content type="html" xml:base="https://milia.dev/blog/2022/04/18/multiple-keyboard-layouts-raspberryos/"><![CDATA[<h2 id="issue">Issue</h2>

<p>The issue is that if one follows the usual steps, the <code>keyboard layout handler</code> doesn’t change the layouts. <a href="https://forums.raspberrypi.com/viewtopic.php?t=329072">It’s a very well known issue</a>.</p>

<h2 id="solution">Solution</h2>

<p>From the above link, and most specifically <a href="https://forums.raspberrypi.com/viewtopic.php?t=329072#p1971175">this post</a>, the solution is as follows:</p>

<ul>
  <li>Edit <code>~/.config/lxsession/LXDE-pi/desktop.conf</code> and  under <code>[Session]</code> change <code>window_manager</code> from mutter to <code>openbox-lxde-pi</code>.</li>
  <li>Make sure that the <code>~/.config/lxpanel/LXDE-pi/panels/panel</code> file looks like as follows, if say you want the languages <code>en,gr,es,ru</code>:</li>
</ul>

<pre><code class="language-bash">Plugin {
  type=xkb
  Config {
    Model=pc105
    LayoutsList=us,gr,es,ru
    VariantsList=polytonic,cat,phonetic
    ToggleOpt=grp:shift_caps_toggle,grp:alt_shift_toggle
    KeepSysLayouts=0
    DisplayType=0
    FlagSize=2
  }
}
</code></pre>

<ul>
  <li>Logout</li>
</ul>

<p>When you relogin it should work.</p>

<h2 id="my-settings">My settings</h2>

<p><code>~/.config/lxsession/LXDE-pi/desktop.conf</code></p>

<pre><code class="language-ini">[GTK]
sNet/ThemeName=PiXflat
iNet/DoubleClickTime=250

[Session]
window_manager=openbox-lxde-pi
</code></pre>
<p><code>~/.config/lxpanel/LXDE-pi/panels/panel</code></p>

<pre><code>Plugin {
  type=xkb
  Config {
    Model=pc105
    LayoutsList=us,gr,es,ru
    VariantsList=,polytonic,cat,phonetic
    ToggleOpt=grp:shift_caps_toggle,grp:alt_shift_toggle
    KeepSysLayouts=0
    DisplayType=0
    FlagSize=2
  }
}
</code></pre>
<h2 id="demo">Demo</h2>

<ul>
  <li>English</li>
</ul>

<p>“the flesh covers the bone
and they put a mind
in there and
sometimes a soul,
and the women break
vases against the walls
and the men drink too
much…”</p>

<ul>
  <li>Greek</li>
</ul>

<p>«Με τόσα φύλλα σου γνέφει ο ήλιος καλημέρα
με τόσα φλάμπουρα λάμπει, λάμπει ο ουρανός
και τούτοι μεσ’ τα σίδερα και κείνοι μεσ’ το χώμα.»</p>

<ul>
  <li>Catalan</li>
</ul>

<p>“Molt exceŀlent, virtuós e gloriós príncep, rey spectant: jatsia per vulgada fama fo informat de vostres virtuts,…”</p>

<ul>
  <li>Russian</li>
</ul>

<p>“Однажды весною, в час небывало жаркого заката, в Москве, на Патриарших прудах, появились два гражданина. Первый из них, одетый в летнюю серенькую пару, был маленького роста, упитан, лыс, свою приличную шляпу пирожком нес в руке, а на хорошо выбритом лице его помещались сверхъестественных размеров очки в черной роговой оправе. Второй – плечистый, рыжеватый, вихрастый молодой человек в заломленной на затылок клетчатой кепке – был в ковбойке, жеваных белых брюках и в черных тапочках.”</p>]]></content><author><name>Milia</name></author><summary type="html"><![CDATA[Issue The issue is that if one follows the usual steps, the keyboard layout handler doesn’t change the layouts. It’s a very well known issue. Solution From the above link, and most specifically this post, the solution is as follows: Edit ~/.config/lxsession/LXDE-pi/desktop.conf and under [Session] change window_manager from mutter to openbox-lxde-pi. Make sure that the ~/.config/lxpanel/LXDE-pi/panels/panel file looks like as follows, if say you want the languages en,gr,es,ru: Plugin { type=xkb Config { Model=pc105 LayoutsList=us,gr,es,ru VariantsList=polytonic,cat,phonetic ToggleOpt=grp:shift_caps_toggle,grp:alt_shift_toggle KeepSysLayouts=0 DisplayType=0 FlagSize=2 } } Logout When you relogin it should work. My settings ~/.config/lxsession/LXDE-pi/desktop.conf [GTK] sNet/ThemeName=PiXflat iNet/DoubleClickTime=250 [Session] window_manager=openbox-lxde-pi ~/.config/lxpanel/LXDE-pi/panels/panel Plugin { type=xkb Config { Model=pc105 LayoutsList=us,gr,es,ru VariantsList=,polytonic,cat,phonetic ToggleOpt=grp:shift_caps_toggle,grp:alt_shift_toggle KeepSysLayouts=0 DisplayType=0 FlagSize=2 } } Demo English “the flesh covers the bone and they put a mind in there and sometimes a soul, and the women break vases against the walls and the men drink too much…” Greek «Με τόσα φύλλα σου γνέφει ο ήλιος καλημέρα με τόσα φλάμπουρα λάμπει, λάμπει ο ουρανός και τούτοι μεσ’ τα σίδερα και κείνοι μεσ’ το χώμα.» Catalan “Molt exceŀlent, virtuós e gloriós príncep, rey spectant: jatsia per vulgada fama fo informat de vostres virtuts,…” Russian “Однажды весною, в час небывало жаркого заката, в Москве, на Патриарших прудах, появились два гражданина. Первый из них, одетый в летнюю серенькую пару, был маленького роста, упитан, лыс, свою приличную шляпу пирожком нес в руке, а на хорошо выбритом лице его помещались сверхъестественных размеров очки в черной роговой оправе. Второй – плечистый, рыжеватый, вихрастый молодой человек в заломленной на затылок клетчатой кепке – был в ковбойке, жеваных белых брюках и в черных тапочках.”]]></summary></entry><entry><title type="html">Youtube from the Linux CLI</title><link href="https://milia.dev/blog/2022/02/28/youtube-from-the-linux-cli/" rel="alternate" type="text/html" title="Youtube from the Linux CLI" /><published>2022-02-28T13:17:02+00:00</published><updated>2022-02-28T13:17:02+00:00</updated><id>https://milia.dev/blog/2022/02/28/youtube-from-the-linux-cli</id><content type="html" xml:base="https://milia.dev/blog/2022/02/28/youtube-from-the-linux-cli/"><![CDATA[<p>I <strong>really</strong> love listening to music when programming, on my old Linux laptop.</p>

<p>So, to save resources I looked for a CLI Youtube app. And there is an amazing one.</p>

<h2 id="enter-yewtube">Enter yewtube</h2>

<ul>
  <li>Yewtube is a fork of <code>mps-youtube</code>. Find <a href="https://github.com/iamtalhaasghar/yewtube">yewtube here</a>. Follow the instructions in the README.md file to install it.</li>
  <li>Suggestion: install it within a virtual environment (virtualenv).</li>
  <li>No API key is needed to use <code>yewtube</code>, in contrast with <code>mps-youtube</code>.</li>
</ul>

<p>Worked for me with <code>python 3.9.0</code> (installed it inside a virtualenv) on the following linux machine:</p>

<pre><code>Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.6 LTS
Release:	18.04
Codename:	bionic

Linux Newton 4.15.0-169-generic #177-Ubuntu SMP Thu Feb 3 10:50:38 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
</code></pre>
<h2 id="limitations">Limitations</h2>
<ul>
  <li>N/A yet.</li>
</ul>

<h2 id="error-messages">Error messages</h2>
<ul>
  <li>N/A yet.</li>
</ul>

<h2 id="printscreens">Printscreens</h2>

<p>Just one, showing that it can play my locally saved 8h long awesome techno playlist:</p>

<p><img src="https://user-images.githubusercontent.com/5833270/156359263-0a8805b6-88e1-4b19-bf22-98b44ce09c27.png" alt="2022-03-02-131036_1440x900_scrot" /></p>

<p>Cheers !</p>]]></content><author><name>Milia</name></author><summary type="html"><![CDATA[I really love listening to music when programming, on my old Linux laptop. So, to save resources I looked for a CLI Youtube app. And there is an amazing one. Enter yewtube Yewtube is a fork of mps-youtube. Find yewtube here. Follow the instructions in the README.md file to install it. Suggestion: install it within a virtual environment (virtualenv). No API key is needed to use yewtube, in contrast with mps-youtube. Worked for me with python 3.9.0 (installed it inside a virtualenv) on the following linux machine: Distributor ID: Ubuntu Description: Ubuntu 18.04.6 LTS Release: 18.04 Codename: bionic Linux Newton 4.15.0-169-generic #177-Ubuntu SMP Thu Feb 3 10:50:38 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux Limitations N/A yet. Error messages N/A yet. Printscreens Just one, showing that it can play my locally saved 8h long awesome techno playlist: Cheers !]]></summary></entry><entry><title type="html">How to use RSS to get updates from Twitter hashtags</title><link href="https://milia.dev/blog/2022/02/26/rss-twitter-hashtags/" rel="alternate" type="text/html" title="How to use RSS to get updates from Twitter hashtags" /><published>2022-02-26T05:37:06+00:00</published><updated>2022-02-26T05:37:06+00:00</updated><id>https://milia.dev/blog/2022/02/26/rss-twitter-hashtags</id><content type="html" xml:base="https://milia.dev/blog/2022/02/26/rss-twitter-hashtags/"><![CDATA[<h2 id="websites">Websites</h2>

<ul>
  <li>https://feeder.co/knowledge-base/rss-feed-creation/twitter-rss-feeds/</li>
  <li>https://www.tecmint.com/best-rss-feed-readers-for-linux/</li>
</ul>

<h2 id="tools">Tools</h2>

<p>From the above websites I found after some testing that the most reliable and useful in the ‘free’ tier are:</p>

<ul>
  <li>https://rss.app/ (to convert the Twitter links to <code>xml</code> RSS files)</li>
  <li><a href="https://quiterss.org/">Quiterss</a> the open source client where from you’ll be reading the RSS feeds</li>
</ul>

<h2 id="how">How</h2>

<ul>
  <li>First create an account at https://rss.app/ . Mind you, it seems that when you create it you’re enlisted in the first paid plan, the “premium” package. The trial lasts 7 days. The advantages of the “premium” package over the “free” package are:
    <ul>
      <li><code>Premium</code>: <strong>40 RSS Feeds</strong>, 4 Widgets, 4 Email Digest, <strong>30 Minute Refresh Rate</strong>, 25 Posts in Collection, Up to 25 posts Per Feed, Link to Source, Social Media, Custom Widgets, Bundle Feeds, Filters, Email Support.</li>
      <li><code>Free</code>: <strong>2 RSS feeds</strong>, 1 Widgets, <strong>24 Hour Refresh Rate</strong>, Up to 5 Posts Per Feed, Link to RSS.app / Ads.</li>
      <li>The disadvantages of the “premium” package are that it costs $9.99/month (monthly subscription) or $8.32/month (annual subscription).</li>
    </ul>
  </li>
  <li>Then copy paste the Twitter URL, say of a specific hashtag search result (<a href="https://twitter.com/search?q=Ukrainian&amp;src=trend_click&amp;f=live&amp;vertical=trends">example</a>).</li>
  <li>Then go to the rss.app page and press the “+New Feed” button on top right.</li>
  <li>Choose “Twitter RSS Feed”.</li>
  <li>Then you’ll be redirected to a new page. Copy the URL ending with an <code>.xml</code> file under the “Your feed is ready”.</li>
  <li><a href="https://quiterss.org/en/download">Download</a> and install the QuiteRSS client.</li>
  <li>Open the QuiteRSS app. Press the “+” symbol on top left and press continue/okay.</li>
</ul>

<p>Congrats, now you’re getting the Tweets for your selected hashtags in the RSS feed reader every 30 minutes (premium package) or every 24h (free package).</p>]]></content><author><name>Milia</name></author><summary type="html"><![CDATA[Websites https://feeder.co/knowledge-base/rss-feed-creation/twitter-rss-feeds/ https://www.tecmint.com/best-rss-feed-readers-for-linux/ Tools From the above websites I found after some testing that the most reliable and useful in the ‘free’ tier are: https://rss.app/ (to convert the Twitter links to xml RSS files) Quiterss the open source client where from you’ll be reading the RSS feeds How First create an account at https://rss.app/ . Mind you, it seems that when you create it you’re enlisted in the first paid plan, the “premium” package. The trial lasts 7 days. The advantages of the “premium” package over the “free” package are: Premium: 40 RSS Feeds, 4 Widgets, 4 Email Digest, 30 Minute Refresh Rate, 25 Posts in Collection, Up to 25 posts Per Feed, Link to Source, Social Media, Custom Widgets, Bundle Feeds, Filters, Email Support. Free: 2 RSS feeds, 1 Widgets, 24 Hour Refresh Rate, Up to 5 Posts Per Feed, Link to RSS.app / Ads. The disadvantages of the “premium” package are that it costs $9.99/month (monthly subscription) or $8.32/month (annual subscription). Then copy paste the Twitter URL, say of a specific hashtag search result (example). Then go to the rss.app page and press the “+New Feed” button on top right. Choose “Twitter RSS Feed”. Then you’ll be redirected to a new page. Copy the URL ending with an .xml file under the “Your feed is ready”. Download and install the QuiteRSS client. Open the QuiteRSS app. Press the “+” symbol on top left and press continue/okay. Congrats, now you’re getting the Tweets for your selected hashtags in the RSS feed reader every 30 minutes (premium package) or every 24h (free package).]]></summary></entry><entry><title type="html">Factoring 10…01</title><link href="https://milia.dev/blog/2022/02/25/factoring-10-01/" rel="alternate" type="text/html" title="Factoring 10…01" /><published>2022-02-25T05:57:45+00:00</published><updated>2022-02-25T05:57:45+00:00</updated><id>https://milia.dev/blog/2022/02/25/factoring-10-01</id><content type="html" xml:base="https://milia.dev/blog/2022/02/25/factoring-10-01/"><![CDATA[<h2 id="tools">Tools</h2>
<p>GNU/Linux <code>factor</code> Bash tool and python3.</p>

<h2 id="code--results">Code &amp; results</h2>

<pre><code class="language-bash"># bash shell
 $ factor 101
101: 101
 $ factor 1001
1001: 7 11 13
 $ factor 10001
10001: 73 137
 $ factor 100001
100001: 11 9091
 $ factor 1000001
1000001: 101 9901
 $ factor 10000001
10000001: 11 909091
 $ factor 100000001
100000001: 17 5882353
 $ factor 1000000001
1000000001: 7 11 13 19 52579
 $ factor 10000000001
10000000001: 101 3541 27961
 $ factor 100000000001
100000000001: 11 11 23 4093 8779
 $ factor 1000000000001
1000000000001: 73 137 99990001
 $ factor 10000000000001
10000000000001: 11 859 1058313049
 $ factor 100000000000001
100000000000001: 29 101 281 121499449
 $ factor 1000000000000001
1000000000000001: 7 11 13 211 241 2161 9091
 $ factor 10000000000000001
10000000000000001: 353 449 641 1409 69857
 $ factor 100000000000000001
100000000000000001: 11 103 4013 21993833369
 $ factor 1000000000000000001
1000000000000000001: 101 9901 999999000001
 $ factor 10000000000000000001
10000000000000000001: 11 909090909090909091
 $ factor 100000000000000000001
100000000000000000001: 73 137 1676321 5964848081
 $ factor 1000000000000000000001
1000000000000000000001: 7 7 11 13 127 2689 459691 909091
 $ factor 10000000000000000000001
10000000000000000000001: 89 101 1052788969 1056689261
 $ factor 100000000000000000000001
100000000000000000000001: 11 47 139 2531 549797184491917
 $ factor 1000000000000000000000001
1000000000000000000000001: 17 5882353 9999999900000001
 $ factor 10000000000000000000000001
10000000000000000000000001: 11 251 5051 9091 78875943472201
 $ factor 100000000000000000000000001
100000000000000000000000001: 101 521 1900381976777332243781
 $ factor 1000000000000000000000000001
1000000000000000000000000001: 7 11 13 19 52579 70541929 14175966169
 $ factor 10000000000000000000000000001
10000000000000000000000000001: 73 137 7841 127522001020150503761
 $ factor 100000000000000000000000000001
100000000000000000000000000001: 11 59 154083204930662557781201849
 $ factor 1000000000000000000000000000001
1000000000000000000000000000001: 61 101 3541 9901 27961 4188901 39526741
 $ factor 10000000000000000000000000000001
10000000000000000000000000000001: 11 909090909090909090909090909091
 $ factor 100000000000000000000000000000001
100000000000000000000000000000001: 19841 976193 6187457 834427406578561
 $ factor 1000000000000000000000000000000001
1000000000000000000000000000000001: 7 11 11 13 23 4093 8779 599144041 183411838171
 $ factor 10000000000000000000000000000000001
10000000000000000000000000000000001: 101 28559389 1491383821 2324557465671829
 $ factor 100000000000000000000000000000000001
100000000000000000000000000000000001: 11 9091 909091 4147571 265212793249617641
 $ factor 1000000000000000000000000000000000001 
1000000000000000000000000000000000001: 73 137 3169 98641 99990001 3199044596370769
 $ factor 10000000000000000000000000000000000001
10000000000000000000000000000000000001: 11 7253 422650073734453 296557347313446299
 $ factor 100000000000000000000000000000000000001
100000000000000000000000000000000000001: 101 722817036322379041 1369778187490592461
 $ factor 1000000000000000000000000000000000000001
factor: ‘1000000000000000000000000000000000000001’ is too large
</code></pre>

<h2 id="interesting-observations">Interesting observations</h2>

<ul>
  <li>From 101 to 100000000000000000000000000000000000001 there’s been only one prime: <code>101</code>.</li>
  <li>Most of the <code>10...01</code> numbers have more than one divisors. Those that have the least divisors (two) are:
    <ul>
      <li>10001: 73 137</li>
      <li>100001: 11 9091</li>
      <li>1000001: 101 9901</li>
      <li>10000001: 11 909091</li>
      <li>100000001: 17 5882353</li>
      <li>10000000000000000001: 11 909090909090909091</li>
      <li>10000000000000000000000000000001: 11, 909090909090909090909090909091.</li>
    </ul>
  </li>
  <li>We notice that the following numbers have divisors with very similar structure:
    <ul>
      <li>100001: 11 9091</li>
      <li>10000001: 11 909091</li>
      <li>10000000000000000001: 11 909090909090909091</li>
      <li>10000000000000000000000000000001: 11, 909090909090909090909090909091.</li>
    </ul>
  </li>
  <li>
    <p>From the previous observation a questions is raised about the numbers that have divisors <code>11</code> and numbers with the structure <code>90..9091</code>. Is there some underlying pattern? Did an experiment that was illuminating:</p>

    <pre><code class="language-python"># python3.x
s = "91"
t = "90"
for i in range(35):
  r = i*t + s
  res = 11*int(r)
  print("11*{}: ".format(r), res, "  len(res): {}".format(len(str(res))))
# RESULTS:
# --------
11*91:  1001   len(res): 4
11*9091:  100001   len(res): 6
11*909091:  10000001   len(res): 8
11*90909091:  1000000001   len(res): 10
11*9090909091:  100000000001   len(res): 12
11*909090909091:  10000000000001   len(res): 14
11*90909090909091:  1000000000000001   len(res): 16
11*9090909090909091:  100000000000000001   len(res): 18
11*909090909090909091:  10000000000000000001   len(res): 20
11*90909090909090909091:  1000000000000000000001   len(res): 22
11*9090909090909090909091:  100000000000000000000001   len(res): 24
11*909090909090909090909091:  10000000000000000000000001   len(res): 26
11*90909090909090909090909091:  1000000000000000000000000001   len(res): 28
11*9090909090909090909090909091:  100000000000000000000000000001   len(res): 30
11*909090909090909090909090909091:  10000000000000000000000000000001   len(res): 32
11*90909090909090909090909090909091:  1000000000000000000000000000000001   len(res): 34
11*9090909090909090909090909090909091:  100000000000000000000000000000000001   len(res): 36
11*909090909090909090909090909090909091:  10000000000000000000000000000000000001   len(res): 38
11*90909090909090909090909090909090909091:  1000000000000000000000000000000000000001   len(res): 40
11*9090909090909090909090909090909090909091:  100000000000000000000000000000000000000001   len(res): 42
11*909090909090909090909090909090909090909091:  10000000000000000000000000000000000000000001   len(res): 44
11*90909090909090909090909090909090909090909091:  1000000000000000000000000000000000000000000001   len(res): 46
11*9090909090909090909090909090909090909090909091:  100000000000000000000000000000000000000000000001   len(res): 48
11*909090909090909090909090909090909090909090909091:  10000000000000000000000000000000000000000000000001   len(res): 50
11*90909090909090909090909090909090909090909090909091:  1000000000000000000000000000000000000000000000000001   len(res): 52
11*9090909090909090909090909090909090909090909090909091:  100000000000000000000000000000000000000000000000000001   len(res): 54
11*909090909090909090909090909090909090909090909090909091:  10000000000000000000000000000000000000000000000000000001   len(res): 56
11*90909090909090909090909090909090909090909090909090909091:  1000000000000000000000000000000000000000000000000000000001   len(res): 58
11*9090909090909090909090909090909090909090909090909090909091:  100000000000000000000000000000000000000000000000000000000001   len(res): 60
11*909090909090909090909090909090909090909090909090909090909091:  10000000000000000000000000000000000000000000000000000000000001   len(res): 62
11*90909090909090909090909090909090909090909090909090909090909091:  1000000000000000000000000000000000000000000000000000000000000001   len(res): 64
11*9090909090909090909090909090909090909090909090909090909090909091:  100000000000000000000000000000000000000000000000000000000000000001   len(res): 66
11*909090909090909090909090909090909090909090909090909090909090909091:  10000000000000000000000000000000000000000000000000000000000000000001   len(res): 68
11*90909090909090909090909090909090909090909090909090909090909090909091:  1000000000000000000000000000000000000000000000000000000000000000000001   len(res): 70
11*9090909090909090909090909090909090909090909090909090909090909090909091:  100000000000000000000000000000000000000000000000000000000000000000000001   len(res): 72
</code></pre>
  </li>
</ul>

<h2 id="conclusion">Conclusion</h2>

<p>From our experiments we can conjecture the following:</p>

<h3 id="conjecture">Conjecture</h3>
<ul>
  <li>Every number of the type <code>10...01</code> with even number of zeroes more than four (6, 8, 10, …) can be created by multiplying <code>11</code> with numbers of the type <code>90...9091</code>.</li>
  <li>The number <code>1001</code> is being created by multiplying <code>11</code> with <code>91</code>. From there on, the rest of such numbers are created by multiplying <code>11</code> with <code>9091</code> (100001), <code>909091</code> (10000001), <code>90909091</code> (1000000001), etc.</li>
</ul>

<p>First five examples:</p>

<ul>
  <li>1001: 11 * 91 (base case), no of zeroes is 2</li>
  <li>100001: 11 * 9091 (first case), no of zeroes is 4</li>
  <li>10000001: 11 * 909091 (second case), no of zeroes is 6</li>
  <li>1000000001: 11 * 90909091 (third case), no of zeroes is 8</li>
  <li>100000000001: 11 * 9090909091 (fourth case), no of zeroes is 10</li>
</ul>

<h2 id="final-thoughts">Final thoughts</h2>
<blockquote>
  <p>THE PURPOSE OF COMPUTING</p>

  <p>IS INSIGHT, NOT NUMBERS</p>
</blockquote>

<p><a href="https://en.wikipedia.org/wiki/Richard_Hamming">R. W. Hamming</a></p>]]></content><author><name>Milia</name></author><summary type="html"><![CDATA[Tools GNU/Linux factor Bash tool and python3. Code &amp; results # bash shell $ factor 101 101: 101 $ factor 1001 1001: 7 11 13 $ factor 10001 10001: 73 137 $ factor 100001 100001: 11 9091 $ factor 1000001 1000001: 101 9901 $ factor 10000001 10000001: 11 909091 $ factor 100000001 100000001: 17 5882353 $ factor 1000000001 1000000001: 7 11 13 19 52579 $ factor 10000000001 10000000001: 101 3541 27961 $ factor 100000000001 100000000001: 11 11 23 4093 8779 $ factor 1000000000001 1000000000001: 73 137 99990001 $ factor 10000000000001 10000000000001: 11 859 1058313049 $ factor 100000000000001 100000000000001: 29 101 281 121499449 $ factor 1000000000000001 1000000000000001: 7 11 13 211 241 2161 9091 $ factor 10000000000000001 10000000000000001: 353 449 641 1409 69857 $ factor 100000000000000001 100000000000000001: 11 103 4013 21993833369 $ factor 1000000000000000001 1000000000000000001: 101 9901 999999000001 $ factor 10000000000000000001 10000000000000000001: 11 909090909090909091 $ factor 100000000000000000001 100000000000000000001: 73 137 1676321 5964848081 $ factor 1000000000000000000001 1000000000000000000001: 7 7 11 13 127 2689 459691 909091 $ factor 10000000000000000000001 10000000000000000000001: 89 101 1052788969 1056689261 $ factor 100000000000000000000001 100000000000000000000001: 11 47 139 2531 549797184491917 $ factor 1000000000000000000000001 1000000000000000000000001: 17 5882353 9999999900000001 $ factor 10000000000000000000000001 10000000000000000000000001: 11 251 5051 9091 78875943472201 $ factor 100000000000000000000000001 100000000000000000000000001: 101 521 1900381976777332243781 $ factor 1000000000000000000000000001 1000000000000000000000000001: 7 11 13 19 52579 70541929 14175966169 $ factor 10000000000000000000000000001 10000000000000000000000000001: 73 137 7841 127522001020150503761 $ factor 100000000000000000000000000001 100000000000000000000000000001: 11 59 154083204930662557781201849 $ factor 1000000000000000000000000000001 1000000000000000000000000000001: 61 101 3541 9901 27961 4188901 39526741 $ factor 10000000000000000000000000000001 10000000000000000000000000000001: 11 909090909090909090909090909091 $ factor 100000000000000000000000000000001 100000000000000000000000000000001: 19841 976193 6187457 834427406578561 $ factor 1000000000000000000000000000000001 1000000000000000000000000000000001: 7 11 11 13 23 4093 8779 599144041 183411838171 $ factor 10000000000000000000000000000000001 10000000000000000000000000000000001: 101 28559389 1491383821 2324557465671829 $ factor 100000000000000000000000000000000001 100000000000000000000000000000000001: 11 9091 909091 4147571 265212793249617641 $ factor 1000000000000000000000000000000000001 1000000000000000000000000000000000001: 73 137 3169 98641 99990001 3199044596370769 $ factor 10000000000000000000000000000000000001 10000000000000000000000000000000000001: 11 7253 422650073734453 296557347313446299 $ factor 100000000000000000000000000000000000001 100000000000000000000000000000000000001: 101 722817036322379041 1369778187490592461 $ factor 1000000000000000000000000000000000000001 factor: ‘1000000000000000000000000000000000000001’ is too large Interesting observations From 101 to 100000000000000000000000000000000000001 there’s been only one prime: 101. Most of the 10...01 numbers have more than one divisors. Those that have the least divisors (two) are: 10001: 73 137 100001: 11 9091 1000001: 101 9901 10000001: 11 909091 100000001: 17 5882353 10000000000000000001: 11 909090909090909091 10000000000000000000000000000001: 11, 909090909090909090909090909091. We notice that the following numbers have divisors with very similar structure: 100001: 11 9091 10000001: 11 909091 10000000000000000001: 11 909090909090909091 10000000000000000000000000000001: 11, 909090909090909090909090909091. From the previous observation a questions is raised about the numbers that have divisors 11 and numbers with the structure 90..9091. Is there some underlying pattern? Did an experiment that was illuminating: # python3.x s = "91" t = "90" for i in range(35): r = i*t + s res = 11*int(r) print("11*{}: ".format(r), res, " len(res): {}".format(len(str(res)))) # RESULTS: # -------- 11*91: 1001 len(res): 4 11*9091: 100001 len(res): 6 11*909091: 10000001 len(res): 8 11*90909091: 1000000001 len(res): 10 11*9090909091: 100000000001 len(res): 12 11*909090909091: 10000000000001 len(res): 14 11*90909090909091: 1000000000000001 len(res): 16 11*9090909090909091: 100000000000000001 len(res): 18 11*909090909090909091: 10000000000000000001 len(res): 20 11*90909090909090909091: 1000000000000000000001 len(res): 22 11*9090909090909090909091: 100000000000000000000001 len(res): 24 11*909090909090909090909091: 10000000000000000000000001 len(res): 26 11*90909090909090909090909091: 1000000000000000000000000001 len(res): 28 11*9090909090909090909090909091: 100000000000000000000000000001 len(res): 30 11*909090909090909090909090909091: 10000000000000000000000000000001 len(res): 32 11*90909090909090909090909090909091: 1000000000000000000000000000000001 len(res): 34 11*9090909090909090909090909090909091: 100000000000000000000000000000000001 len(res): 36 11*909090909090909090909090909090909091: 10000000000000000000000000000000000001 len(res): 38 11*90909090909090909090909090909090909091: 1000000000000000000000000000000000000001 len(res): 40 11*9090909090909090909090909090909090909091: 100000000000000000000000000000000000000001 len(res): 42 11*909090909090909090909090909090909090909091: 10000000000000000000000000000000000000000001 len(res): 44 11*90909090909090909090909090909090909090909091: 1000000000000000000000000000000000000000000001 len(res): 46 11*9090909090909090909090909090909090909090909091: 100000000000000000000000000000000000000000000001 len(res): 48 11*909090909090909090909090909090909090909090909091: 10000000000000000000000000000000000000000000000001 len(res): 50 11*90909090909090909090909090909090909090909090909091: 1000000000000000000000000000000000000000000000000001 len(res): 52 11*9090909090909090909090909090909090909090909090909091: 100000000000000000000000000000000000000000000000000001 len(res): 54 11*909090909090909090909090909090909090909090909090909091: 10000000000000000000000000000000000000000000000000000001 len(res): 56 11*90909090909090909090909090909090909090909090909090909091: 1000000000000000000000000000000000000000000000000000000001 len(res): 58 11*9090909090909090909090909090909090909090909090909090909091: 100000000000000000000000000000000000000000000000000000000001 len(res): 60 11*909090909090909090909090909090909090909090909090909090909091: 10000000000000000000000000000000000000000000000000000000000001 len(res): 62 11*90909090909090909090909090909090909090909090909090909090909091: 1000000000000000000000000000000000000000000000000000000000000001 len(res): 64 11*9090909090909090909090909090909090909090909090909090909090909091: 100000000000000000000000000000000000000000000000000000000000000001 len(res): 66 11*909090909090909090909090909090909090909090909090909090909090909091: 10000000000000000000000000000000000000000000000000000000000000000001 len(res): 68 11*90909090909090909090909090909090909090909090909090909090909090909091: 1000000000000000000000000000000000000000000000000000000000000000000001 len(res): 70 11*9090909090909090909090909090909090909090909090909090909090909090909091: 100000000000000000000000000000000000000000000000000000000000000000000001 len(res): 72 Conclusion From our experiments we can conjecture the following: Conjecture Every number of the type 10...01 with even number of zeroes more than four (6, 8, 10, …) can be created by multiplying 11 with numbers of the type 90...9091. The number 1001 is being created by multiplying 11 with 91. From there on, the rest of such numbers are created by multiplying 11 with 9091 (100001), 909091 (10000001), 90909091 (1000000001), etc. First five examples: 1001: 11 * 91 (base case), no of zeroes is 2 100001: 11 * 9091 (first case), no of zeroes is 4 10000001: 11 * 909091 (second case), no of zeroes is 6 1000000001: 11 * 90909091 (third case), no of zeroes is 8 100000000001: 11 * 9090909091 (fourth case), no of zeroes is 10 Final thoughts THE PURPOSE OF COMPUTING IS INSIGHT, NOT NUMBERS R. W. Hamming]]></summary></entry><entry><title type="html">Weather CLI app</title><link href="https://milia.dev/blog/2022/01/11/weather-cli-app/" rel="alternate" type="text/html" title="Weather CLI app" /><published>2022-01-11T04:16:27+00:00</published><updated>2022-01-11T04:16:27+00:00</updated><id>https://milia.dev/blog/2022/01/11/weather-cli-app</id><content type="html" xml:base="https://milia.dev/blog/2022/01/11/weather-cli-app/"><![CDATA[<h2 id="what">What</h2>

<p>A simple CLI script that tells the weather of any given location.</p>

<p>It uses the <code>https://wttr.in/</code> service along with a <code>curl</code>.</p>

<h2 id="why">Why</h2>
<p>I love CLI GNU/Linux apps.</p>

<h2 id="code">Code</h2>
<pre><code class="language-bash">#!/bin/bash
weather() {
     if [ ! -z $1 ]
     then
         curl -4 http://wttr.in/$1
     else
         curl -4 http://wttr.in/Barcelona
     fi
  
}
weather $1
exit
</code></pre>

<h2 id="example">Example</h2>

<p>Open a GNU/Linux terminal.</p>

<h3 id="default">Default</h3>
<p>Get your default weather. In my case my default case is Barcelona/ES. Feel free to change it with your default location.</p>

<p>When I type:</p>

<pre><code class="language-bash">$weather
</code></pre>

<p>it gives for me the following ASCII weather table, but it’s much more colorful and much more pretty than this.</p>

<p>Don’t take my word for granted, simply visit <a href="https://wttr.in/">https://wttr.in/</a>.</p>

<pre><code>Weather report: Barcelona

      \   /     Clear
       .-.      +8(5) °C       
    ― (   ) ―   ↓ 13 km/h      
       `-’      10 km          
      /   \     0.0 mm         
                                                       ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Thu 25 Nov ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│     \   /     Sunny          │     \   /     Sunny          │     \   /     Clear          │     \   /     Clear          │
│      .-.      +9(7) °C       │      .-.      +10(7) °C      │      .-.      +10(8) °C      │      .-.      +10(7) °C      │
│   ― (   ) ―   → 11-14 km/h   │   ― (   ) ―   → 14-20 km/h   │   ― (   ) ―   → 17-24 km/h   │   ― (   ) ―   ↘ 19-22 km/h   │
│      `-’      10 km          │      `-’      10 km          │      `-’      10 km          │      `-’      10 km          │
│     /   \     0.0 mm | 0%    │     /   \     0.0 mm | 0%    │     /   \     0.0 mm | 0%    │     /   \     0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
                                                       ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Fri 26 Nov ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│     \   /     Sunny          │     \   /     Sunny          │     \   /     Clear          │     \   /     Clear          │
│      .-.      +8(6) °C       │      .-.      +9(7) °C       │      .-.      +10(9) °C      │      .-.      10 °C          │
│   ― (   ) ―   → 9-14 km/h    │   ― (   ) ―   → 9-14 km/h    │   ― (   ) ―   ↑ 6-10 km/h    │   ― (   ) ―   ← 6-9 km/h     │
│      `-’      10 km          │      `-’      10 km          │      `-’      10 km          │      `-’      10 km          │
│     /   \     0.0 mm | 0%    │     /   \     0.0 mm | 0%    │     /   \     0.0 mm | 0%    │     /   \     0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
                                                       ┌─────────────┐                                                       
┌──────────────────────────────┬───────────────────────┤  Sat 27 Nov ├───────────────────────┬──────────────────────────────┐
│            Morning           │             Noon      └──────┬──────┘     Evening           │             Night            │
├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤
│     \   /     Sunny          │     \   /     Sunny          │    \  /       Partly cloudy  │    \  /       Partly cloudy  │
│      .-.      +9(5) °C       │      .-.      +9(6) °C       │  _ /"".-.     +9(6) °C       │  _ /"".-.     +9(5) °C       │
│   ― (   ) ―   → 27-34 km/h   │   ― (   ) ―   → 29-40 km/h   │    \_(   ).   → 28-41 km/h   │    \_(   ).   → 32-46 km/h   │
│      `-’      10 km          │      `-’      10 km          │    /(___(__)  10 km          │    /(___(__)  10 km          │
│     /   \     0.0 mm | 0%    │     /   \     0.0 mm | 0%    │               0.0 mm | 0%    │               0.0 mm | 0%    │
└──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘
Location: Barcelona, BCN, CAT, España [41.3825596,2.1771353]

Follow @igor_chubin for wttr.in updates
</code></pre>

<h3 id="any-city">Any city</h3>

<p>Type:</p>

<pre><code class="language-bash">$weather CITY_NAME
</code></pre>

<p>and you’ll get a similar table as the previous one, with data related to the “CITY_NAME” that you’ve put.</p>]]></content><author><name>Milia</name></author><summary type="html"><![CDATA[What A simple CLI script that tells the weather of any given location. It uses the https://wttr.in/ service along with a curl. Why I love CLI GNU/Linux apps. Code #!/bin/bash weather() { if [ ! -z $1 ] then curl -4 http://wttr.in/$1 else curl -4 http://wttr.in/Barcelona fi } weather $1 exit Example Open a GNU/Linux terminal. Default Get your default weather. In my case my default case is Barcelona/ES. Feel free to change it with your default location. When I type: $weather it gives for me the following ASCII weather table, but it’s much more colorful and much more pretty than this. Don’t take my word for granted, simply visit https://wttr.in/. Weather report: Barcelona \ / Clear .-. +8(5) °C ― ( ) ― ↓ 13 km/h `-’ 10 km / \ 0.0 mm ┌─────────────┐ ┌──────────────────────────────┬───────────────────────┤ Thu 25 Nov ├───────────────────────┬──────────────────────────────┐ │ Morning │ Noon └──────┬──────┘ Evening │ Night │ ├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤ │ \ / Sunny │ \ / Sunny │ \ / Clear │ \ / Clear │ │ .-. +9(7) °C │ .-. +10(7) °C │ .-. +10(8) °C │ .-. +10(7) °C │ │ ― ( ) ― → 11-14 km/h │ ― ( ) ― → 14-20 km/h │ ― ( ) ― → 17-24 km/h │ ― ( ) ― ↘ 19-22 km/h │ │ `-’ 10 km │ `-’ 10 km │ `-’ 10 km │ `-’ 10 km │ │ / \ 0.0 mm | 0% │ / \ 0.0 mm | 0% │ / \ 0.0 mm | 0% │ / \ 0.0 mm | 0% │ └──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘ ┌─────────────┐ ┌──────────────────────────────┬───────────────────────┤ Fri 26 Nov ├───────────────────────┬──────────────────────────────┐ │ Morning │ Noon └──────┬──────┘ Evening │ Night │ ├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤ │ \ / Sunny │ \ / Sunny │ \ / Clear │ \ / Clear │ │ .-. +8(6) °C │ .-. +9(7) °C │ .-. +10(9) °C │ .-. 10 °C │ │ ― ( ) ― → 9-14 km/h │ ― ( ) ― → 9-14 km/h │ ― ( ) ― ↑ 6-10 km/h │ ― ( ) ― ← 6-9 km/h │ │ `-’ 10 km │ `-’ 10 km │ `-’ 10 km │ `-’ 10 km │ │ / \ 0.0 mm | 0% │ / \ 0.0 mm | 0% │ / \ 0.0 mm | 0% │ / \ 0.0 mm | 0% │ └──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘ ┌─────────────┐ ┌──────────────────────────────┬───────────────────────┤ Sat 27 Nov ├───────────────────────┬──────────────────────────────┐ │ Morning │ Noon └──────┬──────┘ Evening │ Night │ ├──────────────────────────────┼──────────────────────────────┼──────────────────────────────┼──────────────────────────────┤ │ \ / Sunny │ \ / Sunny │ \ / Partly cloudy │ \ / Partly cloudy │ │ .-. +9(5) °C │ .-. +9(6) °C │ _ /"".-. +9(6) °C │ _ /"".-. +9(5) °C │ │ ― ( ) ― → 27-34 km/h │ ― ( ) ― → 29-40 km/h │ \_( ). → 28-41 km/h │ \_( ). → 32-46 km/h │ │ `-’ 10 km │ `-’ 10 km │ /(___(__) 10 km │ /(___(__) 10 km │ │ / \ 0.0 mm | 0% │ / \ 0.0 mm | 0% │ 0.0 mm | 0% │ 0.0 mm | 0% │ └──────────────────────────────┴──────────────────────────────┴──────────────────────────────┴──────────────────────────────┘ Location: Barcelona, BCN, CAT, España [41.3825596,2.1771353] Follow @igor_chubin for wttr.in updates Any city Type: $weather CITY_NAME and you’ll get a similar table as the previous one, with data related to the “CITY_NAME” that you’ve put.]]></summary></entry><entry><title type="html">A python implementation of the CORDIC algorithm</title><link href="https://milia.dev/blog/2021/12/24/python-cordic/" rel="alternate" type="text/html" title="A python implementation of the CORDIC algorithm" /><published>2021-12-24T09:36:08+00:00</published><updated>2021-12-24T09:36:08+00:00</updated><id>https://milia.dev/blog/2021/12/24/python-cordic</id><content type="html" xml:base="https://milia.dev/blog/2021/12/24/python-cordic/"><![CDATA[<h1 id="what">What</h1>
<p>According to the <a href="https://en.wikipedia.org/wiki/CORDIC#Implementation">lemma</a> in the English Wikipedia:</p>

<blockquote>
  <p>CORDIC (for COordinate Rotation DIgital Computer), also known as Volder’s algorithm, or: Digit-by-digit method Circular CORDIC (Jack E. Volder),[1][2] Linear CORDIC, Hyperbolic CORDIC (John Stephen Walther),[3][4] and Generalized Hyperbolic CORDIC (GH CORDIC) (Yuanyong Luo et al.),[5][6] is a simple and efficient algorithm to calculate trigonometric functions, hyperbolic functions, square roots, multiplications, divisions, and exponentials and logarithms with arbitrary base, typically converging with one digit (or bit) per iteration. CORDIC is therefore also an example of digit-by-digit algorithms. CORDIC and closely related methods known as pseudo-multiplication and pseudo-division or factor combining are commonly used when no hardware multiplier is available (e.g. in simple microcontrollers and FPGAs), as the only operations it requires are additions, subtractions, bitshift and lookup tables. As such, they all belong to the class of shift-and-add algorithms. In computer science, CORDIC is often used to implement floating-point arithmetic when the target platform lacks hardware multiply for cost or space reasons.</p>
</blockquote>

<h1 id="why">Why</h1>
<p>About three years ago I posted <a href="https://www.reddit.com/r/mathematics/comments/be6vsw/fast_calculation_of_trig_functions">this question</a> at <a href="https://www.reddit.com/r/mathematics/">r/mathematics</a> community over Reddit.</p>

<p>This resulted to a very vibrant discussion and among the many solutions proposed was CORDIC.</p>

<p>I’ve pretty much translated <a href="https://en.wikipedia.org/wiki/CORDIC#Implementation">this</a> Octave/Matlab code from the English wikipedia lemma mentioned earlier, to Python3 + NumPy that I know fairly well.</p>

<h1 id="code">Code</h1>

<pre><code class="language-python">import numpy as np

pi = np.pi

def cordic(beta:float, n:int)-&gt; list[float]:
	"""
	This function computes [cos(beta), sin(beta)] using n iterations. Increasing n will increase the precision.

	Args:
		beta (float): the angle in radians
		n (integer): the number of iterations. Maximum number of n is 23 due to the table sizes.
	
	Returns:
		result (list): a list with the cos(beta) as the first argument and sin(beta) as the second argument
	"""

	if beta &lt; -pi/2 or beta &gt; pi/2:
		if beta &lt; 0:
			result = cordic(beta + pi, n)
		else:
			result = cordic(beta - pi, n) 
		result = -result
		return result

	# Initialization of tables of constants used by CORDIC
	# need a table of arctangents of negative powers of two, in radians:
	# angles = atan(2.^-(0:27));
	angles =  [
		0.78539816339745, 0.46364760900081, 0.24497866312686, 0.12435499454676, 
		0.06241880999596, 0.03123983343027, 0.01562372862048, 0.00781234106010, 
		0.00390623013197, 0.00195312251648, 0.00097656218956, 0.00048828121119, 
		0.00024414062015, 0.00012207031189, 0.00006103515617, 0.00003051757812, 
		0.00001525878906, 0.00000762939453, 0.00000381469727, 0.00000190734863, 
		0.00000095367432, 0.00000047683716, 0.00000023841858, 0.00000011920929, 
		0.00000005960464, 0.00000002980232, 0.00000001490116, 0.00000000745058 ]

	# and a table of products of reciprocal lengths of vectors [1, 2^-2j]:
	# Kvalues = cumprod(1./abs(1 + 1j*2.^(-(0:23))))
	Kvalues = [
		0.70710678118655, 0.63245553203368, 0.61357199107790, 0.60883391251775,
		0.60764825625617, 0.60735177014130, 0.60727764409353, 0.60725911229889,
		0.60725447933256, 0.60725332108988, 0.60725303152913, 0.60725295913894,
		0.60725294104140, 0.60725293651701, 0.60725293538591, 0.60725293510314,
		0.60725293503245, 0.60725293501477, 0.60725293501035, 0.60725293500925,
		0.60725293500897, 0.60725293500890, 0.60725293500889, 0.60725293500888 ]

	Kn = Kvalues[min(n, len(Kvalues))]

	# Initialize loop variables:
	v = [1, 0] # start with 2-vector cosine 1 and sine of zero
	power_of_two = 1
	angle = angles[0]

	# Iterations
	for j in range(0, n-1):
		if beta &lt; 0:
			sigma = -1
		else:
			sigma = 1

		factor = sigma * power_of_two
		# Note the matrix multiplication can be done using scaling by powers of two and addition subtraction
		R = [[1, -factor], [factor, 1]]		
		v = np.dot(R, v)		
		beta = beta - sigma * angle # update the remaining angle
		power_of_two = power_of_two / 2		
		# update the angle from table, or eventually by just dividing by two
		if j + 2 &gt; len(angles):
			angle = angle / 2
		else:
			angle = angles[j+1]

	# Adjust length of output vector to be [cos(beta), sin(beta)]
	v = v * Kn
	result = v	
	return result


def main() -&gt; None:
	zero = cordic(0, 23)      # expected output: [1, 0]
	print(zero)
	pitwo = cordic(pi/2,23)    # expected output: [0, 1]
	print(pitwo)
	pialone = cordic(pi, 23) 	  # expected output: [-1, 0]	
	print(pialone)
	pithree = cordic(pi/3, 23)   # expected output: [0.5, sqrt(3)/2]	
	print(pithree[0], pithree[1])
	pifour = cordic(pi/4, 23)   # expected output: [sqrt(2)/2, sqrt(2)/2]
	print(pifour[0],pifour[1])
	pisix = cordic(pi/6, 23)   # expected output: [sqrt(3)/2, 0.5]
	print(pisix[0],pisix[1])
	pi32 = cordic(3*pi/2, 23) # expected output: [0, -1]  	
	print(pi32[0], pi32[1])	

if __name__ == "__main__":
	main()
</code></pre>

<h1 id="thanks">Thanks</h1>

<p>I’d like to thank all those anonymous members of that subreddit for the great discussion that took place giving me many ideas among which to look for the CORDIC algorithm that I hadn’t heard before.</p>

<p>If none had responded to my original question, this work wouldn’t exist now. So, thank you <code>r/mathematics</code>.</p>]]></content><author><name>Milia</name></author><summary type="html"><![CDATA[What According to the lemma in the English Wikipedia: CORDIC (for COordinate Rotation DIgital Computer), also known as Volder’s algorithm, or: Digit-by-digit method Circular CORDIC (Jack E. Volder),[1][2] Linear CORDIC, Hyperbolic CORDIC (John Stephen Walther),[3][4] and Generalized Hyperbolic CORDIC (GH CORDIC) (Yuanyong Luo et al.),[5][6] is a simple and efficient algorithm to calculate trigonometric functions, hyperbolic functions, square roots, multiplications, divisions, and exponentials and logarithms with arbitrary base, typically converging with one digit (or bit) per iteration. CORDIC is therefore also an example of digit-by-digit algorithms. CORDIC and closely related methods known as pseudo-multiplication and pseudo-division or factor combining are commonly used when no hardware multiplier is available (e.g. in simple microcontrollers and FPGAs), as the only operations it requires are additions, subtractions, bitshift and lookup tables. As such, they all belong to the class of shift-and-add algorithms. In computer science, CORDIC is often used to implement floating-point arithmetic when the target platform lacks hardware multiply for cost or space reasons. Why About three years ago I posted this question at r/mathematics community over Reddit. This resulted to a very vibrant discussion and among the many solutions proposed was CORDIC. I’ve pretty much translated this Octave/Matlab code from the English wikipedia lemma mentioned earlier, to Python3 + NumPy that I know fairly well. Code import numpy as np pi = np.pi def cordic(beta:float, n:int)-&gt; list[float]: """ This function computes [cos(beta), sin(beta)] using n iterations. Increasing n will increase the precision. Args: beta (float): the angle in radians n (integer): the number of iterations. Maximum number of n is 23 due to the table sizes. Returns: result (list): a list with the cos(beta) as the first argument and sin(beta) as the second argument """ if beta &lt; -pi/2 or beta &gt; pi/2: if beta &lt; 0: result = cordic(beta + pi, n) else: result = cordic(beta - pi, n) result = -result return result # Initialization of tables of constants used by CORDIC # need a table of arctangents of negative powers of two, in radians: # angles = atan(2.^-(0:27)); angles = [ 0.78539816339745, 0.46364760900081, 0.24497866312686, 0.12435499454676, 0.06241880999596, 0.03123983343027, 0.01562372862048, 0.00781234106010, 0.00390623013197, 0.00195312251648, 0.00097656218956, 0.00048828121119, 0.00024414062015, 0.00012207031189, 0.00006103515617, 0.00003051757812, 0.00001525878906, 0.00000762939453, 0.00000381469727, 0.00000190734863, 0.00000095367432, 0.00000047683716, 0.00000023841858, 0.00000011920929, 0.00000005960464, 0.00000002980232, 0.00000001490116, 0.00000000745058 ] # and a table of products of reciprocal lengths of vectors [1, 2^-2j]: # Kvalues = cumprod(1./abs(1 + 1j*2.^(-(0:23)))) Kvalues = [ 0.70710678118655, 0.63245553203368, 0.61357199107790, 0.60883391251775, 0.60764825625617, 0.60735177014130, 0.60727764409353, 0.60725911229889, 0.60725447933256, 0.60725332108988, 0.60725303152913, 0.60725295913894, 0.60725294104140, 0.60725293651701, 0.60725293538591, 0.60725293510314, 0.60725293503245, 0.60725293501477, 0.60725293501035, 0.60725293500925, 0.60725293500897, 0.60725293500890, 0.60725293500889, 0.60725293500888 ] Kn = Kvalues[min(n, len(Kvalues))] # Initialize loop variables: v = [1, 0] # start with 2-vector cosine 1 and sine of zero power_of_two = 1 angle = angles[0] # Iterations for j in range(0, n-1): if beta &lt; 0: sigma = -1 else: sigma = 1 factor = sigma * power_of_two # Note the matrix multiplication can be done using scaling by powers of two and addition subtraction R = [[1, -factor], [factor, 1]] v = np.dot(R, v) beta = beta - sigma * angle # update the remaining angle power_of_two = power_of_two / 2 # update the angle from table, or eventually by just dividing by two if j + 2 &gt; len(angles): angle = angle / 2 else: angle = angles[j+1] # Adjust length of output vector to be [cos(beta), sin(beta)] v = v * Kn result = v return result def main() -&gt; None: zero = cordic(0, 23) # expected output: [1, 0] print(zero) pitwo = cordic(pi/2,23) # expected output: [0, 1] print(pitwo) pialone = cordic(pi, 23) # expected output: [-1, 0] print(pialone) pithree = cordic(pi/3, 23) # expected output: [0.5, sqrt(3)/2] print(pithree[0], pithree[1]) pifour = cordic(pi/4, 23) # expected output: [sqrt(2)/2, sqrt(2)/2] print(pifour[0],pifour[1]) pisix = cordic(pi/6, 23) # expected output: [sqrt(3)/2, 0.5] print(pisix[0],pisix[1]) pi32 = cordic(3*pi/2, 23) # expected output: [0, -1] print(pi32[0], pi32[1]) if __name__ == "__main__": main() Thanks I’d like to thank all those anonymous members of that subreddit for the great discussion that took place giving me many ideas among which to look for the CORDIC algorithm that I hadn’t heard before. If none had responded to my original question, this work wouldn’t exist now. So, thank you r/mathematics.]]></summary></entry><entry><title type="html">An oldtimer’s APL Code</title><link href="https://milia.dev/blog/2021/12/23/oldtimers-apl-code/" rel="alternate" type="text/html" title="An oldtimer’s APL Code" /><published>2021-12-23T07:35:38+00:00</published><updated>2021-12-23T07:35:38+00:00</updated><id>https://milia.dev/blog/2021/12/23/oldtimers-apl-code</id><content type="html" xml:base="https://milia.dev/blog/2021/12/23/oldtimers-apl-code/"><![CDATA[<h2 id="what">What</h2>
<p>Some pretty cool code from the 70s’-80s’ that a Reddit user shared at <a href="https://www.reddit.com/r/functionalprogramming/comments/rjs1ie/comment/hpcikjt/?utm_source=share&amp;utm_medium=web2x&amp;context=3">this</a> question.</p>

<p>Here’s what <a href="https://www.reddit.com/user/snarkuzoid/">u/snarkuzoid</a> wrote:</p>

<blockquote>
  <p>5x5 Knight’s Tour in APL</p>

  <p>It puts an A in the middle, then randomly does a knight’s tour, 
marking each cell with the next letter until it runs out of moves. 
Yes, it’s terrible code by modern standards. 
For some reason we were obsessed with very short programs.</p>
</blockquote>

<p>Here’s the printout:</p>

<p><img src="https://snarkus.com/AplContestSmall.jpg" alt="5x5 Knight's Tour in APL" title="5x5 Knight's Tour in APL" /></p>

<p>There’s <a href="https://www.reddit.com/r/functionalprogramming/comments/rjs1ie/comment/hpkbgod/?utm_source=share&amp;utm_medium=web2x&amp;context=3">more</a> to the story of the above code snippet:</p>

<blockquote>
  <p>Alas, I don’t know of any other code fragments I might have laying around.</p>

  <p>I only had this one because it was published as winner of the “Nice Knight” contest and I had a copy of the announcement.</p>

  <p>Thanks again. This really made my day.</p>
</blockquote>

<p>So apparently with this code the Reddit user had won a Leetcode competition of their time.</p>

<p>Pretty, cool, right?</p>

<h2 id="code">Code</h2>
<p>In modern Dyalog APL, v.18.0:</p>

<pre><code class="language-apl">⎕IO←1 ⍝ If it's set to 0 instead, there's no 'A' character in the center and thus the code behaves incorrectly!
∇Z←EX2
  V←13+I←0×⍴A←25⍴'0'
  Z← 5 5 ⍴A,0⍴A[C←1↑V]←'ABCDEFGHIJKLMNOPQRSTUVWXY'[I←I+1]
  R←⍉(2,⍴V)⍴(⌊0.8+V÷5),1+5|¯1+V←(A='0')/⍳25
  T←(⌽2,⍴V)⍴(⌊0.8+C÷5),1+5|C-1
  →2×0≠⍴V←(?8)⌽((10⊥|⍉T-R)∊ 21 12)/V
∇
</code></pre>

<h2 id="results">Results</h2>
<p>Here are the results when run the above <code>tradfn</code> a couple times, from RIDE IDE on a Lubuntu 18.04, when I had <code>⎕IO←0</code>:</p>

<pre><code>     EX2
0JG0M
00DKH
0FIB0
LC0E0
00000
      EX2
00G00
00DIF
0H0BM
JCLE0
O00NK
      EX2
0JG00
000EH
0FIB0
0000D
00C00
      EX2
0RMF0
0EHQL
0NSBG
PIDOT
K0UJC
</code></pre>
<p>The above results are incorrect.</p>

<p>Here are some results with <code>⎕IO←1</code>:</p>

<pre><code>      EX2
00ELG
DMHQ0
IRAFK
NCJSP
0TOB0
      EX2
00000
0E0C0
00AF0
00D0B
0000G
      EX2
GBO00
N0FIP
CHALE
0MDQJ
0RK00
      EX2
GBK00
L0F0J
CHA0E
0MDI0
000N0
</code></pre>
<p>The above results are correct.</p>

<h2 id="correctness-of-the-results">Correctness of the results</h2>
<p><del>There’s no <code>Alpha</code> in the middle. Does the code work correctly with Dyalog APL?</del> (this was because IO had the value zero: <code>⎕IO←0</code>).</p>

<p>Results with <code>⎕IO←1</code> look correct. There’s the ‘A’ char in the middle.</p>

<h2 id="try-it-out-online">Try it out online</h2>
<h3 id="issue">Issue</h3>
<p>As is with the <code>tradfn</code> it doesn’t work on the <a href="tryapl.org">tryapl.org</a> site for some reason:</p>

<pre><code>∇
SYNTAX ERROR
      ∇
      ∧
</code></pre>

<p>It worked fine on the RIDE IDE of Dyalog APL though.</p>

<p>It seems that <code>tryapl.org</code> doesn’t support tradfns.</p>

<h3 id="fix">Fix</h3>
<p>According to Adám from Dyalog, now tryapl.org supports tradfns. But the code cannot be copy pasted as is. Instead:</p>

<blockquote>
  <p>Either paste it line by line, pressing Alt+Enter after each line (except the last), or begin each line (except for the first) with a tab character (not the tab key).</p>
</blockquote>

<p>I’ve found in the <a href="http://help.dyalog.com/12.0/index.html?page=html%2Frelnotes%2Fcontrol%20characters.htm">docs</a> of Dyalog APL that the Tab key has to be defined as <code>⎕UCS 9</code>.</p>

<p>So the following code should work on tryapl.org:</p>

<pre><code class="language-apl">⎕IO←1 ⍝ Without this there's no 'A' character in the center!
Tab←⎕UCS 9 ⍝ Defining the tab character ('\t' in C).

∇Z←EX2_online
Tab V←13+I←0×⍴A←25⍴'0'
Tab Z← 5 5 ⍴A,0⍴A[C←1↑V]←'ABCDEFGHIJKLMNOPQRSTUVWXY'[I←I+1]
Tab R←⍉(2,⍴V)⍴(⌊0.8+V÷5),1+5|¯1+V←(A='0')/⍳25
Tab T←(⌽2,⍴V)⍴(⌊0.8+C÷5),1+5|C-1
Tab →2×0≠⍴V←(?8)⌽((10⊥|⍉T-R)∊ 21 12)/V
∇
</code></pre>
<p>Update: the above code still fails in tryapl.org.</p>

<h2 id="future-work">Future work</h2>
<ul>
  <li><del>Make sure that the <code>tradfn</code> implementation is correct for Dyalog APL.</del> All good.</li>
  <li>Rewrite the <code>tradfn</code> as a <a href="https://aplwiki.com/wiki/Dfn">dfn</a> so that it runs on the  online interpreter…First understand the program. From what the folks in the APLjk discord server say, the line <code>→2×0≠⍴V←(?8)⌽((10⊥|⍉T-R)∊21 12)/V</code> doesn’t work in dfns because the right arrow is only for tradfns and tradfns aren’t supported in <code>tryapl.org</code>.</li>
</ul>

<h2 id="thanks">Thanks</h2>
<ul>
  <li>To the user <code>u/snarkuzoid</code> who trusted me with their code.</li>
  <li>To <code>bubbler</code> from APLjk discord server that found the <code>IO</code> bug.</li>
  <li>To <code>Adám</code> for trying to debug the tradfn error that appeared in tryapl.org.</li>
</ul>]]></content><author><name>Milia</name></author><summary type="html"><![CDATA[What Some pretty cool code from the 70s’-80s’ that a Reddit user shared at this question. Here’s what u/snarkuzoid wrote: 5x5 Knight’s Tour in APL It puts an A in the middle, then randomly does a knight’s tour, marking each cell with the next letter until it runs out of moves. Yes, it’s terrible code by modern standards. For some reason we were obsessed with very short programs. Here’s the printout: There’s more to the story of the above code snippet: Alas, I don’t know of any other code fragments I might have laying around. I only had this one because it was published as winner of the “Nice Knight” contest and I had a copy of the announcement. Thanks again. This really made my day. So apparently with this code the Reddit user had won a Leetcode competition of their time. Pretty, cool, right? Code In modern Dyalog APL, v.18.0: ⎕IO←1 ⍝ If it's set to 0 instead, there's no 'A' character in the center and thus the code behaves incorrectly! ∇Z←EX2 V←13+I←0×⍴A←25⍴'0' Z← 5 5 ⍴A,0⍴A[C←1↑V]←'ABCDEFGHIJKLMNOPQRSTUVWXY'[I←I+1] R←⍉(2,⍴V)⍴(⌊0.8+V÷5),1+5|¯1+V←(A='0')/⍳25 T←(⌽2,⍴V)⍴(⌊0.8+C÷5),1+5|C-1 →2×0≠⍴V←(?8)⌽((10⊥|⍉T-R)∊ 21 12)/V ∇ Results Here are the results when run the above tradfn a couple times, from RIDE IDE on a Lubuntu 18.04, when I had ⎕IO←0: EX2 0JG0M 00DKH 0FIB0 LC0E0 00000 EX2 00G00 00DIF 0H0BM JCLE0 O00NK EX2 0JG00 000EH 0FIB0 0000D 00C00 EX2 0RMF0 0EHQL 0NSBG PIDOT K0UJC The above results are incorrect. Here are some results with ⎕IO←1: EX2 00ELG DMHQ0 IRAFK NCJSP 0TOB0 EX2 00000 0E0C0 00AF0 00D0B 0000G EX2 GBO00 N0FIP CHALE 0MDQJ 0RK00 EX2 GBK00 L0F0J CHA0E 0MDI0 000N0 The above results are correct. Correctness of the results There’s no Alpha in the middle. Does the code work correctly with Dyalog APL? (this was because IO had the value zero: ⎕IO←0). Results with ⎕IO←1 look correct. There’s the ‘A’ char in the middle. Try it out online Issue As is with the tradfn it doesn’t work on the tryapl.org site for some reason: ∇ SYNTAX ERROR ∇ ∧ It worked fine on the RIDE IDE of Dyalog APL though. It seems that tryapl.org doesn’t support tradfns. Fix According to Adám from Dyalog, now tryapl.org supports tradfns. But the code cannot be copy pasted as is. Instead: Either paste it line by line, pressing Alt+Enter after each line (except the last), or begin each line (except for the first) with a tab character (not the tab key). I’ve found in the docs of Dyalog APL that the Tab key has to be defined as ⎕UCS 9. So the following code should work on tryapl.org: ⎕IO←1 ⍝ Without this there's no 'A' character in the center! Tab←⎕UCS 9 ⍝ Defining the tab character ('\t' in C). ∇Z←EX2_online Tab V←13+I←0×⍴A←25⍴'0' Tab Z← 5 5 ⍴A,0⍴A[C←1↑V]←'ABCDEFGHIJKLMNOPQRSTUVWXY'[I←I+1] Tab R←⍉(2,⍴V)⍴(⌊0.8+V÷5),1+5|¯1+V←(A='0')/⍳25 Tab T←(⌽2,⍴V)⍴(⌊0.8+C÷5),1+5|C-1 Tab →2×0≠⍴V←(?8)⌽((10⊥|⍉T-R)∊ 21 12)/V ∇ Update: the above code still fails in tryapl.org. Future work Make sure that the tradfn implementation is correct for Dyalog APL. All good. Rewrite the tradfn as a dfn so that it runs on the online interpreter…First understand the program. From what the folks in the APLjk discord server say, the line →2×0≠⍴V←(?8)⌽((10⊥|⍉T-R)∊21 12)/V doesn’t work in dfns because the right arrow is only for tradfns and tradfns aren’t supported in tryapl.org. Thanks To the user u/snarkuzoid who trusted me with their code. To bubbler from APLjk discord server that found the IO bug. To Adám for trying to debug the tradfn error that appeared in tryapl.org.]]></summary></entry><entry><title type="html">Testing SymPy</title><link href="https://milia.dev/blog/2021/12/22/testing-sympy/" rel="alternate" type="text/html" title="Testing SymPy" /><published>2021-12-22T19:12:08+00:00</published><updated>2021-12-22T19:12:08+00:00</updated><id>https://milia.dev/blog/2021/12/22/testing-sympy</id><content type="html" xml:base="https://milia.dev/blog/2021/12/22/testing-sympy/"><![CDATA[<h2 id="what">What</h2>
<p>I’ve been a great fan of Mathematica since the first time I’ve used it back in 2000.</p>

<p>After a couple discussions of one of the creators of SymPy over Twitter, I decided to look deeper in this interesting project.</p>

<h2 id="tests">Tests</h2>

<p>This is the Python version:</p>

<pre><code>Python 3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)] on win32
</code></pre>

<p>A few simple stuff first.</p>
<pre><code class="language-python">&gt;&gt;&gt; 1+1
2
&gt;&gt;&gt;
&gt;&gt;&gt; from sympy.abc import x,y
&gt;&gt;&gt; e = x + y + x
&gt;&gt;&gt; print(e)
2*x + y
</code></pre>
<p>This is nice. SymPy can do easily simple algebraic manipulations.</p>

<p>Let’s do some indefinite integrals.</p>

<p>I remember a few hard ones from my Calculus1 course.</p>

<pre><code class="language-python">&gt;&gt;&gt; from sympy import *
&gt;&gt;&gt; x = Symbol('x')
&gt;&gt;&gt;
&gt;&gt;&gt; limit(sin(x)/x, x, 0)
1
&gt;&gt;&gt;
&gt;&gt;&gt; integrate(1/x, x)
log(x)
&gt;&gt;&gt;
&gt;&gt;&gt; integrate(cos(x), x)
sin(x)
&gt;&gt;&gt;
&gt;&gt;&gt; integrate(1/cos(x), x)
-log(sin(x) - 1)/2 + log(sin(x) + 1)/2
&gt;&gt;&gt;
&gt;&gt;&gt; integrate(1/sin(x),x)
log(cos(x) - 1)/2 - log(cos(x) + 1)/2
&gt;&gt;&gt;
&gt;&gt;&gt; integrate(sin(x*x), x)
3*sqrt(2)*sqrt(pi)*fresnels(sqrt(2)*x/sqrt(pi))*gamma(3/4)/(8*gamma(7/4))
&gt;&gt;&gt;
&gt;&gt;&gt; integrate(cos(x**2), x)
sqrt(2)*sqrt(pi)*fresnelc(sqrt(2)*x/sqrt(pi))*gamma(1/4)/(8*gamma(5/4))
&gt;&gt;&gt;
&gt;&gt;&gt; integrate(tan(x**2), x)
Integral(tan(x**2), x) # So it seems that this integral can't be evaluated symbolically. 
&gt;&gt;&gt;
&gt;&gt;&gt; integrate(cot(x**2), x)
Integral(cot(x**2), x) # Same as with the tan(x**2).
&gt;&gt;&gt;
&gt;&gt;&gt; integrate(sec(x**2), x)
Integral(sec(x**2), x)  # Same as with the tan(x**2).
&gt;&gt;&gt;
&gt;&gt;&gt; integrate(sin(cos(tan(cot(sec(x))))), x) # Same as with the tan(x**2).
Integral(sin(cos(tan(cot(sec(x))))), x)
</code></pre>
<p>Definite integrals:</p>

<pre><code class="language-python">&gt;&gt;&gt; integrate(sin(x**2), (x, 0, 10))
3*sqrt(2)*sqrt(pi)*fresnels(10*sqrt(2)/sqrt(pi))*gamma(3/4)/(8*gamma(7/4))
&gt;&gt;&gt; N(integrate(sin(x**2), (x, 0, 10)))
0.583670899929623
</code></pre>
<p>Nice !</p>

<h2 id="conclusions">Conclusions</h2>
<p>Pretty amazing project.</p>

<p>I think I’ll try to put some of my time in this OSS project.</p>]]></content><author><name>Milia</name></author><summary type="html"><![CDATA[What I’ve been a great fan of Mathematica since the first time I’ve used it back in 2000. After a couple discussions of one of the creators of SymPy over Twitter, I decided to look deeper in this interesting project. Tests This is the Python version: Python 3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)] on win32 A few simple stuff first. &gt;&gt;&gt; 1+1 2 &gt;&gt;&gt; &gt;&gt;&gt; from sympy.abc import x,y &gt;&gt;&gt; e = x + y + x &gt;&gt;&gt; print(e) 2*x + y This is nice. SymPy can do easily simple algebraic manipulations. Let’s do some indefinite integrals. I remember a few hard ones from my Calculus1 course. &gt;&gt;&gt; from sympy import * &gt;&gt;&gt; x = Symbol('x') &gt;&gt;&gt; &gt;&gt;&gt; limit(sin(x)/x, x, 0) 1 &gt;&gt;&gt; &gt;&gt;&gt; integrate(1/x, x) log(x) &gt;&gt;&gt; &gt;&gt;&gt; integrate(cos(x), x) sin(x) &gt;&gt;&gt; &gt;&gt;&gt; integrate(1/cos(x), x) -log(sin(x) - 1)/2 + log(sin(x) + 1)/2 &gt;&gt;&gt; &gt;&gt;&gt; integrate(1/sin(x),x) log(cos(x) - 1)/2 - log(cos(x) + 1)/2 &gt;&gt;&gt; &gt;&gt;&gt; integrate(sin(x*x), x) 3*sqrt(2)*sqrt(pi)*fresnels(sqrt(2)*x/sqrt(pi))*gamma(3/4)/(8*gamma(7/4)) &gt;&gt;&gt; &gt;&gt;&gt; integrate(cos(x**2), x) sqrt(2)*sqrt(pi)*fresnelc(sqrt(2)*x/sqrt(pi))*gamma(1/4)/(8*gamma(5/4)) &gt;&gt;&gt; &gt;&gt;&gt; integrate(tan(x**2), x) Integral(tan(x**2), x) # So it seems that this integral can't be evaluated symbolically. &gt;&gt;&gt; &gt;&gt;&gt; integrate(cot(x**2), x) Integral(cot(x**2), x) # Same as with the tan(x**2). &gt;&gt;&gt; &gt;&gt;&gt; integrate(sec(x**2), x) Integral(sec(x**2), x) # Same as with the tan(x**2). &gt;&gt;&gt; &gt;&gt;&gt; integrate(sin(cos(tan(cot(sec(x))))), x) # Same as with the tan(x**2). Integral(sin(cos(tan(cot(sec(x))))), x) Definite integrals: &gt;&gt;&gt; integrate(sin(x**2), (x, 0, 10)) 3*sqrt(2)*sqrt(pi)*fresnels(10*sqrt(2)/sqrt(pi))*gamma(3/4)/(8*gamma(7/4)) &gt;&gt;&gt; N(integrate(sin(x**2), (x, 0, 10))) 0.583670899929623 Nice ! Conclusions Pretty amazing project. I think I’ll try to put some of my time in this OSS project.]]></summary></entry></feed>