This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from functools import wraps | |
| def block_imports(*imports): | |
| def real_decorator(func): | |
| @wraps(func) | |
| def wrapper(*args, **kwargs): | |
| saved = {} | |
| import sys | |
| for i in imports: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from contextlib import contextmanager | |
| @contextmanager | |
| def block_system_import(): | |
| block_import = ["os",'sys'] | |
| saved = {} | |
| import sys | |
| for i in block_import: | |
| saved[i] = sys.modules[i] | |
| sys.modules[i] = None | |
| yield None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| wget https://github.com/protocolbuffers/protobuf/releases/download/v3.6.1/protobuf-all-3.6.1.tar.gz | |
| tar xvf protobuf-all-3.6.1.tar.gz | |
| cd protobuf-3.6.1 | |
| ./configure CC=clang CXX=clang++ CXXFLAGS='-std=c++11 -stdlib=libc++ -O3 -g' LDFLAGS='-stdlib=libc++' LIBS="-lc++ -lc++abi" | |
| make -j 4 | |
| sudo make install | |
| protoc --version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import tensorflow as tf | |
| from tensorboard import main as tb | |
| tf.flags.FLAGS.logdir = "/tmp/hima" | |
| tf.flags.FLAGS.port = "6009" | |
| tb.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pkg_resources | |
| print(pkg_resources.get_distribution('typeguard').version) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def maximal_cycle_free_path(graph, v): | |
| """Generate the maximal cycle-free paths in graph starting at v. | |
| graph must be a mapping from vertices to collections of | |
| neighbouring vertices. | |
| >>> g = {1: [2, 3], 2: [3, 4], 3: [1], 4: []} | |
| >>> sorted(get_paths(g, 1)) | |
| [[1, 2, 3], [1, 2, 4], [1, 3]] | |
| >>> sorted(get_paths(g, 3)) | |
| [[3, 1, 2, 4]] | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cv2 | |
| def show_image(img, wait_key=0, text="image", fx=0.5, fy=0.3): | |
| """ | |
| Utility to show image | |
| :param img: Image array | |
| :param wait_key: Wait key to stop showing | |
| :param text: Text to be displayed | |
| :param fx: resize factor in x dimension | |
| :param fy: resize factor in y dimension | |
| :return: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from itertools import islice | |
| def sliding_window(seq, n=3): | |
| """ | |
| Returns a sliding window (of width n) over data from the iterable | |
| s -> (s0,s1,...s[n-1]), (s1,s2,...,sn), ... | |
| """ | |
| it = iter(seq) | |
| result = tuple(islice(it, n)) | |
| if len(result) <= n: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def contains_sublist(big_list, sub_list): | |
| """ | |
| :param big_list: list: bigger list to search in | |
| :param sub_list: list: sub-list | |
| :return: boolean: True if base_list contains sub_list, False otherwise | |
| """ | |
| try: | |
| big_list.__str__().index(sub_list.__str__()) | |
| return True | |
| except ValueError: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| def print_progress(iteration, total, prefix='', suffix='', decimals=1, bar_length=100,reversed =False): | |
| """ | |
| Call in a loop to create terminal progress bar | |
| @params: | |
| iteration - Required : current iteration (Int) | |
| total - Required : total iterations (Int) | |
| prefix - Optional : prefix string (Str) | |
| suffix - Optional : suffix string (Str) | |
| decimals - Optional : positive number of decimals in percent complete (Int) |
NewerOlder