content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
from typing import Union
from typing import Any
from typing import List
from typing import Tuple
def get_sched_value(value_schedule: Union[Any, List[Tuple[Any, int]]], epoch_number: int) -> Any:
"""Get a value that can be scheduled to change based on the epoch number.
value_schedule is either a scalar value o... | 679d19921fa2e7f748c1403f0b00e57216b99212 | 223,130 |
def get_file_type(filename):
"""
Return the extension (if any) of the ``filename`` in lower case.
"""
return filename[filename.rfind('.')+1:].lower() | cb0487e0886d60a6d0e5f97fa7d2313293390f5d | 694,245 |
def notas(*num, sit=False):
"""==> Função para analisr notas e situações de vários alunos.
:param num: uma ou mais notas dos alunos (aceita várias)
:param sit: valor opcional, indicando se deve ou não adcionar a situação
:return: dicionário com várias informações sobre a situação da turma"""
print('... | 25f166f7b56b6a92a3585c53f953d26da23aec7a | 324,556 |
def _do_step(x, y, z, tau, kappa, d_x, d_y, d_z, d_tau, d_kappa, alpha):
"""
An implementation of [1] Equation 8.9
References
----------
.. [1] Andersen, Erling D., and Knud D. Andersen. "The MOSEK interior point
optimizer for linear programming: an implementation of the
homog... | 0c38e2f18f7c934d910c024c23d35e13660eec08 | 688,500 |
def loan_iof(
principal,
amortizations,
return_days,
daily_iof_aliquot,
complementary_iof_aliquot
):
"""The total IOF of a loan.
If :math:`s` is the principal, :math:`A_i` is the :math:`i`-th
amortization, :math:`n_1,\\ldots,n_k` are the return days, :math:`I^*` is
the daily IOF ali... | 22a8ac058ad97bc18064b42947b11d7d6db7949e | 309,205 |
def normalize(X):
"""
Normalize vector or matrix columns X
"""
return X / X.sum(axis=0) | 62703e2ef32af7658fbb632f2d6fad8a3a41aef4 | 502,597 |
def instant_name_to_class_name(name):
"""
This will convert from 'parent_name.child_name' to
'ParentName_ChildName'
:param name: str of the name to convert
:return: str of the converted name
"""
name2 = ''.join([e.title() for e in name.split('_')])
return '_'.join([e[0].upper() +... | 380acd68925ce24846bc30737d7d066609ae3525 | 635,507 |
import logging
def get_logger(name):
"""
Internally calls the logging.getLogger function with the 'name' argument to create or
retrieve a logger object. It is recommended to pass __name__ as argument when calling
get_logger. The returned logger object logs to the standard error stream and formats
... | 462b84f940e3c0804811f3096e3cfdccc6745b4b | 544,219 |
def euclidean(N: int, a: int) -> int:
"""
Uses the Euclidean Algorithm to calculate the GCD of `N` and `a`.
"""
remainder = N % a
if remainder == 0:
return a
return euclidean(a, remainder) | 9ea543061277978ff844150ccf7810c1031c728e | 149,181 |
import struct
def parse_quantization(read_buffer, sqcd):
"""Tease out the quantization values.
Parameters
----------
read_buffer: sequence of bytes from the QCC and QCD segments.
Returns
------
tuple
Mantissa and exponents from quantization buffer.
"""
numbytes = len... | 0a4287c7ac218427da541cbaf860670c2c5aba48 | 506,551 |
from typing import List
def parse_input_file(file_path: str) -> List[List[int]]:
"""Parse a file with the following format:
21 22 24
12
7 21 23
Returns each line as integers in a nested list
"""
with open(file_path) as input_file:
parsed_file = [list(map(int, line.split())) for li... | f281dbcc7c9dc70eab491b1a334e0cb0cc3e45e4 | 697,049 |
import math
def get_distance(x1, x2, y1, y2):
"""
Function to get the distance between any two points
"""
return math.sqrt((x1-x2) ** 2 + (y1-y2) ** 2) | 2dd65e26089c90dd3b7d83566af83463c943b8cc | 145,903 |
import uuid
import hashlib
def _create_token(user):
"""Create a unique token for a user.
The token is created from the user id and a unique id generated
from UUIDv4. Then both are hashed using MD5 digest algorithm.
"""
_id = f"{user.id}-{str(uuid.uuid4())}"
_hash = hashlib.md5(_id.encode('as... | ea2458c45043ed9c0902b0a88d20c9c13ede00d0 | 659,292 |
import base64
import json
def _read_pubsub_json(event):
"""Extracts the json payload from a pub/sub message.
Args:
event: A Pub/Sub event.
Returns:
The json_payload from a pub/sub message.
"""
pubsub_message = base64.b64decode(event['data']).decode('utf-8')
return json.loads(pubsub_mess... | 9bfafe8f36e6bcd0db68f9d4528081c44067b04f | 692,962 |
import re
def check_string(text, search=re.compile(r'[^A-Za-z0-9-_]').search):
"""Test that a string doesnt contain unwanted characters.
:param text: Text that you want to verify is compliant.
:type text: str
:param search: Regex to use to check the string. Defaults to allowing
[^a-z0-9-_].
... | 59348de4e86bc762cc8a7aef2243e1d2b2ce9f85 | 42,511 |
from datetime import datetime
def get_es_index_name(project, meta):
"""
Get the name for the output ES index
:param project: seqr project identifier
:param meta: index metadata
:return: index name
"""
return '{project}__structural_variants__{sample_type}__grch{genome_version}__{datestamp}... | fc1245287aed07ddd8d90f33cadc095c22f944a3 | 7,256 |
def isfused(cycle_sets):
"""Determine whether all cycles (represented as sets of node IDs) share at least one node."""
intersection = cycle_sets[0]
for cycle in cycle_sets[1:]:
intersection = intersection.intersection(cycle)
return len(intersection) > 0 | 1011e472f22cde7bfd186be64bbe688092519ce2 | 199,062 |
def split_obj_identifier(obj_identifier):
"""
Break down the identifier representing the instance.
Converts 'notes.note.23' into ('notes.note', 23).
"""
bits = obj_identifier.split('.')
if len(bits) < 2:
return (None, None)
pk = '.'.join(bits[2:])
# In case Django ever handles... | 60d3a9f478ddff9d5e44c7955ca01e14d78a706f | 319,681 |
def link_regulator(incoming_links: list) -> list:
"""
Regulates the links coming from Google Search.
Input URL: "/url?q=https://www.example.com/SparqlEndpoint&sa=U&ved=2ahUKEwiU"
Output URL: "https://www.example.com/SparqlEndpoint"
:param incoming_links: List of links to be regulated
:return:... | 9c7c451c65da2f3f0240c26903cdfe2a9ced1913 | 656,169 |
def error_500(error):
"""Return a custom 500 error."""
return 'Sorry, internal server error.' | f45c15482d3c768ed9672a39ad14adac24d2ebfd | 653,050 |
import hashlib
def validateFile(data, hash):
"""
Validates a file using the MD5 algorithm.
Returns True if the files MD5 hash signature matches
the provided hexadecimal string, False otherwise.
"""
h = hashlib.md5()
h.update(data)
return h.hexdigest().lower() == hash.lower() | 992170e8cc731f21d65834a332983b5759c3a636 | 510,385 |
def serialize_article_to_values(article):
"""Serialize an article to a list of values.
Args:
article: The article to be serialized.
Returns:
list of primitives that can be used with a DB API v2 compliant connection.
"""
author = article.get_author()
author_str = author if author... | aefb17035fa798103cd148318651f3e57de02ec7 | 179,939 |
def _unpack_player(sid, p, **_): # pylint: disable=invalid-name
"""Unpack a player"""
return sid, p | c0c0e37bafbd14488c6cf7ca58ecc8ac5f330a45 | 79,943 |
def _get_directive(line_info):
"""Gets a directive from the start of the line.
If the line is ":param str foo: Description of foo", then
_get_directive(line_info) returns "param str foo".
Args:
line_info: Information about the current line.
Returns:
The contents of a directive, or None if the line d... | 569683434a796957b222bd9c8f55e1d3c7798aa0 | 335,641 |
def parity(n):
"""
parity(n) determines the value (-)^n
input
n: integer
output
p: sign
"""
if n%2==0:
p=1
else:
p=-1
return p | 5688fdb28efed43af30bb8b056885dfaf6b32652 | 332,513 |
def get_match(match, index, default=''):
"""
Returns a value from match list for a given index. In the list is out of
bounds `default` is returned.
"""
if index >= len(match):
return default
else:
return match[index] | 8669380d3d5e3379d7169754c284498872f46570 | 597,586 |
import requests
from bs4 import BeautifulSoup
def get_sra_ids(gsm_ids):
"""
Get SRA IDs
Args:
gsm_ids: the GSM IDs
Returns:
the list of SRA IDs
"""
url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=sra&term={}".format(" or ".join(gsm_ids))
r = requests.g... | c3d40c97b301660998dc365ca7651e69e07ea63e | 513,462 |
import random
def position_mod_normal(in_str):
"""Select any position in the given input string with normally distributed
likelihood where the average of the normal distribution is set to one
character behind the middle of the string, and the standard deviation is
set to 1/4 of the string length.
... | 6ed75d80ccb4c4328639549133748126c7e3eec4 | 76,853 |
def wrapPos(angDeg):
"""Returns the angle (in degrees) wrapped into the range [0, 360)"""
res = angDeg % 360.0
# First wrap into [0, 360]; result is 360 if ctrAng < 0 but so near 0 that adding 360 rounds it
if res == 360.0:
return 0.0
return res | c87d73d9155cc6b65ff64f92f635162d9c25c913 | 83,062 |
def get_table(client,start,end,table_id,date_part = None):
"""Getting table data from bigquery client.
Args:
client (bigquery.Client) : Configured client to access bigquery
start (str) : time str in the format of yy-mm:dd [HH-MM-SS.FFFFFF]
end (str) : time str in the format of yy-mm:dd ... | 5ba84bb622d8bd818abb6fd325885c08cf585a5f | 167,677 |
def transform_op_if_inside_handler(info, op, keep_if_possible=True):
"""Transform an optional op only if it is inside the subgraph.
This handler is typically use to handle original op: it is fine to keep them
if they are inside the subgraph, otherwise they are just ignored.
Args:
info: Transform._TmpInfo ... | b7566d5c2e5a8e1fd0bfa073e50270d4ea8f8e28 | 189,140 |
def palindrome(word: str) -> bool:
"""
Check if a string is palindrome
:param word: the word to analyze
:return: True if the statement is verified, False otherwise
"""
i=0
while i < int((len(word)+1)/2):
if word[i] != word[-(i+1)]: return False
i+=1
return True | 98da35f89c6c245c66aa5b0c2d65305b9090b1da | 585,424 |
from typing import Set
def file_to_set(file_name: str) -> Set[str]:
"""
Loads a file to a set.
:returns: the lines of the file in a ``set``, an empty ``set`` if
_file_name_ is ``None``.
"""
if file_name:
with open(file_name, 'rt') as inf:
set_from_file = set(line... | 8ff2852992516726dd009249c9db6eda6896e566 | 147,945 |
def clear_url(url):
""" Remove domain and protocol from url """
if url.startswith('http'):
return '/' + url.split('/', 3)[-1]
return url | 769f0d321cb085218e02d483f44fbf06c300aac1 | 278,855 |
def limbs_for_int(v):
"""
Return the number of bytes required to represent this integer.
"""
return (v.bit_length() + 7) >> 3 | 3ef1d3e4863065a1afaa0911934c5dc562dada06 | 297,270 |
def validate_maximum_distance(vrp, **kwargs):
"""
Validates the maximum travel distance of given individual's solution.
:param vrp: An individual subject to validation.
:param kwargs: Keyword arguments. The following are expected
from it:
- (int) 'maximum_distance': Maximum travel distance for ... | ee5e7c44b0d095835e5ab350bff32e10ac1abb88 | 556,159 |
import pathlib
def _detect_home_location() -> pathlib.Path:
"""Detects the location of the root directory"""
# path/to/home/backend/core/config_loader.py
path_to_self = pathlib.Path(__file__).absolute()
# path/to/home/backend/core/
path_to_core_module = path_to_self.parent
# path/to/home/ba... | c309656d5a56261fd96c86c179947981dc65dc58 | 10,763 |
import csv
def load_original_file(filename, delimiter, skipline):
"""
File loader
:param filename: str: path
:param delimiter: str: delimiter used, passed to csv.reader
:param skipline: bool: does the frst line contains column names (true) or data (then false)
:return: data, firstline
"""
... | 88d985cd86607e4d0b485862246dd64133499c3e | 571,907 |
def IntToTime( time_int ):
"""
Function used to convert an integer into a time-string.
Args:
time_int ( int ): the integer.
Returns:
string: the converted time-string.
Testing:
>>> IntToTime( 20220314092000 )
'2022.03.14 09:20:00'
>>> IntToTime( 202... | d77c58b45976d55fa3e193536e211bdb6d3a240b | 279,220 |
def ArchToBits(arch):
"""Takes an arch string like x64 and ia32 and returns its bitwidth."""
if not arch: # Default to x64.
return 64
elif arch == 'x64':
return 64
elif arch == 'ia32':
return 32
assert False, 'Unsupported architecture' | a87b38eca83aa968d9ab235e064f16855a346ad2 | 461,853 |
from pathlib import Path
def script_loc(request):
"""Return the directory of the currently running test script"""
return Path(request.fspath).parent | 23ebda0ad4dbdd94808b4b3da54eb86b634849e7 | 260,225 |
import random
def backoff_time(attempt, retry_backoff=2., max_delay=30.):
"""Compute randomized exponential backoff time.
Args:
attempt (int): attempt number, starting at zero.
Keyword Args:
retry_backoff(float): backoff time on the first attempt.
max_delay(float): maximum returned value.
"""
... | 907e636dc60a81fa9d7d0ebf5c42841b828a693c | 32,275 |
import re
def create_auxiliary_table_name(field_name, table_name):
"""
Args:
field_name: A table field whose value identifies a record in a foreign
table.
table_name: The table containing the field field_name.
Returns:
A conventional name for the foreign table. Some whitesp... | cd744f1fde76d23252e37bb85a51f5c4709c7dea | 369,206 |
def XlaLaunchOpCount(labels):
"""Count how many XlaLaunch labels are present."""
return sum("XlaLaunch(" in x for x in labels) | e3b083de64bf1627ca98c427a268412cacf9f43b | 23,499 |
def format_date(date:str) -> str:
"""return YYYYmmdd as YYYY-mm-dd"""
return f"{date[:4]}-{date[4:6]}-{date[6:]}" | dfcc434006df8a7f6bd89003f592792faa891f30 | 20,911 |
from typing import Tuple
from typing import Dict
def parse_line_protocol_stat_key(key: str) -> Tuple[str, Dict[str, str]]:
"""Parseline protocolish key to stat prefix and key.
Examples:
SNMP_WORKER;hostname=abc.com,worker=snmp-mti
will become:
("SNMP_WORKER", {"hostname": "abc.com", "... | a6806f7dd67fb2a4734caca94bff3d974923f4b2 | 5,382 |
def getProducts(products_list):
"""Reads products from the SBML file and returns a dictionnary"""
final_products = {}
for prod in products_list:
products = prod.getElementsByTagName("speciesReference")
for p in products:
final_products[p.getAttribute("species")] = float(
... | 4a85f0fa6106cedb52094d749d43fe10304499cc | 490,958 |
import re
def extract_authorization_token(request):
"""
Get the access token using Authorization Request Header Field method.
Or try getting via GET.
See: http://tools.ietf.org/html/rfc6750#section-2.1
Return a string.
"""
auth_header = request.META.get('HTTP_AUTHORIZATION', '')
if r... | 9776df3ecd59ba3db15664259a6e65114ec61a07 | 700,716 |
def _binary_op(result_name, func_name, arg1_name, arg2_name):
"""
Generates a binary operator indicated by func_name in infix notation
with arguments arg1_name and arg2_name storing the result in result_name.
Supported func_names are add, sub, mul, and div.
"""
funcs = {'add': '+', 'sub': '-', '... | 5a8cb925aefa4850f182c87595fee9c1409809c6 | 64,380 |
def get_repository_id(repository_info, api_root, repository_name=None):
"""Return the ID of a repostiory from the server.
This will look up all accessible repositories on the server and try to
find the ID of one that matches the provided repository information.
Args:
repository_info (rbtools.c... | 02ce8504df5900c69f80747534413724e0b2baab | 395,791 |
def check_id(string):
""" Runs a basic check for things that look like ID numbers.
Currently, simply checks to see that numerals outnumber
other types of characters, and that the string is probably
long enough to contain an ID."""
string = string.strip()
if len(string) == 0 or len(string) < 4:
... | a5cad89ddc71a754fd5f3f2b8a17aa723eb5eca4 | 180,861 |
def get_t_demand_list(temp_curve, th_curve):
"""
Sorts thermal energy demand based on values of ambient temperatures.
Parameters
----------
temp_curve : list of ambient temperatures for one year
th_curve : list of thermal energy demand for one year
Returns
-------
t_demand_curve : ... | f4f01d609e593653c19faa6c82fd3db07db60510 | 464,760 |
def subdict_in_dict(subdict, superdict):
"""True is subdict in subdict_in_dict. Else False.
>>> subdict_in_dict({"k1": "v1"}, {"k1": "v1"})
True
>>> subdict_in_dict({"k1": "v1"}, {"k1": "v1", "k2": "v2"})
True
>>> subdict_in_dict({}, {"k1": "v1"})
True
>>> subdict_in_dict({"k1": "v1"}, ... | b2d802045002de15c9eec86028317527a6480304 | 244,378 |
def in_list(metric_name, check_list):
"""
Check if the metric is in list.
# @added 20170602 - Feature #2034: analyse_derivatives
# Feature #1978: worker - DO_NOT_SKIP_LIST
This is a part copy of the SKIP_LIST allows for a string match or a match on
dotted elements within the m... | 51d401585a292933c8652a93a42391ec001efcc5 | 400,129 |
import getpass
def get_pass(prompt, require=False):
"""Ask the user for a password.
Args:
prompt (unicode):
The text to prompt the user with.
require (bool, optional):
Whether to require a result. If ``True``, this will keep prompting
until a non-empty val... | 220f53a5b53a57b8046709a0c7b0da20bbad6418 | 396,179 |
import random
def random_horizontal_flip(image, bboxes):
"""
Randomly horizontal flip the image and correct the box
:param image: BGR image data shape is [height, width, channel]
:param bboxes: bounding box shape is [num, 4]
:return: result
"""
if random.random() < 0.5:
_, w, _ = i... | 2a865b32a9ed94fdee35b4b075313a5e9d733e90 | 687,605 |
def _sudoku_syntax(file):
"""
Return the full name of the given sudoku syntax based on the base name.
"""
return "Packages/Sudoku/resources/syntax/%s.sublime-syntax" % file | 4db4e557b416b578a9202980589ff8b0de1c5acb | 314,136 |
def parse_slate(slate):
"""Parses slate document
Args:
slate (dict): slate document
Returns:
dict
"""
wanted = ['_id', 'slateTypeName', 'siteSlateId', 'gameCount', 'start', 'end', 'sport']
return {k: slate[k] for k in wanted} | f0d422d3b934ae20c6a8ad758aa1e92f5bd85c23 | 195,109 |
def isColorImage(np_image):
"""
Check if image is colored (has 3 channels)
Return
True if image is colored, false otherwise
"""
if len(np_image.shape) == 3:
if np_image.shape[2] == 3:
return True
return False | 91d8749905727af1c02caa3a66484b31eb931a94 | 51,739 |
import re
def bundle_offset(fname):
"""
>>> bundle_offset("path/to/R0000C0000.bundle")
(0, 0)
>>> bundle_offset("path/to/R0380C1380.bundle")
(4992, 896)
"""
match = re.search(r'R([A-F0-9]{4,})C([A-F0-9]{4,}).bundle$', fname, re.IGNORECASE)
if match:
r = int(match.group(1), 16)
... | 9e0627e9085f47ec3dfff8241bff083d45849e3a | 468,349 |
def delete_at(my_list=[], idx=0):
"""
deletes an element from a list at a given index
"""
l_len = len(my_list)
if idx >= l_len or idx < 0:
return (my_list)
del my_list[idx]
return (my_list) | 63c1897eb87a2feed7c013c0b277bacd7d3f61d5 | 677,093 |
def _extract_exception_details(request, response, exception):
"""Extracts exception information from a request-response and an exception.
"""
# Set some standard values to fall back to if nothing comes of parsing the
# request and exception details.
code = 500 # Internal server error
title = 'U... | 018c4b86a3df7dd0d53a2b558e27efb577450126 | 592,271 |
def _extract_keys_to_unique_list(lists_of_dictionaries):
"""
Extract the keys for a list of dictionaries and merge them into a unique list.
:param lists_of_dictionaries: List of dictionaries to pull unique keys from.
:type lists_of_dictionaries: list(dict)
:return: Merged list of keys into a uniqu... | 9f94d46cec063a46fd4b506cc08e5cf20b3b98ac | 66,129 |
def strategy_func_longest(zmws):
"""
>>> strategy_func_longest([])
[]
>>> strategy_func_longest([('synthetic/1', 9)])
[('synthetic/1', 9)]
>>> strategy_func_longest([('synthetic/1', 9), ('synthetic/2', 21), ('synthetic/3', 9), ('synthetic/4', 15), ('synthetic/5', 20)])
[('synthetic/2', 21), ... | 5e83f5d396ccc81c9861a9bc4151d184d188ae83 | 145,194 |
def field(request):
"""
Fixture for returning the field. Needed because indirect=True is
used for loading the datasets.
"""
return request.param | 41320222310d51c0dec2fd3b03feda5a045fe3bb | 334,686 |
def sequential_search(value, array):
"""
Implementação de um algoritmo de busca sequencial.
Argumentos:
value: Any. Valor a ser buscado na lista
array: list. lista na qual o valor será buscado
Retorna o índice do valor em "array" ou -1 caso não exista nela.
"""
for i in range(0, len(ar... | 84b0fa89752d44d30fcb3f581617f6e65c3f5a0e | 183,961 |
def find_y_overlap(rect1, rect2):
"""
Return bottom_y and height of overlapping y of two rects
"""
r1bottom = rect1['bottom_y']
r1top = r1bottom + rect1['height']
r2bottom = rect2['bottom_y']
r2top = r2bottom + rect2['height']
highest_start_point = r1bottom if r1bottom >= r2bottom else r2bottom
lowest_end_poi... | f5e9b61371b4dfc100e443b42bd6a640dc9440fb | 143,221 |
def peak_to_entry_text(peak, chromatogram):
"""
For writing the peak's row in a peak table.
Parameters
----------
peak: Classes.Peak
chromatogram: Classes.Chromatogram
Returns
-------
entry: str
Row for the peak table output
"""
st_ind = 0
end_ind = 0
peak_... | 97721393bea68549de05e14b96c3849085dd6802 | 538,929 |
import torch
def init_tdl_zeros(model, batch_size, device):
"""
Initialize TDLs with zeros.
:param model: NARX model
:param batch_size: size of batch
:param device: device type
:return: input TDL, output TDL
"""
# input tap-delay
itdl = torch.zeros((batch_size, model.input_delay... | d741a57592d619b6915afd57a82b4fa5f2aa7c3f | 410,986 |
import json
def json_decode(s):
""" Decodes a json string to a dict. """
if not s:
return None
return json.loads(s) | 9549e6a0f6615fcbb8d7f5ec0687ac1bc3626079 | 74,042 |
def sort_dict(src_dict):
"""
Sort given dictionary
:param src_dict: source dict
:return: sorted dictionary
"""
sorted_dict = {k: src_dict[k] for k in sorted(src_dict.keys())}
return sorted_dict | 71ceb261848eb7458e71ea4ea0b4cd9f1d6164a3 | 67,680 |
import pickle
def load_pickle(ifpath):
"""
Load an object from pickle
Args:
ifpath (str): path from where a graph is loaded
"""
with open(ifpath, 'rb') as ifh:
return pickle.load(ifh) | 59c32698755b7eff21eb80aa514ea4d8d22e128c | 271,489 |
def get_tile_position(node, target):
""" Return (row,col) of a tile """
return divmod(node.matrix.index(target), node.width) | bbf1c451fdf1908dea83b9f4b0405727f22f0cce | 602,072 |
from sympy import diff, symbols, lambdify
def newton1D(f, x_0, df=None, delta=0.00001):
"""
Find solution to f(x) = 0 with newton's method
:param f: function f
:param x_0: starting point for x
:param df: first order derivative of f
:param delta: threshold for solution
:return: x
"""
... | 85199d3caf9d54c6ce087c01aaec6bbaa56cbc93 | 599,403 |
import time
def sisock_to_unix_time(t):
"""Convert a sisock timestamp to a UNIX timestamp.
Parameters
----------
t : float
A sisock timestamp.
Returns
-------
unix_time : float
If `t` is positive, return `t`. If `t` is zero or negative, return
:math:`time.time() -... | 9480b99b2c18a989421c2bff8c9629f8d17f1f7b | 362,735 |
def hump_to_underscore(name):
"""
Convert Hump style to underscore
:param name: Hump Character
:return: str
"""
new_name = ''
pos = 0
for c in name:
if pos == 0:
new_name = c.lower()
elif 65 <= ord(c) <= 90:
new_name += '_' + c.lower()
... | 77f407da9202e049e75f7dfa015ce501e1492ac7 | 516,892 |
import asyncio
def schedule_coroutine(target):
"""Schedules target coroutine in the given event loop
If not given, *loop* defaults to the current thread's event loop
Returns the scheduled task.
"""
if asyncio.iscoroutine(target):
return asyncio.ensure_future(target, loop=asyncio.get_event_... | d23b2f1374df010ea855f0e53dd5576bf24d974b | 191,411 |
def atfile_ivm(filename):
"""
Return the filename of the IVM file
which is assumed to be the second word
in the atfile the user gave.
"""
return filename.split()[1] | fa5523e7e7a7e963dcfe36b9eef8b3132f768719 | 153,665 |
def get_all_categories(product_list):
"""
Function to get a unique list of categories out of the list of products.
:param product_list: List of products
:return: dict with category names as keys
"""
categories_dict = dict()
for product in product_list:
if product['category_name'] no... | a29c156b337bbbb0045584d8d57dc5794d57718c | 440,446 |
def reshape_sum_backward(gy, x_shape, axis, keepdims):
"""Reshape gradient appropriately for dezero.functions.sum's backward.
Args:
gy (dezero.Variable): Gradient variable from the output by backprop.
x_shape (tuple): Shape used at sum function's forward.
axis (None or int or tuple of in... | afb274d59a4f3b39c8ad70c98a089b3ad6041f1e | 574,531 |
def validate_password(password: str):
""" Validate the user password
>>> validate_password("short")
Traceback (most recent call last):
...
raise ValueError("password must have at least 8 characters")
ValueError: password must have at least 8 characters
>>> validate_password("This is a g... | d613c5b2e6e495b68dfbbae473910729a7014b77 | 503,683 |
import re
def check_community(name) -> bool:
"""Perform basic validation on community name"""
if (name and isinstance(name, str) and len(name) > 5 and name[:5] == 'hive-'
and name[5] in ['1', '2', '3'] and re.match(r'^hive-[123]\d{4,6}$', name)):
return True
return False | f9f936a0a85299cef6decfd61d84f0f5ef0cf23b | 107,384 |
def normalise_coordinates(x1, y1, x2, y2,min_x,max_x,min_y,max_y):
"""
Parameters:
x1, y1, x2, y2: bounding box coordinates to normalise
min_x,max_x,min_y,max_y: minimum and maximum bounding box values (min = 0, max = 1)
Returns:
Normalised bounding box coordinates (scaled between 0 an... | 988b523ed8fb85cfc9adc571eaf837fcffb843ff | 385,956 |
def not_(a: object) -> bool:
"""
Return `not a`, for _a_.
Example:
>>> not_(True)
False
Args:
a: argument of `not` expression
Return:
`False` if `a`, `True` otherwise
"""
return not a | 320c5416a7a7eaf23f922f7abbacead10a78b448 | 442,229 |
def q_inv(a):
"""Return the inverse of a quaternion."""
return [a[0], -a[1], -a[2], -a[3]] | e8d06e7db6d5b23efab10c07f4b9c6088190fa07 | 371,704 |
from io import StringIO
def get_number(token):
""" Turn leading part of a string into a number, if possible.
"""
num = StringIO()
for ch in token:
if ch.isdigit() or ch == '.' or ch == '-':
num.write(ch)
else:
break
val = num.getvalue()
num.close()
r... | 43e703f8fc1993aabc325de3729f87ca27c8fc85 | 687,099 |
def mac_byte_mask(mask_bytes=0):
"""Return a MAC address mask with n bytes masked out."""
assert mask_bytes <= 6
return ':'.join(['ff'] * mask_bytes + (['00'] * (6 - mask_bytes))) | 3e3acd78402fc4307141e3ef38aaa73e6e546d20 | 98,641 |
def has_decorator(
text,
pre_decor='"',
post_decor='"'):
"""
Determine if a string is delimited by some characters (decorators).
Args:
text (str): The text input string.
pre_decor (str): initial string decorator.
post_decor (str): final string decorator.
... | 1547125e7bf175b6c2a8b6a5306ffcad2c3f8206 | 531,185 |
def is_cert_valid(cert, dt):
"""Check if `cert` is valid at `dt` (datetime in UTC)."""
if cert is None:
return False
return cert.not_valid_before < dt and dt < cert.not_valid_after | 82805f9b2f9b93188d39c15e69a3332243595776 | 375,362 |
def opposite_sub_simplex(simplex, sub_simplex):
"""
Get the opposite sub simplex of a given sub simplex in a simplex.
The opposite sub simplex of a sub simplex f in a simplex T is the simplex consisting of all the vertices
of T not in f.
:param simplex: Simplex defined by a list of vertex indices.... | e92032623bb5cd2dfa57e5530d40fee7e96b715c | 359,312 |
def PNT2Tidal_Pv14(XA,chiA=0,chiB=0,AqmA=0,AqmB=0,alpha2PNT=0):
""" TaylorT2 2PN Quadrupolar Tidal Coefficient, v^14 Phasing Term.
XA = mass fraction of object
chiA = aligned spin-orbit component of object
chiB = aligned spin-orbit component of companion object
AqmA = dimensionless spin-induced quadrupo... | 4530916fded5b0c930af91476d94f7aefd8d755f | 301,256 |
def remove_duplicates_retain_order(seq):
"""Code credited to https://stackoverflow.com/a/480227.
Args:
seq (list): Any list of any datatype.
Returns:
list: The list in same order but only first occurence of all duplicates retained.
"""
seen = set()
seen_add = seen.add
return([x for x in seq if not (x in se... | a928c63a53ddd032ebcafc3d958d4e8efe313844 | 663,732 |
import re
def keep_e(st):
"""
Takes in string, returns that string with all letters that
are not e's changed to (NOT_E).
"Hello" -> "(NOT_E)e(NOT_E)(NOT_E)(NOT_E)"
"""
return re.sub(r"[A-D | F-Z | a-d | f-z]", "(NOT_E)", st) | 5e486037553c24a0689554e6524c25a63d39b1f9 | 459,537 |
def filter_df(df, filter_dict, drop_list=None):
"""Filter DataFrame by dictionary of key and values."""
for key, val in filter_dict.items():
df = df[df[key] == val]
if drop_list is not None:
df = df.drop(columns=drop_list)
return df | 99bbdb6437ffcb087fc5151cdcc2e94dd08afd24 | 534,032 |
import random
def rand_real(range_start, range_stop):
"""
Generates a random real number by using random.random to generate a random x in [0,1)
and transforming it to be y between range_start and range_stop:
y = x * (range_stop - range_start) + range_start
"""
return random.random()*(rang... | 4d41ee7275cecfe50c2bbcc402d8d70c6d9b98b1 | 429,364 |
def process_which(which, max_index):
"""
Parameters
----------
which: int or tuple or list, optional
single index or tuple/list of integers indexing the eigenobjects.
If which is -1, all indices up to the max_index limit are included.
max_index: int
maximum index value
R... | 5a14620c04f173ddf1c211676444de648f89c11e | 453,754 |
def is_typed_dict(type_or_hint) -> bool:
"""
returns whether the type or hint is a TypedDict
"""
return issubclass(type_or_hint, dict) and hasattr(type_or_hint, "__annotations__") | f5b06f6ae56cd2be4a3b9ca6cbdf0f0cdc979417 | 233,384 |
def batch_index(batch: dict, index):
"""Index into the tensors of a batch.
Args:
batch (dict): Batch dictionary.
index (object): Index.
Returns:
dict: `batch` indexed at `index`.
"""
return {k: batch_index(v, index) for k, v in batch.items()} | d59aa80c7f27614a288b625ade0a92042d0069d0 | 159,747 |
import random
def mutate(x, mutation_rate=1):
"""
Mutate a random gene
:param x: individual to mute (numpy vector)
:param mutation_rate: increasing/decreasing factor
:return: mutated x (numpy vector)
"""
mut_gene = random.randint(1, len(x) - 2)
x[mut_gene] += (mutation_rate if random.r... | 85300ff3b8ca41c733ec1559697ddd9435be87e7 | 374,764 |
def get_pubkey(point, compressed=True):
"""
Get the Serialized pubkey from an ecdsa Point object.
point = ecdsa Point object
compressed = Boolean whether or not you want the pubkey compressed.
"""
if compressed:
return ("0" + str(2 + (1 & point.y())) + ("%064x" % point.x())).decode('hex'... | fce6bceeab17bcadbf62ee31bd6c11cb870a04e4 | 301,196 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.