Skip to content

Instantly share code, notes, and snippets.

@magixx
magixx / number_clustering.py
Last active August 29, 2015 14:12
String number matching magic for scene releases
import regex
test_release = 'Release.Name.v1.3.0.DISC.1.Other.Tags.x.264.<RESOLUTION>.WMV'
memory = []
main = []
split_release = test_release.split('.')
split_release.reverse()
split_release_copy = split_release[:]
# Tags that I want to know about
@magixx
magixx / Parameters_from_fix.py
Last active August 29, 2015 14:13
Parameters from functions in fixture
import ipdb
import pytest
@pytest.fixture(scope='function')
def resource_a(request):
default_value = '2'
if request.scope == 'function' and 'value' in request.funcargnames:
default_value = request.getfuncargvalue('value')
@magixx
magixx / fix_as_fix_param.py
Created January 9, 2015 20:42
Fixtures as Fixture Paramaters
import pytest
@pytest.fixture(scope="class")
def resource_a(request):
r = {'name': 'A'}
def fin():
print ("\nteardown " + r['name'])
request.addfinalizer(fin)
return r
@magixx
magixx / languages.py
Created January 10, 2015 23:33
Most common foreign scene languages
tracked_languages = ['persian', 'lithuanian', 'ukrainian', 'romanian', 'vietnamese', 'slovak', 'bulgarian', 'slovenian',
'hebrew', 'arabic', 'serbian', 'turkish', 'estonian', 'icelandic', 'thai', 'korean', 'hungarian',
'russian', 'latin', 'czech', 'truefrench', 'japanese', 'chinese', 'portuguese', 'polish',
'finnish', 'norwegian', 'flemish', 'nordic', 'danish', 'swedish', 'dutch', 'spanish', 'italian',
'french', 'german']
@magixx
magixx / fixture_modified.py
Created January 16, 2015 19:17
Modified Fixture setup from test param
import ipdb
import pytest
from collections import Mapping
PARTITION_NAME = 'PARTITION'
PARTITION_PASSWORD = 'PASSWORD'
@pytest.fixture(scope='class')
def computer_resource(request):
@magixx
magixx / gist:df64a5bdbb2cbce28ea6
Created February 5, 2015 14:30
rpyc mock classic
class MockClassicConnection(object):
"""Mock classic RPyC connection object. Useful when you want the same code to run remotely or locally.
"""
def __init__(self):
self._conn = None
self.namespace = {}
self.modules = ModuleNamespace(self.getmodule)
if is_py3k:
self.builtin = self.modules.builtins
@magixx
magixx / mifare_linux2android_dump.py
Created March 3, 2015 02:38
nfctools (Linux) dump to Mifare Classic Tool (Android) dump
import binascii
import glob
char_count = 32
for filename in glob.glob('f7w*'):
with open(filename, 'rb') as f, open(filename + '.txt', 'w') as output:
data = binascii.hexlify(f.read())
for i, line in enumerate([data[i:i+char_count] for i in range(0, len(data), char_count)]):
if i % 4 == 0:
def remove_from_console(console, log, levels=['DEBUG']):
to_remove = [x for x in log if x['level'] in levels]
skip_lines = 0
console_filtered = []
for index, line in enumerate(console):
if skip_lines:
skip_lines -= 1
continue
@magixx
magixx / test_mock_gen.py
Created August 14, 2015 21:35
Mock generator of tests
import pprint
import random
def weighted_random(weights):
number = random.random() * sum(weights.values())
for k, v in weights.iteritems():
if number < v:
break
number -= v
@magixx
magixx / gist:1fd2d4b84d0b17bc6093
Created January 30, 2016 01:32
update keys with path
import collections
from pprint import pprint as pp
from copy import copy
smp = {'nine': {'eee': True, 'fff': {'ooo': 3, 'type': 'hsm'}, 'type': 'pc'},
'one': {'bar': 6, 'foo': 5},
'two': {'four': {'bar': 3, 'zzz': 3, 'type': 'g5', 'ge': {'v': 3}}, 'three': {'bar': 9, 'zzz': 9}}}
def find_resource_type(item):