content
stringlengths
39
14.9k
sha1
stringlengths
40
40
id
int64
0
710k
def get_buildings(expo, tax, ds): """ Helper method to get the buildings value. """ expo_tax = expo[expo.Taxonomy == tax] expo_ds = expo_tax[expo_tax.Damage == ds] return expo_ds.Buildings.iloc[0]
59f99854cad80d5037cad09b96cf0254923f0376
34,264
def stat_ahead_behind(git, local_ref, remote_ref): """ Returns a tuple (ahead, behind) describing how far from the remote ref the local ref is. """ behind = 0 ahead = 0 (ret, out) = git.call("rev-list", "--left-right", "%s..%s" % (remote_ref, local_ref), raises=Fals...
7275a43a94bf8bc9d4971aa79a198cdedca39031
34,265
def bpas_log_snr_new(file_name: str, mode: str = "INIT"): """ Retrieve ``new`` SNR values from bandpass log file. Parameters ---------- file_name : str Log file name. mode : str, optional Bandpass stage. The default is 'INIT' that is all stages. Returns ------- res ...
2a323067ace8b8f2965be5ac69d16206a5b93cf3
34,266
import re def _remove_phrasing(ipt_txt, phrase, replacement): """ removes the given phrase and replaces it with the replacement :param ipt_txt: string to change :param phrase: unwatned phrase to be removed :param replacement: replacement phrase :return: string with the phrase replaced with rep...
9b36a46f28c222d44b7b5290e0c02dded81562f7
34,270
from typing import Tuple from typing import Optional def get_dbt_prefix_config(config) -> Tuple[Optional[str], Optional[str]]: """ Return (bucket, prefix) tuple """ if config.dbtPrefixConfig: return ( config.dbtPrefixConfig.dbtBucketName, config.dbtPrefixConfig.dbtObjec...
762e8afc8b40db49d8fa115b33a0cfc69ea038ac
34,271
def isUsdCrate(path): """ Check if a file is a USD crate file by reading in the first line of the file. Doesn't check the file extension. :Parameters: path : `str` USD file path :Returns: If the USD file is a crate (binary) file. :Rtype: `bool` """ wi...
aa6bc6a94552f49b83f2a17239a061d7f0672950
34,272
def xml_escape(str): """Replaces chars ' " < > & with xml safe counterparts""" if str is None: return None str = str.replace("&", "&amp;") str = str.replace("'", "&apos;") str = str.replace("\"", "&quot;") str = str.replace("<", "&lt;") str = str.replace(">", "&gt;") return str
8bec0fc289be43e84fba847d4d51bccb44df2839
34,273
def makeSquare(x, y, w, h): """ Convert a rectangle ROI to square. @param: left-most column @param: top-most row @param: width of region @param: height of region @return: x, y, w, h of the new ROI """ c_x = x + w // 2 c_y = y + h // 2 sz = max(w, h) x = c_x - sz // 2 y...
c6b9cae46fbcb929511802ef125a808a81087e7f
34,275
def make_relative(path: str, root_path: str) -> str: """Make path relative with respect to a root directory Arguments: path (str): current path. root_path (str): root directory path. Returns: str: relative path. """ r_path = path.replace(root_path, '') if r_path: ...
04e98d971a3b1ee0a698f4b082c8cb3529b60185
34,276
def count_missense_per_gene(lines): """ count the number of missense variants in each gene. """ counts = {} for x in lines: x = x.split("\t") gene = x[0] consequence = x[3] if gene not in counts: counts[gene] = 0 if consequence !...
b20b7deca5b48af30378ee40ed03763069a45768
34,278
import datetime as dt def make_dates_ordinal(df, dates_column): """ This function converts the dates of a DataFrame column to integers, in order to easily fit the data to a regression model. More specifically, the function toordinal() returns the proleptic Gregorian ordinal of a date. In si...
43b84eca8c9329d6c7598a506c2703122f2fb634
34,284
def generate_filename(in_path, out_dir, bitrate, encoder): """ Create a new filename based on the original video file and test bitrate. Parameters ---------- in_path : str Full path of input video. out_dir : str Directory of output video. bitrate : int Video bitrate ...
6e8edb9a0bfd7e1c8ae779bd5c546f0f50389415
34,286
def preconvert_bool(value, name): """ Converts the given `value` to an acceptable boolean by the wrapper. Parameters ---------- value : `int` The value to convert. name : `str` The name of the value. Returns ------- value : `str` Raises ------ ...
d326f4d414a01f156e7ba1793d8f5a667a0e8b72
34,287
def _compare(data, k, threshold, sign=True): """ Obtain indicator vector for the samples with k-th feature > threshold :param data: array-like of shape (n_sample, n_feat) :param k: int Index of feature in question :param threshold: float Threshold for the comparison :param sign:...
730582aa42dec9087de0d4869af42b3b47dd83e0
34,290
def get_common_subpeptides(list1, list2): """Get intersection of two sub-peptide chain lists (chain names)""" common_list = [sub_peptide for sub_peptide in list1 if sub_peptide in list2] return common_list
fa088fa56c2e77cb252af26d7cc848e99bc5dd04
34,296
def trace_driven_cache_hit_ratio(workload, cache, warmup_ratio=0.25): """Compute cache hit ratio of a cache under an arbitrary trace-driven workload. Parameters ---------- workload : list or array List of URLs or content identifiers extracted from a trace. This list only needs to co...
f19da290fc4edf5284e8e52ff14ef60b2c59956b
34,299
def post_process_weird(system_mentions): """ Removes all mentions which are "mm", "hmm", "ahem", "um", "US" or "U.S.". Args: system_mentions (list(Mention): A list of system mentions. Returns: list(Mention): the filtered list of mentions. """ return sorted( [mention for...
4cc8198ff29768178859b6115d28dd958f8599be
34,311
def getCluster(self): """Get the HDInsight cluster object""" # Get all the HDInsight clusters hdinsight_clusters = self.hdinsight_client.clusters.list() # Get current cluster for hdinsight_cluster in hdinsight_clusters: if hdinsight_cluster.name == self.params["CLUSTER_DNS_NAME"]: ...
a6dbd63c1e85db8893d32cbe12c01b5d9df5b350
34,315
import requests def get_remaining_rate_limit(api_key: str) -> int: """ Returns your remaining rate limit by making a request to :ref:`Apod <extensions/apod:Apod>` and getting the header ``X-RateLimit-Remaining``, that's returned on every API response. For example, if you are using an ...
39a1b49ca9148a655cc90e25f8a1b8027f4821b5
34,318
import six def is_iterable(x): """Determine whether ``x`` is a non-string iterable""" if isinstance(x, six.string_types): return False return hasattr(x, "__iter__")
38e1d8955c6114bd1dfa2b7b6acdbed7572b5212
34,319
def _is_fileobj(obj): """ Is `obj` a file-like object?""" return hasattr(obj, 'read') and hasattr(obj, 'write')
8d09dce78239fe134116e641d4cf5934ffc173ec
34,321
def ends_with_blank_line(block): """ Returns true if block ends with a blank line, descending if needed into lists and sublists. """ if block.last_line_blank: return True if block.t in ['List', 'ListItem'] and block.children: return ends_with_blank_line(block.children[-1...
2b079351e69ad288ce17b9d42b5774814a97aed3
34,322
def clause_time(verb, api): """Look for an adjunctive Time element in the clause.""" L, F = api.L, api.F clause_atom = L.u(verb, 'clause_atom')[0] time_phs = [ p for p in L.d(clause_atom, 'phrase') if F.function.v(p) == 'Time' ] data = {'has_time': 0} if time_phs: ...
8a4ca0ac32970089e9a4d19dc029a91dfcc1512b
34,324
import pip import site def install_package(package): """Install a pip package to the user's site-packages directory.""" exitval = pip.main(['install', '--user', package]) if exitval == 0: # Reload sys.path to make sure the user's site-packages are in sys.path site.main() return exitval...
3c9781a290e84a2414ba28ea737a774e41dc49e1
34,327
def get_hit_table(hit): """Create context for a single hit in the search. Args: hit(Dict): a dictionary representing a single hit in the search. Returns: (dict).The hit context. (list).the headers of the hit. """ table_context = { '_index': hit.get('_index'), ...
50a6d4b2304381b7cd9977213fb64f36d3485e80
34,328
def scaler(scale): """Create a function that scales by a specific value.""" def inner(val): return val * scale return inner
b2e9a8efb5f0aff079fbfaf8c5326978a6990660
34,329
def _remove_empty_events(sse): """ Given a sequence of synchronous events (SSE) `sse` consisting of a pool of pixel positions and associated synchronous events (see below), returns a copy of `sse` where all empty events have been removed. `sse` must be provided as a dictionary of type .. cente...
0596d43cc75fdd040c5096e3ddb81277b48d7456
34,332
def remove_comments(s): """removes the comments starting with # in the text.""" pos = s.find("#") if pos == -1: return s return s[0:pos].strip()
47e44d12f35c7b254f3f4ec001c630b5175b1e32
34,335
import re def rmspecialchars(value): """ Remove any special characters except period (.) and negative (-) from numeric values Parameters ---------- value : string String value to remove any existing characters from Returns ------- value : string String ...
26de451a5cfef33f9384ce13bda9e495ae81fc5d
34,342
import re def remove_urls(text): """Remove urls from text""" return re.sub('(https:|http:|www\.)\S*', '', text)
db7c2fa5e96ee525aa8c2d17ddf2888a354958f7
34,347
def get_config_rules_statuses(config): """Retrieves all of the AWS Config rules. Args: config: boto3 config object Returns: List of AWS Config rules """ config_rules = [] page_iterator = config.get_paginator("describe_compliance_by_config_rule") for page in page_iterator.p...
7c3ec7281d06966fb97193274fc62465e8910d08
34,348
def check_params(params, field_list): """ Helper to validate params. Use this in function definitions if they require specific fields to be present. :param params: structure that contains the fields :type params: ``dict`` :param field_list: list of dict representing the fields ...
8ce0ad0123c3dfed278564b6cd7fdb8545fdc7a7
34,349
def resolve_attr(obj, path): """A recursive version of getattr for navigating dotted paths. Args: obj: An object for which we want to retrieve a nested attribute. path: A dot separated string containing zero or more attribute names. Returns: The attribute referred to by obj.a1.a2.a...
3951e8436b2e51f7f2815ea0ed2bda35a8fc08ce
34,350
def column_to_list(data, index): """ Função para adicionar as colunas(features) de uma lista em outra lista, na mesma ordem. Argumentos: data: amostra de dados. index: índice da coluna na amostra. Retorna: Uma lista apenas com os dados da coluna informada no index. """ co...
55c8201e72234af57289d546078953aa07f3f1bb
34,353
def selection_sort(nums: list[float]) -> list[float]: """Sorts a list in-place using the Selection Sort approach. Time complexity: O(n^2) for best, worst, and average. Space complexity: total O(n) auxiliary O(1). Args: nums: A list of numbers. Returns: The sorted list. """ ...
c96c12e7361e6b617528b9cc632b4003963ea8ab
34,361
import itertools def get_pwdist_indices(sequences): """ From a list of sequences get lower triangle indices tuples (i,j) for pairwise comparisons. Parameters ---------- sequences : list of strings list of (likely amino acid) strings Returns ------- ind_tuples : list ...
f9ab2bbcc4481f898ff83963ad595240b95ad2b2
34,363
def shot_direct_neighbors(graph, reconstruction, shot_id): """Reconstructed shots sharing reconstructed points with a given shot.""" neighbors = set() for track_id in graph[shot_id]: if track_id in reconstruction.points: for neighbor in graph[track_id]: if neighbor in rec...
9b7ff5689aa32c30b85d62e535feab15ca6916e9
34,365
def fix_iso(job): """ Add couple xyz to the fix_ensemble inside LAMMPS Args: job (LAMMPS): Lammps job object Returns: LAMMPS: Return updated job object """ job.input.control["fix___ensemble"] = ( job.input.control["fix___ensemble"] + " couple xyz" ) return job
376bfb69abc2d59f42e766f4c9bda198468046ee
34,366
def get_version_v2(uri): """ Canned response nova v2 version. Cf: http://developer.openstack.org/api-ref-compute-v2.1.html #listVersionsv2.1 """ return {"version": {"status": "SUPPORTED", "updated": "2011-01-21T11:33:21Z", "links": [{"href": uri, ...
a34b5a0e1ee3e055dd3e559e9e4a79f611654414
34,368
def read_iba_file(file_path): """ :param file_path: absolute file path :return: a list of strings, each item being a row in the text file :rtype: list """ f = open(file_path, 'r') text = f.read() return text.replace('\r', '').split('\n')
f536f2b2d520799fe4f81825055315ed3a1f9d6d
34,370
def format_messages(messages_dict): """ Formats input messages in Polymer format to native Android format. This means replacing hyphens with underscores in keys and escaping apostrophes in values. """ formatted_messages = {} for k,v in messages_dict.items(): formatted_messages[k.replace("-", "_")] = v.r...
00fe6bfb76ce8e146a16a3bc3f108fc2d1277908
34,372
from functools import reduce def getAllTextWords(texts): """ Returns a set of all the words in the given texts """ return reduce(lambda x,y: x | set(y), texts.values(), set())
52e475b180031b0abf67bad3fe148b9509baaed1
34,375
def get_tensor_dependencies(tensor): """ Utility method to get all dependencies (including placeholders) of a tensor (backwards through the graph). Args: tensor (tf.Tensor): The input tensor. Returns: Set of all dependencies (including needed placeholders) for the input tensor. """ dep...
1c92b9fda9e5ca563bc43638f74f09c0bc16f264
34,378
def _get_vals_wo_None(iter_of_vals): """ Returns a list of values without Nones. """ return [x for x in iter_of_vals if x is not None]
e020ec4049217c5656c74bed6d20bfcdb8a89e78
34,379
def read_rescue(spark): """ Reads animal rescue CSV data from HDFS Args: spark (SparkSession): active Spark session Returns: spark DataFrame: animal rescue data """ return spark.read.csv("/training/animal_rescue.csv", header=True, inferSch...
6260b6914e2b1d8747791a1b2531793cd3c82781
34,384
def to_bool(val): """Conservative boolean cast - don't cast lists and objects to True, just existing booleans and strings.""" if val is None: return None if val is True or val is False: return val if isinstance(val, str): if val.lower() == 'true': return True ...
21934eb7ab28d53e2c415da988eee2cd3af2d2cc
34,386
def node_value(node, input_values, neuron_outputs): # PROVIDED BY THE STAFF """ Given * a node (as an input or as a neuron), * a dictionary mapping input names to their values, and * a dictionary mapping neuron names to their outputs returns the output value of the node. This function d...
4088211ce025b6e868c1a9ecffdd7955d5adf168
34,389
def check_domain_whitelist(string, whitelist): """ Returns True if a white listed domain appears in the string, otherwise returns False. :param string: A string possibly containing a domain name. :param whitelist: A list of strings containing white listed domains. :return: Bool """ for i in wh...
e92376a001fee8365ade4b829dd5daa7079063d8
34,394
def summarize_reduced_diffs(reduced_diffs): """ Print a human-readable summary of the relevant reduced diff data """ buf = "" ### General summary if 'sum_data_units_read_gibs' not in reduced_diffs: read_gibs = reduced_diffs.get('sum_data_units_read_bytes', 0) * 2.0**(-40) write_g...
8e3be22d11a3ae9f011edfa0fb28fdb859c7a980
34,395
import torch def copy_model_to_gpu(model, loss=None): """ Copies a model and (optional) loss to GPU and enables cudnn benchmarking. For multiple gpus training, the model in DistributedDataParallel for distributed training. """ if not torch.backends.cudnn.deterministic: torch.backends.c...
4fa61832eacdf3ab055e931fd9f952406f4aeca4
34,397
def get_strings(filename): """ Read strings from files generated by an IDAPython script and store them in a list for further processing. """ list_strings= [] with open(filename,'rU') as f: list_strings= [line[:-1] for line in f.readlines()] return list_strings
1f01bce01bd601e9bf25c8673fdcc97443384719
34,398
from typing import Any import hashlib def hex(data: Any) -> str: """Get sha512.""" if isinstance(data, str): data = data.encode("utf-8") return hashlib.sha512(data).hexdigest()
aad95dbcf69245d41b23115fd022f99340de060d
34,406
import difflib def compare_configs(cfg1, cfg2): """ This function, using the unified diff function, will compare two config files and identify the changes. '+' or '-' will be prepended in front of the lines with changes :param cfg1: old configuration file path and filename :param cfg2: new configu...
e0ad56de3f601a4f04347036106eb4de112afa83
34,410
def _limit_description_to_key(description): """Translate between the description of the Text widget and the corresonding key and value pos in the fitarg dictionary. Parameters ---------- description : str The string describing the widget Returns -------- key : string The ke...
2fe559dbce1c61ac0c298e3132ca188b52a4b9e2
34,413
import warnings import collections import re def read_quants_gianninas(fobj): """Read and parse custom file format of physical stellar parameters from Gianninas et al 2014, [1]_. Parameters ---------- fobj : file object An opened file object to the text file with parameters. E...
0b0750686cb127c81d80566a7d6e40d48570fd72
34,414
import math def getCosineSetSim(concepts_1: set, concepts_2: set): """ Returns Cosine Set Similarity for the given concept sets """ intersection = len(concepts_1.intersection(concepts_2)) return intersection/(math.sqrt(len(concepts_2)*len(concepts_1)))
f6c03fa83d55c19f6d5953ef84a4d9233262386d
34,420
import functools def dec_busy(func): """ Decorator to set the amp/lcd controller state to busy while executing function. """ @functools.wraps(func) def wrapper(self, *args, **kwargs): self.busy = True output = func(self, *args, **kwargs) self.busy = False return o...
730a7cbe34f8323098aca441142c1c3c5fd1788c
34,421
def is_run(part): """ >>> is_run([4]) False >>> is_run([1, 2, 3]) True >>> is_run([3, 2, 1]) False """ if len(part) != 3: return False return part[0] + 2 == part[1] + 1 == part[2]
a7719c1a02a8a8a573e2bc69052711ec551b100f
34,422
def form_tree_definition(proj, formname): """Turn the form (instrument) definition in the project xml file into a python dictionary tree. In the XML structure items are defined in different places and the are various places where 'ref' items have to be looked up to find 'def'. Turn it into a nice ...
d1a2eb638eed9443af11ec933942f2179e20c79b
34,423
def parse_one_line(line): """ Get one line of a file in this format 16:17:266:2864 3:4:194:2443 and return a couple of lists [16,17,266,2864], [3,4,194,2443] """ line_trial, line_success = line.split(' ') one_trial = [int(s) for s in line_trial.split(':')] one_success = [...
8397e9fa742f42af5348d0bab0d459e98991b95f
34,426
def get_employee_sick_leave_days(employee, month): """Calls the sick leave days for the given employee and month.""" return month.get_employee_sick_leave_days(employee)
171a17828c834718e79267bd1524194c66904bf7
34,429
import requests def get_tnstats(url, cookie): """ Retrieve Tunneled Node's agregated statistics :param url: base url :param cookie: Cookie value :return: TN Statisctics JSON :Example: result = get_tnstats(base_url, sessionid) """ header = {'cookie': cookie} get_tn_stats = requ...
2b182029d5e7fabebcb8df5fdd5ce42bf83ae1cd
34,432
import re def normalize(text: str) -> str: """ Replace all whitespaces in the text with a single space. For example " foo bar " is converted to "foo bar". """ return re.sub(r"\s+", " ", text).strip()
b8015d6004b57ff13c9d78acac4ff479ea327a11
34,438
def check_digit13(firsttwelvedigits): """Check sum ISBN-13.""" # minimum checks if len(firsttwelvedigits) != 12: return None try: int(firsttwelvedigits) except Exception: # pragma: no cover return None # checksum val = sum( (i % 2 * 2 + 1) * int(x) for i, x i...
434cb3e71ecba49a0e5a13c73a6808c8c5e80446
34,446
import torch def batch_colout(X: torch.Tensor, p_row: float, p_col: float) -> torch.Tensor: """Applies ColOut augmentation to a batch of images, dropping the same random rows and columns from all images in a batch. Args: X: Batch of images of shape (N, C, H, W). p_row: Fraction of rows to...
1ff4311127749afc9eb56797b76d18c706ebf378
34,450
def paginate(query, page, count): """ Returns the items given the count and page specified :param query: :param page: :param count: """ return query.paginate(page, count)
ce6bc412de90b9333c8febbf75a35b2abfa3e0ae
34,453
def _get_s3_presigned_put_url(s3_client, bucket, filepath, md5sum, lifetime_sec): """ Creates a pre-signed URL for S3-like backends, e.g. Minio. Note that since our production object storage backend is GCS, we do not enforce or require any Content-MD5 value. :param: s3_client: an initialized S3 cl...
d020281a0ce4d71eb3492d5f8a7a693b35d03c32
34,454
def reverse_bits(n): """ Reverses the bits in an integer. :param n: an integer value. :return: finds the integer value of a reversed integer bit. """ return int(bin(n)[::-1][0:-2], 2)
e19979b487c84ab4a7925ca64aaebeddd2fb0655
34,463
from math import isnan def clamp(x: float, lower=0., upper=1.) -> float: """ Clamps a float to within a range (default [0, 1]). """ if x <= lower: return lower elif x >= upper: return upper elif isnan(x): raise FloatingPointError('clamp is undefined for NaN') return...
e1af0a40b4f0e9ecb0f917faa4b8ab5f4c9b2ac5
34,467
import socket def get_free_ports(n): """Based on https://gist.github.com/dbrgn/3979133""" ports = [] sockets = [] for i in range(n): s = socket.socket() s.bind(('', 0)) port = s.getsockname()[1] ports.append(port) sockets.append(s) for s in sockets: ...
eff425d1c1c10267271bbf821de7294c58d03765
34,471
import random def rand_trial(tgt_num,min_itv,max_itv): """ Generate a list of number, which would be used to make sure that there are some filler sentence(s) between any 2 target sentences. Parameters ---------- tgt_num: Int The number of target sentences min_itv: In...
8d16b943804556c80d84a9050ce89cc2e4cf82dc
34,474
def qual_class_name(cls): """ Returns the fully qualifieid class name (module + class name). """ return cls.__module__ + "." + cls.__name__
ff433a30616851fdb0951fba4295230f9fa01907
34,478
def WDM_suppression(m, m_c, a_wdm, b_wdm, c_wdm): """ Suppression function from Lovell et al. 2020 :return: the factor that multiplies the CDM halo mass function to give the WDM halo mass function dN/dm (WDM) = dN/dm (CDM) * WDM_suppression where WDM suppression is (1 + (a_wdm * m_c / m)^b_wdm)^c...
e9ad362bc63be58a465d0e11a0bfb45ad3f1bc2d
34,483
def remove_chars(value,char_list=''): """ Remove specific chars from a string :param value: Value to be formatted :type value: String :param char_list: String containing the characters you want to remove :type char_list: String :returns: String without punctuation symbols :rtype: St...
2090ad14efff19974af8aa7bd68cdee11536e056
34,485
def rule(index): """Convert decimal index to binary rule list.""" return [int(x) for x in list(format(index, '08b'))]
33b167503e9caac338d747240dcc07b0d40bc057
34,487
def get_sections_url(request): """ A fixture that returns URL for two different section endpoints: - /v1/hearing/<hearing id>/sections/ - /v1/section/?hearing=<hearing id> """ return { 'nested': lambda hearing: '/v1/hearing/%s/sections/' % hearing.id, 'root': lambda hearing: '/v1...
1ecae93851fe50f26e6f6bb0fc0ae6f386ddb626
34,490
import torch def charbonnier_loss(pred: torch.Tensor, target: torch.Tensor, q: float = 0.2, eps: float = 0.01) -> torch.Tensor: """Generalized Charbonnier loss function between output and ground truth. The loss function is .. math:: los...
481de25b3d379f0c5f6c6f79f353166bc1bc1194
34,500
from typing import Optional def format_op_params(params: Optional[list]) -> str: """format operation params nicely for display""" if params is not None: return "(" + ", ".join(map(str, params)) + ")" if len(params) > 0 else "" return ""
4620011e1f12ac0b0165e591eaf50ed539142cdf
34,504
import json def build_address_map(tilegrid_file): """ Loads the tilegrid and generates a map (baseaddr, offset) -> tile name(s). Parameters ---------- tilegrid_file: The tilegrid.json file/ Returns ------- A dict with lists of tile names. """ address_map = {} ...
c5debba6159f847267b228cefdbe3ae88015c887
34,506
def get_word(word_type): """Get a word from a user and return that word.""" # The lower() function converts the string to lowercase before testing it if word_type.lower() == 'adjective': # Use 'an' in front of 'adjective' a_or_an = 'an' else: # Otherwise, use 'a' in front of 'no...
44447b8478e857956b5a328c514d632a8ba90bb3
34,509
import io import array def part1(stdin: io.TextIOWrapper, stderr: io.TextIOWrapper) -> int: """Find two numbers that sum to 2020, then multiply them.""" numbers = array.array('i') iterations = 0 for line in stdin: iterations += 1 number = int(line.strip()) pair = 2020 - numbe...
cd0b88df8d6dbb7cd6aefff70a4fe68a43ee4c8c
34,515
from string import printable def unprintable(mystring): """return only the unprintable characters of a string""" return ''.join( character for character in mystring if character not in printable )
bb48580d525d1e829f5b4b33cd4c0e540aa3a21a
34,516
def can_review(user): """Checks if a user can review a translate""" return user.permissions['perm_review']
ab0dcb8cb0372c1421e6b9171e01e2be7113e3f1
34,519
def select_frames(frames, frames_per_video): """ Select a certain number of frames determined by the number (frames_per_video) :param frames: list of frames :param frames_per_video: number of frames to select :return: selection of frames """ step = len(frames)//frames_per_video if step =...
d00ca8381e919cb38858d236186c4ebbd2b8a064
34,520
def doc_freqs(docs) -> dict: """ Takes in a list of spacy Doc objects and return a dictionary of frequencies for each token over all the documents. E.g. {"Aarhus": 20, "the": 2301, ...} """ res_dict = {} for doc in docs: # create empty list to check whether token appears multiple times ...
2bdeaf2150b4c2ecb8f240984d6d5f7eb210c585
34,524
def get_pubkey(elem) -> str: """Returns the primary key element from a tag""" return elem.get('key')
2f11661dee73d858dbd8c37b5045442c192f8799
34,525
def round_tat(num): """Changes the turnaround time from a float into natural language hours + minutes.""" remain = num%1 if num.is_integer(): if int(num) == 1: return str(int(num)) + " hour." else: return str(int(num)) + " hours." else: if num < 1: return str(int(remain*60)) + " minutes." elif num-...
cccf14355b7fc090df855a45b88e9b8562449f9a
34,530
def score_pop( population_value, min_population_acceptable=10, max_population_acceptable=30 ): """ :param population_value: population value to be scored :param min_population_acceptable: minimum population value in the scoring range (saturates at 0) :param max_population_acceptable: maximum populat...
074837e892cea618705139513ea03889aa76fac3
34,532
def _first_upper(k): """Returns string k, with the first letter being upper-case""" return k[0].upper() + k[1:]
f28bfa9f6457c4c0b3d75704e44486f31f247831
34,535
def has_samples(args): """Returns whether there's some kind of sample option in the command """ return args.sample or args.samples or args.sample_tag
47728a442d90538e72f47b72882ba22dd102d61a
34,537
def graph_order(graph): """Get graph order.""" graph = graph.get_vertices() order = len(graph.keys()) return order
1ea6fea10bdd80033a67fac1e5326f6a80239c58
34,538
import json def make_json(data_dict, simple=None): """Make well formatted JSON for insertion into cascade word docs. JSON will be enclosed by '$ like: '${"key":"value"}$' JSON will be on one line (simple) if it contains only one key/value pair, or if the argument simple==true """ if simp...
c7b8400995ed105f88de4bb6c3e22c5b17aedd4a
34,546
import collections def get_sorted_transitive_dependencies(top, deps_func): """Gets the list of all transitive dependencies in sorted order. There should be no cycles in the dependency graph (crashes if cycles exist). Args: top: A list of the top level nodes deps_func: A function that takes a...
7e758410c785e7f1b6df0dbd2a3571a402b95641
34,547
def r1_p_r2(R1, R2): """ Calculate the Resistance of a parallel connection """ return R1 * R2 / (R1 + R2)
3c98e8a24020e76b008d151a2611fa85856b8417
34,549
def enum2str(enumType, enum): """ Translates a pokerth_pb2 enum type to a string. :param enumType: enum type class :param enum: the enum element of the type :return: identifier string of enum """ return [k for k, v in enumType.items() if v == enum][0]
46de0fcd78f2e8b450ede050679f9e776b5a0bf9
34,550
def get_data_from_context(context): """Get the django paginator data object from the given *context*. The context is a dict-like object. If the context key ``endless`` is not found, a *PaginationError* is raised. """ try: return context['endless'] except KeyError: raise Exception...
304fd11f75ec72f703e03e7a8431c613a3648f47
34,555
def window_width(g_core: float, t_in: float, t_out: float, g: float, t_r: float, g_r: float) -> float: """ is the calculated winding width if there x g_core - is the distance between the core and the inner winding in [mm] x t_in - is the thickness of the inner winding in [mm] x t_out - is the t...
fd86eeb816c75b8e7d940d5321259c62abc0ec50
34,556
def build_key_name(app_name, os_name, file_name): """ Creates key using app name, os and filename :param app_name: app name :param os_name: OS the app is written for :param filename: the name of the file :return: S3 bucket key for given app/os/filename combination """ return (app_name....
845e6c2734ec105c6a9bbcd5032bc7569063c297
34,558
import re def name_in_string(string: str, name: str) -> bool: """Checks if string contains name. Args: string (str): input searchable string name (str): input name Examples: >>> assert name_in_string("Across the rivers", "chris") >>> assert not name_in_string("Next to a l...
168abc4ebfd078a2d9220bcea3c0efd2e0e79091
34,559
from typing import Dict from typing import List from typing import Set from typing import Tuple def _validate_reply( reply: Dict[str, List[str]], performatives_set: Set[str] ) -> Tuple[bool, str]: """ Evaluate whether the reply structure in a protocol specification is valid. :param reply: Reply struc...
2243e60edd6497a7f699676be5fe765711db4134
34,563