Skip to content

Instantly share code, notes, and snippets.

View metatoaster's full-sized avatar

Tommy Yu metatoaster

  • Auckland Bioengineering Institute, University of Auckland
  • Auckland, New Zealand
View GitHub Profile
@metatoaster
metatoaster / cls_int_prop_get.py
Last active April 19, 2024 01:27
Python type hinting woes
from typing import Protocol
class IFoo(Protocol):
value: int
class Foo:
_value: int
@property
def value(self) -> int:
class SomeClassToMock(object):
def __init__(self, key=None):
self.key = key
old_new, SomeClassToMock.__new__ = SomeClassToMock.__new__, lambda: None
SomeClassToMock.__new__ = old_new
SomeClassToMock(key='value')
def match_value(number: int) -> str:
three = 3
match number:
case 1:
return "Yay you are number wan"
case 2:
return "Second mouse gets the cheese"
case three:
return "You came third"
case 42:
import random
choices = [chr(i) for i in range(ord('a'), ord('z'))]
with open('rawlist.py', 'w') as rl, open('splitlist.py', 'w') as sp:
rl.write('items = [\n')
sp.write('items = """\n')
for _ in range(1000000):
item = ''.join(random.sample(choices, 10))
rl.write(" %r,\n" % item)
sp.write("%s\n" % item)
@metatoaster
metatoaster / unfuck_firefox.patch
Last active November 4, 2020 04:41
Fix Firefox accident-prone Ctrl+Q on not just Windows (force include shift modifier key) and make tabbox switchByScrolling actually work
diff --git a/browser/base/content/browser-sets.inc b/browser/base/content/browser-sets.inc
Make quit shortcut be ctrl+shift+q
--- a/browser/base/content/browser-sets.inc
+++ b/browser/base/content/browser-sets.inc
@@ -299,11 +299,7 @@
<key id="key_sanitize_mac" command="Tools:Sanitize" keycode="VK_BACK" modifiers="accel,shift"/>
#endif
<key id="key_quitApplication" data-l10n-id="quit-app-shortcut"
-#ifdef XP_WIN
modifiers="accel,shift"
import unittest
from os.path import dirname
def make_suite(): # pragma: no cover
test_loader = unittest.TestLoader()
test_suite = test_loader.discover(
__name__, pattern='test_*.py',
top_level_dir=dirname(__file__),
)
// Insert the following function inside the kc3 developer console (which
// may be accessed by right-clicking on any of the Strategy Room pages,
// and select "Inspect", then open the console tab), and then navigate
// to any of the maps/event pages, invoke `sum_resources()` to get the
// total resources spent as per the consumption reported by each of the
// hover tooltip for all the visible sorties.
var sum_resources = () => {
var filter_icon = /<img src="\/assets\/img\/client\/([^\.]*).png"[^>]*>/g;
var values = $(".sortie_column.sortie_map").toArray().map(e => {
#!/usr/bin/env python
import sys
import zipfile
import json
import os
from io import BytesIO
from os.path import splitext
from math import ceil, floor, log
from time import perf_counter
from urllib.parse import urljoin
@metatoaster
metatoaster / gentoo_install.sh
Last active January 26, 2018 12:41
Install Gentoo with these three easy commands after booting the live CD
mkdir /root/.ssh && cat > /root/.ssh/authorized_keys # type your ssh keys here, finish by hitting enter and ctrl-d; alternatively replace it with a less interactive command
parted --script /dev/sda mklabel gpt mkpart primary 0 1MB mkpart primary 1MB 100% set 1 bios_grub on && mkfs.ext4 /dev/sda2 && mount /dev/sda2 /mnt/gentoo && curl -s http://distfiles.gentoo.org/releases/amd64/autobuilds/`curl -s http://distfiles.gentoo.org/releases/amd64/autobuilds/latest-stage3-amd64.txt | tail -n1 |cut -f1 -d\ ` | tar xpJf - --xattrs-include='*.*' --numeric-owner -C /mnt/gentoo && mount -t proc proc /mnt/gentoo/proc && mount -R /dev /mnt/gentoo/dev && mount -R /sys /mnt/gentoo/sys && cp -L /etc/resolv.conf /mnt/gentoo/etc/ && cp -a /root/.ssh /mnt/gentoo/root/ && chroot /mnt/gentoo /bin/bash -c 'source /etc/profile && emerge-webrsync && emerge --update --deep --newuse @world && emerge app-admin/syslog-ng net-misc/dhcpcd sys-apps/mlocate sys-boot/grub:2 sys-kernel/genkernel-next sys-kernel/gentoo-sources sys-process/cro
# -*- coding: utf-8 -*-
"""
Keyboard to scancode mapping for US keyboard layout.
"""
from itertools import chain
keys_base = (
'`1234567890-='
'qwertyuiop[]\\'