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
/*
[dependencies]
rand = "0.8"
*/
use rand::seq::SliceRandom;
use rand::thread_rng;
use std::collections::HashMap;
fn main() {
let w: i16 = 8;
from random import shuffle
W = 8
H = 8
B = 10
A = W * H
S = A - B
line = [1] * B + [0] * S
shuffle(line)
checkidxs = [
[chk for chk in [
@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