content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def PeerDownHasBgpNotification(reason):
"""Determine whether or not a BMP Peer Down message as a BGP notification.
Args:
reason: the Peer Down reason code (from the draft)
Returns:
True if there will be a BGP Notification, False if not
"""
return reason == 1 or reason == 3 | 8ee214798f6766916e8784dd907eeb45ff6620db | 704,670 |
def set_purpose(slack_client, channel, purpose):
"""
Set the purpose of a given channel.
"""
response = slack_client.api_call("channels.setPurpose",
purpose=purpose, channel=channel)
return response | 786a495b55300b955e2f7ec525117be75b251a07 | 704,671 |
import os
def generate_aes_key(size=256):
"""
Generates aes key with specified size
:param size: aes bits, default 256
:return: generated key bytes
"""
return os.urandom(int(size / 8)) | 604b626ae0996499c2d855ede91f70ded8f585cc | 704,672 |
import json
def decode_stderr_json(stderr):
""" return a list of decoded json messages in stderr """
# - check for blank input
if not stderr:
# - nothing to do
return list()
# - split the input (based on newlines) into list of json strings
output = list()
for line in stderr.spl... | d527730d8d9a77a1ec434ee6203c4e08433306c9 | 704,673 |
def get_validate_result_form(tel_num, validate_code):
"""
Assemble form for get_validate_result
:param tel_num: Tel number
:param validate_code: Validate code from capcha image
:return: Param in dict
"""
post_data_dict = dict()
post_data_dict['source'] = 'wsyyt'
post_data_dict['telno... | 6340c97522a097c0cf96170e08466fb795e16dc3 | 704,674 |
import os
def getFileInfoFromXML(thisfile):
""" Get the PFN from the XML """
pfn = thisfile.getElementsByTagName("pfn")[0].getAttribute("name")
# lfn will not be present in XML any longer, get it from the PFN - possible problem with LFN file name extensions
# lfn = thisfile.getElementsByTagName("lfn"... | 788080388a4c7984f8646a944eefa04a7ce22536 | 704,675 |
def _serialize_noise_model(config):
"""Traverse the dictionary looking for noise_model keys and apply
a transformation so it can be serialized.
Args:
config (dict): The dictionary to traverse
Returns:
dict: The transformed dictionary
"""
for k, v in config.items(... | f3453e174d5ba858b9eec678e7bc1574f74d50eb | 704,676 |
import os
def sequential_name(folder, basename):
"""
Given a proposed name for a file (string 'basename') to be saved in a
folder (identified by its path in string 'folder'), produces a new
name to use that avoids overwriting other files - as long as their
names were made with this function, too.
"""
i... | 1a1afd78371da050ef6e44aa909d8c800f82ac21 | 704,677 |
def metric_max_over_ground_truths(metric_fn, predictions, ground_truths):
"""Take the average best score against all ground truth answers.
This is a bit different than SQuAD in that there are multiple answers
**and** predictions that we average over. For some situations (e.g., *top k*
beams or multiple human r... | 7c78fc1cca29bc9784a4e4687d794c1f2b6872c9 | 704,678 |
def attSummaryDict(request, reqs, flist):
""" Return a dictionary summarizing the field values for the chosen most interesting fields """
sumd = {}
for req in reqs:
for f in flist:
if f in req and req[f]:
if not f in sumd: sumd[f] = {}
if not req[f] i... | bafbbe51555cb46c664d33ea31a0e36c56152fa9 | 704,679 |
def ext_bottom_up_cut_rod(price, length):
""" bottom up implementation of cut rod memoized algorithm """
incomelst = [float("-Inf") for _ in range(length + 1)]
cutlst = [0 for _ in range(length + 1)]
# set zero income for zero length
incomelst[0] = 0
for j in range(1, length + 1):
income... | 7dd8c43afa9f71793d372b474963ff84d2ce607f | 704,680 |
def _build_config_dict(cfg_node):
"""
Updates the config dict provided from the given etcd node, which
should point at a config directory.
"""
config_dict = {}
for child in cfg_node.children:
key = child.key.rsplit("/").pop()
value = str(child.value)
config_dict[key] = va... | 567fca19a6e1890c881170200ba44fc262148948 | 704,681 |
import time
def stamp_to_ymd(timestamp):
"""
Caller sends a timestamp in seconds of epoch. Return string for
year month day of that time as YYYYMMDD' as used by url requests, as in
http://<fitsstore_server>/qaforgui/20130616
parameters: <float>, seconds of epochs.
return: <string>, YYYYM... | 2928e93a48f1a5c3abdddcb6285bed7b0cebb369 | 704,682 |
import os
def exists(b, d, n):
"""Check if the folder specified by the given parameters exists"""
return os.path.isdir("../Output/B" +
str(b) + " D" + str(d) + " N" + str(n)) | b94f8bfb38351127e77fa9f19b706906d9805e82 | 704,683 |
def not_contains(a, b):
"""Evaluates a does not contain b"""
result = False if b in a else True
return result | a0dc087049c8e93c1acdf0e59e3530a6ff8b54e5 | 704,684 |
def create_func_result_identifier(func, params_str, key=None, key_separator="__"):
"""
Creates a string of the following format:
If ``key`` is None:
``<FUNC_NAME><PARAMS_STR>``
If ``key`` is not None:
``<FUNC_NAME><PARAMS_STR>__key``
In both cases, ``<FUNC_NAME>`` represents the name of... | 6f3a7a6a8a94629dae7817403d78ef1f970ad5b2 | 704,685 |
import csv
def import_town(data_file):
"""
Reads town raster data from a CSV file.
Parameters
----------
data_file : str
Name of CSV raster data file to use for the town.
Returns
-------
town : list
List (cols) of lists (rows) representing raster data of the town.
... | b7749dfd4d698fddfe610c6a51c8ccc43c375cc2 | 704,686 |
def pe44(limit=1500):
"""
>>> pe44()
(5482660, 7042750, 1560090, 2166, 1019)
"""
pents = [i * (3 * i - 1) >> 1 for i in range(1, limit << 1)]
ps = set(pents)
for i in range(limit):
p1 = pents[i]
for j in range(i + 1, (limit << 1) - 1):
p2 = pents[j]
di... | e41f513c518b502de0c47f3a70390f9df01a1868 | 704,687 |
def sanitize_markdown(markdown_body):
"""
There are some symbols used in the markdown body, which when go through Markdown -> HTML
conversion, break. This does a global replace on markdown strings for these symbols.
"""
return markdown_body.replace(
# This is to solve the issue where <s> and... | adf21a9bbea1a95f0f4c0aca8d61ab6d69627074 | 704,688 |
def _build_jinja2_expr_tmp(jinja2_exprs):
"""Build a template to evaluate jinja2 expressions."""
exprs = []
tmpls = []
for var, expr in jinja2_exprs.items():
tmpl = f"{var}: >-\n {{{{ {var} }}}}"
if tmpl not in tmpls:
tmpls.append(tmpl)
if expr.strip() not in exprs:
... | 3e5d944345316a40b7b8052f9b13801228607099 | 704,689 |
def load_coco_name(path):
"""Load labels from coco.name
"""
coco = {}
with open(path, 'rt') as file:
for index, label in enumerate(file):
coco[index] = label.strip()
return coco | 2da456b7c2879ec5725172280dacbcaaacd86bfc | 704,690 |
import base64
import gzip
import json
def decompress_metadata_string_to_dict(input_string): # pylint: disable=invalid-name
"""
Convert compact string format (dumped, gzipped, base64 encoded) from
IonQ API metadata back into a dict relevant to building the results object
on a returned job.
Parame... | c521da786d2a9f617c560916cc5f058b20cb3e21 | 704,691 |
import struct
import socket
def inet_atoni(ip):
"""Like inet_aton() but returns an integer."""
return struct.unpack('>I', socket.inet_aton(ip))[0] | 3bd18b7aecf9a5a45033c7873163ee1387cb8a13 | 704,692 |
import re
def rep_unicode_in_code(code):
""" Replace unicode to str in the code
like '\u003D' to '='
:param code: type str
:return: type str
"""
pattern = re.compile('(\\\\u[0-9a-zA-Z]{4})')
m = pattern.findall(code)
for item in set(m):
code = code.replace(item, chr(int(item[2... | 70e28ea741f0347190628876b59e27a56a5c0ccf | 704,693 |
def f(spam, eggs):
"""
:type spam: list of string
:type eggs: (bool, int, unicode)
"""
return spam, eggs | 7d315898332b099eb1105f77b08bfe69e29c051e | 704,694 |
def print_person(first, last, middle=None):
"""Prints out person's names
This funciton prints out a person's name. It's not too useful
Args:
first (str): This person's first name
last (str): This person's last name
middle (str): Optional. This person's middle name
"""
middl... | 643ce351ec13a076c9fd36af39c97505084f1437 | 704,695 |
def _chomp_element(base, index, value):
"""Implementation of perl = and chomp on an array element"""
if value is None:
value = ''
base[index] = value.rstrip("\n")
return len(value) - len(base[index]) | 66cfde7c8d8f2c92f0eebb23f717bf50b676ca31 | 704,696 |
import time
def generate_nonce():
"""
Generates nonce for signature
Returns:
nonce (int) : timestamp epoch
"""
return int(time.time() + 100) | c439fc6598b4f5359d71bde8865afacb6162df19 | 704,697 |
import ast
def is_py3(file_path):
"""Check if code is Python3 compatible."""
# https://stackoverflow.com/a/40886697
code_data = open(file_path, "rb").read()
try:
ast.parse(code_data)
except SyntaxError:
return False
return True | 78a48bdcc682108ce4fbe6fffe4a235898beec1c | 704,699 |
import time
def getDate():
"""获得时间"""
return time.localtime() | 6f4f127b96ab6f754cc20e76219a54d039938320 | 704,700 |
def reverse(x):
"""
:type x: int
:rtype: int
"""
new_str = str(x)
i = 1
rev_str = new_str[::-1]
if rev_str[-1] == "-":
rev_str = rev_str.strip("-")
i = -1
if (int(rev_str)>=2**31):
return 0
return (int(rev_str)) * i | 5775fe83f500ac844fa9fc94a4d71fc3bb6f165b | 704,701 |
def part_1(input_data: list[int]) -> int:
"""Count the number of times a depth measurement increases from the previous measurement.
Args:
input_data (str): depths
Returns:
int: number of depth increases
"""
inc_count = 0
for i, depth in enumerate(input_data):
if i != 0 a... | 3ee506aca019f9393c93ced75e430d53b31a9fc2 | 704,702 |
def single_varint(data, index=0):
"""
The single_varint function processes a Varint and returns the
length of that Varint.
:param data: The data containing the Varint (maximum of 9
bytes in length as that is the maximum size of a Varint).
:param index: The current index within the data.
:ret... | 55b052300cc0cf5ac2fd8f7451ac121b408c1313 | 704,703 |
import glob
def tumor_list(version):
"""
version: cross validation version and train or val
"""
path_list = []
for i in version:
paths = sorted(glob.glob(f'./data/tumor_-150_150/{i}/label_*/*.npy'))
path_list.extend(paths)
return path_list | da390686072613177a4f3f5b483d980640090d1c | 704,704 |
from typing import Tuple
def _color_int_to_rgb(integer: int) -> Tuple[int, int, int]:
"""Convert an 24 bit integer into a RGB color tuple with the value range (0-255).
Parameters
----------
integer : int
The value that should be converted
Returns
-------
Tuple[int, int, int]:
... | df3eb5ad92d9383b0e6fe5c1603e0caec0df5c45 | 704,705 |
def label2binary(y, label):
"""
Map label val to +1 and the other labels to -1.
Paramters:
----------
y : `numpy.ndarray`
(nData,) The labels of two classes.
val : `int`
The label to map to +1.
Returns:
--------
y : `numpy.ndarray`
(nData,) Maps ... | 5bce8491e9eef3a8c36b784ee0e252c641b24fdf | 704,706 |
def in_suit3(list, list0):
"""
test 2 suits of street numbers if they have crossed numbers
For example: "22-27" in "21-24"retruns True
:param a: Int of number
:param b: String List of number
:return: boolean
"""
text = list.replace("-", "")
text0 = list0.replace("-", "")
if (... | 57409220b93c66ab4b957a05713e5e89b380253a | 704,707 |
def extract_power(eeg, D=3, dt=0.2, start=0):
""" extract power vaules for image
Parameters
----------
seizure : EEG | dict
eeg data
D : int, optional
epoch duration, by default 3
dt : float, optional
time step (seconds), by default 0.2
start : int, optional
... | 04c3fed38fa2a2d46ba7edee4bb3f04011d9d2a7 | 704,708 |
def build_training_response(mongodb_result, hug_timer, remaining_count):
"""
For reducing the duplicate lines in the 'get_single_training_movie' function.
"""
return {'movie_result': list(mongodb_result)[0],
'remaining': remaining_count,
'success': True,
'valid_key': True,
'took': float(hug_timer)} | 77d541957ff9abaa51bd3eb7fd06b550f41291e2 | 704,709 |
def calc_fm_perp_for_fm_loc(k_loc_i, fm_loc):
"""Calculate perpendicular component of fm to scattering vector."""
k_1, k_2, k_3 = k_loc_i[0], k_loc_i[1], k_loc_i[2]
mag_1, mag_2, mag_3 = fm_loc[0], fm_loc[1], fm_loc[2]
mag_p_1 = (k_3*mag_1 - k_1*mag_3)*k_3 - (k_1*mag_2 - k_2*mag_1)*k_2
mag_p_2 = (k_... | 00ba68c74d781748f39d2a577f227316dc523f0f | 704,710 |
import glob
import os
def find_output(directory, extension="out", abspath=True):
""" Find output file in a directory.
Parameters
----------
directory : str
Path to folder in which output should be located.
extension : str
File extension of output file (default: 'out').
abspath... | bb45e97990ea0a6ec98c9212ce9aa1b9effe3040 | 704,711 |
def trim_mismatches(gRNA):
"""
trim off 3' mismatches
1. first trim to prevent long alignments past end of normal expressed gRNAs
2. second trim to mismatches close to end of gRNA
"""
pairing = gRNA['pairing']
# 1. index of right-most mismatch before index -40
# if no MM is... | ab0bed78d29d64e9218201a561bb857fd80ed885 | 704,712 |
def WTERMSIG(status):
"""Return the signal which caused the process to exit."""
return 0 | d4f45d41de95308c4a16f374e58c16b4384f8fc0 | 704,713 |
import io
def create_toplevel_function_string(args_out, args_in, pm_or_pf):
"""
Create a string for a function of the form:
def hl_func(x_0, x_1, x_2, ...):
outputs = (...) = calc_func(...)
header = [...]
return DataFrame(data, columns=header)
Parameters
-... | 44d78a9d0a3146b4008868073e5828422b819cc8 | 704,714 |
def is_live_request(request):
"""
Helper to differentiate between live requests and scripts.
Requires :func:`~.request_is_live_tween_factory`.
"""
return request.environ.get("LIVE_REQUEST", False) | 1e5e64901715131f363d6d343acbd4d631cf6b6f | 704,715 |
from typing import OrderedDict
def pyvcf_calls_to_sample_info_list(calls):
"""
Given pyvcf.model._Call instances, return a dict mapping each sample
name to its per-sample info:
sample name -> field -> value
"""
return OrderedDict(
(call.sample, call.data._asdict()) for call in call... | 937a748b3a0ff26a28ff4a4db5e1505dbb927ff9 | 704,716 |
from typing import Optional
def injection_file_name(
science_case: str, num_injs_per_redshift_bin: int, task_id: Optional[int] = None
) -> str:
"""Returns the file name for the raw injection data without path.
Args:
science_case: Science case.
num_injs_per_redshift_bin: Number of injectio... | 57b034b6a60c317f0c071c1313d0d99f2802db30 | 704,717 |
def query_add(session, *objs):
"""Add `objs` to `session`."""
for obj in objs:
session.add(obj)
session.commit()
return objs | 95ffa9e0f5a4a9255f8b0b063c5bd092f0f66039 | 704,719 |
def sd_title(bs4_object, target=None):
"""
:param bs4_object: An object of class BeautifulSoup
:param target: Target HTML tag. Defaults to class:title-text, a dict.
:return: Returns paper title from Science Direct
"""
if target is None:
target = {"class": "title-text"}
return bs4_o... | 8429fe680fafb86c773a0cd2b3280e893b95fc9a | 704,720 |
def split_formula(formula, net_names_list):
"""
Splits the formula into two parts - the structured and unstructured part.
Parameters
----------
formula : string
The formula to be split, e.g. '~ 1 + bs(x1, df=9) + dm1(x2, df=9)'.
net_names_list : list of strings
A... | 1fce8617cbdaf767c1aebb6d0d685ca63975c820 | 704,721 |
from sys import intern
def joinHostmask(nick, ident, host):
"""nick, user, host => hostmask
Joins the nick, ident, host into a user hostmask."""
assert nick and ident and host
return intern('%s!%s@%s' % (nick, ident, host)) | e039f6afe37638a24f07a924bd537e6f6b6eb415 | 704,722 |
from itertools import combinations
from typing import List
from functools import reduce
from operator import mul
def max_triple_product_bare_bones(nums: List[int]) -> int:
"""
A bare-bones O(n3) method to determine the largest product of three numbers in a list
:param nums: the list of numbers
:retur... | 8053bc6e35120f6ee8eca2b24e81cbaa7713dfb3 | 704,723 |
import requests
def analyze_comments_page(username, repo, per_page, page, print_comments, print_stage_results):
"""
Analyzes one page of GitHub comments. Helping function.
Parameters
----------
username : str
The GitHub alias of the repository owner
repo : str
The GitHub repo... | e3d153a0319db0bc723df65cb8a92533f9b37b82 | 704,725 |
def get_remotes(y, x):
"""
For a given pair of ``y`` (tech) and ``x`` (location), return
``(y_remote, x_remote)``, a tuple giving the corresponding indices
of the remote location a transmission technology is connected to.
Example: for ``(y, x) = ('hvdc:region_2', 'region_1')``,
returns ``('hvdc... | 3c479d818947362349982c77a9bbd87a97a3d4d5 | 704,726 |
from typing import List
def ingrid(x: float, y: float, subgrid: List[int]) -> bool:
"""Check if position (x, y) is in a subgrid"""
i0, i1, j0, j1 = subgrid
return (i0 <= x) & (x <= i1 - 1) & (j0 <= y) & (y <= j1 - 1) | d296d8a7abe5eeb3da8d57691755a2bd19dd15b6 | 704,727 |
from typing import Union
from pathlib import Path
from typing import Any
import json
def load_jsonl(path: Union[Path, str]) -> list[dict[str, Any]]:
""" Load from jsonl.
Args:
path: path to the jsonl file
"""
path = Path(path)
return [json.loads(line) for line in path.read_text().splitlines()] | a59d2920bfa491b1d4daa693b5e2e1b4846d6fc6 | 704,728 |
import subprocess
import re
def git_version():
""" Get the full and python standardized version from Git tags (if possible) """
try:
# Full version includes the Git commit hash
full_version = subprocess.check_output('git describe --dirty', shell=True).decode("utf-8").strip(" \n")
# Py... | 12f90dc2dc6cd620acff215aa2b0ad20079a2484 | 704,729 |
def wrap(get_io_helper_func):
"""A decorator that takes one argument. The argument should be an instance
of the helper class returned by new_helper(). This decorator wraps a method
so that is may perform asynchronous IO using the helper instance. The
method being wrapped should take a keyword argumen... | f2cdd8009d1722a81d848ab05c3cb6f3acaf5e50 | 704,730 |
def internal_superset_url():
"""The URL under which the Superset instance can be reached by from mara (usually circumventing SSOs etc.)"""
return 'http://localhost:8088' | 8a66c1d2c0587e9e6a563d08506606d389c2e6be | 704,731 |
import tempfile
def temp():
"""
Create a temporary file
Returns
-------
str
Path of temporary file
"""
handle, name = tempfile.mkstemp()
return name | 5955f3ceabd30ba5bb487677d9382253e1fde50a | 704,732 |
def ignoreNamePath(path):
"""
For shutil.copytree func
:param path:
:return:
"""
path += ['.idea', '.git', '.pyc']
def ignoref(directory, contents):
ig = [f for f in contents if
(any([f.endswith(elem) for elem in path]))]
return ig
return ignoref | 9d51d53c8dae8fb2322c3f90ea0f451731395816 | 704,733 |
def row2string(row, sep=', '):
"""Converts a one-dimensional numpy.ndarray, list or tuple to string
Args:
row: one-dimensional list, tuple, numpy.ndarray or similar
sep: string separator between elements
Returns:
string representation of a row
"""
return sep.join("{0}".form... | f81a2ec54b8c37285715cadca4458918962440b9 | 704,734 |
def build_aggregation(facet_name, facet_options, min_doc_count=0):
"""Specify an elasticsearch aggregation from schema facet configuration.
"""
exclude = []
if facet_name == 'type':
field = 'embedded.@type'
exclude = ['Item']
elif facet_name.startswith('audit'):
field = facet... | b8c3f337143a229401b9a41a8fde8903027cf67e | 704,735 |
def spawn(pool):
"""spawn a greenlet
it will be automatically killed after the test run
"""
return pool.spawn | fadea4b814e77f7fb26af27f0cc7bce1189a7dcf | 704,736 |
def inline(text):
"""
Convert all newline characters to HTML entities:
This can be used to prevent Hypertag from indenting lines of `text` when rendering parent nodes,
and to safely insert `text` inside <pre>, <textarea>, or similar elements.
"""
return text.replace('\n', ' ') | 658f7e5adbf5747ea069fad8a9599e9bd499a381 | 704,737 |
def get_bq_col_type(col_type):
"""
Return correct SQL column type representation.
:param col_type: The type of column as defined in json schema files.
:return: A SQL column type compatible with BigQuery
"""
lower_col_type = col_type.lower()
if lower_col_type == 'integer':
return 'I... | 86cac08a04d804cc6addbeee86014f1aa6d35735 | 704,738 |
def col(loc, strg):
"""
Returns current column within a string, counting newlines as line separators.
The first column is number 1.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See
:class:`ParserElement.parseString` for more
... | 0dfc4387e391c4823939350ad19c60d106211a58 | 704,739 |
import unicodedata
def remove_accents(string):
"""
Removes unicode accents from a string, downgrading to the base character
"""
nfkd = unicodedata.normalize('NFKD', string)
return u"".join([c for c in nfkd if not unicodedata.combining(c)]) | 41c8e05aa8982c85cf5cf2135276cdb5e26fefec | 704,740 |
def parse_range(rng, dictvars={}):
"""Parse a string with an integer range and return a list of numbers, replacing special variables in dictvars."""
parts = rng.split('-')
if len(parts) not in [1, 2]:
raise ValueError("Bad range: '%s'" % (rng,))
parts = [int(i) if i not in dictvars else dictva... | 214109a71c84d06241e29cacaa052d9ce00302c5 | 704,741 |
def is_odd(num: int) -> bool:
"""Is num odd?
:param num: number to check.
:type num: int
:returns: True if num is odd.
:rtype: bool
:raises: ``TypeError`` if num is not an int.
"""
if not isinstance(num, int):
raise TypeError("{} is not an int".format(num))
return num % 2 ==... | 0e5781596a99909e58583859948332c3afb06fb0 | 704,742 |
import runpy
import imp
def mod_from_file(mod_name, path):
"""Runs the Python code at path, returns a new module with the resulting globals"""
attrs = runpy.run_path(path, run_name=mod_name)
mod = imp.new_module(mod_name)
mod.__dict__.update(attrs)
return mod | 3ea8109d912582555b76816f55fbb632ba82f189 | 704,743 |
def interpolation(x0: float, y0: float, x1: float, y1: float, x: float) -> float:
"""
Performs interpolation.
Parameters
----------
x0 : float.
The coordinate of the first point on the x axis.
y0 : float.
The coordinate of the first point on the y axis.
x1 : float.
T... | f8fc96c6dc6c2eeeeceb22f92b32023f3873fe3e | 704,744 |
import collections
def product_counter_v3(products):
"""Get count of products in descending order."""
return collections.Counter(products) | 22c57d50dc36d3235e6b8b642a4add95c9266687 | 704,745 |
def rossler(x, y, z, a, b, c):
""" Rössler System of Ordinary Differential Equations """
dx = - y - z
dy = x + a*y
dz = b + z*(x - c)
return dx, dy, dz | bcf27c7ff8223681d6dc7d0c49497e975b826d80 | 704,747 |
import re
def get_extension(filename):
"""
Extract file extension from filename using regex.
Args:
filename (str): name of file
Returns:
str: the file extension
"""
match = re.search(r"\.(?P<ext>[^.]+)$", filename)
if match:
return match.group("ext")
raise Val... | 8f5195b339a153d5fa144182505dba986992d4df | 704,748 |
def scale_val(val, factor, direction):
"""Scale val by factor either 'up' or 'down'."""
if direction == 'up':
return val+(val*factor)
if direction == 'down':
return val-(val*factor)
raise ValueError('direction must be "up" or "down"') | 16c2efe16fc787fe4461fb0ae640e2cf22d556e0 | 704,749 |
def addattrs(field, css):
"""
在模板的form的field中,特别是input中添加各种attr
"""
attrs = {}
definition = css.split(',')
for d in definition:
if '=' not in d:
attrs['class'] = d
else:
t, v = d.split('=')
attrs[t] = v
return field.as_widget(attrs=attrs) | cdbb2b4b44b6e7facbe2af44d503c3118eb31ef7 | 704,750 |
def adjust_update_rules_for_fixed_nodes(predecessor_node_lists, truth_tables, fixed_nodes):
"""
Adjust "update rules" matrix and its free element vector so that the fixed nodes will end up in their fixed
states on each time step automatically, with no manual interventions required.
:param predecessor_n... | f41609ae25c3622100674372de5a364b095650f8 | 704,751 |
def parse_list_from_string(value):
"""
Handle array fields by converting them to a list.
Example:
1,2,3 -> ['1','2','3']
"""
return [x.strip() for x in value.split(",")] | 51e9c654b9d18b8be61c37aab5f5029dfdea2213 | 704,753 |
import itertools
def merge(d1, d2):
"""Merge to dicts into one.
Args:
d1 (dict): dataset 1
d2 (dict): dataset 2
Returns:
dict: merged dict
"""
return dict(itertools.chain(list(d1.items()), list(d2.items()))) | bb1d38f3cb45de6e98855fb04ae1d3d7e73e4a40 | 704,755 |
import re
def is_valid(number):
"""
Check if number is roman
:param number: string to check
:type number: str
:return: True or False
:rtype: bool
"""
return re.match(
r"^(M{0,3})(D?C{0,3}|C[DM])(L?X{0,3}|X[LC])(V?I{0,3}|I[VX])$", number
) | 52e1937418d28701ee3d30da139f16ae64cfe480 | 704,756 |
def has_open_quotes(s):
"""Return whether a string has open quotes.
This simply counts whether the number of quote characters of either type in
the string is odd.
Returns
-------
If there is an open quote, the quote character is returned. Else, return
False.
"""
# We check " first... | a9adbcd42518a71458c69c9aa1ff751fa3998573 | 704,758 |
def _qt(add_row, secondary_dict_ptr, cols, key):
"""
This sub-function is called by view_utils.qt to add keys to the secondary_dict and
is NOT meant to be called directly.
"""
if cols[key]:
if cols[key] in secondary_dict_ptr:
return add_row, secondary_dict_ptr[cols[key]]
... | ce1cec842822077cbfbd908ff92b1552626cd5f2 | 704,759 |
def row_contains_data(fieldnames, row):
"""Returns True if the value of atleast on of the fields is truthy"""
for field in fieldnames:
if row.get(field):
return True
return False | 7575d1280186c582a652ab37deb4a93e667b51b2 | 704,761 |
import torch
def spherical_schwarzchild_metric(x,M=1):
""" Computes the schwarzchild metric in cartesian like coordinates"""
bs,d = x.shape
t,r,theta,phi = x.T
rs = 2*M
a = (1-rs/r)
gdiag = torch.stack([-a,1/a,r**2,r**2*theta.sin()**2],dim=-1)
g = torch.diag_embed(gdiag)
print(g.shape)... | 4e65d520a88f4b9212bab43c7ebc4dfc30245bd3 | 704,763 |
def get_picard_mrkdup(config):
"""
input: sample config file output from BALSAMIC
output: mrkdup or rmdup strings
"""
picard_str = "mrkdup"
if "picard_rmdup" in config["QC"]:
if config["QC"]["picard_rmdup"] == True:
picard_str = "rmdup"
return picard_str | 87e24c0bf43f9ac854a1588b80731ed445b6dfa5 | 704,764 |
import random
def ChoiceColor():
""" 模板中随机选择bootstrap内置颜色 """
color = ["default", "primary", "success", "info", "warning", "danger"]
return random.choice(color) | 15779e8039c6b389301edef3e6d954dbe2283d54 | 704,765 |
import hashlib
def __get_str_md5(string):
"""
一个字符串的MD5值
返回一个字符串的MD5值
"""
m0 = hashlib.md5()
m0.update(string.encode('utf-8'))
result = m0.hexdigest()
return result | 1d55cd42dc16a4bf674907c9fb352f3b2a100d6c | 704,766 |
def dc_coordinates():
"""Return coordinates for a DC-wide map"""
dc_longitude = -77.016243706276569
dc_latitude = 38.894858329321485
dc_zoom_level = 10.3
return dc_longitude, dc_latitude, dc_zoom_level | c07812ad0a486f549c63b81787a9d312d3276c32 | 704,767 |
import argparse
def get_arguments():
"""
Obtains command-line arguments.
:rtype: argparse.Namespace
"""
parser = argparse.ArgumentParser()
parser.add_argument(
'--clusters',
type=argparse.FileType('rU'),
required=True,
metavar='CLUSTERS',
help='read c... | 32ce1446d8ac04208a4387bcd2ac31a2609580a3 | 704,768 |
from typing import Callable
from typing import Iterable
from typing import List
def lmap(f: Callable, x: Iterable) -> List:
"""list(map(f, x))"""
return list(map(f, x)) | 51b09a3491769aafba653d4198fde94ee733d68f | 704,769 |
def multiply_something(num1, num2):
"""this function will multiply num1 and num2
>>> multiply_something(2, 6)
12
>>> multiply_something(-2, 6)
-12
"""
return(num1 * num2) | 1a726c04df146ab1fa7bfb13ff3b353400f2c4a8 | 704,771 |
def estimate_infectious_rate_constant_vec(event_times,
follower,
t_start,
t_end,
kernel_integral,
count_events... | 207833e1b32885fe39a209bfef227665c8c59ad1 | 704,772 |
def find(word,letter):
"""
find letter in word , return first occurence
"""
index=0
while index < len(word):
if word[index]==letter:
#print word,' ',word[index],' ',letter,' ',index,' waht'
return index
index = index + 1
return -1 | bdeb0f0993fb4f7904b4e9f5244ea9d7817fa15f | 704,773 |
import re
def file_read(lines):
""" Function for the file reading process
Strips file to get ONLY the text; No timestamps or sentence indexes added so returned string is only the
caption text.
"""
# new_text = ""
text_list = []
for line in lines:
if re.search('^[0-9]', line) is No... | 7d37bb79c6b1cdd43d7b813e03bf3d8b18f5a6ed | 704,774 |
def has_file_ext(view, ext):
"""Returns ``True`` if view has file extension ``ext``.
``ext`` may be specified with or without leading ``.``.
"""
if not view.file_name() or not ext.strip().replace('.', ''):
return False
if not ext.startswith('.'):
ext = '.' + ext
return view.fil... | 043edf03874d1ec20e08fcb5795fd205206f7194 | 704,775 |
def get_genes(exp_file, samples, threshold, max_only):
"""
Reads in and parses the .bed expression file.
File format expected to be:
Whose format is tab seperated columns with header line:
CHR START STOP GENE <sample 1> <sample 2> ... <sample n>
Args:
exp_file (str): Name... | 62b27eef9c863078c98dee0d09bada5e058909e2 | 704,776 |
def conv_name_to_c(name):
"""Convert a device-tree name to a C identifier
This uses multiple replace() calls instead of re.sub() since it is faster
(400ms for 1m calls versus 1000ms for the 're' version).
Args:
name: Name to convert
Return:
String containing the C version of this... | 150af670d8befea7374bbb5b13da9d6e0734863e | 704,777 |
def get_account_id(role_arn):
"""
Returns the account ID for a given role ARN.
"""
# The format of an IAM role ARN is
#
# arn:partition:service:region:account:resource
#
# Where:
#
# - 'arn' is a literal string
# - 'service' is always 'iam' for IAM resources
# - 'regi... | 623eb66eefd59b9416deb478c527062ae4454df7 | 704,778 |
from typing import Any
def list_to_dict(data: list, value: Any = {}) -> dict:
"""Convert list to a dictionary.
Parameters
----------
data: list
Data type to convert
value: typing.Any
Default value for the dict keys
Returns
-------
dictionary : dict
Dictionary ... | 1e73bb6ca98b5e2d9b1e0f8d4cb19fc044a9ce63 | 704,780 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.