Skip to content

Instantly share code, notes, and snippets.

@magixx
magixx / docker_names.py
Last active May 3, 2021 20:17
Docker Container Names in Python
"""
https://github.com/docker/docker/blob/master/pkg/namesgenerator/names-generator.go
"""
from random import choice
ADJECTIVES=["admiring","adoring","affectionate","agitated","amazing","angry","awesome","blissful","boring","brave","clever","cocky","compassionate","competent","condescending","confident","cranky","dazzling","determined","distracted","dreamy","eager","ecstatic","elastic","elated","elegant","eloquent","epic","fervent","festive","flamboyant","focused","friendly","frosty","gallant","gifted","goofy","gracious","happy","hardcore","heuristic","hopeful","hungry","infallible","inspiring","jolly","jovial","keen","kickass","kind","laughing","loving","lucid","mystifying","modest","musing","naughty","nervous","nifty","nostalgic","objective","optimistic","peaceful","pedantic","pensive","practical","priceless","quirky","quizzical","relaxed","reverent","romantic","sad","serene","sharp","silly","sleepy","stoic","stupefied","suspicious","tender","thirsty","trusting","unruffled","upbeat","vibrant","vigilant","w
import pytest
from collections import OrderedDict
from pprint import pprint
@pytest.hookimpl(trylast=True)
def pytest_collection_modifyitems(session, config, items):
"""
Create an ordered dict containing clustered tests based on classes
class NodeFactory(object):
@staticmethod
def create(node_type):
if node_type == 'SANode':
return SANode
else:
return Node
@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):
@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
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 / 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:
@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 / 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 / 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']