Skip to content

Instantly share code, notes, and snippets.

@tritium21
tritium21 / fizzbuzz.py
Last active December 6, 2023 22:41
One of the least readable fizzbuzz
print("\n".join(["FizzBuzz", *[["Buzz", *[["Fizz", *[str(i)]*2][i%3]]*4][i%5]]*14][i%15] for i in range(1,101)))
print(
"\n".join(
[
"FizzBuzz",
*[
[
"Buzz",
*[
@tritium21
tritium21 / .gitignore
Last active May 29, 2020 09:28
A tool to make a windows installer for nikola
python*.zip
dist/
@tritium21
tritium21 / blah.py
Last active February 9, 2020 13:00
magicians = "penn teller copperfield".split()
for magicians in magicians:
print(magicians)
# IS THE SAME AS
magicians = "penn teller copperfield".split()
_magicians_it = iter(magicians) # never enters the namespace
#!/usr/bin/env python3.8
import hashlib
import io
import json
import pathlib
import tarfile
def make_tarinfo(path, data):
fob = io.BytesIO(data.encode())
info = tarfile.TarInfo(name=path)
@tritium21
tritium21 / decorator.py
Last active June 8, 2020 13:00
This is a demo of one way to write a decorator.
"""
This is not the right way, or wrong way, to write a decorator;
its just things you can do, with Python 3.8+, to make decorators
more powerful
"""
import functools
import inspect
def demo(func=None, /, *, message='Default Message'):
@tritium21
tritium21 / alchemical_model.py
Created September 19, 2019 08:25
SQLAlchemy to/from PyQt Adapters
#!/usr/bin/env python3
# © 2013 Mark Harviston, BSD License
# 2016: update to use PyQt5/Python3, some enhancements by Christian González
"""
Qt data models that bind to SQLAlchemy queries
"""
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtSql import QSqlTableModel
from PyQt5.Qt import QVariant, Qt
@tritium21
tritium21 / spelltextedit.py
Created September 18, 2019 08:46 — forked from ssokolow/spelltextedit.py
Spell-checked QPlainTextEdit for PyQt 5.x using PyEnchant
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""QPlainTextEdit With Inline Spell Check
Original PyQt4 Version:
https://nachtimwald.com/2009/08/22/qplaintextedit-with-in-line-spell-check/
Copyright 2009 John Schember
Copyright 2018 Stephan Sokolow
@tritium21
tritium21 / LICENSE.md
Last active September 16, 2019 08:49

./*

The MIT License (MIT) (Except where stated below)

Copyright © 2019 Alexander Walters

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

import ast
import re
split = re.compile(r'(({{|{%)(.*?)(%}|}}))').split
class Visit:
def __init__(self, funcname):
self.names = []
self.funcname = funcname
import ast
def bad_idea(op):
"""
When overcomplicated isn't complicated enough...
"""
OP_TABLE = {
'add': ast.Add,
'sub': ast.Sub,