This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Minimal proof of concept for atomic and iterable string types, 17 Feb 2023. | |
Illustration for Python Ideas discussion | |
see https://discuss.python.org/t/an-interesting-pytype-experiment-and-a-possible-extension-to-strings/23749/51 | |
""" | |
from collections.abc import Container, Sequence, Sized | |
from typing import Final, overload, Self, TYPE_CHECKING | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''AoC 2018 #03, safari-https://adventofcode.com/2018/day/3 - Olaf, 3 Dec 2018''' | |
import numpy, re | |
regexp = re.compile(r'#(\d+) @ (\d+),(\d+): (\d+)x(\d+)') | |
with open('AoC03.txt') as file: | |
data = numpy.array(tuple(tuple(map(int, regexp.match(line).groups())) for line in file)) | |
W, H = (max(data[..., 1 + dim] + data[..., 3 + dim]) for dim in range(2)) # max(x + w), max(y + h) | |
board = numpy.zeros((W + 1, H + 1), dtype=int) # size [0, W] x [0, H] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''AoC 2018 #02, safari-https://adventofcode.com/2018/day/2 - Olaf, 2 Dec 2018''' | |
import collections, functools, operator, typing | |
with open('AoC02.txt') as file: | |
ids = tuple(map(str.strip, file.readlines())) | |
def freq_counts(s: str) -> typing.Iterable[int]: | |
'''frequency counts >1 that apply to chars in string s | |
>>> ids = 'abcdef bababc abbcde abcccd aabcdd abcdee ababab'.split() # from AoC explanation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'''AoC 2018 #01, https://adventofcode.com/2018/day/1 - Olaf, 1 Dec 2018''' | |
with open('AoC01.txt') as file: | |
deltas = tuple(map(int, file.readlines())) | |
print('first answer', sum(deltas)) | |
frequency, previous, found = 0, set(), False | |
while not found: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# Olaf, Dec 2015, Pythonista 1.6 beta | |
'''Appex GetFromURL | |
Pythonista app extension for use on share sheet of other apps to import file from URL into Pythonista | |
The file is saved at HOME/DESTINATION without user interaction (no 'save as' dialog) unless duplicate''' | |
from __future__ import print_function | |
try: | |
import appex, console, contextlib, itertools, os, os.path, sys, time, urllib, urlparse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Retrieved from https://gist.githubusercontent.com/omz/9882a00abf59c6009fa4/raw/139afad596c6d46f2f104b16120eefbb36e9960c/Audio%2520Recorder.py on Sat 26-Dec-2015 07:22:53 | |
# Olaf, 26 Dec 2015, updated to use objc_util instead of ctypes; also removed seemingly superfluous AVAudioSession | |
import objc_util, os | |
def main(): | |
NSMutableDictionary = objc_util.ObjCClass('NSMutableDictionary') | |
settings = NSMutableDictionary.dictionary() | |
kAudioFormatMPEG4AAC = 1633772320 | |
settings.setObject_forKey_(kAudioFormatMPEG4AAC, 'AVFormatIDKey') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 2014-08-18 New from Gist.py downloaded from https://gist.github.com/dhutchison/8528503 | |
# 2014-08-18 added generation of header with date, name, download url | |
### Based on: https://gist.github.com/b0644f5ed1d94bd32805 | |
### This version strips unicode characters from the downloaded script | |
### to work around the currently limited unicode support of the editor | |
### module. | |
# This script downloads and opens a Gist from a URL in the clipboard. | |
# It's meant to be put in the editor's actions menu. |