ix5 tech
Technology section • ix5.org
Pandas: Apply function per row with context
April 12, 2023
def get_affected_days(start, finish): pass pairs = df.apply( lambda row: get_affected_days(row['started_at'], row['finished_at']), axis=1 )
Plotly
March 31, 2023
Sane plotly defaults, margins, with legends inside chart import pandas as pd import numpy as np import plotly.express as px import plotly.graph_objects as go plotly_config = dict( autosize=True, margin=dict(l=0, r=0, b=0, t=0, pad=0), ) fig.update_layout(**plotly_config) fig.update_layout(legend=dict( yanchor="top", y=0.99, xanchor="center", x=0.1, )) _filename = 'filename' fig.write_image(f'{_filename}.svg') fig.show() Setting plotly labels fig = px.bar(df['url'].resample('1w').count(), labels={'value': 'Disruptions'}).update_layout( autosize=True, margin=dict(l=0, r=0, b=0, t=0, pad=0), ).update_layout(showlegend=False) fig.write_image("image.svg") fig.show() Pivot operations and MultiIndex to flat columns important = russia_bans important.loc[~russia_bans['product'].str.startswith(_cols), 'product'] = 'Other' sanctions_with_other = (important .groupby( by=[important['date.implemented'], important['product'].str[:2]], group_keys=True, ) .count() .rename(columns={'product': 'product.count'}) .reset_index('product') .loc[:, ['product', 'product.count']] ) sanctions_with_other = pd.DataFrame( sanctions_with_other.pivot(columns=['product']) ) sanctions_with_other.columns = sanctions_with_other.columns.get_level_values(1) # Only for including "Other" sanctions_with_other = sanctions_with_other.loc[:, ('Ot',) + _cols].rename(columns={'Ot': 'Other'}) sanctions_with_other.index = pd.to_datetime(sanctions_with_other.index) Helper: Embedding plotly charts as static images for (PDF) export EXPORT_TO_PDF = False import os from IPython.display import Image def plotly_img_save_and_inline(fig, filename): fig.write_image(f'{filename}.svg') fig.write_image(f'{filename}.png', width=1000) if EXPORT_TO_PDF: print('To pdf, saving') img = Image(data=f'{filename}.png', width=1000) # Declutter by removing the png file from disk again, # we only need vector graphics os.remove(f'{filename}.png') return img print('Inline') fig.show() fig = px.line( strikes.resample('d').count() ) _filename = 'image' plotly_img_save_and_inline(fig, _filename)
Changed Zoho IMAP Access for Custom Domain
March 24, 2023
Zoho, a suite of business applications allowing, among others, having an email account using your own domain name, silently changed their access procedure, leading to Login failed messages in e.g. Thunderbird. The gist of it is that you need to use imappro.zoho.eu for your IMAP server and smtppro.zoho.eu for outgoing SMTP server to continue using your own domain name. The updated guide is at the Help pages for Zoho mail. Incoming server hostname: If you are an organization user with a domain-based account, provide imappro.zoho.eu, select 993 for Port from the drop-down, and Normal Password for authentication. For Outgoing server hostname: If you are an organization user with a domain-based account, provide smtppro.zoho.eu, select 465 for Port from the drop-down, and Normal Password for authentication.
GNOME: Clear lock timer
February 21, 2023
Run faillock --user <username> --reset. Sources: reddit, reddit
Zotero: Eliminate imported duplicates
February 14, 2023
After exporting a “collection” in Zotero to send to an acquaintance, I imported the exported file to check that the archive file was valid, choosing to “link” the imported files rather than importing them (i.e., storing them inside the Zotero data folder). The import had gone smoothly and I deleted the collection again, but foolishly did not chose to delete the collection contents. This left me with a large number of duplicate items scattered around, as “orphan” items with no parents.
spaCy Terms Cheat Sheet
December 22, 2022
I am currently learning to deal with Natural Language Processing (NLP) using spaCy. These are the terms that I often end up having to look up. I wrote a small bash helper function for myself: # spaCy explain term function explain() { _query=$1 # activate virtualenv here, if necessary python -c "from spacy import explain; print(explain('"$_query"'))" } Glossary Extracted from spaCy: glossary.py and polished up a bit. spaCy license: MIT. POS tags: Universal POS Tags See universaldependencies.org/u/pos/
Launching scripts from GNOME shortcuts
September 24, 2022
As of at least 2022-09-24, launching small scripts that spawn a rofi interface via the GNOME shell shortcuts interface would fail for me with the following message: app-gnome-\x7e\x2fcontrol.sh-3565.scope: No PIDs left to attach to the scope's control group, refusing. app-gnome-\x7e\x2fcontrol.sh-3565.scope: Failed with result 'resources'. Failed to start Application launched by gsd-media-keys. My control script would be executable and located at ~/control.sh and launch something like rofi -dmenu -i <choices>. I had the association (e.g. for <Super>-i) entered through the GNOME settings keyboard shortcuts as command ~/control.sh and this used to work just fine for years.
Anki Webview Issues
April 15, 2022
As of 2022-04-15, Anki will open on my up-to-date Arch Linux install, but show a blank page instead of my decks. $ pacman -Q anki qt5-base qt6-base anki-official-binary-bundle 2.1.49-1 qt5-base 5.15.3+kde+r137-1 qt6-base 6.3.0-1 I suspected an issue with the webview implementation, since menus, preferences and the like still work. A topic on the [Ankiweb Forums][forums] surfaces the suggestion to disable the Qt webengine seccomp filter: QTWEBENGINE_CHROMIUM_FLAGS="--disable-seccomp-filter-sandbox" Add the environment variable to your .bashrc or wherever or just prepend it to any launches of Anki:
Netgear R6120 OpenWRT
February 16, 2021
Links Netgear R6120 OpenWRT page Firmware download nmrpflash Get nmrpflash $ git clone https://github.com/jclehner/nmrpflash.git $ cd nmrpflash/ $ make Check interfaces ./nmrpflash -L enp0s31f6 192.168.1.8 8c:16:45:22:f5:71 wlp2s0 192.168.1.6 74:e5:f9:e7:79:26 For me, enp0s31f6 showed 0.0.0.0 as IP: enp0s31f6 0.0.0.0.0 8c:16:45:22:f5:71 Flash Plug LAN cable from computer into LAN port 1 of the router. NOT into the WAN port. Turn off router. $ sudo ./nmrpflash -i enp0s31f6 -f ~/downloads/netgear-openwrt/factory/openwrt-ramips-mt76x8-netgear_r6120-squashfs-factory.img Waiting for physical connection. Turn on router
Languages
February 7, 2021
For reasons that (I swear!) have nothing to do with my nationality, I have always avoided acquiring any modicum of French language skills. I took Latin in high school and while at university, Spanish sounded like the clearly superior investment, especially for my social life. Hearing people speak French, I was having trouble holding it together, because, obviously this was a fake language designed to make you emit as many silly noncoherent noises as possible.