content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def sort_quick(data): """ๅฟซ้€ŸๆŽ’ๅบใ€‚ ้€‰ๆ‹ฉ็ฌฌไธ€ไธชๅ…ƒ็ด ไธบไธปๅ…ƒ `pivot`๏ผŒๅ…ถไฝ™ๅ…ƒ็ด ่‹ฅๅฐไบŽ `pivot`๏ผŒๅˆ™ๆ”พๅ…ฅ `left_list`๏ผŒๅฆๅˆ™ๆ”พๅ…ฅ `right_list`ใ€‚้€’ๅฝ’ๅœฐๅฏนๅญๅˆ—่กจ่ฐƒ็”จ `sort_quick`๏ผŒ็›ด่‡ณๆŽ’ๅบๅฎŒๆˆใ€‚ """ if len(data) <= 1: return data pivot = data[0] left_list = [] right_list = [] for i in data[1:]: # `data` ไธญ่‡ณๅฐ‘ๆœ‰ 2 ไธชๅ…ƒ็ด  if i < pivot...
edf1aabddc992aa04e0db6631011a498f7aa65be
697,082
import cProfile import io import pstats def profile(func): """ Decorator to profile functions with cProfile Args: func: python function Returns: profile report References: https://osf.io/upav8/ """ def inner(*args, **kwargs): pr = cProfile.Profile() ...
081c544261bded127bb59743a6ba9da38997a4eb
697,083
def model_to_vector(model, emb_layer_name='input_emb'): """ get the wordvec weight :param model: :param emb_layer_name: :return: """ sd = model.state_dict() return sd[emb_layer_name + '.weight'].cpu().numpy().tolist()
65f1a70022a9d1077fe959f8dbfd7504d66be6c6
697,084
import torch def finalize(s0, s1, s2): """Concatenate scattering of different orders. Parameters ---------- s0 : tensor Tensor which contains the zeroth order scattering coefficents. s1 : tensor Tensor which contains the first order scattering coefficents. s2 : tensor ...
f9c1bd7f9072b7e34c5e90ca1c245a98b9d7bf8c
697,085
def quarter_for_month(month): """return quarter for month""" if month not in range(1, 13): raise ValueError('invalid month') return {1: 1, 2: 1, 3: 1, 4: 2, 5: 2, 6: 2, 7: 3, 8: 3, 9: 3, 10: 4, 11: 4, 12: 4}[month] # return (month + 2) // 3
559bb2d194753efa3c2ee18aee3040dba05a4f85
697,086
import os import csv def load_samples(dataset_name, output_dir): """ Returns {sample_id: [feature,]} for the named dataset. """ samples_dir = os.path.join(output_dir, 'samples') assert os.path.exists(samples_dir) file_path = os.path.join(samples_dir, dataset_name +'.tsv') assert os.path.exists(file_path) ...
1bb74346897b06d2a5a7b4c180e8a627f0834541
697,087
def is_equal(x, y, tolerance=0.000001): """ Checks if 2 float values are equal withing a given tolerance :param x: float, first float value to compare :param y: float, second float value to compare :param tolerance: float, comparison tolerance :return: bool """ return abs(x - y) < toler...
2773cb526d00149e735853310986b581e1eec1e8
697,088
import copy def get_key_from_mission_info(info, key, default, inst=None, mode=None): """Get the name of a header key or table column from the mission database. Many entries in the mission database have default values that can be altered for specific instruments or observing modes. Here, if there is a ...
02dc51526bf0843f2c24d1c51d41791cd722de88
697,089
from typing import List def _create_cmd_header(commands: List[str]): """ Generate a command header. Note: here we always allow to generate HTML as long as we have it between CLICK-WEB comments. This way the JS frontend can insert it in the correct place in the DOM. """ def generat...
54ed275c83a711dcfaaed9cda504afc5b8defdca
697,090
def get_list(): """ """ coffee_shops = { 'header': [ { 'key': 'name', 'name': 'Name' }, { 'key': 'star', 'name': 'Star' }, { 'key': 'sf-location', 'name': 'SF Location' } ], 'rows': [ { 'name': 'Ritual Coffee Ro...
48be88339107e7e871da44c80c431c22a6ffe246
697,091
def use_model_attr(attr): """Use the validator set on a separate attribute on the class.""" def use_model_validator(instance, attribute, value): getattr(instance, attr)(instance, attribute, value) return use_model_validator
7947c13bf413a0d5dbdced110dccb4c1765ecea6
697,092
def _find_seam_what(paths, end_x): """ Parameters ========== paths: 2-D numpy.array(int64) Output of cumulative_energy_map. Each element of the matrix is the offset of the index to the previous pixel in the seam end_x: int The x-coordinate of the end of the seam Returns ...
dcff07b965f17ffc2fb5b5607fc88338301ca076
697,093
def read_scalar(group, dataset_name): """ Read a HDF5 `SCALAR` as a dict. All attributes will be assigned as key: value pairs, and the scalar value will be assigned the key name 'value'. :param group: A h5py `Group` or `File` object from which to write the dataset to. :param da...
6d9908e64f6584d0128756778679f87ffc8cb46f
697,094
def ma(error, params, offset): """ Calculate the moving average part. :param error: list of error terms :param params: list of coefficients :param offset: index of last predicted value :return: float """ return sum([params[i] * error[offset - i] for i in range(len(params))])
5ac853fca6a57dd4f349e79445b75b29f62ccbd7
697,095
import os def get_local_path(fname: str) -> str: """Returns relative path for the local file Args: fname (str): path of the file. Generally __file__ is passed which contains path form where function is directly or indirectly invoked Returns: str: relative path """ return ...
04787b8bb972971ab8aa3647d7c72d16d0e3467a
697,096
import torch def my_sample_gumbel(shape, eps=1e-20): """Samples arbitrary-shaped standard gumbel variables. Args: shape: list of integers eps: float, for numerical stability Returns: A sample of standard Gumbel random variables """ #Sample from Gumbel(0, 1) U = torch.rand(shape).float() return -torch.log(ep...
21e471bf5fca80316d93ec2a96230471ddc83a45
697,097
def _get_package_dict1(reqs: str) -> dict: """Helper to parse requirements str into a dict of (package, version) k, v pairs """ return dict(line.split("==") for line in reqs.strip().splitlines())
8b851a871a2e2ef9d9c984831393bf30b29d7a02
697,098
def lowercase(lista): """Function to lowercase list of texts Args: lista ([list]): list of texts Returns: [list]: List of texts lowercased """ return [text.lower() for text in lista]
2be877aa3b80c5e01eb4237625b426123d5b9976
697,099
import re def get_text_between_parenthesis(string): """ Return a list with all the found substrings between parenthesis. If the strings doesn't contains parenthesis the function return an empty list :param string: a string :return: a list """ try: text_list = re.findall('\(([\d\w\...
cce6abdb5618474848d9cff0f0ace1fab01f5b84
697,101
def get_elevated_session_input(response): """Create input for get_elevated_session.""" return { 'aws_access_key_id': response['Credentials']['AccessKeyId'], 'aws_secret_access_key': response['Credentials']['SecretAccessKey'], 'aws_session_token': response['Credentials']['SessionToken'] }
cede7d9a695953b8b0f57c6b58e5c69bf84d7887
697,102
def reverse_array(arr): """ Reverse an array along all axes, so arr[i,j] -> arr[-(i+1),-(j+1)]. """ reverse_slice = [slice(None, None, -1) for ii in arr.shape] return arr[reverse_slice]
659e4aea2f62287aeef6d3d4d80b3c58f937ace2
697,104
from functools import reduce def split_camel_case(text) -> list: """Splits words from CamelCase text.""" return list(reduce( lambda a, b: (a + [b] if b.isupper() else a[:-1] + [a[-1] + b]), text, [] ))
5a6f2fcfcdb378295554cc38a88679e054341068
697,105
def init_ground_station(): """initialize the configurations for the ground station author: zack step 1: figure out all the commands we need to do (on paper) step 2: after write_to_ground_station is complete then write out code""" return 0
d8b4e776c00f8714aaeccb5cded71c3103ace719
697,106
def pageurl_template(category, pagenum, date): """ Function to return formatted URL given category, page number, date """ assert len(str(date)) == 8, 'Invalid input date format' return f"https://news.daum.net/breakingnews/{category}?page={pagenum}&regDate={date}"
e6a7c9c86c16cd775919588b918c6d49b8d3a5bd
697,107
def parse_transaction_weights(config_root): """ Parse the transaction types and weights from the XML configuration. Parameters ---------- config_root : xml.Element The root of the XML config file. Returns ------- transaction_weights : [dict] An array of dictionaries for...
085a963d95d7e14fcaf688317374f33373dc6c0d
697,109
def unmangle(cls, name): """Given a name mangled using cls unmangles it. Undefined output (probably an empty string or an error) if it is not a mangled name or wasn't mangled using cls. """ return name[3+len(cls.__name__):]
2c29eb31d56043e2174b45f07161dcf9885c7007
697,110
def cumsum(vals): """Return a cumalative sum of vals (as a list).""" lst = [] tot = 0 for v in vals: tot += v lst.append(tot) return lst
e9ea4065fa7a044ae738e33dbd855cd1948e8c45
697,111
def subtract_and_increment(a, b): """" Return a minus b, plus 1 """ c = a - b + 1 return c
8307b0c5a58571bcaa34909aca90194781ebaddc
697,112
import os def walk_files(path): """ Returns all files within a directory recursively - If path is a file, returns a singleton list containing only path """ if not os.path.isdir(path): return [path] paths = [] for dirpath, _, files in os.walk(path): for f in files: ...
e76f49a05a5e60d14893a5d377e939e4e7067fdb
697,113
import requests def send_wechat(title, content): """Send Message.""" payload = { "summary": title, "content": content, "appToken": "AT_xx", "contentType": 1, "topicIds": [1411], "url": "https://live.bilibili.com/34027" } url = 'http://wxpusher.zjiecode....
c783d4ecaea84bcf7fb9b1cfc275550d4012ccc2
697,114
def count_measurements(report_uuid: str, database) -> int: """Return the number of measurements.""" return database.measurements.count_documents(filter={"report_uuid": report_uuid})
c9f20149ec975134ad7f0abab28a2c632f5295a1
697,115
import os import glob import logging def check_required_files(dir_to_validate): """Check if required files exists.""" REQUIRED_FILES = ["01-*.md", "discussion.md", "index.md", "instructors.md", "LICENSE.md", ...
ec1345cb749f0b7c89881a357b4a016d277cbdf1
697,116
def normalize_letters(one_letter_code) : """Convert RAF one-letter amino acid codes into IUPAC standard codes. Letters are uppercased, and "." ("Unknown") is converted to "X". """ if one_letter_code == '.' : return 'X' else : return one_letter_code.upper()
ad1d80a4663859194f84a31dc03001481b477503
697,117
def is_original_process_func(clsdict, bases, base_class=None): """Only wrap the original `process` function. Without these (minimal) checks, the `process` function would be wrapped at least twice (the original `process` function from the user's DoFn, and our wrapped/decorated one), essentially causing ...
17598fa632fc4dc9c8e52613325e6448b3064559
697,119
def int32(buffer, byte): """Retorna o valor inteiro de 4 bytes da posiรงรฃo byte, contido em buffer""" # return int(buffer[(byte-1):(byte-1)+4].encode('hex'), 16) return int(buffer[(byte - 1):(byte - 1) + 4].hex(), 16)
5d038fc68990297f691f1ed744d4e086d6742f3e
697,121
def parse_identifiers(identifiers): """ Reads identifiers, which may be a string or list/tuple/set of objects instances with name instances as string, returning a frozen set of names. """ if isinstance(identifiers, str): return frozenset(identifiers.split(',')) if not isinstance(identifiers, (list, tuple...
285a12352607ecc6b4a0c9ceb6f0ca7e2f56988e
697,122
def dhash_hamming_distance(dhash1, dhash2): """ Calculate the hamming distance between two dhash values :param dhash1: str, the dhash of an image returned by `calculate_dhash` :param dhash2: str, the dhash of an image returned by `calculate_dhash` :return: int, the hamming distance between two dhash...
14c5f44750e008edea59cef9d1950cb24d959630
697,123
def has_metadata(trait, metadata, value=None, recursive=True): """ Checks if a given trait has a metadata (and optionally if it is set to particular value) """ count = 0 if ( hasattr(trait, "_metadata") and metadata in list(trait._metadata.keys()) and (trait._metadata[metadat...
9318bd6705ceb6ed5f2c9401d77bdf3dc74103dd
697,124
def csc_cumsum_i(p, c, n): """ p [0..n] = cumulative sum of c [0..n-1], and then copy p [0..n-1] into c @param p: size n+1, cumulative sum of c @param c: size n, overwritten with p [0..n-1] on output @param n: length of c @return: sum (c), null on error """ nz = 0 nz2 = 0.0 for...
ab567b6b357fc7e5e1b0a961b9b66d88487a0e7f
697,125
def boolean_flag(name, configurable, set_help='', unset_help=''): """Helper for building basic --trait, --no-trait flags. Parameters ---------- name : str The name of the flag. configurable : str The 'Class.trait' string of the trait to be set/unset with the flag set_help : uni...
dabb654a75123a79b865c1570e6ed74568c5ae41
697,127
import pathlib import argparse def _parse_args(): """Define and parse the command line arguments. Args: None Return: argparse.Namespace Command line arguments specified by the user. """ BASE_PATH = pathlib.Path(__file__).parent.absolute().parents[0] CONFIG_PATH = pathlib.Path....
3accb68e0cb23cba18801a99ccf8f5a8afd090cf
697,128
from typing import Callable def recursive_map(func: Callable, obj: object) -> object: """ Map `func` recursively, which affects all items in lists and all values in dictionaries. """ if isinstance(obj, dict): return {k: recursive_map(func, v) for (k, v) in obj.items()} if isinstance(ob...
a7638f68ec7c1d4f57418fba03d4ae251cb5e9f0
697,129
def get_all_users(conn): """Get all users from table""" cursor = conn.cursor() cursor.execute('SELECT * FROM users') data = cursor.fetchall() return data
aedbca17a40912f37843b8ef48a6abbe7db9b980
697,130
def PassN(s,substring,iFrom,iN): """Find index after passing substring N times. """ while iN>0: iIndex= s.find(substring,iFrom) if iIndex==-1: return -1 else: iFrom=iIndex+1 iN-=1 return iFrom
1c98cb95ae95ffcb510dd38b1a6b7300f10448e7
697,131
def LevenshteinCost(a, b): """Cost function for Levenshtein distance with substitutions. Cost function for what is now thought of as the classical Levenshtein distance, which is the minimum number of insertions, deletions, and substitutions required to edit one sequence into another. Returns zero for matche...
8d82b0003d1fa00720270c33cfd4a119dd5f00c7
697,132
def str_to_dict(headers): """ ๅฐ†"Host: mp.weixin.qq.com"ๆ ผๅผ็š„ๅญ—็ฌฆไธฒ่ฝฌๆขๆˆๅญ—ๅ…ธ็ฑปๅž‹ ่ฝฌๆขๆˆๅญ—ๅ…ธ็ฑปๅž‹ :param headers: str :return: dict """ headers = headers.split("\n") d_headers = dict() for h in headers: h = h.strip() if h: k, v = h.split(":", 1) d_headers[k] = v.st...
62d4b3f5a2fbeb42428bdc138a3db0b87d1873b9
697,134
def array2SpecMca(data): """Write a python array into a Spec array. Return the string containing the Spec array """ tmpstr = "@A " length = len(data) for idx in range(0, length, 16): if idx + 15 < length: for i in range(0, 16): tmpstr += "%.8g " % data[idx + i...
fa4934ab38fab9f6f07369877956214041c34f2c
697,135
import requests def get_repo_version(): """ Get the current version on GitHub """ url = 'https://raw.githubusercontent.com/aquatix/ns-notifications/master/VERSION' try: response = requests.get(url) if response.status_code != 404: return response.text.replace('\n', '') ...
523e8b79f4621406f42810a03237094fd334c412
697,137
def floor_division(dividend: int, divisor: int): """Describes and gives an example of how floor division and the "//" symbols are used in Python. Examples: >>> floor_division(15, 6)\n Floor division returns the nearest whole number as the quotient, rounding down when there is a remainder.\n ...
962bb32f4f6ad28819a8178e9e70824ae91fd514
697,138
def pedersenOpen(n,g,h,m,r,c): """Open a pedersen commit. Arguments: n modulus (i.e. Z*_n) g generator 1 h generator 2 m message r random c commit generated by pedersenCommit() to verify""" if c == g**m*h**r % n: return True else: r...
4657cd68214566f4e2e8231b61067963478af9a1
697,139
def extend_indices(segments, margin): """ Decrease and increase the values of the first and last elements respectively in each list of segments by a given margin. The first indice of the first segment and the last indice of the last segments are not modified. Parameters ---------- segme...
34da9377af9342a811fb40bdadcadce174fcb605
697,140
def _set_delta_rbound(d, size): """Truncate the given delta to the given size :param size: size relative to our target offset, may not be 0, must be smaller or equal to our size :return: d""" d.ts = size # NOTE: data is truncated automatically when applying the delta # MUST NOT DO THIS HERE return d
d756bcbcb0cadcee02989a2ab417e35dc9d851c7
697,141
import os def _get_filepath(in_dir, basename): """Find correct name of file (extend basename with timestamp).""" all_files = [ f for f in os.listdir(in_dir) if os.path.isfile(os.path.join(in_dir, f)) ] for filename in all_files: if filename.endswith(basename): retur...
8ee2800a2686fb08d1b99cd236b6d7829b804f81
697,142
def z_norm(result): """ here we get mean,standard deviation and returns the same """ result_mean = result.mean() #.mean() is a predifined func which finds the mean result_std = result.std() # .std() is a predefined func which finds the standard deviation result -= result_mean # result = result- res...
6117bd15f9b5f7d0634366e36c0c8e2ef90d7cdd
697,143
import multiprocessing import hashlib import subprocess import os def system_parallel(cmdL, nproc=None, verbose=True): """ Run a list of commands (each a string) via the shell using GNU parallel with nproc processes, return all outputs in a single str instance. """ if nproc is None: nproc = mu...
d456cadf20bc6f9435a516649282770fa6ff630e
697,144
def greet(name, /, greeting="Hello"): """ the slash '/' is placed between 'name' and 'greeting' to signify that 'name' is a positional-only argument while 'greeting' is a regular argument that can be passed either by position or keyword """ return f"{greeting}, {name}"
4fd1ff5620a245535f3c701f1ce452780804faaa
697,145
def get_longest_soft_clipped_bases(read): """Function that takes as input the cigar string and returns a dictionary containing the longest soft-clipped part of the read, the quality values and the read mapping quality""" read_cigar = read.cigar #get index of the soft-clipped in the cigar match_...
9aa6a10006dd8271232776f0c7de1046a62e4e3a
697,146
import os def file_checksum(file_path, hash_callable): """Given path of the file and hash function, calculates file digest""" if os.path.isfile(file_path) and callable(hash_callable): hash_obj = hash_callable() with open(file_path, "rb") as f: for chunk in iter(lambda: f.read(4096)...
dda5abb734aebdb67ac895c60eb7317d75991e66
697,147
from datetime import datetime def datetime_to_ms(dt: datetime) -> int: """Convert a datetime to milliseconds.""" epoch = datetime.fromtimestamp(0, dt.tzinfo) return int((dt - epoch).total_seconds() * 1000.0)
c14128887dfa7201d68b055c2af5be56f5f8ab37
697,148
def get_length(key_list): """ Get length in the TLV :param key_list: Key to parse :return: Length in the TLV """ # Find tag value if 2 == int(key_list[0], 16): # pylint: disable=misplaced-comparison-constant # check MSB is zero, if yes then this byte indicates length # else ...
70b2b2069b9cd55f49da5711cfcd816e371affb8
697,149
from typing import List from typing import Tuple from typing import Optional from typing import Match import re def parse(mod_path: str) -> List[Tuple[str, str]]: """ Given a module name (file path, relative to ., eg src/acko/utils.rs), this function returns: List (arg, type) """ with op...
0c85bdd780c6abc43cf2c9c1c1b4cb3ad4a8bccc
697,150
def get_skidl_spice_ref(skidle_element): """ Helper function to retrieve SKiDL element name as appears in the final netlist Args: skidle_element (skidl.Part.Part): SKiDl part to get the netlist name from Returns: returns a string with the netlist name of `skidle_element`, or th...
4eacd423cbcdbc5171eb1f4b5ef81d6482f34843
697,151
def admit_util_getplain(formula): """ Method to make a chemical formula more readable for embedding in filenames Examples: CH3COOHv=0 -> CH3COOH g-CH3CH2OH -> CH3CH2OH (CH3)2COv=0 -> (CH3)2CO cis-CH2OHCHOv= -> CH2OHCHO g'Ga-(CH2OH)2 -> (CH2OH)2 ...
1f5f704da7fda9f4266a169f01c3790203087809
697,152
import subprocess def conn_status(): """Checks, parses and returns status of VPN connection as True or False""" result = subprocess.check_output(["expressvpn", "status"]) if b"Connected" in result: print("ExpressVPN connection was checked and is live.") if b"A new version" in result: ...
76e7c96fa825436a643e081ae56db51d593f2fab
697,153
def weighted_values(values, weights): """Returns paired lists of results and their GCM weights. Args: values: Dictionary of GCM -> result value weights: Dictionary of GCM -> GCM weight """ models = values.keys() values_list = [values[model] for model in models if model in weights] w...
6bd59e99d19d68535148f5bdf34bcec2f0cb4736
697,154
from typing import Tuple def set_add(arr: Tuple[str, ...]) -> int: """ >>> set_add(('UK', 'China', 'USA', 'France', 'New Zealand', 'UK', 'France')) 5 """ return len(set(arr))
e47705878c34400e3763a887cba4568dd5d621e4
697,155
def rank_index(square): """Gets the rank index of the square where ``0`` is the first rank.""" return square >> 3
d4d3f896b5a7cd8b7184320efd69a652c61ccbcf
697,156
def html_summary_table(data): """Generate HTML table of novelty detection statistics. data: dict A JSON like structure of the table data that has the following format: data = { 'modelA': { 'inlier_name': 'MNIST' 'outliers': { 'Fashion MNIST': { ...
53162dfab20859b03408ff67c3a2421b0e84e33e
697,157
def hello ( name ): """ Say hello .""" return " hello " + name
3fd85b4c2f719e6c2abb7cd21bd7df2fe38c0272
697,158
def getSize(l): """ Returns size of list Example >>> getSize([0,4,32,21]) 4 """ c=0 for i in l: c=c+1 return c
ab59a55778ed4b8034debea20d33c1cb609a4243
697,159
import os def is_executable(filename, mode=os.F_OK | os.X_OK): """ Check whether the given file is executable. :param filename: A relative or absolute pathname (a string). :returns: :data:`True` if the file is executable, :data:`False` otherwise. """ return os.path.exists(filena...
420de83f5d5126d4538f72524ab7a60848f35790
697,160
def _miriam_identifiers(type_, namespace, identifier): """ Fix the MetaNetX identifiers into miriam equivalents. MetaNetX doesn't use correct miriam identifiers. This function maps the known namespace and entity identifiers used by MetaNetX to valid miriam identifiers. Parameters ---------...
19218dbe7e086dabf6527b26e770986462428ecb
697,161
import re import sys import os def parse_otool_output(output): """Search otool output for MKL dependencies. Return (mkl_dirs, mkl_libs).""" # like "@rpath/libmkl_intel.dylib (compatibility version 0.0.0, current version 0.0.0)" re1 = re.compile(r"\s*@rpath/(.+) \(.+\)") # like "/usr/lib/libSyste...
112a7aa1f5f222165a899e96061e013bd4cab6f7
697,163
from typing import List def add_to_rightmost_int(stack: List, x: int) -> List: """ Add x to rightmost int in l if no int in l, do nothing return modified l """ int_locations = [isinstance(i, int) for i in stack] if not any(int_locations): return stack int_locations.reverse() ...
84240d412539cc221edd24462f97bb84a1eca051
697,164
def mapToRange(val, src, dst): """ Map the given value from the range of src to the range of dst. """ return ((val - src[0]) / (src[1] - src[0])) * (dst[1] - dst[0]) + dst[0]
769dd6f6c52b0c8cdc2b0358457820c0ed15a1f8
697,165
def is_true(boolstring: str): """ Converts an environment variables to a Python boolean. """ if boolstring.lower() in ('true', '1'): return True return False
466c839ff5ea25e970c9ce1a86fbcbc7d5fec3a1
697,166
def get_pr_filenames(fj): """ Parse filenames from file json :param fj: pull requests files JSON :type fj: JSON :returns: list of filenames from one pull request :rtype: list """ fns = [] for i in range(len(fj)): fns.append(fj[i]['filename']) return fns
23adfe04b83d1829851cacb63e841cba18022a75
697,167
def get_sm_from_descriptor(descr): """ This method returns a list of specific managers based on a received desriptor """ sm_dict = {} if "service_specific_managers" in descr: sm_dict = {} for ssm in descr["service_specific_managers"]: for option in ssm["options"]: ...
53d06e9f399689a715e812b849337e04555f95cf
697,168
import optparse def parse_shards_into(option, opt, value, parser): """Parse lists of shard or shard ranges into a set(). Examples: 0-2 0,1-3,5 1,3,5 """ def shard_range_parser(shards): result = set() for part in shards.split(','): x = part.split('-') result.update(...
1262db211fe698f3e38b5b61e8dce1bddd2dcb21
697,169
def add(x, y): """Compute the sum of x and y.""" return x+y-y+y-y+y-y+y-y+y-y+y-y+y-y+y-y+y-y+y-y+y-y+y-y+y-y+y-y+y-y+y-y+y
a107334c4b1d7da50302555f18c3a4488a2423c5
697,170
def edits2str(edits): """ get a printable representation for a list of edits """ output_str = [edit.__str__() for edit in edits] return output_str
599afcd8636e0939b72ebc88ebb88743fd4fe6a6
697,171
def summerB(n: int) -> int: """ Iterates over the multiples only. Uses a set to avoid repeats. """ total = 0 fizzvisits = set() for i in range(0, n, 3): total += i fizzvisits.add(i) for j in range(0, n, 5): if j not in fizzvisits: total += j return tot...
7b968a859fa42a0a72cc1a7352506f60c7e0f97a
697,172
import re def _get_enclosed_str(text, prefix, suffix): """ Remove prefix and suffix from the string if the string contains both prefix and suffix. """ success = False text = text.strip() pattern = f"^{prefix}.+{suffix}$" if re.search(pattern, text): pattern1 = f"^{prefix}" ...
4a4305d18308491f477ae929c4009af39f345472
697,173
import os def diff_path(top, subdir): """difference between two absolute paths""" top = os.path.normpath(top).replace('\\', '/').split('/') subdir = os.path.normpath(subdir).replace('\\', '/').split('/') if len(top) == len(subdir): return '' diff = subdir[len(top) - len(subdir):] return os.path.join(*diff)
ed5073d6759c04a46dd41e3bfb634b03a29755b1
697,174
import re import textwrap def process_description(description_fce): """Removes special character delimiters, titles and wraps paragraphs. """ def inner(description): clear_description = \ re.sub(r'\s+', ' ', # multiple whitespaces # general URLs re.sub(r'\w...
1a8f39704a025669c1b70ae279f7d9db8de84855
697,175
def demo_app_name(name): """ Returns a capitalized title for the app, with "Dash" in front.""" return 'Dash ' + name.replace('app_', '').replace('_', ' ').title()
58e39a80c1940f784daa6e0f6ee35df2757c5ca6
697,178
import logging def check_input(channel_name, vods_clips, start, end, tracker, download, rename, try_muted, workers, test): """checks if input is valid returns 0 or 1""" logger = logging.getLogger(__name__) if (len(channel_name) < 4 or (not (vods_clips == "clips" or vods_clips == "vods" or vods...
b833a8a3c67b6c1320323f083a963010c3d1b476
697,180
def parse_italic(soup): """ Replace i tags with text:span with automatic style """ italic_tags = soup.find_all("em") for i_tag in italic_tags: i_tag.name = 'text:span' i_tag.attrs['text:style-name'] = "ITALIC" return soup
c2c58afa0a68328088900e5324f4908d74ddbb94
697,181
import argparse def parse_args(): """Parse arguments for module. Returns: argparse.Namespace: contains accessible arguments passed in to module """ parser = argparse.ArgumentParser() parser.add_argument("--task", help=("task for neural network to train on; " ...
9fc925aa04a6ea376ad6993419629cc3f2a5f1ac
697,182
def csvheader(parent, nodelist): """ Gives the header for the CSV """ header = "" for subnode in nodelist: if (subnode.nodeType == subnode.ELEMENT_NODE): header = header + "," + parent + "." + subnode.tagName return header[1:] + "\n"
9a488d29c52e421f5a7e2e2f9929274422f41ffc
697,183
def calc_time_cost_function_total(natom, nkpt, kmax, niter, nspins=1): """Estimates the cost of simulating a all iteration of a system""" costs = natom**3 * kmax**3 * nkpt * nspins * niter return costs
bba431933e38c035f3e5285536beecbb677c7175
697,184
def to_dict(condset: set) -> dict: """ Create a dictionary of conditions with a unique integer value for each condition. :param condset: Conditions set. :return: Dictionary of all conditions with integer values. """ conds = {} index = 0 for item in condset: conds[str(item)] =...
3fd9953139ac3785aeb2ba527bc0365e3908f376
697,185
import struct async def probe(stream): # type: ignore """Probe for img dimensions.""" w, h = None, None chunk = await stream.readexactly(26) if chunk.startswith(b"\x89PNG\r\n\x1a\n"): if chunk[12:16] == b"IHDR": w, h = struct.unpack(">LL", chunk[16:24]) elif chunk[12:16] ...
f42dfbbbe766b1a655f1f6b299172d6568c66498
697,187
import os import glob def get_files(filepath: str) -> list: """ Load all *.json files found in filepath and its subdirectories. """ all_files = [] for root, dirs, files in os.walk(filepath): files = glob.glob(os.path.join(root,'*.json')) for f in files : all_files.appen...
197aa244ec55a343b28a7d9ae2b88fb5eed47bba
697,188
def GL2PL(gl): """ Converts Genotype likelyhoods to phred scaled (PL) genotype likelyhoods. """ return -int(gl * 10)
d842a4a25ee6b095cfb456ab21965df4ccc24c1d
697,189
import socket def port_to_int(port): """Convert a port string to an integer.""" try: return int(port) except ValueError: return socket.getservbyname(port)
9f4ca2d80fdb70e16aaa0f0ccfa027fed772a986
697,191
def expand_markings(granular_markings): """Expand granular markings list. If there is more than one selector per granular marking. It will be expanded using the same marking_ref. Example: >>> expand_markings([ ... { ... "selectors": [ ... "descri...
1d97c93b7953293cd71a86d06e988373f0a9150d
697,192
def first_nonequal_idx(left: str, right: str) -> int: """ Find first string index where left and right strings do not match In [1]: first_nonequal_idx("", "californian") Out[1]: 0 In [2]: first_nonequal_idx("aba", "abc") Out[2]: 2 Note, if the strings match, the first-non-...
7bc0397dd290c6005adc96b8b45f14e04385a257
697,194
def isHappy(self, n): """ :type n: int :rtype: bool """ mem = set() while n != 1: n = sum([int(i) ** 2 for i in str(n)]) if n in mem: return False else: mem.add(n) else: return True
cacc997c4e3241abc7e288bd1eb95890dfca6b99
697,195
def parse_coref_idx(string): """ return: ([starting], [ending], [singleton]) """ starting = [] ending = [] singleton = [] idxes = string.strip().split('|') for idx in idxes: if idx.startswith('(') and idx.endswith(')'): singleton.append(int(idx[1:-1])) elif idx.startswith('('): start...
f651a880ad28586569c78ad0f2aa702b91a0ffe4
697,196