content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def get_visited_coordinates_steps(path: str) ->dict:
"""
Function for part2
"""
x = y = total_steps = 0 #initial point
visited_coordinates = {}
for movement in path.split(","):
direction = movement[0]
steps = int(movement[1:])
for _ in range(steps):
total_st... | d290a486905388c278576bf4d288aa4c73230fa2 | 691,951 |
import os
def to_api_path(os_path, root=""):
"""Convert a filesystem path to an API path
If given, root will be removed from the path.
root must be a filesystem path already.
"""
if os_path.startswith(root):
os_path = os_path[len(root) :]
parts = os_path.strip(os.path.sep).split(os.pa... | cd94e2e9f500988c272f62b4bd5a4a2120ff4955 | 691,952 |
def upstream_ids(id, fromtoseries, maxcycle=1e6):
"""Return all ids upstream of id given a from (index) to (values) map.
"""
s = [id]
ids = []
cycles = 0
while len(s) > 0:
si = []
for i in s:
si.extend(list(fromtoseries[fromtoseries == i].index))
ids.extend(si... | e695f84958a4297578972d407ea5278416da0b40 | 691,953 |
def _get_reference_header(header_element):
"""Parses ReferenceInput Header element
"""
header = {}
header['key'] = header_element.attrib('key')
header['value'] = header_element.attrib('value')
return header | ebff12dca53059d2f584a9bd55651998c2c5f0cb | 691,954 |
def document_order(node):
"""Compute a document order value for the node.
cmp(document_order(a), document_order(b)) will return -1, 0, or 1 if
a is before, identical to, or after b in the document respectively.
We represent document order as a list of sibling indexes. That is,
the third child of ... | 788c211e064718b9cd4e4b38d2616c0cfdfd645d | 691,955 |
def tei_to_omeka_header(csv_header_info):
""" Transforms an XML-TEI header path to a Omeka (semantic-web compliant) header."""
# XML-TEI headers elements to Linked Data correspondences
xml_tag_to_voc = {
u"#fileDesc#titleStmt_title": u"dc:title",
u"#fileDesc#titleStmt_author_key": u"dc:cre... | 9d4132f55c758fc9df4d3a82d3f2134f2092fe7a | 691,956 |
def create_mail_body(messages):
"""status counts to messages
Args:
messages (list): messages
Returns:
body (string): statuses to mail body
"""
body_message = messages[1:]
body = "".join(body_message)
return body | a343c73724bfed86ea7bde03db0770d17279ca8f | 691,957 |
def multiplexer(a, bits, aut):
"""Return BDD node for selection of elements from `a`.
The resulting expression is:
```
ite(bits[-1], a[-1],
ite(bits[-2], a[-2],
...
ite(bits[1], a[1],
ite(bits[0], a[0], FALSE)
```
This shows that if i < j,
t... | d80426cb1a7603007ef99d87a03b838476707d29 | 691,958 |
def chained(fn):
"""Chain instance methods
Can do things like user.unfollow().follow().unfollow()
"""
def _decorator(self, *args, **kwargs):
fn(self, *args, **kwargs)
return self
return _decorator | f7d66a17c47759ede545d896343a38cfe9a092ad | 691,959 |
def _copy_jar_to_srcjar(ctx, jar):
"""Copy .jar to .srcjar
Args:
ctx: the <ctx> object
jar: the <Generated File> of a jar containing source files.
Returns:
<Generated File> for the renamed file
"""
srcjar = ctx.actions.declare_file("%s/%s.srcjar" % (ctx.label.name, ctx.label.name... | 2d34723d4c993f3c8a192c49a33e8e34d9f82afb | 691,960 |
def save_list(list_text, path_folder, filename:str):
"""
Save list.
Save list at given path with filename in csv format.
Parameters
----------
list_text : dict
Dictionary to save.
path_folder : path
Pathlib path to save list.
filename : str
Name of file.
... | 556a161ede8cca079bb062258901a83d9592a962 | 691,961 |
def __hash_byte_str_iter(bytes_iter, hasher, as_hex_str=False):
"""
:param bytes_iter:
:param hasher:
:param as_hex_str:
:return:
"""
for block in bytes_iter:
hasher.update(block)
return hasher.hexdigest() if as_hex_str else hasher.digest() | 6d8a94deb3190fa58075e9107d1cfc2996d3280e | 691,962 |
def create_positional_array(cigar_tuples):
"""
# ========================================================================
CREATE POSITIONAL ARRAY
PURPOSE
-------
Create a positional array that maps positions in a
CIGAR tuple to a list.
Ex. CIGAR tuple is: [(0, 4), (2, 1) (1, 2)]
... | e5a06a82defe6534094acfeaf0093764550bf384 | 691,963 |
def portfolio_returns(df_long, df_short, lookahead_returns, n_stocks):
"""
Compute expected returns for the portfolio, assuming equal investment in each long/short stock.
Parameters
----------
df_long : DataFrame
Top stocks for each ticker and date marked with a 1
df_short : DataFra... | 39459b0d68ff6c887b1de8e7303f0674578b8bac | 691,964 |
def calculate_pot_temp(pressure, temperature):
"""calculate_pot_temp
Description:
Temp * (1000/Pressure)^0.286
Return potentail temp from pressure and temperature
"""
return temperature * (1000 / pressure)**(0.286) | d8171db43bf37ad2933295e0e8b4688d34271b44 | 691,965 |
from dateutil import tz
from datetime import datetime
def convertTimeToLocal(time: str):
"""Converts an ISO format UTC time to a local time.
Args:
time: UTC time to be converted in ISO format.
Returns:
The time in local time based on POSIX TZ variable.
"""
from_zone =... | 4e1663dfda16be87b4583372944e0bdf72ce8092 | 691,966 |
from typing import Optional
def _to_volts(value: Optional[float]):
"""Convert µV to V if not None."""
if value is None:
return None
return float(value) / 1e6 | 623b6824c7307352fa01f7c00502adab8a10c451 | 691,967 |
def file_list(filename):
"""checks if the input file is a .txt file and adds each separate line
as a book to the list 'Lines'.
After return this list to download_from_txt
"""
if filename.endswith(".txt"):
try:
file1 = open(filename, "r", encoding="utf-8")
Lines = fil... | b7f82f8894539b5fde0d41438f02b70add7ed092 | 691,968 |
def activation(active_name='rrelu'):
"""Activation functions.
Parameters
----------
active_name : str, optional
The name of activation function, which can be 'relu', 'leakyrelu', 'prelu', 'rrelu',
'relu6', 'elu', 'selu', 'sigmoid', 'tanh', or 'softsign'. Default: 'rrelu'
Retur... | dabe01cee97bfe8f181478513dfced9e854e9103 | 691,969 |
from bs4 import BeautifulSoup
import re
def get_last_episode(html_content):
"""Return the highest episode number availabel (int)"""
soup = BeautifulSoup(html_content)
max = 0
for link in soup.find_all('a', text=re.compile('Episode')):
for s in link.string.split():
if s.isdigit():
... | d6df9f00b502200c54cd9d439d4e0e34eddf1e77 | 691,970 |
import re
def _project_is_apache():
"""Determine if a project is Apache.
Look for a key string in a set of possible license files to figure out
if a project looks to be Apache. This is used as a precondition for
enforcing license headers.
"""
license_files = ["LICENSE"]
for filename in license_files:
... | 417f5668851e31e2e3f5288520920c8b55c6b978 | 691,972 |
def isPhysicalUnit(x):
"""
@param x: an object
@type x: any
@returns: C{True} if x is a L{PhysicalUnit}
@rtype: C{bool}
"""
return hasattr(x, 'factor') and hasattr(x, 'powers') | 2377aa36cd3965175d95d38a5e1d4ccd6b0bc848 | 691,974 |
import hashlib
def sha_sum(fname):
"""Returns the sha256 checksum of a file.
Args:
fname (str): Path to a file.
Returns:
str: The sha256 checksum as a hex string.
"""
hasher = hashlib.sha256()
with open(fname, 'rb') as fd:
for block in iter(lambda: fd.read(65536), b""... | e3a95c962d50cdc8118b4298a3b083b7bcd6ee58 | 691,975 |
def get_labels ():
"""
Generates the labels.
Returns
-------
list : the list of labels
"""
return ["rectangle_mean", "ellipse_mean", "aspect_ratio", "area",
"area_hull", "solidity", "extent", "perimiter", "perimeter_hull",
"circularity","heywood_circularity", "wadd... | 69f03419c49c495d6278593d821fae2488efe9e0 | 691,976 |
def torrentfile_create(args, creator, name): # pragma: no cover
"""Create new .torrent file in a seperate thread.
Parameters
----------
args : `dict`
keyword arguements for the torrent creator.
creator : `type`
The procedure class for creating file.
name : `list`
contai... | 3a5f8cd94b406fa045dc71c94d5629394025e8b8 | 691,977 |
import re
def _extract_asm_operands(asm):
"""
:param asm:
:type asm:
"""
operands = " ".join(asm.strip().upper().split()[1:])
operands = operands.replace(",", " ")
return re.findall(r"[.a-zA-Z0-9_+-@]+", operands) | d215060cf93abc62c24695ade7ee76caab250eb8 | 691,978 |
def get_sorted(dictionary):
"""
Sort the dictionary
"""
return sorted(dictionary, key=lambda x: dictionary[x], reverse=True) | 666e80219196bb2221860d687c53f36efc334cd5 | 691,980 |
import re
def isCnpjValid(cnpj):
""" If cnpf in the Brazilian format is valid, it returns True, otherwise, it returns False. """
# Check if type is str
if not isinstance(cnpj,str):
return "CPF e invalido"
# Remove some unwanted characters
cpf = re.sub("[^0-9]",'',cnpj)
# Checks if s... | 5de9cd60066878cde20d1819a696c9525ba1e956 | 691,981 |
def ignore_command(command, ignore):
"""
Проверяет содержатся ли в с команде строки из списка ignore
command - строка
ignore - список слов
Возвращает True если в команде найдено слово из списка ignore, False иначе.
"""
return any(word in command for word in ignore) | f7a57e2c841c770582b8fdbb0bba5e4b494dd273 | 691,982 |
def dec2bin(decvalue, init_length):
"""Convert decimal value to binary"""
value = str(bin(int(decvalue))[2:])
return value.zfill(init_length) | 8e5b9969dfd24546792f2ecc7aed54a6b0fefb27 | 691,983 |
def mk_int(s):
"""
Function to change a string to int or 0 if None.
:param s: String to change to int.
:return: Either returns the int of the string or 0 for None.
"""
try:
s = s.strip()
return int(s) if s else 0
except:
return s | 7d1c4133c0571b25ef4f161a1bd6b1e094ebec7e | 691,984 |
def unwrapMethod(obj):
"""obj -> (unwrapped, wrapperCount)
Unwrap 'obj' until we get to a real function, counting the number of
unwrappings.
Bail if we find a class or something we can't identify as callable.
"""
wrapperCount = 0
unwrapped = obj
for i in range(10):
bases = get... | e14973b2ace0175d1b1827285b655697108f6882 | 691,985 |
import re
def find_file(string,extension):
"""
Find .extension file list from the given list and the regular expression
============== ========== =======================================================
**Parameters** **Type** **Description**
*string* string raw splitted command result contai... | 37a035cba85c6799dc86308bc89ebb7fe60c8cc7 | 691,986 |
def kortti_välissä(kortti1, kortti2, kortti3):
"""Tarkistaa onko ensimmäinen kortti kahden seuraavan välissä.
Parametrit
----------
kortti1, kortti2, kortti3 : tuple(int, str)
Vertailtavat kortit
Palauttaa
---------
True
jos kortti1 on korttien 2 ja 3 välissä.
"""
#... | c729a17530ce7b3b8feed3f388287d34d3769dcd | 691,987 |
def trySurroundSelection(editor, char, map_table):
"""Try to do char-surrounding using a mapping table.
Will not do any surrounding if a keyboard modifier key (e.g. Ctrl) is in pressed state.
If the editor has multiple selections, each selection will be surrounded separately.
:param editor: editor where to try to... | 7388f3d34c9d3a1cf6218ca1c76448092b9c2102 | 691,988 |
def squared_loss(y_hat, y): #@save
"""Squared loss."""
return (y_hat - y.reshape(y_hat.shape)) ** 2 / 2 | 323671e7d9a989870fa3ab04a8770d7fbf49b2ed | 691,989 |
def add(arg1, arg2):
"""
Function for adding two variables
"""
return arg1 + arg2 | dde33dc5030943afd9da6afd63b070045f5df09e | 691,990 |
def get_pointer_parent(pointer):
"""Given a `Pointer` object, return its parent node.
"""
# The `parent_node` property of the `Pointer` schema refers to the parents
# of the pointed-at `Node`, not the parents of the `Pointer`; use the
# back-reference syntax to find the parents of the `Pointer`.
... | b8db4f1eae1f4f723f368f993d16fa7f7c86e6c4 | 691,991 |
def read_file(file):
""" Open given file and returns the content as a string. """
with open(file) as f:
wall = f.read()
return wall | bcfb29a31ac2cfcdf5b733a0bfd3019889a30fba | 691,992 |
def linear_function(x, a, b):
""" Equation for a line.
Parameters:
x: array
The independet variable where the data is measured.
a: float
The linear coefficient.
b: float
The angular coefficient.
Returns:
f: array
The linear ... | 542ff23efb35e273043d64f0f13027792d6394a5 | 691,993 |
def rk4_ode(df_ds, x0, s, ds, *f_args, f1=None):
"""Implements Runge-Kutta RK4 for numerically solving an ODE."""
# https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods
if f1 is None:
f1 = df_ds(x0, s, *f_args)
f2 = df_ds(x0 + 0.5 * ds * f1, s + 0.5 * ds, *f_args)
f3 = df_ds(x0 + 0.5 * ds * f2, s + 0... | 5b0ed8225f5eaa07f6a14d5e9d960e19d172c98b | 691,994 |
import re
def remove_hashtags(text):
"""Remove '#' from hashtags. The hashtag text is kept as it is an organic part of the tweets"""
return re.sub('#+', '', text) | 1385c5525b104d61fb05b33dc9a53c268c6a719b | 691,995 |
def recolour(shape, source_colours, target_colour):
""" Recolours a shape from source_colours to target_colour.
>>> recolour([(0, 0, 1), (0, 1, 1), (0, 2, 1), (0, 3, 5)], [1], 4)
[(0, 0, 4), (0, 1, 4), (0, 2, 4), (0, 3, 5)]
>>> recolour([(0, 0, 1), (0, 1, 1), (0, 2, 2), (0, 3, 5)], [1, 2], 4)
[(0,... | e9a347c339cf8614917cf71a23809207fb8f2a6f | 691,997 |
import torch
def gaussian_stein_kernel(
x, y, scores_x, scores_y, sigma, return_kernel=False
):
"""Compute the Gaussian Stein kernel between x and y
Parameters
----------
x : torch.tensor, shape (n, p)
Input particles
y : torch.tensor, shape (n, p)
Input particles
score_x... | 02beba589956c8726d31afff93028d7560c3f310 | 691,998 |
import argparse
def arguments() -> dict:
"""
Console arguments.
"""
parser = argparse.ArgumentParser()
parser.add_argument(
"-s",
"--subreddits",
type=str,
default=None,
nargs="+",
help="Images would be parsed from these."
)
parser.add_argu... | 957c1266642d450168ffbad72b5547e8a4b980c7 | 691,999 |
def queue_text(state):
"""Returns a block of text describing a given song queue."""
index = 0
if len(state.playlist) > 0:
message = [f"{len(state.playlist)} songs in queue. Currently playing {state.current_index}"]
message += [
f" {index}. **{song.title}** (requested by **{song.... | a55dc91b68f23d74eb28b9d59e199cf9ce1ba753 | 692,000 |
def get_digit_num(num: int) -> int:
"""
Return sum of each in a number.
"""
res = 0
while num:
res += num % 10
num //= 10
return res | 5670ff237c913a17c1c935c165758b3c5aff9e97 | 692,001 |
def to_ini(settings = {}):
"""
Custom Ansible filter to print out a YAML dictionary in the INI file format.
Similar to the built-in to_yaml/to_json filters.
"""
s = ''
# loop through each section
for section in settings:
# print the section header
s += '[%s]\n' % section
... | dac53b16ea4b29fe6a54feab2bc20938b309ef10 | 692,002 |
def from_phase_to_jd(x, t0, p):
"""
:param x: phases
:param t0: ephemeris
:param p: period
:return: x in jd
"""
_x = [((phase * p) + t0) for phase in x]
return _x | 0a19ca676513f3e5a3ae09988d7124fd4da2a3cc | 692,003 |
def write_script(p_pth, p_contents):
"""Write a script to disk
Parameters
----------
p_pth
Path to the script
p_contents
Contents of the script
Returns
-------
subprocess.CompletedProcess
See https://docs.python.org/3.9/library/subprocess.html#subprocess.CompletedPr... | 0c4eb8bbb7d32f22d0fb07bbaaa3a05d7f90dbdb | 692,004 |
def rk2(y, f, t, h):
"""Runge-Kutta RK2 midpoint"""
k1 = f(t, y)
k2 = f(t + 0.5*h, y + 0.5*h*k1)
return y + h*k2 | 6d08e6c0893a2e71e1d2f908009e04d302d62223 | 692,006 |
import requests
def url_ok(url):
"""
Check if server at remote URL answers ok
"""
req = requests.head(url)
return req.status_code == 200 | 42380ce706a01d82b9206293b92f063e36d8300a | 692,007 |
import re
def make_name_safe(project_name):
"""
Converts a name with underscores into a valid class name (PascalCase).
E.g. test_project will become TestProject
:param project_name: the name we want to convert
:type project_name: str
"""
words = re.split('_', project_name)
result = '... | 86f634a2bbf6e5fb2f7da721690e6e83714dd3e2 | 692,008 |
from typing import Dict
from typing import List
def _cast_strings_keys_to_int(obj: Dict) -> Dict:
"""Casts string to int keys in dictionary when '__int_keys__' flag is set
Args:
obj: dictionary
Returns:
obj with string keys cast to int keys and '__int_keys__' flags removed
"""
if... | 106912f6f9d052db244963ccffc0cd4685850fb6 | 692,009 |
def A1ToXy(space):
"""Convert user-friendly coordinates (like A1 or B5) to (x, y)
coordinates (like 0,0 or 1,4)."""
column = space[0]
row = space[1:]
# The ASCII value of 'A' is 65:
return (ord(column) - 65, int(row) - 1) | 8f576cf7b8d1750dc52c3117ba075686ff29ac74 | 692,010 |
def mm__to__km():
"""Convert millimeter to kilometer"""
return '1.0E-6{kind}*{var}' | c8c32a8dcc6fcae9fa35013c06c5dba5a08802b3 | 692,011 |
import os
def get_file_names_for_dataset(name='train',
path='/Users/zeynep068/efficientdet/voc_data/'):
""" Get file names.
Args:
name: Train or validation dataset.
path: Path to dataset.
Returns: List of file names corresponding to dataset type.
"""
... | 90f0e77db84d385e9b5544a4d7b2a41d0fcfb7e1 | 692,013 |
def emission_objective(model):
"""
The emission objective calculates the total emissions.
the total emissions are equal to the amount of energy bought from which supplier * load hours * carbon emissions per MWh
:param model: model reference
:return: total emissions
"""
total_emissions = []
... | be532bfb30e1a3bcef7335ed7058ad977fdee9a2 | 692,014 |
def common_cols(df1,df2):
""" Return the intersection of commun columns name """
return list(set(df1.columns) & set(df2.columns)) | 1119806c0ba43ba4c5e272c8292b40c201e3f952 | 692,015 |
def date_remove_dashes(std_date):
"""STD_DATE is a date in string form with dashes. Removes dashes for storage in JSON."""
return std_date[0:4] + std_date[5:7] + std_date[8:] | 67e6337a90d6d966325cdd96f4b1844da540fa2e | 692,016 |
def frequencies_library(peptides):
"""
Calculate the frequency of each amino acid in a particular peptide library
Arguments:
peptides -- List of peptides in the library
Return:
count_dict -- Dictionary with the numbers per each natural amino acid
"""
# Create counter dicti... | 55f21fba2cf836daca1eaeb6a3f07ff78cd61776 | 692,017 |
def to_interval(points: list):
""" Transforms the set of points into set of intervals - Orthogonal hull
Args:
points (list of tuples): which are the points
Example:
POINT INTERVALS
A B X Y
[(0, 2), (1, 3)] --> [[0, 1], [2, 3]]
... | 782a6f41b536091a9aceff3ea216c3aa100e7aff | 692,018 |
import pkg_resources
def goodstuff():
"""Shortcut for specifying path to goodstuff.j2k.
Returns
-------
file : str
Platform-independent path to goodstuff.j2k.
"""
filename = pkg_resources.resource_filename(__name__, "goodstuff.j2k")
return filename | 0c900c59b17a4be923a56eebe07fdd328b1f907c | 692,019 |
def setup_method_options(method, tuning_options):
""" prepare method specific options """
kwargs = {}
# Note that not all methods iterpret maxiter in the same manner
if "maxiter" in tuning_options.strategy_options:
maxiter = tuning_options.strategy_options.maxiter
else:
maxiter = 10... | a83ab4dc597a2818ebe258100a5c401a4bfedc33 | 692,021 |
def local_time(time):
"""Returns the local time of the given (e.g. UTC) time.
Args:
time: A `datetime.datetime` object.
Returns:
A `datetime.datetime` object with local (system) time zone.
"""
return time.astimezone() | 085a59e16d9aeec30e861d2e97ae196e18ac6b46 | 692,023 |
def search(state, path):
"""Get value in `state` at the specified path, returning {} if the key is absent"""
if path.strip("/") == '':
return state
for p in path.strip("/").split("/"):
if p not in state:
return {}
state = state[p]
return state | 49b19542dc8ddf0a0c29494dbe1e6a14f269734a | 692,024 |
import configparser
def convert_ini2json(ini_file_name):
""" Convert INI parms to JSON for use in the Docker containers"""
ini_json = {}
cfgp = configparser.ConfigParser()
cfgp.read(ini_file_name)
for section in cfgp.sections():
ini_json[section] = dict(cfgp.items(section))
return ... | 5f7dfaa19669a8c219b7313d053f3ef1421c9b0a | 692,025 |
def has_el(el, el_name):
"""Return True if an element with a given name exists in the branch rooted at el"""
return True if el.xpath(f'.//{el_name}') else False | 8deba680775ba0d0b49c99c2acecbd2833da793d | 692,026 |
def metadata_cid(nft_project, artwork_path):
"""NOTE: This actually makes HTTP calls"""
content_hash_map = nft_project.pin_artwork(artwork_path)
content_hashes = [f"ipfs://{cid}" for _, cid in content_hash_map.items()]
nft_metadata_list = nft_project.create_nft_data(content_hashes)
folder_cid = nft_... | aa41768252e593065b0650a02d1c5ea31fb68d87 | 692,028 |
def make_tree(words):
"""
Method to transform parser data into a trie DS (keys stored as BST), aka nested hash map
time complexity : O(M*logN), where M - max. string length, N - number of items,
search - O(M)
penalty - storage requirements
"""
## creates our root dict()
trie = dict()
... | 1df537c90f765105d13c04134acd03fd20804c54 | 692,029 |
import json
def _get_layerconfig_from_json(file):
""" JSONファイルの読み込み
"""
config = None
with open(file,'r') as stream:
config = json.load(stream)
return config | 951bb5fdd9e3a74e623b168daf8ced750ff091dc | 692,030 |
import torch
def optimizer_creator(model, config):
"""Returns optimizer"""
return torch.optim.SGD(model.parameters(), lr=config.get("lr", 0.1)) | 9c0aea37d942615ee77b60b9a5e0651d9f87dbe8 | 692,031 |
def parser_html(json_data, content=''):
"""parser html and return content
資料結構應該要長[{[],[],[]}],回傳 str
"""
for c in json_data:
for k2, v2 in c.items():
#print(k2, '-->', v2)
if k2 == 'h1':
content = content + v2 + '\r\n'
elif k2 == 'h2':
... | 7e3996a17df825959368211d211789bf6f0bc804 | 692,032 |
def get_dict_list(data_array):
"""Returns a list of dictionaries based on the column headers
(the 0th line in the column headers)
"""
key_list = data_array[0]
dict_list = []
for index, line in enumerate(data_array[1:]):
params = {}
for i in range(len(key_list)):
# t... | bd39aea582205bbd39b111ba344f132f55e97c8b | 692,033 |
from datetime import datetime
def convert_str_to_date(date: str):
"""
Function to convert a date in a string format into a datetime YYYY/MM/DD.
:param date: (str) Date in a string format
:return: (datetime) return datetime of a string date. The time will always be 0.
"""
try:
return d... | 7dc57344cc99f8c9066aedddddd89f479764b444 | 692,035 |
def _get_date_fields(date):
""" This function converts a datetime object to a map object contaning the date.
Args:
date: Type datetime.
Returns:
map object in the format {'year':int, 'month':int, 'day':int}.
"""
return {'year': date.year, 'month': date.month, 'day': date.day} | 47887e57a610ae94a8b7618e53c477357bcffe36 | 692,036 |
from typing import Any
def maybelen(value: Any) -> int:
"""
A "maybified" version of the len() function.
"""
return len(value) | 2b43e4bc7a52fa7a854915f12d0bb324663596e0 | 692,037 |
import re
def pulse_factory(cls, name=None, **kwargs):
"""Returns a function that creates an instance
if the given pulse class.
Keyword arguments are passed to ``cls.__init__()``.
Args:
cls (type): Subclass of Pulse of which to create an instance.
name (optional, str): Name of the re... | 9ab2b10960e2484e5b761721740e14674f89ec05 | 692,038 |
def _in_directories(filename, dirs):
"""Tests whether `filename` is anywhere in any of the given dirs."""
for dirname in dirs:
if (filename.startswith(dirname)
and (len(filename) == len(dirname) or filename[len(dirname)] == '/')):
return True
return False | fc93e4bef45a4364446c0daa3e5969f143fbacc4 | 692,039 |
import random
def gen_sequence(length):
"""
Generates a test sequence to hash of size length
:param length: size of sequence
:return: bytes sequence of length length
"""
options = ['a', 'b', 'c', 'd', 'e', 'f']
string = ''.join([random.choice(options) for _ in range(length)])
return st... | da2562a6d88184c0498546c90c2057ee93e79e00 | 692,040 |
def is_sha256(content):
"""Make sure this is actually an valid SHA256 hash."""
digits58 = ('0123456789ABCDEFGHJKLMNPQRSTUVWXYZ'
'abcdefghijkmnopqrstuvwxyz')
for i in range(len(content)):
if not content[i] in digits58:
return False
return le... | 0f1f9a69797ac652737bfad9c5eceade59174811 | 692,042 |
def _float_parameter(level: float, maxval: float):
"""Helper function to scale a value between ``0`` and ``maxval`` and return as a float.
Args:
level (float): Level of the operation that will be between [0, 10].
maxval (float): Maximum value that the operation can have. This will be scaled to
... | b13f0fe99f921997f4b54b93f3d2649c2ea8253a | 692,043 |
import string
def _get_symbol(i):
"""Finds the i-th ASCII symbol. Works for lowercase and uppercase letters, allowing i up to
51."""
if i >= len(string.ascii_letters):
raise ValueError(
"Set the use_opt_einsum argument to True when applying more than "
f"{len(string.ascii_l... | 65197c4d43792e52db9c596f40fe3802291e256b | 692,044 |
def num_from_bins(bins, cls, reg):
"""
:param bins: b x 2 tensors
:param cls: b long tensors
:param reg: b tensors
:return: bin_center: b tensors
"""
bin_width = (bins[0][1] - bins[0][0])
bin_center = (bins[cls, 0] + bins[cls, 1]) / 2
return bin_center + reg * bin_width | 77fc74dd8c084009c8c306321d1608de9a15e092 | 692,045 |
def monthlyCorr(xlabel):
"""
"""
df = xlabel['k'].reset_index()
cluster_size = df.groupby('k')['ProfileID'].count().rename('cluster_size')
month_lbls = df.groupby(['k',df.date.dt.month])['ProfileID'].count().unstack(level=0)
# month_lbls = clusterColNames(month_lbls)
month_likelihoo... | b907beda1fb60868425b57d6cc4f73dc8e46c90f | 692,046 |
def per_iter(per_iter, n_iter, result, header):
""" Optionally modifies speed functions to produce per-iteration results.
Args:
per_iter: Whether or not to do the modification.
n_iter: The number of iterations.
result: The speed estimate.
header: The unmodified header.
Returns:
result: result... | a3cc08de96b9d00fab2df64be9087a7e4eb4cc81 | 692,047 |
def get_filenames(i):
"""Returns the filepaths for the output MusicXML and .png files.
Parameters:
- i: unique identifier for the score
Returns:
- (sheet_png_filepath, musicxml_out_filepath)
"""
output_folder_prefix = "dataset/"
sheet_png_out_filepath = output_folder_prefix + "{}-s... | 4e26391eff80e08756431221d53c862c810c8071 | 692,048 |
def hass_client(hass, aiohttp_client, hass_access_token):
"""Return an authenticated HTTP client."""
async def auth_client():
"""Return an authenticated client."""
return await aiohttp_client(hass.http.app, headers={
'Authorization': "Bearer {}".format(hass_access_token)
})
... | bf7c568de945a03fd7c5ae4525f7b884587572e0 | 692,049 |
def code(visitor, block):
"""
Format:
{% code %}
code
{% endcode %}
"""
return block['body'] | f36c140a6e5a793e50ca7aa53008036b1ed37651 | 692,050 |
def retry_once(self):
"""Task that fails and is retried. Returns the number of retries."""
if self.request.retries:
return self.request.retries
raise self.retry(countdown=0.1) | 903695931ee7c7620c1b31d593a239014b9d83d8 | 692,051 |
def get_value(df, n_intervals):
"""Function which outputs the tweet text given the interval for live updates"""
text = df['tweet'][n_intervals]
return text | 8d08fa10efb57382e72f18e65d5b53492d14fbb6 | 692,052 |
def add(vector1,vector2):
"""
Calculate the sum of vector1 and vector 2
:param vector1: list of numerical values
:param vector2: list of numerical values
:return:
"""
return [vector1[i] + vector2[i] for i in range(len(vector1))] | 2a8bbfb9aad6d05fe08c1798bc2eceb99fd81266 | 692,053 |
def intersect_paths(paths1, paths2):
"""Intersect graph paths."""
if not isinstance(paths1, list):
paths1 = list(paths1)
if not isinstance(paths2, list):
paths2 = list(paths2)
index1 = {seq for seq, alts in paths1}
index = {seq for seq, alts in paths2 if seq in index1}
paths1 ... | b9eb51b8bd872f61b5ebf0997cfc935750c125f5 | 692,054 |
def split_list_by(lst, key):
"""
Splits a list by the callable *key* where a negative result will cause the
item to be put in the first list and a positive into the second list.
"""
first, second = [], []
for item in lst:
if key(item):
second.append(item)
else:
first.append(item)
retu... | de69cf738f6bfbaf1b81245d9ad89ba906f1ca71 | 692,056 |
def create_padding_block(sizeOfPaddingAndHeaderInBytes):
"""
Creates an analog UXG binary padding block with header. The padding block
is used to align binary blocks as needed so each block starts on a 16 byte
boundary. This padding block is also used to align PDW streaming data on
4096 byte bounda... | 29432db62e06fa57380df805b372aca110f62cdd | 692,057 |
import json
def load_json_hyper_params(file):
"""
Loads hyper_parameters dictionary from .json file
:param file: string, path to .json file
:return: dict, hyper-paramters.
"""
with open(file, mode='r') as f:
hyper_params = json.load(f)
print('Read %d hyperparameters from %s' % (len... | 7e901ddcd707c2207ecf71644a82bdd207057c2e | 692,058 |
def peso_ideal():
"""
Tendo como dados de entrada a altura de uma pessoa, construa um algoritmo que calcule seu peso ideal,
usando a seguinte fórmula: (72.7*altura) - 58
1 - Pedir altura
2 - usar fórmula
3 - retornar peso
4 - Chamar função
"""
altura = float(input("Digite sua altura:... | e8a067adeacd6f4e0e0cc7c8a03472999791500e | 692,059 |
def truncate_string(s, limit=140):
"""Truncate a string, replacing characters over the limit with "...".
"""
if len(s) <= limit:
return s
else:
# Try to find a space
space = s.rfind(' ', limit - 20, limit - 3)
if space == -1:
return s[:limit - 3] + "..."
... | aa476e750fe8d4864d06791ab89a1e9324f4f7c5 | 692,061 |
def p1_rec(input_list, out=0):
"""Compute some of numbers in list with for loop."""
if len(input_list) > 0:
p1_rec(input_list[1:], out+input_list[0])
else:
return out | 948749ed4914b1c48cb3b50ee683fc1192a75b0b | 692,062 |
import logging
def judge_payload(response, use_json):
"""
Pull out the request payload, provided it's either text or json.
"""
try:
if response.status_code:
pass
except Exception as exc:
logging.error('No response to HTTP query. Returning -None-.')
return None
if response.status_code ==... | 46bc3703ee25512490123b0539cfdbc11b9ae937 | 692,063 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.