Skip to content

Instantly share code, notes, and snippets.

View yunruse's full-sized avatar
don't forget to drink some water!

Mia yun Ruse yunruse

don't forget to drink some water!
View GitHub Profile
@yunruse
yunruse / pypi_stats.py
Last active January 29, 2023 12:05
Python 3.x minor version usage stats, by proxy of PyPI downloads
'''
Python 3.x minor version usage stats, by proxy of PyPI downloads.
Placed into public domain by Mia yun Ruse.
(I wouldn't recommend using it though. It's a tad hacky.)
'''
from datetime import date as Date, timedelta
from requests import get
from json import loads
@yunruse
yunruse / phoneticpassword.py
Created December 2, 2022 17:14
Phonetic password schema, a la iCloud
'''
Small tool that generates a phonetic password with a schema
identical to that used in iCloud's password generators.
Pronouncable-ish with 20 characters and ~70 bits of entropy.
Useful for password managers or sysadmins.
'''
# Example password from schema: fivhAp-riznux-0mizhi
# Let V be the set of all lowercase vowels "aiueoy".
# Let C be the set of all lowercase consonants in the Latin (English) alphabet.
@yunruse
yunruse / pangram.ipynb
Created May 17, 2022 03:55
Toki Pona Pangram Maker
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@yunruse
yunruse / redirect.py
Created February 5, 2022 16:07
Output to stdout only if currently being redirected with > or >>
from os import fstat
from stat import S_ISREG
def is_redirected() -> bool:
'''Detect if program is being redirected (i.e. using the > or >> operator).'''
return S_ISREG(fstat(1).st_mode)
if __name__ == '__main__':
if is_redirected():
print('Hi file!')
@yunruse
yunruse / ed_event.py
Created January 14, 2022 14:03
University of Edinburgh event pre-booking calendar generator
from datetime import datetime, timedelta
import re
from ics import Calendar, Event
def read(path):
calendar = Calendar()
with open(path) as f:
description = None
@yunruse
yunruse / safari_history.py
Last active January 1, 2022 17:15
Extract Safari history
import sqlite3
from typing import NamedTuple
from datetime import datetime
HISTORY_EPOCH = 978307200
class Visit(NamedTuple):
date: datetime
title: str
url: str
@yunruse
yunruse / passwords-bitwarden-to-icloud.py
Created August 27, 2021 23:56
Quick script to turn Bitwarden exported CSVs to iCloud CSVs with basic config
import csv
import sys
from urllib.parse import urlparse
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument("input")
parser.add_argument("output")
parser.add_argument(
"--format-name", "-n", action="store_true",
@yunruse
yunruse / arbitary_base.py
Last active May 22, 2021 14:44
Math, in arbitrary bases! Even irrational ones!
import re
from math import log, ceil
DIGITS = '0123456789abcdefghijklmnopqrtstuvwxyz'
def to_number(
base,
string_or_digits,
decimal_digits=None,
assert_base=True,
@yunruse
yunruse / taylor.py
Last active May 21, 2021 13:07
Yes, you can do trigonometry on matrices using the Taylor series, and identities will hold.
import math
import numpy as np
import numpy as np
from numpy.linalg import matrix_power
def pow(a, n):
if isinstance(a, np.ndarray):
return matrix_power(a, n)
else:
@yunruse
yunruse / mcu.md
Last active May 16, 2021 18:11
Because sometimes, you just get bored, okay?

Every time in the MCU someone says "Marvel", "Cinematic" or "Universe". It took me 31 minutes of searching the film scripts, so here it is.

Currently goes up to Phase 3 (i.e. up to and including Avengers Endgame.)

Total count:

  • "Marvel": 4 (the name "Mar-Vell" was not counted)
  • "Cinematic": 0
  • "Universe": 68