Skip to content

Instantly share code, notes, and snippets.

View ignamv's full-sized avatar

ignamv

View GitHub Profile
@ignamv
ignamv / objectbrowser.py
Created November 11, 2023 15:46
Collapsible Jupyter display for hierarchies of dict/list/tuple
import html
def to_html(x):
if isinstance(x, (list, tuple, dict)):
if isinstance(x, (list, tuple)):
elements = "".join(
f"<li>[{ii}]: {to_html(elem)}</li>" for ii, elem in enumerate(x)
)
else:
@ignamv
ignamv / poll_exam_vacancies.py
Created February 13, 2022 09:45
Poll whether exam vacancies are still available for Goethe B1 exam in Münchner Volkshochschule, show message if not
import requests
import subprocess
import datetime
from bs4 import BeautifulSoup
def are_there_free_places(html):
soup = BeautifulSoup(html, 'html.parser')
places = soup.find(**{'data-label': 'Plätze: '}).text.strip()
return places == 'Noch Plätze frei'
import bs4
import dateparser
import re
with open('/home/imartinezvazquez/rss/mp3_long.php') as fd:
doc = bs4.BeautifulSoup(fd.read())
links = doc.find_all('a')
links = [l for l in links if l.attrs['href'].endswith('.mp3')]
<?xml version='1.0' encoding='UTF-8'?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<channel>
<title>Dhammatalks.org Lectures</title>
<link>https://www.dhammatalks.org/mp3_long.php</link>
<description>Dhammatalks.org Lectures</description>
<itunes:explicit>no</itunes:explicit>
<docs>http://www.rssboard.org/rss-specification</docs>
<generator>python-podgen v1.0.0 https://podgen.readthedocs.org</generator>
<lastBuildDate>Fri, 08 Feb 2019 17:23:37 +0000</lastBuildDate>
<?xml version='1.0' encoding='UTF-8'?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<channel>
<title>Dhammatalks.org Lectures</title>
<link>https://www.dhammatalks.org/mp3_long.php</link>
<description>Dhammatalks.org Lectures</description>
<itunes:explicit>no</itunes:explicit>
<docs>http://www.rssboard.org/rss-specification</docs>
<generator>python-podgen v1.0.0 https://podgen.readthedocs.org</generator>
<lastBuildDate>Fri, 08 Feb 2019 17:23:37 +0000</lastBuildDate>
@ignamv
ignamv / spectre.vim
Last active February 6, 2019 18:12
Spectre line folding for Vim
setlocal keywordprg=manspectre
setlocal foldmethod=expr
setlocal foldexpr=GetSpectreFold(v:lnum)
function! NextNonCommentLine(lnum)
let numlines = line('$')
let current = a:lnum + 1
while current <= numlines
@ignamv
ignamv / format_si.py
Created May 21, 2016 19:30
Python SI prefix formatting
def format_si(number, significant_digits=3):
"""Format number using SI prefixes
The prefix is chosen such that the number before the prefix is 1<x<1000."""
if number == 0:
return '0 '
prefixes = list('afpnμm') + [''] + list('kMGTPE')
multipliers = 10.**np.arange(-18, 19, 3)
inv_multipliers = 10.**(-np.arange(-18, 19, 3))
abs_number = abs(number)
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@ignamv
ignamv / gist:6406714
Last active December 30, 2021 19:21
Zotero translator for libgen.org
{
"translatorID": "d1b38d36-6bcc-4828-969f-b08a2a2e0723",
"label": "Libgen",
"creator": "Ignacio Martinez V.",
"target": "libgen\\.org|gen\\.lib\\.rus\\.ec",
"minVersion": "1.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,