Random text magiceye page for daily visual recorvery http://ats-min.com/dailymagiceye github Thanks MagicEye.js
Linux: Resize wubi’s virtual disk
1. Check the wubi’s virtual disk file path sudo losetup /dev/loop0 2. Increase the disk file’s size sudo dd if=/dev/zero bs=1MiB of=/path/to/file conv=notrunc oflag=append count=xxx * xxx is the number of MiB you want to add 3. Reread disk file…
Python: add attribute to MagicMock
>>> from unittest.mock import MagicMock >>> foo = MagicMock(attr1=’spam’, attr2=’ham’, attr3=’eggs’) >>> foo <MagicMock id=’3059559436′> >>> foo.attr1 ‘spam’ >>> foo.attr2 ‘ham’ >>> foo.attr3 ‘eggs’
CheckIO: Repeating decimals
def convert(numerator, denominator): to_str = lambda L: ”.join(map(str, L)) decimals, remains = [], [] integer, remain = numerator // denominator, numerator % denominator remains.append(remain) while True: quotient, remain = remain * 10 // denominator, remain * 10 % denominator decimals.append(quotient)…
CheckIO: The shortest Knight’s path
import itertools as it from string import ascii_lowercase as alpha def checkio(cells): “””str -> int Number of moves in the shortest path of knight “”” restrict = lambda c: 0 < c[0] < 9 and 0 < c[1] < 9…
CheckIO: The Good Radix
from string import ascii_uppercase as alpha import itertools MAX_K = 37 def checkio(number): to_int = lambda x: int(x) if x.isdigit() else alpha.index(x) + 10 digits = list(map(to_int, number)) k = max(digits) + 1 for k in itertools.count(k): if k >…
CheckIO: Broken Clock
from datetime import datetime, timedelta import re def to_sec(unit): dct = {‘second’: 1, ‘minute’: 60, ‘hour’: 3600} m = re.compile(‘^(second|minute|hour)’) return dct[m.match(unit).group()] def broken_clock(starting_time, wrong_time, error_description): a, b, c, d = error_description.replace(‘at ‘, ”).split() err_per_sec = (int(a) * to_sec(b)) /…
CheckIO: Pattern Recognition
import itertools as it def checkio(pattern, image): pattern_height, pattern_width = len(pattern), len(list(zip(*pattern))) image_height, image_width = len(image), len(list(zip(*image))) scan = lambda: it.product(range(pattern_height), range(pattern_width)) for i, j in it.product(range(image_height), range(image_width)): try: if all(image[i + x][j + y] == pattern[x][y] for (x, y)…
CheckIO: Determinant
def cofactor(matrix, row_num, col_num): cols = [col for i, col in enumerate(matrix) if i != col_num] rows = [row for i, row in enumerate(zip(*cols)) if i != row_num] return list(zip(*rows)) def checkio(matrix): if len(matrix) == 1: return matrix[0][0] else: sign…
CheckIO: Shooting range
import math def calc_hitpoint(crd1, direction1, crd2, direction2): (a, b), (c, d) = crd1, crd2 (d1, d2), (d3, d4) = direction1, direction2 if d1 * d4 == d2 * d3: return None, None # parralel lines k = ((b – d)…