content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def get_email_settings(settings): """ Helper function for grouping email-related properties """ email_settings = {} email_settings['smtp_host_for_outbound_mail'] = settings.smtp_host_for_outbound_mail email_settings['redcap_support_sender_email'] = settings.redcap_support_sender_email email_...
46f8d74b7595b9dcdf58284817f64462e4df7862
47,112
def natural_key_fixed_names_order(names_order): """Convert symbol to natural key but with custom ordering of names. Consider a QAOA ansatz in which parameters are naturally ordered as: gamma_0 < beta_0 < gamma_1 < beta_1 < ... The above is an example of natural_key_fixed_names_order in which name 'gam...
74e20a7e19305716d501da8ced49ec28bf85eac1
47,113
def circuit_path_string_to_int(circuit_rpp): """ Converts nodes in path lists from strings to integers Args: circuit_rpp (list): rpp circuit generated by postman_problems.solver.rpp Returns: circuit_rpp (list): modified circuit """ for e in circuit_rpp: if type(e[3]['path...
7663f8010d802c6d10ec1dd9a1cdf218eeb49f5a
47,114
def update_upload_api(requests_pathname_prefix, upload_api): """Path join for the API path name. This is a private method, and should not be exposed to users. """ if requests_pathname_prefix == "/": return upload_api return "/".join( [ requests_pathname_prefix.rstrip("/")...
65338eb81e3c60665ed755e86c18ea17ea75f8bc
47,115
def find_set(x): """Finds representant of the given data structure x.""" if x.parent is None: return x x.parent = find_set(x.parent) return x.parent
47b332938e6a648f0d353d027979b63b0c1e8826
47,116
def to_list(x): """ :param x: :return: """ return x if type(x) == list else [x]
b3434e2239830f9d7b57f0346f2a00202374ba1a
47,118
def not_submitted_count(drafts): """ Get count of not-submitted services Defaults to 0 if no not-submitted services :param drafts: :return: """ return drafts.get('not-submitted', 0)
dda309998234be6c560cf3b4ecafda41c43d20e3
47,119
import math import numpy def bdsnr(metric_set1, metric_set2): """ BJONTEGAARD Bjontegaard metric calculation Bjontegaard's metric allows to compute the average gain in psnr between two rate-distortion curves [1]. rate1,psnr1 - RD points for curve 1 rate2,psnr2 - RD points for curve 2 r...
cf96e38d07e83afde80de4967c0e8f1535bff5e4
47,120
def unpack_args(args, num): """ Extracts the specified number of arguments from a tuple, padding with `None` if the tuple length is insufficient. Args: args (Tuple[object]): The tuple of arguments num (int): The number of elements desired. Returns: Tuple[object]: A tuple co...
9f0a2ab601a7974f7ae5ba5dc008b04ee07f0678
47,121
from typing import Iterable def _variable_or_iterable_to_set(x): """ Convert variable or iterable x to a frozenset. If x is None, returns the empty set. Arguments --------- x: None, str or Iterable[str] Returns ------- x: frozenset[str] """ if x is None: return frozenset([]) if isinst...
36ab763a3a4341c49fefb6cb3b10d88bef040fa8
47,123
import os def list_dir_files(folder_path, full_path=False): """ List all files in directory. Args: folder_path (str): full_path (bool): Return full file paths Returns: list (list): Files list """ file_names = os.listdir(folder_path) files_list = [] for file_...
5a5b343eef6ca632d45f5b8341899ee60cb79b8a
47,125
import re def workdir_from_dockerfile(dockerfile): """Parse WORKDIR from the Dockerfile.""" WORKDIR_REGEX = re.compile(r'\s*WORKDIR\s*([^\s]+)') with open(dockerfile) as f: lines = f.readlines() for line in lines: match = re.match(WORKDIR_REGEX, line) if match: # We need to escape '$' sinc...
33a927626a023ba988534afe5b3f8885e18db471
47,126
import re def CellStartsWith(regex, cell): """Checks if the first line of the cell matches the regexp with re.match. Args: regex (str): A regexp string. cell (dict): A JSON object representing a cell in the IPython notebook Returns: None if the regexp does not match. The match object if the fi...
1ca17fa085ab7f458a275ab293e3c969d8b78b48
47,127
def count_one_four_seven_eight(data): """ >>> data = read_input('example') >>> count_one_four_seven_eight(data) 26 """ onefourseveneights = 0 for digits, values in data: vlengths = [len(value) for value in values] onefourseveneights += sum(1 if vlen in (2, 3, 4, 7) else 0 for...
750b422feafea7b381feacfb2ade4ee928ef5ee8
47,128
import six def _get_program_cmd(name, pconfig, config, default): """Retrieve commandline of a program. """ if pconfig is None: return name elif isinstance(pconfig, six.string_types): return pconfig elif "cmd" in pconfig: return pconfig["cmd"] elif default is not None: ...
55f04c1fc3598afc410cdda7d27e6cd4b15c57a5
47,129
def openstack_connection_kwargs(self): """ :rtype: ``dict`` """ rv = {} if self._ex_force_base_url: rv['ex_force_base_url'] = self._ex_force_base_url if self._ex_force_auth_token: rv['ex_force_auth_token'] = self._ex_force_auth_token if self._ex_force_auth_url: rv['e...
2363cc2e0278f7e8ff6674d5cb66b6f2baf0cd5e
47,130
import pickle def load_database(filename): """Read in pickled database file.""" with open(filename, 'rb') as fin: return pickle.load(fin)
ee9f55e626585624f75eb17663b7393628941ece
47,131
def get_beshp_xml( map_file, people, person_path_weight, people_speed, display_path_cost_p, add_person_spacing_p, people_wait_p, equal_diagonal_weight_p, people_move_rates, set_fire_p, fire_speed, ): """<experiments> <experiment name="FireSim" repetitions="1" runMetri...
26c6bd26d8bbdc4a8c48eb1587ccaac4c3c3b3e4
47,132
def loadstastic(file): """ this method takes an ALREADY SCRUBBED chunk of file(string), and convert that into a WordLists (see :return for this function or see the document for 'test' function, :param WordLists) :param file: a string contain an AlREADY SCRUBBED file :return: a WordLists: Array type...
96f3173d7be184b1211f330674ef937a1aac68d6
47,133
import logging def get_video_bitrate(dict_inf, stream_video): """Bitrate search. It may be in one of the 2 possible places. Args: dict_inf (dict): video metadata stream_video (dict): video stream data Raises: NameError: If Bitrate is not found in any of the possible places R...
cc7e2423c3288c9f392776cd5b6477973492874c
47,134
def _clean_state(state): """Return purged state of values so only wanted values can be modified. Args: state(dict): device state dictionary. Original won't be modified. """ out = {} for k, v in state.items(): if isinstance(v, dict): # recurse nested dicts out[k] = _clean_st...
43fbcf5d4e9554ff604aebe991bc19a9c3503530
47,136
import os from pathlib import Path def _get_xdg_cache_dir(): """ Return the XDG cache directory. See https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html """ cache_dir = os.environ.get('XDG_CACHE_HOME') if not cache_dir: cache_dir = os.path.expanduser('~/.cache...
70236c9830687feb0d45f817f56e1d31b189a4f4
47,137
import argparse def get_args(): """Argparse Setup""" parser = argparse.ArgumentParser(description='Pixel for Pixel websites clones using BeEF') # Beef password parser.add_argument('password', metavar='password', help='Password for BeEF server instance') # Site to be cloned parser.add_argumen...
2c5e3191f1c645fe0d1546aa029338df46fbfc84
47,138
import torch def raw_morlets(grid_or_shape, wave_vectors, gaussian_bases, morlet=True, ifftshift=True, fft=True): """ Helper function for creating morlet filters Parameters: grid_or_shape -- a grid of the size of the filter or a tuple that indicates its shape wave_vectors -- direc...
307a0b3e104e436c3ba2d37c5cf661b44959d411
47,139
def Rgb2Hex(rgb=(255, 255, 255)): """ 将 RGB 颜色三元组转换成十六进制颜色的字符串 如: (255, 255, 0) -> #ffff00 https://blog.csdn.net/hepu8/article/details/88630979 """ return "#%02x%02x%02x" % rgb
8430428588466890695cf0296c3dc4504fcc05c3
47,140
import os def get_upload_path(instance, filename): """ 첨부파일이 업로드 되는 경로를 반환하는 함수. 첨부파일은 포스트별로 다른 디렉토리에 저장됩니다. """ return os.path.join("post-%d" % instance.post.id, filename)
bdea2878d388f94146b1324239c01841143f1d0e
47,141
def logic(number: int) -> int: """Perform logic for even-odd transformation. Each even-odd transformation: * Adds two (+2) to each odd integer. * Subtracts two (-2) to each even integer. """ # Determine the modifier based on number being even or odd. modifier = -2 if number % 2 == 0...
64d10c9a605f09a1ecaaec695320a98094a63bc3
47,142
from datetime import datetime def inject_date(): """ Inject date so it can be used in the footer easily. """ year = datetime.now().year return dict(year=year)
945be669e85390e5fc1e714199e3a9038e302772
47,144
def get_label(timestamp, commercials): """Given a timestamp and the commercials list, return if this frame is a commercial or not. If not, return label.""" for com in commercials['commercials']: if com['start'] <= timestamp <= com['end']: return 'ad' return commercials['class']
72d96f35c63d5f6e8859b2c5bc3a0b8dab37fc39
47,147
import re def _parse_multiplicity(strings, substance_keys=None): """ Examples -------- >>> _parse_multiplicity(['2 H2O2', 'O2']) == {'H2O2': 2, 'O2': 1} True >>> _parse_multiplicity(['2 * H2O2', 'O2']) == {'H2O2': 2, 'O2': 1} True >>> _parse_multiplicity(['']) == {} True >>> _p...
ef1a2729b657ab6463372866609a241c2aced370
47,148
import io def config_to_string(config): """ Convert ConfigParser object to string in INI format. Args: config (obj): ConfigParser object Returns: str: Config in one string """ strio = io.StringIO() config.write(strio, space_around_delimiters=False) return strio.getva...
264159206b7367ed584c25ec36c2232a1a558880
47,149
def count_fn(true_fn_flags, ground_truth_classes, class_code): """ Count how many true FN are left in true_fn_flags for class given by class_code Args true_fn_flags: list of flags that are left 1 if ground truth has not been detected at all ground_truth_classes: list of classes correspondin...
bb68474afe5d60fd30db59a9dc8e640f5ab3f00e
47,150
def read_IMDB(file_name): """ :param file_name: Takes as input the IMDB dataset file name as a string :return: and outputs a list of lists containg datapoins consisting of a sentence (string) and a target (an integer) """ with open(file_name, 'r', encoding="latin-1") as text_file: l = [] ...
72638f65ff1d6f220f299f996ed59b5d24bd6c16
47,151
import argparse def parse_args(): """Parse Arguments""" parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('mutations', metavar='M', help="Individual list file") parser.add_argument('wt...
dd72467b24e21e06d17a4cf6736030aff680e0ab
47,153
def toHexByte(n): """ Converts a numeric value to a hex byte Arguments: n - the vale to convert (max 255) Return: A string, representing the value in hex (1 byte) """ return "%02X" % n
e6a7ceab39731f38d1c3fdaa4cba847d1ad41929
47,154
def conj(coll, to_add): """ Similar to clojure's function, add items to a list or dictionary See https://clojuredocs.org/clojure.core/conj for more reading Returns a new collection with the to_add 'added'. conj(None, item) returns (item). The 'addition' may happen at different 'places' depending ...
62cca3766c3a4467db73372209d6f173647ed3af
47,155
import re def split_host_and_port(netloc): """Returns ``(host, port)`` tuple from ``netloc``. Returned ``port`` will be ``None`` if not present. .. versionadded:: 4.1 """ match = re.match(r'^(.+):(\d+)$', netloc) if match: host = match.group(1) port = int(match.group(2)) ...
4bc29e7861c84385fd09cd5b4dc60b1b76f1e447
47,156
import collections def _format_expand_payload(payload, new_key, must_exist=[]): """ Formats expand payloads into dicts from dcids to lists of values.""" # Create the results dictionary from payload results = collections.defaultdict(set) for entry in payload: if 'dcid' in entry and new_key in e...
ae9af5400f0bf38954c99afca62914e30f42ec32
47,158
def get_dominant_letter_count(word_list, valid_word): """ :param word_list: a list of words composing a sentence. :param valid_word: a regex string defining the acceptance criteria being matched. :return: returns the total of dominant characters across all words in the sentence. """ total = 0 ...
de8a585a1c7c4a3c7f76ecaa1e46bfa6b915025f
47,159
def to_float_list(a): """ Given an interable, returns a list of its contents converted to floats :param a: interable :return: list of floats """ return [float(i) for i in a]
8576c649802c9a88694097ceefb55c86ab845266
47,161
from pathlib import Path def join_legacy_read_path(sample_path: Path, suffix: int) -> Path: """ Create a path string for a sample read file using the old file naming convention (eg. reads_1.fastq). :param sample_path: the path to the sample directory :param suffix: the read file suffix :retur...
c5efb0da5ace242b916ea0515062190fb55346f5
47,164
from typing import Counter import re def get_word_counts(txt): """ Counts word occurrences in "txt". The methodology of dealing with unknown words is to calculate a count of "UNK" by splitting the set of words, and after counting words in the bigger set, every unknown word that appears in the smaller ...
c513e4713e222ee5bc0726f84889a3dfbf4ab278
47,165
def remove_hidden(names): """Remove (in-place) all strings starting with a '.' in the given list.""" i = 0 while i < len(names): if names[i].startswith('.'): names.pop(i) else: i += 1 return names
19ed2fc093f96038612c6eb5b943f89f9b91f452
47,166
def normalize(rngs): """Function: normalize Description: Normalizes a list of ranges by merging ranges, if possible, and turning single-position ranges into tuples. The normalization process is to sort the ranges first on the tuples, which makes comparsions easy when merging range s...
b173c5d2f85d753c053c6436f86c76dada1d1d2f
47,167
import re import operator def is_valid(policy: str, password: str) -> bool: """ Given a policy (e.g. `1-3 a`) and a password (e.g. `abcde`), determine if the password complies with the policy """ char = policy[-1:] pos_1 = int(re.findall("[0-9]+", policy)[0]) pos_2 = int(re.findall("[0-9]+...
aa513b29d7575e80ee962055e0933e173c18441c
47,168
def _append_docs(cls): """ Add a note to documentation on parent expansion process. .. Note:: This function assumes the class is defined at module-level scope. If not the indentation may be funny. """ new_doc = (cls.__doc__ + "\n") if cls.__doc__ else "" new_doc += """\n .. Not...
00f6da32a1d27b93a51f522226a24b42f05d1897
47,169
def _convert2dict(file_content_lines): """ Convert the corosync configuration file to a dictionary """ corodict = {} index = 0 for i, line in enumerate(file_content_lines): stripped_line = line.strip() if not stripped_line or stripped_line[0] == '#': continue ...
31ffb2449e8f4b52478fa79197b10dfc96b76f4a
47,170
import requests def get_seed(pulse_url): """ Given a pulse url does a GET request to the Random UChile API to get the seed given by that pulse. :param pulse_url: String representing the URL of the pulse. :return: A 512-bit random string that can be used as seed by a pseudo random generator. """ ...
411746e0768599ea6d3e4fc23a5efc7482a18373
47,171
def map_zero_one(A): """ Maps a given array to the interval [0,1] """ # return A # print("MI max and min ",A.max(),A.min()) A_std = (A - A.min())/(A.max()-A.min()) retval = A_std * (A.max() - A.min()) + A.min() return A_std # return softmax(A) # return torch.sigmoid(torch.Tensor(...
222e43212e1e6c1eab04f74db16cee2cd3b203b0
47,172
import argparse def parse_arguments(argv): """Parse command line arguments. Args: argv: A list of command line arguments. Returns: The parsed arguments returned by argparse.ArgumentParser. """ parser = argparse.ArgumentParser( description='Runs preprocessing for input raw data.') parser.ad...
84959ae05a1837a8ea2bcbf46f2bd0844b8e14ec
47,173
import re def _is_pattern_match(re_pattern, s): """Check if a re pattern expression matches an entire string.""" match = re.match(re_pattern, s, re.I) return match.group() == s if match else False
30b65a696c27b2141e50672775333642a1fb2b57
47,175
import torch def double_features(f: torch.Tensor) -> torch.Tensor: """Double feature vector as (A, B, C, D) --> (A, A, B, B, C, C, D, D) Args: f: Feature vectors (n_batch, n_features) Returns: f: Feature vectors (2*n_btach. n_features) """ return torch.repeat_interleave(f, 2, dim=...
d7f1dca83d1933a7a550d3fadfbf2ff96fe79ad8
47,176
def flatten_dictionary(dictionary): """ Input: a request's JSON dictionary output with nested dictionary Output: a flattened dictionary (format: key1.key2 = value2) """ flattenedDictionary = dict() for key, value in dictionary.items(): if isinstance(value, dict): for subkey, ...
1ca7c9021360bc6c39fb1f3ba07794ac74831272
47,177
def five_uneven_peak_trap(x=None): """ F1: Five-Uneven-Peak Trap Variable ranges: x in [0, 30 No. of global peaks: 2 No. of local peaks: 3. """ if x is None: return None result = None if 0 <= x < 2.50: result = 80*(2.5-x) elif 2.50 <= x < 5: ...
530994e36bd8f5d895e8e4ff65f43ec784760618
47,178
import numpy as np def get_normals(space, npoints): """Get the normal vectors on the quadrature points.""" grid = space.grid number_of_elements = grid.number_of_elements normals = np.empty((npoints * number_of_elements, 3), dtype="float64") for element in range(number_of_elements): for n...
c7ae6248e973258f277fce3d3e2c1c9566f2e3b6
47,180
import torch def _to_real(x: torch.Tensor) -> torch.Tensor: """View complex tensor as real.""" x = torch.view_as_real(x) return x.view(*x.shape[:-2], -1)
8bb7b8db208bcfd433976236fa56ce42560b8adf
47,181
def compute_path_cost(nxobject, path): """ Compute cost of a path """ cost = 0 for index_station in range(len(path) - 1): cost += nxobject[path[index_station]][path[index_station + 1]]["weight"] return cost
01652396938f2431a0b8e077723e615680856e32
47,182
from typing import Any import numpy def should_sanitize(indexing_element: Any) -> bool: """Decide whether to sanitize an indexing element or not. Sanitizing in this context means converting supported numpy values into python values. Args: indexing_element (Any): the indexing element to decide sa...
8ab59d2f8397a7b8e63b0be5e418ef3baca8d4ee
47,183
def parse_request(event): """ Parses the input api gateway event and returns the product id Expects the input event to contain the pathPatameters dict with the productId key/value pair :param event: api gateway event :return: a dict containing the productId key/value """ if 'pathParamete...
1f56867c5a15ea602f92d2c08c3410cc690b392b
47,184
def listify(l): """Encapsulate l with list[] if not.""" return [l] if not isinstance(l, list) else l
f029b8df4f4442ec8e3f16f7c92ec59fe6338cce
47,185
def paste(x, sep=", "): """ Custom string formatting function to format (???) output. """ out = "" for i in x: out += i + sep return out.strip(sep)
5b1667fda6c82eff3764a09aee90b0c642811c83
47,187
def getContainerName(ctx, containerFlavor): """ Get name of the container for a specific flavor """ return getattr(ctx.cf.ocp.containers, containerFlavor).name
66baf4ab95b8a6a8a43fb70568140d46158b2e41
47,188
def clean_non_ascii(str): """ remove non ascii chars from a string """ str = ''.join([i if ord(i) < 128 else ' ' for i in str]) return str
634ac8410c483a398ef4efd86dcab6e841e26666
47,189
import csv def tab_to_csv(txtfile, csvfile): """ Converts a file from tab delimited to comma delimited format.""" with open(txtfile, 'r') as infile, open(csvfile, 'w') as outfile: stripped = (line.strip() for line in infile) lines = (line.split(",") for line in stripped if line) write...
837dd58def6ea40b8a78cc680c52d2db2eeb82b7
47,190
def check_image_in_supercell(site1, site2, supercell_size): """ Checks whether site1 and site2 are periodic images of each other in the super cell structure given the size of the super cell :param site1: (Site) site in super cell :param site2: (Site) site in super cell :param supercell_size: (in...
905ab373287586c34a6b19f23c5acdb91bc821d7
47,191
def get_n_week(dfi, n=1): """Get data for the week -N""" df = dfi.resample("W-MON", closed="left").sum().iloc[-n].T return df[df > 0].sort_values(ascending=False).to_dict()
00c0a994d6527225222d9dea25c8465ee3de055a
47,192
def formatAbn(abn): """Formats a string of numbers (no spaces) into an ABN.""" if len(abn)!=11: return abn return u'{0} {1} {2} {3}'.format(abn[0:2],abn[2:5],abn[5:8],abn[8:11])
2746c206ee5156fa7939ed11f04af1865824ef8c
47,193
def login_elements(tag): """A filter to find cas login form elements""" return tag.has_key('name') and tag.has_key('value')
66913948af672500cdbbbaf742e3842479350138
47,195
def disjoint_bounds(bounds1, bounds2): """Returns True if bounds do not overlap Parameters ---------- bounds1: rasterio bounds tuple (xmin, ymin, xmax, ymax) bounds2: rasterio bounds tuple """ return (bounds1[0] > bounds2[2] or bounds1[2] < bounds2[0] or bounds1[1] > bounds2[3]...
866162f11f293609a07179b1b688ddc10157e72a
47,196
def text_to_be_spellchecked(request): """Represents the text fields that can be spellchecked, including: - tactic and technique names and descriptions - case study names and summaries, procedure step descriptions """ return request.param
f259c73afe06e254bedd06c6f19fb57ee90833ac
47,198
import pkgutil import importlib import sys def list_modules(package, exclude=None): """ Get a list of modules in a package :param package: object, a module object :param exclude: set, a set of modules to exclude from the resulting list :return: list, a list of modules of a package """ ...
c0356004b686c2e343572a67914e4fee92d25a78
47,199
import codecs def encoding(argument): """ Verfies the encoding argument by lookup. (Directive option conversion function.) Raises ValueError for unknown encodings. """ try: codecs.lookup(argument) except LookupError: raise ValueError('unknown encoding: "%s"' % argument) ...
4563ab18821d22f8613c82227a9b6192080e95bb
47,202
def get_dependencies(cells): """ Retrieves the 'pip install' commands from the cells. :param cells: the cells to iterate :type cells: list :return: the list of dependencies (instances of "pip install ...") :rtype: list """ result = [] for cell in cells: if ("cell_type" in ...
b938d24025da8aa1b4198b00f3f539943a304717
47,204
import os def _input_to_bed(theta_input, work_dir, get_coords, headers): """Convert input file to a BED file for comparisons """ theta_bed = os.path.join(work_dir, "%s.bed" % os.path.splitext(os.path.basename(theta_input))[0]) with open(theta_input) as in_handle: with open(theta_bed, "w") as o...
b67fe99d143697a1d236bda4315f4c3a52018633
47,206
def qvarToString(qv): """converts a QVariant to a python string.""" return str(qv)
e1174510d6071b815bcc88819f3583901862d763
47,207
def has_linear_regression(args): """Returns whether some kind of linear regression """ return args.linear_regression or args.linear_regressions or \ args.linear_regression_tag
459679a4489f30ee96496c1086e413441119f686
47,208
import os def find_file_name_without_suffix(file_full_path): """ 获取不含后缀的文件名 :param file_full_path: 文件完全路径 :return: """ file_path, file_name = os.path.split(file_full_path) suffix_begin_index = file_name.rfind('.') # 找到最后一个.出现的位置 return file_name[0: suffix_begin_index]
11544a76953e10dbbabab55628f1bc4bf4957cdc
47,209
import os def checkFileIsWritable(filename, create=False): """ Check that the input filename is writable. That is, the path leading up to it exists and you can write to it. If it doesn't exists the needed folders can be created. :param file: File to check :param create: If True then needed dir...
9a023328e3af7371d9be4af0cef4bd7fa8a8cfa8
47,210
def _is_spark_step_type(step_type): """Does the given step type indicate that it uses Spark?""" return step_type.split('_')[0] == 'spark'
31d367c44f1a856e21c25f03e78a4eab48fc3af8
47,211
def is_message(line, msg_number): """Return 'True' if 'line' contains the message identified by 'msg_number'. Parameters ---------- line: A single line from the NEST CI build log file. msg_number: Message number string. Returns ------- True or False """ if msg_number in ...
d1290a8b2e13955f2dcb6d59576d032c8f499165
47,212
def _clean_header_str(value: bytes) -> str: """Null-terminates, strips, and removes trailing underscores.""" return value.split(b'\x00')[0].decode().strip().rstrip('_')
e5776a36eeb36320aec8085f094d6d00f3c3a718
47,213
def factors(number): """Give a list of all the facotrs of given natural number.""" if number > 1: return [i for i in range(1, number) if number % i == 0] elif number == 1: return [] else: raise ValueError("Requires a Natural number")
78613f8c7aff72855b3b1a95806e0d38f3879c67
47,214
def _get_query_sample(query): """Format query sample.""" return f""" <p><b>Example</b></p> <p>{{QueryProvider}}[.QueryPath].QueryName(params...)</p> <pre>qry_prov.{query}(start=start, end=end, hostname=host)</pre> """
f32740e77d4d6916d52d04c2a6e4efc33aa83a29
47,215
def binData(data, new_shape): """bin time-series. Parameters ----------- data : nd array time-series (numTrials * time-points). new_shape : 1d array [numTrials, numBin] Returns ------- binned_data : nd array binned time-series (numTrials * numBin). """ ...
1f27c77a695404c516aa19dc94d0d60ca6d455cd
47,216
import os def checkCudaInstalation(version): """ Checks if Cuda is installed. """ if 'libcuda.so' in os.listdir('/usr/lib/{}-linux-gnu'.format(version)): return True else: return False
60d686422001f296c8b0909ee2637448bec6367f
47,217
def compose_batch_command_of_script( source, destination, script, particle, wait_jobs, suffix ): """ Creates the slurm command of the 'cmd' script Parameters ---------- source: str Source directory destination: str Destination directory script: str Script to be u...
aa5ed37eeb0a75da60ea2c2100ba5bc3f02503f5
47,219
def fib(num): """Resuelve la sucesión de Fibonacci""" anterior,actual=0,1 for x in range(0,num//2): aux = anterior + actual print(anterior, actual) anterior = aux actual += anterior return anterior,actual
ab87dcd4a217b675e05ec765b594d9886de2a9ae
47,220
def check_greenlist_positions(curword: str, grn: list) -> bool: """ Checks the greenlist positions to ensure every word has a green letter in the correct positions :param curword: The current word from the word pool :param grn: Array representing the correct letters :return: Bool -false if the word ...
aad1e8267fd77134c9408c28724f6077f58ae984
47,221
def find_klt_for_frame(klt, klt_frames, i): """ Finds all KLT tracks appearing in a given frame """ if not i in klt_frames: return [] ids = klt_frames[i] klt_this = [klt[x] for x in ids] return klt_this
108e0dc926ed175d8e5bde1bdceb7c7ed038571b
47,222
def properGetitem(f): """ This decorator modifies a __getitem__/__setitem__ method such that it will always receive a tuple """ def proper(self,mbt,*args): if not isinstance(mbt,tuple): mbt = (mbt,) return f(self,mbt,*args) return proper
1e87742a555a34a86cc0a925f3da504e4ae2e7c7
47,225
import re def process_reddit(comment): """ Pre-processes a given comment by removing some characters Parameters ---------- comment : str Given sentence Returns ------- Processed sentence """ comment = comment.encode("ascii", errors="ignore").decode() comment = re.sub('...
861cf172e15f8a699bad31ce27ed836de02afff0
47,226
def divisors(num): """ m < n ==> m = k n | k in (0, 1) T = T1 + T2 + n (T3 + T4) + k n T5 ==> O(n) = Tb + n (T3 + T4 + k T5) = Tb + n Ta T = n Ta + Tb O(n/2) = O(0.5 n) ==> O(n) T = 0.5 n Ta + Tb """ assert isinstance(num, int) # T1 divs = [] # T2 #...
472340ae97ece2eeb81db53492a721a9f40d1f56
47,227
import math def translate_point(point, angle, distance): """Translate a point a distance in a direction (angle).""" x, y = point return (x + math.cos(angle) * distance, y + math.sin(angle) * distance)
a32c4209cad97fc670c18acb47c27ec7fbc8bc5c
47,228
def dict_in_list_always(main, sub): """ >>> main = [{'c': 'c', 'a': 'a', 'b': 'b'}, {'c': 'c', 'd': 'd'}] >>> dict_in_list_always(main, {'a': 'a', 'b': 'b', 'c': 'c'}) False >>> dict_in_list_always(main, {'c': 'c', 'd': 'd'}) False >>> dict_in_list_always(main, {'a': 'a', 'c': 'c'}) Fals...
549e27bf42ed5bd64e7e2d5b57e4b00328b83fca
47,229
def compute_Ia_fr(stretch,stretchVel,muscActivation,species): """ Compute the firing rates of the Ia afferent fibers. Uses the experimetnally derived model devloped by Prochazka (1999 pag 136). Keyword arguments: stretch -- muscle stretch in mm. stretchVel -- muscle stretch velocity in mm/s. muscActivation -- no...
1b0c534d2a47b17797d72cb6f79845410725d9d3
47,230
def get_U_d_windowdoor(U_d_W, U_d_D, A_d_W, A_d_D): """欄間付きドア、袖付きドア等のドアや窓が同一枠内で併設される場合の開口部(窓又はドア)の熱貫流率U_d…………式(10) Args: U_d_W(float): ドアや窓が同一枠内で併設される場合の開口部(窓又はドア)の窓部分の熱貫流率 U_d_D(float): ドアや窓が同一枠内で併設される場合の開口部(窓又はドア)のドア部分の熱貫流率 A_d_W(float): ドアや窓が同一枠内で併設される場合の開口部(窓又はドア)の窓部分の面積…………入力(WindowPart>...
16158ddf47c90b4078ed3024acdf6828401d5486
47,231
import collections def decode_attribute_idx_data(submissions): """Return a list of dicts representing the decoded data. Some of the form data returned from MTurk is encoded as ``"attribute-idx": value`` mappings, where attribute represents the attribute encoded and idx is the index of the problem ins...
3a1853e18e1038e9c0891ad684b39c916e26fade
47,232
def get_index_with_default(header, column_name, default_value=None): """Helper function to extract the index of a column.""" return header.index(column_name) if column_name in header else default_value
0a2fefc8def6e6d91c4852d42da0db5ca4813a8c
47,233
def concat(arrays): """ Concatenates an array of arrays into a 1 dimensional array. """ concatenated = arrays[0] if not isinstance(concatenated, list): raise ValueError( "Each element in the concatenation must be an instance " "of `list`." ) if len(arrays)...
669217a26058553b25db580ecf4ed61cb0e1f513
47,234
import argparse def parse_args(argv=None): """DRY and KISS.""" parser = argparse.ArgumentParser( description="partitioning of small sets with 25 or less members") group = parser.add_mutually_exclusive_group() # group.add_argument("-v", "--verbose", action="store_true") group.add_argument(...
a6faab2b98db691736dbdd8509a0e2c201a5c049
47,235