content stringlengths 39 9.28k | sha1 stringlengths 40 40 | id int64 8 710k |
|---|---|---|
def nbsp(text):
"""
Replace spaces in the input text with non-breaking spaces.
"""
return str(text).replace(' ', '\N{NO-BREAK SPACE}') | 74c990deb67413b7811792493b97493cb2b3c93f | 299,723 |
import time
def _init_step_result(step_object):
"""
Initializer for step_result structure.
"""
return {
'status': 'unknown',
'date': step_object.step_date,
'start_time': time.time(),
'end_time': None,
'type': step_object.step_type,
'error_info': {},
... | 94a95fed8e27a659e9dfcc88ff3a774274830faa | 592,406 |
import re
def ElementToComplexType(xsd):
"""Replaces the first <element> tag with the complexType inside of it.
The complexType tag will use the name attribute from the removed element tag.
Args:
xsd: str XSD string contents.
Returns:
str: Modified XSD.
"""
xsd = re.sub(r'<(\w+:)?element name="... | 5c78d07a8a900dc84512a69342ef82f00b92ed33 | 57,699 |
def getFilename(url):
"""Attempts to get the filename from the URL"""
components = url.split('/')
fname = components[-1]
if '.' in fname:
return fname
else:
return None | 7b127de42e9c67c05546c8df92b9c5f9a246b622 | 336,050 |
def complex_matrix(mat):
"""Converts real-imag interleaved real matrix into a python complex matrix."""
return mat[:,0::2] + 1j * mat[:,1::2] | c4dcb907c3cf72c5a0c7e465431f062e5f756ad7 | 257,379 |
def rgb(r, g, b):
"""
Converts RGB decimal values to hexadecimal.
:param r: integer value.
:param g: integer value.
:param b: integer value.
:return: hexadecimal version of RGB decimal numbers.
"""
return "".join(["%02X" % max(0, min(x, 255)) for x in [r, g, b]]) | 8bdf2a9e0f9597df04e75fe5edbd1c0b21c7d6e7 | 469,559 |
def gchp_metname(prior_to_13):
"""
Deterimines the correct collection name for GCHP StateMet data.
"""
if prior_to_13:
return "StateMet_avg"
return "StateMet" | 77eab1163e8a010c1d74dccdfdb12fffd09d059b | 60,183 |
def split_game_path(path):
"""Split a game path into individual components."""
# filter out empty parts that are caused by double slashes
return [p for p in path.split('/') if p] | 9b939058aa7f8b3371d3e37b0252a5a01dba4e7b | 6,998 |
def CleanGrant(grant):
"""Returns a "cleaned" grant by rounding properly the internal data.
This insures that 2 grants coming from 2 different sources are actually
identical, irrespective of the logging/storage precision used.
"""
return grant._replace(latitude=round(grant.latitude, 6),
... | 648bb0a76f9a7cfe355ee8ffced324eb6ceb601e | 8 |
def checkerboard_basis(c: complex) -> str:
"""Classifies a coordinate as X type or Z type according to a checkerboard pattern."""
return 'X' if int(c.real + c.imag) & 1 == 0 else 'Z' | 49a1a2296b45328a2ffcd04186800fd9379a1946 | 599,715 |
def get_ip_from_raw_address(raw_address: str) -> str:
"""
Return IP address from the given raw address.
>>> get_ip_from_raw_address('91.124.230.205/30')
'91.124.230.205'
>>> get_ip_from_raw_address('192.168.1.15/24')
'192.168.1.15'
"""
return raw_address.rsplit('/')[0] | 07d9fa9ae41f0c84e109d925114f56a1efccbe66 | 650,969 |
from typing import Any
import re
import importlib
def load_code(c: str) -> Any:
"""
Deserializes an object from a Python code string.
Parameters
----------
c
A string representing the object as Python code.
Returns
-------
Any
The deserialized object.
See Also
... | 8e85bc08d218b0847d0a9fe9d809dc0b7e630114 | 349,913 |
def timeoutDeferred(reactor, deferred, seconds):
"""
Cancel a L{Deferred} if it does not have a result available within the
given amount of time.
@see: L{Deferred.cancel}.
The timeout only waits for callbacks that were added before
L{timeoutDeferred} was called. If the L{Deferred} is fired the... | ddf45ebbedee68d9a93a6529fabd6100b55d4c33 | 129,248 |
from functools import reduce
def _calculate_num_of_value(dimensionAttr):
"""
Based on dimension information, caculate how many size of the list when squeeze
the high dimension value into single dimension array.
:param dimensionAttr: The dimension attribute
:return: An integer which specifi... | cb128ab549c76292271b6fc6a8333a9d67e280b8 | 80,415 |
def to_pilot_alpha(word):
"""Returns a list of pilot alpha codes corresponding to the input word
>>> to_pilot_alpha('Smrz')
['Sierra', 'Mike', 'Romeo', 'Zulu']
"""
pilot_alpha = ['Alfa', 'Bravo', 'Charlie', 'Delta', 'Echo', 'Foxtrot',
'Golf', 'Hotel', 'India', 'Juliett', 'Kilo', 'Lima', 'M... | c53faed46af9a1508af5baa0d4940e16dd0f7603 | 330,556 |
def convert_lowercase(in_str):
""" Convert a given string to lowercase
:param in_str: input text
:return: string
"""
return str(in_str).lower() | 941630030b297b9eb4b91d5989a813099aef5d06 | 195,413 |
import random
def rand_scale(s):
""" Return a random scale """
scale = random.uniform(1, s)
if(random.randint(1,10000)%2):
return scale
return 1./scale | e8113d3600de96606e43d07d9964e29804afbb09 | 145,916 |
def __is_const_str(data: str) -> bool:
""" Returns true if predicate is a constant string.
Note: supports constant strings starting with a lowercase letter
or a number
"""
# common case: string starts with a lowercase letter
test_str = data[0].islower()
# special case: string starts with a... | ec6c45ea1bfc01dfa1949fea6c32b61341a86893 | 80,179 |
from re import compile
def check_regex(regex):
"""Generate a function to match the regex.
The regex will be compiled to speed up."""
regex = compile(regex)
def _check_regex(text):
result = regex.match(text)
return result is not None
return _check_regex | 74e562f0c96e0da9faaa3abd6ee50c87601fcfed | 565,314 |
def cast_python_object_to_aggregate(obj, aggregate):
""" This function casts a python object to an aggregate type. For instance:
[1.,2.,3.]-> ARRAY(1,3,REAL)"""
aggregate_lower_bound = aggregate.bound_1()
aggregate_upper_bound = aggregate.bound_2()
if type(obj)==list:
for idx in range(aggreg... | 75563a8f1d359d97214066fe8fef32da377bcb23 | 240,850 |
def katex_rendering_delimiters(app):
"""Delimiters for rendering KaTeX math.
If no delimiters are specified in katex_options, add the
katex_inline and katex_display delimiters. See also
https://khan.github.io/KaTeX/docs/autorender.html
"""
# Return if we have user defined rendering delimiters
... | d1933ffda9b4fa4f668bdffc603bdfbcc07fc8ef | 150,079 |
def list_del_indices(mylist,indices):
"""
iteratively remove elements of a list by indices
Parameters
----------
mylist : list
the list of elements of interest
indices : list
the list of indices of elements that should be removed
Returns
-------
list
the red... | c128bcadd6bc7b4589fc9da5bc26981078dbe5fe | 272,870 |
def valid_day(tms):
"""Checks if day of month is valid"""
year, month, day = tms[:3]
if day > 31:
return 0
if month in [4, 6, 9, 11] and day > 30:
return 0
if month == 2 and (year%4 == 0 and day > 29 or day > 28):
return 0
return 1 | d066c5bffdb0a192514b841481d2852867d06977 | 520,286 |
def handles(cursor):
"""Returns a dict of handles that form (ROWID, id) pairs."""
sql_handles = cursor.execute("SELECT ROWID, id FROM handle").fetchall()
all_handles = dict()
for handle in sql_handles:
rowid, contact_id = handle
all_handles[rowid] = contact_id
return all_handles | 0b9b865770f7775feb70d60680ea9a36f0f259f0 | 578,492 |
def get_object_location(object):
""" Retrieves the location of an object.
Parameters:
object (obj): Object to get location.
Returns:
list: Object location.
"""
return list(object.location) | 57fc0ebb30aab4bf78103aefc7cafabfa5b8bac7 | 479,002 |
def getAccuracy(l1, l2):
"""
Returns accuracy as a percentage between two lists, L1 and L2, of the same length
"""
assert(len(l1) == len(l2))
return sum([1 for i in range(0, len(l1)) if l1[i] == l2[i]]) / float(len(l1)) | 9fc02154334d8cc7f7d817d9e425bb89dfa1e9cd | 291,841 |
def calculate_accuracy(y_target, y_pred):
"""Returns accuracy
# Arguments
y_target: true label data
y_pred: estimated label data
# Returns
accuracy
"""
return y_target[y_target == y_pred].size * 1.0 / y_target.size | 962539dec6f6aa4873b0d7111824c7ea21096d56 | 348,807 |
def score2voice(score):
""" Generates a sequence of voice numbers from a score.
Args:
score (music21.Score): the input score
Returns:
list[int]: a list of voice numbers corresponding to each note in the score
"""
return [
int(str(n.getContextByClass("Voice"))[-2])
i... | 89aae5df1f43042e344e6c78af2cd68ab0feddb6 | 466,901 |
import configparser
def _copy_ini(config: configparser.ConfigParser, section: str, option: str) -> str:
"""Returns the text needed to set the given option.
If the option isn't set in the old config, this returns the empty string.
Args:
config: Old configuration.
section: Section to copy from.
opti... | fbcf5d718f811a676c8aa8725e07d1472b01ae20 | 532,056 |
def to_numeric(s):
"""Convert string to int or float
Args:
s (str): string to be converted to numeric
Returns:
int or float
"""
try:
return int(s)
except ValueError:
return float(s) | 15bdf94ca894d4b2732f4ae456577b7aa9ebf05b | 202,676 |
import requests
def check_url_response(url: str) -> bool:
"""Confirms the HTTP response from the provided url.
Using HTTP requests attempts to check
whether a site under the url is online.
Args:
url: url to a site
Returns:
True if site is online, False otherwise
"""
with ... | bc762579c974c5797d052a2512b7075b251db303 | 499,235 |
def a_function(x=0):
"""This regular docstring does not conflicts with the above markdoc"""
return f'Hello {x}' | 094e11b59e9277fda9ee6fadfaed31af5640abf4 | 368,072 |
import requests
def upload_photo(account, f, group):
"""
Загружает фото на стену группы. Подробнее: https://vk.com/dev/upload_files
:param account: Объект vk.API, от имени которого будет загружено фото
:param f: file-like объект, содержащий фотографию
:param group: айди группы
:return: Объект ... | 4529c6c4e38a55af192f2149e92f49e277eb1bd6 | 131,219 |
def vhost_scsi_controller_add_target(client, ctrlr, scsi_target_num, bdev_name):
"""Add LUN to vhost scsi controller target.
Args:
ctrlr: controller name
scsi_target_num: target number to use
bdev_name: name of bdev to add to target
"""
params = {
'ctrlr': ctrlr,
... | 5052ba8d02572aa1e8971dce02d959b1827ee070 | 149,069 |
def GetPlistValue(plist, value):
"""Returns the value of a plist dictionary, or False."""
try:
return plist[value]
except KeyError:
return False | 783f7d675f20f3ed81158b1c22ad549a0770bc00 | 561,621 |
import linecache
def checkline(filename, lineno, ui):
"""Return line number of first line at or after input
argument such that if the input points to a 'def', the
returned line number is the first
non-blank/non-comment line to follow. If the input
points to a blank or comment line, return 0. At ... | acdcc76a91e7882a0a836e2783847e23deb1f84b | 659,623 |
def create_req_and_opt_graph(req_comp_g_contracted, complete_g, circuit_rpp, GranularConnector_EdgeList):
"""
Creates a graph with required and optional edges delineated for visualization
Args:
req_comp_g_contracted (NetworkX MultiDiGraph): required component graph containing contracted edges
... | 991ba857418d49ef7ce29cde2ad1fb45826951b8 | 455,031 |
import hashlib
def hash_file(fpath, block_size=2**16):
"""
Get the SHA1 hash of a file.
Args:
fpath (str): Path to file.
block_size (int): Number of bytes to read from the file at a time.
Returns:
str: hash
SHA1 digest as a hex string.
"""
hash_ = hashlib.... | 855471f796ab00dbea2e6c3b0633ee2b2a63da56 | 54,284 |
def make_grouped_share(df, variable, name="share"):
"""Normalise a variable (for using in grouped dfs)"""
df[name] = df[variable] / df[variable].sum()
return df | 258f93b82bac8439f002e4f4b1bd95a3c04878a0 | 603,292 |
import logging
def create_caplog(caplog):
"""Set global test logging levels."""
def _level(level=logging.INFO):
caplog.set_level(level, logger="aiocrontab.core")
return caplog
return _level | 39aa8814066eebd5181e6443c5a2900f9149844e | 413,895 |
from datetime import datetime
def datetime_range_inclusive(min, max, format):
"""
Return a value check function which raises a ValueError if the supplied
value when converted to a datetime using the supplied `format` string is
less than `min` or greater than `max`.
"""
dmin = datetime.strpti... | 92fe58094dcc9cf8ed11c5b829614ca83b1acc76 | 579,744 |
from typing import Counter
def parse(filename):
"""Parse the input file into Python objects.
Input file has lines like this:
sdfsjdfk sjdkf lfke ljrl (contains dairy, soy)
Parameters:
filename (str): the name of the input file to open
Returns:
candidates (Dict[str, Set[s... | bd2ca6dcd3c843d462a4d3faf507c47fb49b8984 | 606,175 |
def font_style(keyword):
"""``font-style`` descriptor validation."""
return keyword in ('normal', 'italic', 'oblique') | 6b49a62708cd2955d142cbd9fbda2efbb669dfcf | 305,135 |
def _allnan_or_nonan(df, column: str) -> bool:
"""Check if all values in a column are NaN or not NaN
Returns
-------
bool
Whether the dataframe column has all NaNs or no NaN valles
Raises
------
ValueError
When the column has a mix of NaNs non NaN values
"""
if df[c... | 6f1a531055cc7eed7c184e4861d6e0cc03231954 | 290,428 |
def num2lett(ind):
""" Returns the alphabet string based on the order number """
# 0 -> a, ..., 25 -> z
return chr(ind + 97) | a20df5babccf45579033000f4adc14288402cfb7 | 413,531 |
import random
import string
def random_str(length: int = 8):
"""Generate a random string of fixed length
"""
return ''.join(random.choice(string.ascii_letters) for i in range(length)) | bd5af189398a610055660098ebfae78b134d837d | 91,649 |
from datetime import datetime
def now_str(time=False):
"""Return string to be used as time-stamp."""
now = datetime.now()
return now.strftime(f"%Y-%m-%d{('_%H:%M:%S' if time else '')}") | 02b73bda5f27e7c25120d50d50244bd103661c90 | 9,174 |
def path_macro_sub(s, ip='', dp='', gp='', ei=''):
"""
Replace macros with current paths:
- <INSTALL_DIR> is replaced with the contents of ip
- <DATA_DIR> is replaced with the contents of dp
- <GLOBAL_DATA> is replaced with the contents of gp
- <EVENT_ID> is replaced with the contents of ei
... | 6c847345d572859b5f852933d7654ac9a6ae0a10 | 105,439 |
def get_bb_ops(bb, ops):
"""Helper function returning all instructions (sorted by address) from ops
that are inside the basic block bb"""
bb_ops = [ op for addr, op in ops.items() if addr >= bb['addr'] and addr < bb['addr'] + bb['size']]
bb_ops = sorted(bb_ops, key=lambda op : op['offset'])
return b... | da51d3818b4203e2f9e8a8c3bed73f2dd8e08dd9 | 376,764 |
def get_transitions(state_list, xml_transition_list):
"""Get transitions if state(s) from state_list are source/destination"""
new_transition_list = set()
for new_state in state_list:
for transition in xml_transition_list:
if new_state.id == transition.source:
new_transit... | e6741759d77fade600edff63442f6e4aecdb5d14 | 584,145 |
def is_pull_request(issue):
"""Return True if the given issue is a pull request."""
return 'pull_request_url' in issue | 8b295f2d6743868bfcdb50ae9db02c0c7b30c605 | 291,421 |
import torch
def dump_ir(tensors, ir_format):
"""Return a dump of the tensors in the specified format.
Valid format are
- text: for LTC IR
- backend: for the activate backend IR
"""
if ir_format == "text":
return torch._C._lazy._get_tensors_text(tensors)
elif ir_format == ... | 2b502a5ae1c8ef2fb2aaf4f1671f6f2aef85c4a4 | 392,004 |
def to_binary(val, expected_length=8):
"""Converts decimal value to binary
:param val: decimal
:param expected_length: length of data
:return: binary value
"""
val = bin(val)[2:] # to binary
while len(val) < expected_length:
val = "0" + val
return val | ab84ace5a149d4dcb709e9865457c0d0fe461cfd | 194,896 |
def dansRectangle(x,y, cx,cy, L, H):
"""
Test l'appartenance à un rectangle.
Paramètres:
(x,y) --> point à tester,
(cx,cy) --> coin supérieur gauche du rectangle,
L -->.width du rectangle,
H -->.height du rectangle.
Retourne ``Vrai`` si le point est dans l... | 9227ec67800e5f1552c01824b63434f8a0740d39 | 74,129 |
def int_ceil(x):
"""return ceiling of value should be an integer"""
_int = int(x)
if _int < x:
return int(x + 1)
else:
return _int | 9f9de801bb24039a6ae5e89c700b4268a73eb30b | 602,893 |
def unflatten(dictionary):
""" Unflattens a dictionary by splitting keys at '.'s.
This function unflattens a hierarchical dictionary by splitting
its keys at '.'s. It is used internally for converting the
configuration dictionary to more convenient formats. Implementation was
inspired by `this Stac... | 8e0f45ff4166a19b6f21d5a18119e1bed742c08d | 327,220 |
import math
def angle_dev(a, b):
"""
Computes the minimum signed difference between two radian angles.
Parameters
----------
a: float
angle A
b: float
angle B
Returns
-------
float
difference between A and B
"""
diff = math.fmod((a - b + math.pi), ... | 2cb08967f48991f9cf2205ff7b867ff7b79deb93 | 458,519 |
from typing import List
def _sampling_from_alias_wiki(
alias: List[int],
probs: List[float],
random_val: float,
) -> int:
"""
Draw sample from a non-uniform discrete distribution using Alias sampling.
This implementation is aligned with the wiki description using 1 random number.
:param a... | c67d2d698ace15c798cda51049b7ddd880c48a71 | 36,124 |
def get_triangle_top_midpoint(point_list):
"""Returns the midpoint of the top of a triangle regardless of the orientation."""
y = int(min([x[1] for x in point_list]))
x = int((min([x[0] for x in point_list]) + max([x[0] for x in point_list])) / 2)
return x, y | 57d585044790702f85f8e73c69e07aa6698dd888 | 196,491 |
def write_flaggelin_db_fasta(df, fasta_name = "flagellin_db.fasta"):
"""
Creates a fasta file from a Dataframe
Parameters
----------
df : Pandas DataFrame
This will be the DataFrame output from construct_reference_flagellin_dataframe
fasta_name : str
Name of the output fasta file
Returns
-------
fasta_na... | 073d5501ede76006756adc2cca31e3b8b418af22 | 597,805 |
def assign_coordinate_file_ending(program: str):
"""
Returns the coordinate file ending specific to the program
Paramaeters
-----------
program: str
Program being used.
Returns
-------
file_ending: str
string of the file ending
"""
if program == 'Tinker':
... | 3c3b7fdf8544f4a389f0380f96c6bb0bc08a09b9 | 371,088 |
def isotropic_rp(**kwargs):
"""
Returns constant (1.0)
:return:
"""
return 1.0 | 71bfc2d910abe1b2891b621f0f99da2b2a721004 | 521,664 |
def FlavorName(flavor):
"""Given a flavor, get a string name for it."""
if isinstance(flavor, tuple):
return flavor[0]
else:
return flavor | 319b186e738abef990a9b84b098aaba7895eb4eb | 449,957 |
def remaining_G9_12_cap(k12):
"""
Remaining enrollment capacity available at the school.
"""
return (k12['G9_12_cap'] - k12['G9_12']).clip(0) | 68d31e3b24ff3405b50cd53691be0f92baee0ba9 | 629,869 |
def find_flank_zerox(sig, flank):
"""Find zero-crossings on rising or decaying flanks of a filtered signal.
Parameters
----------
sig : 1d array
Time series to detect zero-crossings in.
flank : {'rise', 'decay'}
Which flank, rise or decay, to use to get zero crossings.
Returns
... | 0ab0c446e358e47eeb0ec13f1968de8ac5f687f2 | 221,482 |
async def callback(app, message):
"""Print the message retrieved from the file consumer."""
print(app.name, "received:", message)
return message | a92eb3f1637e48cb2eca44334e4801ede1c5b4a7 | 475,107 |
def _help_body_atom(body: str) -> str:
"""Helper for converting body for an Atom snippet"""
body = body.replace('\\', '\\\\\\\\')
body = body.replace('"', '\\"')
return body | 0ea31d390519f3c4f93c0d36a25687e93a7d1c9b | 480,512 |
def num_grid_points(density_file_name):
"""
This function extracts the number of points in each cartesian direction.
Parameters
----------
density_file_name : string
This input is the full path of the .dx file from which to get data.
Returns
-------
num_x : int
This outpu... | e13fb42803fa36a71369d3d7ba0afaa8ea730a54 | 325,716 |
def unqualify(name: str) -> str:
"""Return an Unqualified name given a Qualified module/package Name"""
return name.rsplit(".", maxsplit=1)[-1] | bbf4cc310fb26ff4c1c0f103242c204e1c147f9d | 561,328 |
def is_related_field(field):
"""
Returns true if the field created as a related field from another model.
"""
return hasattr(field, 'related_name') | e396246c7170c7829f83898a10298e591147478a | 562,483 |
import logging
def _make_logger(name, /, level='error'):
"""
Return a logger.
"""
# See: https://stackoverflow.com/q/43109355/4970632
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter('%(name)s (%(levelname)s): %(message)s'))
logger = logging.getLogger(name)
logg... | 3ca60291e8996e72914551095365e88e4b313e1f | 492,471 |
def weeds_prec(x_row, y_row):
"""
WeedsPrec(x -> y) = (\sigma_c \in Fx,y w_x(c)) / (\sigma_c \in Fx w_x(c))
Fx,y is the mutual contexts (non-zero entries) of x and y rows in the ppmi matrix
w_x(c) is the weight of feature c in x's feature vector, i.e. ppmi(x, c)
Fx is the row of x in the ppmi matrix... | 2319a22d9aa8fe8d0d1deb26b328add8bb943814 | 336,547 |
from typing import Iterable
def wherevarinlist(var: str, vals: Iterable[str]) -> str:
"""Return str sql query for when variable value is in a list of values
>>> wherevarinlist("STATE", ["FL", "GA", "SC", "NC"])
"STATE In ('FL', 'GA', 'SC', 'NC')"
"""
vals = [f"'{val}'" for val in vals]
vals_st... | efde9f40021c798216d5c17f950f7dc434e09f56 | 188,593 |
def scale_image(x):
"""Normalize iamge for visualization purpose."""
x = x - x.min()
if x.max() > 0:
x = x / x.max()
return x | 6cd3bbdc525c8ef8728b73aa7444c49890738852 | 459,796 |
import json
def erl_tuple_to_list(raw_data):
"""
Formats Erlang data to be testable in Python.
raw_data is a list of Erlang tuples serialised as string
E.g.: '[{"giver1","recipient1"},{"giver2","recipient2"}]'
formatted_list is a list of lists:
E.g.:[ ['giver1','recipient1'], ['giver2','recipi... | 010edd5630a4d311289ca3f1a6aeb6f549ea3cfc | 528,523 |
import math
def f2E(f, e):
"""
Function: f2E
Purpose: Maps true anomaly angles into eccentric anomaly angles.
This function requires the orbit to be either circular or
non-rectilinar elliptic orbit.
Inputs:
f = true anomaly angle (rad)
e = eccentricity (0 <= e < 1)
... | 1e2cbacec7403833113051c96970d08e82b58b97 | 417,613 |
def get_timestamp(row):
"""
Extract the timestamp from the annotations.
"""
return row[1] | 872f9c06a542cd9bbe5ff696d490620e0b735a2b | 407,949 |
def multiproduct(seq=(), start=1):
"""
Return the product of a sequence of factors with multiplicities,
times the value of the parameter ``start``. The input may be a
sequence of (factor, exponent) pairs or a dict of such pairs.
>>> multiproduct({3:7, 2:5}, 4) # = 3**7 * 2**5 * 4
279936... | b1f40f1251e521e773f29355161f7c8b5c804b29 | 632,899 |
def format_card(cards):
"""
Returns a dictionary with the passed cards rank, color, and suit.
Args:
cards: A list of 2-letter strings representing card rank and suit.
"""
formated_cards = []
for card in cards:
if card[0] == 'T':
card_dict = {'rank': '10'}
el... | efe497b9552b77f109d7096132e5fb465e268b8f | 448,426 |
from typing import Optional
import math
def _phantom_float_format(
val: float, length: Optional[int] = None, justify: Optional[str] = None
):
"""Float to Phantom style float string.
Parameters
----------
val : float
The value to convert.
length : int
A string length for the re... | cd8b7fd3e9f6a38c72a61a3403f82485eee6514f | 248,668 |
def _decode_node(s):
"""Map string `s` to node-like integer."""
if s == 'F':
return -1
elif s == 'T':
return 1
else:
return int(s) | b7c8f80d523e35201d306a5b21f4f4c9f1471e91 | 304,033 |
def t01_SimpleGetPut(C, pks, crypto, server):
"""Uploads a single file and checks the downloaded version is correct."""
alice = C("alice")
alice.upload("a", "b")
return float(alice.download("a") == "b") | 6f58d83a48856e339a4698f1717a8b464127e02a | 673,364 |
def _key_in_string(string, string_formatting_dict):
"""Checks which formatting keys are present in a given string"""
key_in_string = False
if isinstance(string, str):
for key, value in string_formatting_dict.items():
if "{" + key + "}" in string:
key_in_string = True
... | 706beaa06973b5071ecdbf255be83ee505202668 | 677,773 |
def param_invalid_value_info(param_name, default_value):
"""
Returns info warning an invalid parameter configuration.
"""
return "Parameter warning: the configuration of hyper-parameter "+ \
"'{}' is not valid, will use default value '{}'" \
.format(param_name, default_value) | 87008226a851f512f19224440a2c501ca85957d5 | 117,217 |
async def toggle_group(role_title, ctx):
"""Toggles the user's roles. For example, adds a role if they do not have it already, or removes it if they do.
We allow the message handling to be done by the function calling this function, for more customizability.
Function has four potential return results.
'... | 9ab882212e15f302f5fac5f65573b22c901fb4b9 | 300,152 |
def deltaify_traces(traces, final_byte_duration=9999):
"""Convert absolute start times in traces to durations.
Traces returned by `read_traces_csv` pair bytes with start times. This
function computes how long each byte remains on the bus and replaces the
start time with this value in its output. Note that the ... | 8185a9825d4706bdf8a579fcefec5e27ca8c3baa | 701,612 |
def in2pt(inval=1):
"""1in -> 72pt"""
return float(inval) * 72.0 | fd3be8149df6b1ea3e8848a313b9d36eb51af4a9 | 294,196 |
def MakeGoogleUniqueID(cloud_instance):
"""Make the google unique ID of zone/project/id."""
if not (cloud_instance.zone and cloud_instance.project_id and
cloud_instance.instance_id):
raise ValueError("Bad zone/project_id/id: '%s/%s/%s'" %
(cloud_instance.zone, cloud_instance.proje... | 1327d17dc431ff5300f1f27a7ed36788476b10c1 | 206,127 |
import ipaddress
def isOverlapCIDR(cidrA,cidrB):
"""
Check if the CIDR A have overlap with CIDR B
"""
return ipaddress.IPv4Network(cidrA).overlaps(ipaddress.IPv4Network(cidrB)) | 31a9f7ac1573bd618106569ea4e26573eecc3bac | 254,375 |
def is_root(dmrs, nodeid):
"""
Check if a node has no incoming links
"""
return not any(dmrs.get_in(nodeid, itr=True)) | 9680901fb212d32c5e64c077fb73247c443374f7 | 488,274 |
from datetime import datetime
def to_epoch(dt: datetime) -> float:
"""Given a datetime object, return seconds since epoch.
Args:
dt: Datetime object
Returns:
seconds since epoch for dt
"""
dt = dt.replace(tzinfo=None)
return (dt - datetime(1970, 1, 1)).total_seconds() | b0dfd68331026fc1c92f1f0f21a832a27e735daa | 513,989 |
def _aggregate_score_dicts(scores , name = None):
""" Aggregate a list of dict to a dict of lists.
Parameters
----------
scores : list of dictionaries
Contains a dictionary of scores for each fold.
name : str, optional
Prefix for the keys. The default is None.
... | cde1662990249573677e122ad107485c251bb297 | 308,751 |
def combine_annotations(annotations):
"""Given a list of annotations made by a Saber model, combines all annotations under one dict.
Args:
annotations (list): a list of annotations returned by a Saber model
Returns:
a dict containing all annotations in `annotations`.
"""
combined_a... | d096f04ec99cca4cf6a3e7c315703d2c8d659eea | 377,362 |
def _compile_model(model):
""" Compile the CNN """
model.compile(optimizer='rmsprop',
loss='categorical_crossentropy',
metrics=['accuracy'])
return model | a2a0e3fd32584fdb50a10ba3312b1fd757e8677c | 401,116 |
import re
def count_ops_in_hlo_proto(hlo_proto,
ops_regex):
"""Counts specific ops in hlo proto, whose names match the provided pattern.
Args:
hlo_proto: an HloModuleProto object.
ops_regex: a string regex to filter ops with matching names.
Returns:
Count of matching ops... | 0e1a933a85e738e505f1b229625023f88e4c2d33 | 679,489 |
def archimedes(dp, rhog, rhos, mu):
"""
Calculate the dimensionless Archimedes number.
.. math:: Ar = \\frac{dp^3 \\rho_g (\\rho_s - \\rho_g) g}{\\mu^2}
Parameters
----------
dp : float
Particle diameter [m]
rhog : float
Gas density [kg/m³]
rhos : float
Solid de... | 6ab7a9eaa4110af00e5340e18f39ca7143d3f58f | 572,262 |
import random
def randomiser(count):
"""
Returns a random number from 0 to count.
"""
return random.randint(0, count-1) | 5bd3ea52d6b1adc019d5370eb648ea55ca797404 | 153,680 |
import time
import calendar
def adjust_time(t, delta):
"""
Adjust a (UTC) struct_time by delta seconds
:type t: struct_time
:type delta: int
:param delta: seconds
:rtype: struct_time
"""
return time.gmtime(calendar.timegm(t) + delta) | 4d2ff67523b05a6f0af02ebb3b230e8875a39ae4 | 39,943 |
def get_between(txt:str, open_char:str="'", close_char:str="'", start:int=1 ):
"""Parse all content in supplied text that appears between the open and close characters, exclusively.
If txt is empty, or open_char is not found, returns ('', -1, -1). If the close_char is never found,
returns the txt from the... | d7709de9c12676ba8a139df15795279924bf6165 | 454,013 |
def ij2bl(i, j):
"""
Convert antenna numbers to baseline number.
Parameters
----------
i : int
first antenna number
j : int
second antenna number
Returns
-------
int
baseline number
"""
if i > j:
i, j = j, i
if j + 1 < 256:
retur... | a51f64b7856b771ca2f800120bab7a108fe8acf0 | 442,056 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.