content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def gen_filelist(infiles, tmpd) : """Write all audio files to a temporary text document for ffmpeg Returns the path of that text document.""" filename = tmpd/"files.txt" with open(filename, "w") as f: for file in infiles: # This part ensures that any apostro...
c7d21c62de34fea98725a39fec735836e0cfd3d9
3,656
import os def check_envs(): """Checks environment variables. The MONGODB_PWD is a needed variable to enable mongodb connection. Returns: bool: If all needed environment variables are set. """ if not os.environ.get('MONGODB_PWD', False): return False return True
22ac892b0eee827f63f7d8258ca49f0e462452fd
3,657
def getLines(filename): """Return list of lines from file""" with open(filename, 'r', errors='ignore') as ff: return ff.readlines()
36e515decaa3876eed3b5db8363fb81a5db89c84
3,658
import requests def dog(argv, params): """Returns a slack attachment with a picture of a dog from thedogapi""" # Print prints logs to cloudwatch # Send response to response url dogurl = 'https://api.thedogapi.com/v1/images/search?mime_types=jpg,png' dogr = requests.get(dogurl) url = dogr.json(...
cb80426e6cab0aa2fc58b78baa0ff225d654f04a
3,660
import torch def convert_to_torch_tensors(X_train, y_train, X_test, y_test): """ Function to quickly convert datasets to pytorch tensors """ # convert training data _X_train = torch.LongTensor(X_train) _y_train = torch.FloatTensor(y_train) # convert test data _X_test = torch.LongTensor(X_test)...
0d40fe19c977b25e3a2571adc98790d7058a77d9
3,661
def get_pybricks_reset_vector(): """Gets the boot vector of the pybricks firmware.""" # Extract reset vector from dual boot firmware. with open("_pybricks/firmware-dual-boot-base.bin", "rb") as pybricks_bin_file: pybricks_bin_file.seek(4) return pybricks_bin_file.read(4)
7d504e7e6e6ca444932fd61abb701a010a259254
3,662
def parse_img_name(path): """parse image by frame name :param name [str] :output img_lists """ code = path.split('\\')[-1].split('.')[0] vid_id = path.split('\\')[-2] rcp_id = path.split('\\')[-3] seg_id = int(code[:4]) frm_id = int(code[4:]) return rcp_id, vid_id, seg_id, frm_id
6e0a140934c584400365f12feb8a86cfea3bbb2b
3,663
import time def tokenize_protein(text): """ Tokenizes from a proteins string into a list of strings """ aa = ['A','C','D','E','F','G','H','I','K','L', 'M','N','P','Q','R','S','T','V','W','Y'] N = len(text) n = len(aa) i=0 seq = list() timeout = time.time()+5 for i...
7dba531023aef97dcbfb37af75a9a1459a1e94d2
3,665
from typing import Callable def read_xml_string() -> Callable[[int, int, str], str]: """Read an XML file to a string. Subsection string needs to include a prepending '-'.""" def _read_xml_string(number: int, year: int, subsection: str) -> str: xmlfile = f"tests/data/xmls/session-{number:03}-{year}{su...
2b4e4c3585e26138e5fecf820699e97e1011a842
3,666
def all_ndcubes(request): """ All the above ndcube fixtures in order. """ return request.getfixturevalue(request.param)
906412ebe9a26de5cfddcb1d1431ab014c8084c6
3,667
def filter_order_by_oid(order, oid): """ :param order: :type order: :class:`tests.testapp.testapp.trading.models.Order` :param oid: Order ID :type oid: int """ return order.tid == oid
bf84e2e9f2fa19dc19e1d42ceef92dd3050d1e89
3,668
def has_poor_grammar(token_strings): """ Returns whether the output has an odd number of double quotes or if it does not have balanced parentheses. """ has_open_left_parens = False quote_count = 0 for token in token_strings: if token == '(': if has_open_left_parens: ...
b35c6af0ec771ac22ff66d9ca875f5d916cb9489
3,669
import subprocess def countbam(sortedbam, outdir): """calculates the raw counts from a BAM index parameters ---------- sortedbam string, the name of the sorted bam file outdir string, the path of the output directory returns ---------- counts_file = file containing the ...
de60c7af2a479d00487a1891a64c926f9a2e0ae0
3,671
def tick2dayfrac(tick, nbTicks): """Conversion tick -> day fraction.""" return tick / nbTicks
50d01778f62203d37e733a6b328455d3ea10e239
3,673
def matrixMultVec(matrix, vector): """ Multiplies a matrix with a vector and returns the result as a new vector. :param matrix: Matrix :param vector: vector :return: vector """ new_vector = [] x = 0 for row in matrix: for index, number in enumerate(row): x += numb...
8a03b3acfec0d91fcf0d2c85b4e2bdd4f3053dd2
3,674
def url_to_filename(base, url): """Return the filename to which the page is frozen. base -- path to the file url -- web app endpoint of the page """ if url.endswith('/'): url = url + 'index.html' return base / url.lstrip('/')
35084e8b5978869bf317073c76bafc356a7d9046
3,676
def _msd_anom_3d(time, D_alpha, alpha): """3d anomalous diffusion function.""" return 6.0*D_alpha*time**alpha
e5204c52368202665e4dd4acd7d86096349c0d29
3,677
import os def tmp_envfile(tmp_path, monkeypatch): """Create a temporary environment file.""" tmp_file_path = tmp_path / "setenv.txt" monkeypatch.setenv("GITHUB_ENV", os.fspath(tmp_file_path)) return tmp_file_path
04deab16ce4b0e115e9fdc9b65a023f7c63f054f
3,679
def url_root(): """根路径""" return """ <p>Hello ! Welcome to Rabbit's WebServer Platform !</p> <a href="http://www.miibeian.gov.cn/" target="_blank" style="">京ICP备 18018365 号</a>&#8195;@2018Rabbit """
2e6d1d5301ac67bdec30cdeeaeed3c8638568de9
3,680
def map_keys(func, d): """ Returns a new dict with func applied to keys from d, while values remain unchanged. >>> D = {'a': 1, 'b': 2} >>> map_keys(lambda k: k.upper(), D) {'A': 1, 'B': 2} >>> assert map_keys(identity, D) == D >>> map_keys(identity, {}) {} """ return dict(...
5e9798d208db5e43dad497d64a4b8e469c67eb3b
3,681
def defaults(dictionary, overwriteNone=False, **kwargs): """ Set default values of a given dictionary, option to overwrite None values. Returns given dictionary with values updated by kwargs unless they already existed. :param dict dictionary: :param overwriteNone: Whether to overwrite None values....
6def5bb71839b3b627a5597ea6fa7fa1b48e463b
3,682
import json def dump_into_json(filename, metrics): """Dump the metrics dictionary into a JSON file It will automatically dump the dictionary: metrics = {'duration': duration, 'voltage_extremes': voltage_extremes, 'num_beats': num_beats, 'mean_hr_bpm': mean_hr_...
2e6effbcefe7cb3033c4c472cbee3850c00ae06b
3,683
def object_comparator_lookup(src_obj, dst_obj): """ Compare an object with another entry by entry """ dont_match = [] no_upstream = [] for i in dst_obj: count_name = 0 count_value = 0 for j in src_obj: if list(j.keys())[0] == list(i.keys())[0]: ...
ba5767624255da915d9c07d25b62880c387f6f00
3,686
def is_primitive(v): """ Checks if v is of primitive type. """ return isinstance(v, (int, float, bool, str))
d22607c0e2b93b82b1da6beb50de68668624dd71
3,687
def linkify_only_full_urls(attrs, new=False): """Linkify only full links, containing the scheme.""" if not new: # This is an existing <a> tag, leave it be. return attrs # If the original text doesn't contain the scheme, don't linkify. if not attrs['_text'].startswith(('http:', 'https:')): ...
89fcc7f3fc53353686260779ae8ddb4c0523c57b
3,688
def set_vars(api, file:str, tess_profile:dict): """ Reads the user-specific variables from the tess_profile :param api: :param file: :param tess_profile: :return: """ # Set necessary information api.SetImageFile(file) # Set Variable api.SetVariable("save_blob_choices", "T") ...
a7fbe0c5bc584928623e2eadc36240ea3b0f37de
3,691
def serialize_to_jsonable(obj): """ Serialize any object to a JSONable form """ return repr(obj)
c8632b8b475d49b56d47b29afa8b44676b7882a5
3,692
import torch def fps_and_pred(model, batch, **kwargs): """ Get fingeprints and predictions from the model. Args: model (nff.nn.models): original NFF model loaded batch (dict): batch of data Returns: results (dict): model predictions and its predicted fingerprints, conformer w...
1a8cca3ffe0d386e506ab42f6e77e00b1a5975d1
3,694
import re def replace_subject_with_object(sent, sub, obj): """Replace the subject with object and remove the original subject""" sent = re.sub(r'{}'.format(obj), r'', sent, re.IGNORECASE) sent = re.sub(r'{}'.format(sub), r'{} '.format(obj), sent, re.IGNORECASE) return re.sub(r'{\s{2,}', r' ', sent, re...
1c7f8115968c4e4ef10dcc3b83f0f259433f5082
3,695
import sys def get_title_count(titles, is_folder): """ Gets the final title count """ final_title_count = 0 if len(titles.all) == 0: if is_folder == False: sys.exit() else: return 0 else: for group, disc_titles in titles.all.items(): for titl...
bdd239698f98c845cbecb27924725c38257547b6
3,697
def judgement(seed_a, seed_b): """Return amount of times last 16 binary digits of generators match.""" sample = 0 count = 0 while sample <= 40000000: new_a = seed_a * 16807 % 2147483647 new_b = seed_b * 48271 % 2147483647 bin_a = bin(new_a) bin_b = bin(new_b) la...
9d778909ba6b04e4ca3adbb542fce9ef89d7b2b7
3,698
def accession(data): """ Get the accession for the given data. """ return data["mgi_marker_accession_id"]
132dcbdd0712ae30ce7929e58c4bc8cdf73aacb2
3,699
def atomic_number(request): """ An atomic number. """ return request.param
6f1a868c94d0a1ee4c84a76f04b4cabc3e0356e0
3,700
import re def load_mac_vendors() : """ parses wireshark mac address db and returns dict of mac : vendor """ entries = {} f = open('mac_vendors.db', 'r') for lines in f.readlines() : entry = lines.split() # match on first column being first six bytes r = re.compile(r'^([0-9A-F]{...
361e9c79de8b473c8757ae63384926d266b68bbf
3,701
def reorganize_data(texts): """ Reorganize data to contain tuples of a all signs combined and all trans combined :param texts: sentences in format of tuples of (sign, tran) :return: data reorganized """ data = [] for sentence in texts: signs = [] trans = [] for sign,...
27b4efd99bbf470a9f8f46ab3e34c93c606d0234
3,702
def query_schema_existence(conn, schema_name): """Function to verify whether the current database schema ownership is correct.""" with conn.cursor() as cur: cur.execute('SELECT EXISTS(SELECT 1 FROM information_schema.schemata WHERE SCHEMA_NAME = %s)', [schema_name]) return cu...
9c556283d255f580fc69a9e41a4d452d15e1eb17
3,703
import mimetypes def img_mime_type(img): """Returns image MIME type or ``None``. Parameters ---------- img: `PIL.Image` PIL Image object. Returns ------- mime_type : `str` MIME string like "image/jpg" or ``None``. """ if img.format: ext = "." + img.format ...
fe46af6e5c03a1ae80cb809c81ab358ac5c085fa
3,704
def get_yourContactINFO(rows2): """ Function that returns your personal contact info details """ yourcontactINFO = rows2[0] return yourcontactINFO
beea815755a2e6817fb57a37ccc5aa479455bb81
3,706
def filter_out_nones(data): """ Filter out any falsey values from data. """ return (l for l in data if l)
39eb0fb7aafe799246d231c5a7ad8a150ed4341e
3,707
import itertools def testBinaryFile(filePath): """ Test if a file is in binary format :param fileWithPath(str): File Path :return: """ file = open(filePath, "rb") #Read only a couple of lines in the file binaryText = None for line in itertools.islice(file, 20): ...
809a962881335ce0a3a05e341a13b413c381fedf
3,708
def factor_size(value, factor): """ Factors the given thumbnail size. Understands both absolute dimensions and percentages. """ if type(value) is int: size = value * factor return str(size) if size else '' if value[-1] == '%': value = int(value[:-1]) return '{0}%...
41b061fb368d56ba18b52cd7a6a3322292671d83
3,709
def temp_database(tmpdir_factory): """ Initalize the Database """ tmpdb = str(tmpdir_factory.mktemp('temp'))+"/testdb.sqlite" return tmpdb
5cfcb27e6ac76766e21a1612691dbe79d1713abd
3,710
import ast def get_classes(pyfile_path): """ Obtiene las clases que están dentro de un fichero python :param str pyfile_path: nombre del fichero a inspeccionar :return: devuelve una lista con todas las clases dentro de un fichero python :rtype: list .. code-block:: python >> get_cla...
72f376d10fd02574085a0236e10ea8901033ebd0
3,711
import array def ordinate(values,maxrange,levels): """Ordinate values given a maximum data range and number of levels Parameters: 1. values: an array of continuous values to ordinate 2. maxrange: the maximum data range. Values larger than this will be saturated. 3. levels: the number of level...
4db4a26579d9208cd90ec630cf82e54a4a7ec3fe
3,713
def get_book_info(book_id, books): """Obtain meta data of certain books. :param book_id: Books to look up :type: int or list of ints :param books: Dataframe containing the meta data :type: pandas dataframe :return: Meta data for the book ids :rtype: List[str], List[str], List[str] "...
64a91a498f9bf9df918d256a7ce705e98dadbbd9
3,719
import functools import six def save_error_message(func): """ This function will work only if transition_entity is defined in kwargs and transition_entity is instance of ErrorMessageMixin """ @functools.wraps(func) def wrapped(*args, **kwargs): try: return func(*args, **kwa...
9ac592100445a0232efc4afaa3807b050c8eddff
3,720
import requests import json def GetTSAWaitTimes(airportCode): """ Returns data from the TSA Wait Times API for a particular airport shortcode. :param airportCode: 3-letter shortcode of airport :return: Returns the full parsed json data from TSA Wait Times API """ base_url = "http://apps.tsa.dh...
bd03be14c95a3892ac75a0396da12ca04b52a59b
3,721
def namedtuple_to_dict(model_params): """Transfers model specification from a named tuple class object to dictionary.""" init_dict = {} init_dict["GENERAL"] = {} init_dict["GENERAL"]["num_periods"] = model_params.num_periods init_dict["GENERAL"]["num_choices"] = model_params.num_choices ...
9ac2f23aff3b9c57599eb2c2c6cacd455ac711a5
3,722
from typing import Mapping from pathlib import Path import os def _strip_paths(notebook_json: Mapping, project_root: Path): """Strip user paths from given notebook.""" project_root_string = str(project_root) + os.sep mutated = False for cell in notebook_json["cells"]: if cell["cell_type"] ==...
318493239c964104b4838ffe2ba2b37a295ef792
3,723
import time def time_as_int() -> int: """ Syntactic sugar for >>> from time import time >>> int(time()) """ return int(time.time())
f7f6d037d156c09a01c0ff13f8b43418133ab1b0
3,724
def should_retry_http_code(status_code): """ :param status_code: (int) http status code to check for retry eligibility :return: (bool) whether or not responses with the status_code should be retried """ return status_code not in range(200, 500)
69acb5bd34b06e1ff1e29630ac93e60a3ccc835c
3,725
def extract_values(inst): """ :param inst: the instance :return: python values extracted from the instance """ # inst should already be python return inst
087bb00ee6e3666b4a9e682ca420623982a12102
3,726
import re def eq_portions(actual: str, expected: str): """ Compare whether actual matches portions of expected. The portions to ignore are of two types: - ***: ignore anything in between the left and right portions, including empty - +++: ignore anything in between left and right, but non-empty :p...
704b2a83575347c5143c2dc0aca5227a8fc5bd4b
3,727
import numpy as np def _organize_arch(fils, pth): """Allocate data from each specific type of file (keys from the input dict) to a new dict Arguments: fils {dict} -- Dictionary containing type of files and list of files Returns: [dict] -- [description] """ imgdata ...
c62c9b23bf4735c2062090d77278ce5a8acbd668
3,728
def sort(request): """Boolean sort keyword for concat and DataFrame.append.""" return request.param
83f35eb41bc0cf7eecea932ae4f14646d9e8732f
3,729
def is_comprehension(leaf): """ Return true if the leaf is the beginning of a list/set/dict comprehension. Returns true for generators as well """ if leaf.type != 'operator' or leaf.value not in {'[', '(', '{'}: return False sibling = leaf.get_next_sibling() return (sibling.type in...
11fff76ff8ed19b3d57359b56db886c003603a86
3,730
def get_awb_shutter( f ): """ Get AWB and shutter speed from file object This routine extracts the R and B white balance gains and the shutter speed from a jpeg file made using the Raspberry Pi camera. These are stored as text in a custom Makernote. The autoexposure and AWB white balance valu...
cfafdf531809729ae0ec96ab90a60a4961b9437a
3,732
def format_rfidcard(rfidcard): """ :type rfidcard: apps.billing.models.RfidCard """ return { 'atqa': rfidcard.atqa if len(rfidcard.atqa) > 0 else None, 'sak': rfidcard.sak if len(rfidcard.sak) > 0 else None, 'uid': rfidcard.uid, 'registered_at': rfidcard.registered_at.is...
120ca8e338b01235b2ba12ae3f874fd317ffebe8
3,733
def make_exposure_shares(exposure_levels, geography="geo_nm", variable="rank"): """Aggregate shares of activity at different levels of exposure Args: exposure_levels (df): employment by lad and sector and exposure ranking geography (str): geography to aggregate over variable (str): varia...
02d990f2b08e3acb2a2b8ac01e44848770bdea71
3,734
from typing import OrderedDict def load_jed(fn): """ JEDEC file generated by 1410/84 from PALCE20V8H-15 06/28/20 22:42:11* DM AMD* DD PALCE20V8H-15* QF2706* G0* F0* L00000 0000000000000000000000000100000000000000* """ ret = {} d = OrderedDict() with open(fn) as f: ...
6570bcdaabb495c13e9419a532c85b15efdf957a
3,739
def load_decoder(autoencoder): """ Gets the decoders associated with the inputted model """ dim = len(autoencoder.get_config()['input_layers']) mag_phase_flag = False decoders = [] if dim == 2: mag_phase_flag = True decoders.append(autoencoder.get_layer('mag_decoder')) ...
8e39470e48f5a6c147d93567c0bdb33a588c790d
3,740
def detect_side(start: dict, point: dict, degrees): """detect to which side robot should rotate""" if start['lat'] < point['lat'] and start['lng'] < point['lng']: return f'{degrees} degrees right' elif start['lat'] < point['lat'] and start['lng'] > point['lng']: return f'{degrees} degrees...
124833bbdcdf36c280cdde8e829f15ae5301e323
3,741
import torch def moving_sum(x, start_idx: int, end_idx: int): """ From MONOTONIC CHUNKWISE ATTENTION https://arxiv.org/pdf/1712.05382.pdf Equation (18) x = [x_1, x_2, ..., x_N] MovingSum(x, start_idx, end_idx)_n = Sigma_{m=n−(start_idx−1)}^{n+end_idx-1} x_m for n in {1, 2, 3, ..., N} ...
fa3cb672e23fccad75965da2ca10955134167c7e
3,742
def make_sequence_output(detections, classes): """ Create the output object for an entire sequence :param detections: A list of lists of detections. Must contain an entry for each image in the sequence :param classes: The list of classes in the order they appear in the label probabilities :return: ...
019d3b74699af20a9f3cbc43b575e8bae5e15946
3,743
def fix(text): """Repairs encoding problems.""" # NOTE(Jonas): This seems to be fixed on the PHP side for now. # import ftfy # return ftfy.fix_text(text) return text
7fd97db345a604131f52b272a7dd13ab4f3f9153
3,744
def from_url_representation(url_rep: str) -> str: """Reconvert url representation of path to actual path""" return url_rep.replace("__", "/").replace("-_-", "_")
5cf4e1e8cb284c66449807ea275e4fa6b5a3e3ad
3,745
def encode(value): """ Encode strings in UTF-8. :param value: value to be encoded in UTF-8 :return: encoded value """ return str(u''.join(value).encode('utf-8'))
697f99f028d4b978b591d006273b9d5f688711f3
3,747
def get_season(months, str_='{}'): """ Creates a season string. Parameters: - months (list of int) - str_ (str, optional): Formatter string, should contain exactly one {} at the position where the season substring is included. Returns: str """ if months is None: retur...
73b4e8169f08ef286a0b57779d22c3436538fc30
3,748
def data_availability(tags): """ get availability based on the validation tags Args: tags (pandas.DataFrame): errors tagged as true (see function data_validation) Returns: pandas.Series: availability """ return ~tags.any(axis=1)
240bed8f169d23610f11c214d3644f02e5435412
3,749
def is_empty_config(host): """ Check if any services should to be configured to run on the given host. """ return host.AS is None
c4ec3861c497ac49ed69ecd1d6da31ab8fe2829c
3,751
def total_value(metric): """Given a time series of values, sum the values""" total = 0 for i in metric: total += i return total
4454bfaeb0797bc03b14819bde48dc8f5accc4d3
3,752
def se_beta_formatter(value: str) -> str: """ SE Beta formatter. This formats SE beta values. A valid SE beta values is a positive float. @param value: @return: """ try: se_beta = float(value) if se_beta >= 0: result = str(se_beta) else: ...
30dde489e1a8a70c0f1093caa1ce289c759b26d6
3,754
def extract_urlparam(name, urlparam): """ Attempts to extract a url parameter embedded in another URL parameter. """ if urlparam is None: return None query = name+'=' if query in urlparam: split_args = urlparam[urlparam.index(query):].replace(query, '').split('&') ret...
198771d40eeddc3b7dbf2924d9d49fe7a7f0a51d
3,755
def parse_gt_from_anno(img_anno, classes): """parse_gt_from_anno""" print('parse ground truth files...') ground_truth = {} for img_name, annos in img_anno.items(): objs = [] for anno in annos: if anno[1] == 0. and anno[2] == 0. and anno[3] == 0. and anno[4] == 0.: ...
63ba02bb0511cdc02245528041257639e764605f
3,759
def pt_to_tup(pt): """ Convenience method to generate a pair of two ints from a tuple or list. Parameters ---------- pt : list OR tuple Can be a list or a tuple of >=2 elements as floats or ints. Returns ------- pt : tuple of int A pair of two ints. """ return (...
7013b2477959f528b98d364e4cc44ac8700fb366
3,760
import argparse def parsing(lst=None): """ Function for parsing command line >>> parsing(["2020", "80", "90", "dataset"]) (2020, 80.0, 90.0, 'dataset') """ parser = argparse.ArgumentParser(description="""Module, which reads data from a file\ with a films list, determines films, \ ma...
f625f09b31b60b80d91474560ca01b5df92d567c
3,762
def flatten(lst): """Shallow flatten *lst*""" return [a for b in lst for a in b]
203e971e43aea4d94bfa0ffa7057b416ef0bf545
3,763
def sep_num(number, space=True): """ Creates a string representation of a number with separators each thousand. If space is True, then it uses spaces for the separator otherwise it will use commas Note ---- Source: https://stackoverflow.com/questions/16670125/python-format-string-thousand-separ...
ee7dfbb60fb01bb7b6bb84cbe56ec50dfab4b339
3,764
def all_results_failed(subsystems): """Check if all results have failed status""" for subsystem in subsystems.values(): if subsystem['subsystemStatus'] == 'OK': # Found non-failed subsystem return False # All results failed return True
6612397c5b1605ad3e623e3c47264869c93cd47d
3,765
def LowercaseMutator(current, value): """Lower the value.""" return current.lower()
7fed0dc4533948c54b64f649e2c85dca27ee9bc5
3,767
from typing import Dict from typing import Any from typing import MutableMapping import logging def merge_optional(default_dict: Dict[str, Any], update_dict: Dict[str, Any], tpe: str): """ Function to merge dictionaries to add set parameters from update dictionary into default dictionary. @param default_d...
32e52e58604b01061b6c5a3122287c0e5d8a9a84
3,769
import pathlib def testdata(request): """ If expected data is required for a test this fixture returns the path to a folder with name '.testdata' located in the same director as the calling test module """ testdata_dir = '.testdata' module_dir = pathlib.Path(request.fspath).parent retu...
5d9a440b178aca00635f567420aaa9c406a1d7d2
3,770
import math def inverse_document_frequency(word_occurrence, num_texts): """Takes in a word (string) and texts (list of lists and calculates the number of texts over number of texts where the word occurs""" try: IDF = float(num_texts) / float(word_occurrence) return math.log(IDF) except...
a64e84b3c7d378e61765a84d3f4405e77b2ffd40
3,771
import argparse def parse_command_arguments(): """Returns parsed command arguments""" parser = argparse.ArgumentParser(description="svg-to-swift converter") parser.add_argument("--input_file", required=True, help="SVG file to convert.") parser.add_argument("--output_file", default="svg.swift", help="F...
c01ed5e6c1f5ca116e87da4e686d866a67876daa
3,772
def drop_useless_columns(data): """Drop the columns containing duplicate or useless columns.""" data = data.drop( labels=[ # we stay in a given city "agency_id", "agency_name", "agency_short_name", # we stay on a given transportation network ...
7a47625a5df7e9fa66cefe2f326af3f0b9f59b79
3,773
import math def expfloats (floats): """Manipulates floats so that their tiles are logarithmic sizes large to small""" return [math.exp(i) for i in floats]
3943b8f8eedd4195693e0bace2223819f3728bb2
3,774
import re def normalize(string: str) -> str: """ Normalize a text string. :param string: input string :return: normalized string """ string = string.replace("\xef\xbb\xbf", "") # remove UTF-8 BOM string = string.replace("\ufeff", "") # remov...
2adaeffb60af598dad40bd6f5cd7e61e6b238123
3,775
def extract_data(mask, dra, ddc, dra_err, ddc_err, ra_rad, dc_rad, ra_dc_cor=None): """Get a clean sample based on mask Parameters ---------- mask : array of boolean mask for extract data dra/ddc : array of float R.A.(*cos(Dec.))/Dec. differences dra_err/ddc_err : array of float...
70286c6134fb19833f6033c827bb2ab2cd26afb1
3,776
from typing import Iterable def token_converter(tokens: Iterable[str]) -> Iterable[str]: """Convert tokens.""" def convert(token: str) -> str: return token.lower().replace("-", "_") return map(convert, tokens)
93bf2436c81091ec55b6a7a4d6d3fc728a68e093
3,778
def update_instance(instance, validated_data): """Update all the instance's fields specified in the validated_data""" for key, value in validated_data.items(): setattr(instance, key, value) return instance.save()
2f4d5c4ec9e524cbe348a5efad9ecae27739b339
3,779
import pipes def _ShellQuote(command_part): """Escape a part of a command to enable copy/pasting it into a shell. """ return pipes.quote(command_part)
31ccd5bd64de657cd3ac5c36c643e9f2f09f2318
3,780
import math def circlePoints(x, r, cx, cy): """Ther dunction returns the y coordinate of a circonference's point :x: x's coordinate value. :r: length of the radius. :cx: x coordinate of the center. :cy: y coordinate of the center.""" return math.sqrt(math.pow(r,2) - math.pow(x-c...
c2cc14a845dccbcf62a38be3af69808024289adc
3,781
import torch def get_gram_matrix(tensor): """ Returns a Gram matrix of dimension (distinct_filer_count, distinct_filter_count) where G[i,j] is the inner product between the vectorised feature map i and j in layer l """ G = torch.mm(tensor, tensor.t()) return G
ad86f06768c07d6fe1ff509d996991f786ea1ffa
3,782
def deduplicate(s, ch): """ From http://stackoverflow.com/q/42216559/610569 s = 'this is an irritating string with random spacing .' deduplicate(s) 'this is an irritating string with random spacing .' """ return ch.join([substring for substring in s.strip().split(ch) if su...
5b2bb10376143a1597ddfab1711716c802cdf113
3,783
def sum_series(n): """Calculate sum of n+(n-2)+(n-4)...""" return n if n < 2 else n + sum_series(n - 2)
317317fc6a7f14a9cbd564266b73ac087b2bdbd2
3,784
def get_all_contained_items(item, stoptest=None): """ Recursively retrieve all items contained in another item :param text_game_maker.game_objects.items.Item item: item to retrieve items\ from :param stoptest: callback to call on each sub-item to test whether\ recursion should continue....
d04e5c297dddb70db83637e748281f04b08b6a25
3,785
def conv_seq_to_sent_symbols(seq, excl_symbols=None, end_symbol='.', remove_end_symbol=True): """ Converts sequences of tokens/ids into a list of sentences (tokens/ids). :param seq: list of tokens/ids. :param excl_symbols: tokens/ids which should be excluded from the final ...
a87da4bb5c34882d882832380f3831929ad41415
3,786
def param_value(memory, position, mode): """Get the value of a param according to its mode""" if mode == 0: # position mode return memory[memory[position]] elif mode == 1: # immediate mode return memory[position] else: raise ValueError("Unknown mode : ", mode)
e02ed7e1baea57af4b08c408b6decadee9c72162
3,787
def prob17(limit=1000): """ If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used? NOTE: Do n...
586f60fa4411a5818102a903286aa97095faeffb
3,789
import re def get_replaceid(fragment): """get replace id for shared content""" replaceid=re.findall(r":[A-z]+:\s(.+)", fragment)[0] return replaceid
25e1a940904d86c5e57d2d36dbd91247c6e08bb3
3,790