content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import requests
def consume(session: requests.Session, response: requests.Response, key="items"):
"""
Consume all pages of an API request.
"""
items = response.json()[key]
while "_next" in response.json()["_links"]:
response = session.get(response.json()["_links"]["_next"])
respons... | cc77a0d47a8568edff9a112796fcec2781e3f075 | 44,631 |
from typing import Dict
import os
def set_build_tools(triplet: str) -> Dict:
"""
Sets the environment for compilation. This will actually set
TOOL=triplet+tool where tool can be gcc, g++, etc...
:param triplet: a triplet in the form "riscv64-linux-gnu"
:return a dictionary corresponding to the env... | ed6d1844995ad307ddb095684ed2ae1b8a147bfa | 44,633 |
import sys
import os
def get_system_info():
"""
Return os and desktop information
Param: None
Return: os_name - name of the current operating system
- linux, windows, osx, unknown
desktop_env - name of the desktop environment
- gnome, unity, aqu... | 16aed55d8252f2d60cc7a889658eb096991f782c | 44,635 |
def base26(w):
"""Convert string into base26 representation where a=0 and z=25."""
val = 0
for ch in w.lower():
next_digit = ord(ch) - ord('a')
val = 26*val + next_digit
return val | b929ec5c9dcfbc4254fc0f4d646ac24537c22b72 | 44,636 |
def grade_distribution(parsed_list, max_grade, bin_number=10):
"""
This funtion calculates the distribution of the given grades by splitting
them into 'n' equal bins (intervals) and finding the number of grades
corresponding to each bin. The bins are left-closed, right-open:
[a, b) = x | a <= x < b,... | 73fbd33cd1c7f9fb043f62d949749a39c2db33d1 | 44,637 |
import sys
def get_instance(module, class_name, *args, **kwargs):
"""
Return an instance of the object based on module name and class name.
:param module: module name.
:param class_name: name of class to instantiate.
:param args: args to pass to class.
:param kwargs: keyword args to pass to c... | 45293abcc649af2ede4f5ff7a25e0c0347f41507 | 44,639 |
def getCumPos(chrom,pos):
"""
getCumulativePosition
"""
n_chroms = int(chrom.max())
x = 0
for chrom_i in range(1,n_chroms+1):
I = chrom==chrom_i
if I.any():
pos[I]+=x
x=pos[I].max()
return pos | 25e3781c3341215df78b8eb8cbbc3a37e53a3d4c | 44,642 |
def poly_filename():
"""
"""
return 'solution.csv' | 870af4a4c63fe6e449a773b6b055d88a57310c9f | 44,644 |
def normalise_version_str(version_num, normal_len):
"""Normalise the length of the version string by adding .0 at the end
>>> normalise_version_str(1.0, 3)
1.0.0
>>> normalise_version_str(1.0.0, 4)
1.0.0.0
"""
version_num_parts = len(version_num.split("."))
if version_num_parts < norma... | e844416c617a2ca61399848a5d0090eafcfcb832 | 44,646 |
import warnings
def get_weight(target_easy_negative, easy_negative, hard_negative):
"""
Args:
target_easy_negative ([type]): [description]
easy_negative ([type]): [description]
hard_negative ([type]): [description]
Returns:
w_h, w_e: scaling factor for hard and easy and ne... | 56d8bcbcfc21145a164ca1882d245225e13cf5c7 | 44,647 |
def _parse_single_key(keystr: str) -> str:
"""Get a keystring for QKeySequence for a single key."""
return 'Shift+' + keystr if keystr.isupper() else keystr | 2e9d54622871b6c347d7569bdc67d63754381b4f | 44,650 |
def normalize_empty_to_none(text):
"""Return verbatim a given string if it is not empty or None otherwise."""
return text if text != "" else None | 4d15f1101efe87e58e3855cef5d131b1c5eacef6 | 44,651 |
def run_if_true(function, boolean, data):
"""
Run the given function if the boolean is true.
Else return the data.
"""
if boolean:
return function(data)
return data | ea9facfed120a8fdd88717375c76c93b77edbfcf | 44,652 |
def _find_weather_data(tables):
"""`tables` is a list of dataframes returned by `pandas.read_html`"""
for i, raw in enumerate(tables):
if len(raw) > 16:
return raw | dd2cf0be1d4591d9def6a10e728ebf23738db608 | 44,653 |
def stations_level_over_threshold(stations, tol):
"""Returns a list of tuples of stations at which the latest water level
is greater than the input tolerance"""
res = []
for station in stations:
if (station.relative_water_level() != None) and (station.relative_water_level() > tol):
r... | d7363c8836d7a80c8430f1b4b4792000aaa4c268 | 44,655 |
import os
def parse_sample_file_path(parser, args):
"""
Return validated input file path or terminate program.
"""
try_help_msg = "Try '%s -h' for more information" % parser.get_prog_name()
if len(args) != 1:
parser.error("Please provide a valid file path\n%s" % try_help_msg)
sample_fi... | 683aceac3436800061e6db1d955342a2c2fd8a87 | 44,657 |
def personal_top_three (scores):
"""
:param scores - list of high scores
:return: list of int - the three highest scores from the list
"""
result = []
scores_copy = scores.copy ()
scores_copy.sort (reverse = True)
if len (scores) <= 3:
return scores_copy
return [scor... | ed1d6302403db6cdb917ff6db88027e9a6159eb6 | 44,658 |
def get_synplas_morph_args(config, precell=False):
"""Get morphology arguments for Synplas from the configuration object.
Args:
config (configparser.ConfigParser): configuration
precell (bool): True to load precell morph. False to load usual morph.
Returns:
dict: dictionary contain... | 3410bf9aa3987dc626310affb8ebbd13b382c5d9 | 44,659 |
def get_f_C_i(f_ang_C, f_sh_C):
"""開口部iの冷房期の取得日射熱補正係数 式(3b)
Args:
f_ang_C(float): 冷房期の垂直入射に対する斜入射の規準化日射熱取得率
f_sh_C(float): 冷房期の日除け効果係数
Returns:
float: 開口部iの冷房期の取得日射熱補正係数
"""
return f_ang_C * f_sh_C | 1b2db34a14fae093c5603e4352992a87431831d9 | 44,660 |
import os
import glob
def get_test_parameter_file_list():
"""Contains the test parameter file paths
Returns:
list[str]
"""
absolute_current_file_path = os.path.abspath(__file__)
current_directory = os.path.dirname(absolute_current_file_path)
test_directory = os.path.join(current_dir... | f6fe15975422adeb6a7122e53be4f4ab687059d7 | 44,661 |
def load_cov( cov_file ):
"""! @brief load all information from coverage file """
cov = {}
with open( cov_file, "r" ) as f:
line = f.readline()
header = line.split('\t')[0]
tmp = []
while line:
parts = line.strip().split('\t')
if parts[0] != header:
cov.update( { header: tmp } )
header = part... | d067aa2a8742b7555778a1cd0f38be641cc6ed56 | 44,662 |
def checkPointsButtonClicked(game, clickX, clickY):
"""
Returns true if points button was clicked, else false
"""
return (game.pointsButtonObj is not None and
game.pointsButtonObj.collidepoint(clickX, clickY)) | f95c7190db951b072d7517a3ec16641358a8a027 | 44,663 |
def seq_to_list(seq):
""" Convert non-sequence to 1 element sequence, tuples to lists
"""
if not isinstance(seq, (list, tuple)):
return [seq]
return list(seq) | 460275a31e023f47dd0b0fba0289e0c3804c6f34 | 44,664 |
def mock_purge_success(url, request):
"""
Mock a success Purge request
"""
return {'status_code': 201,
'content-type': 'application/json',
'server': 'Apache',
'content-location': '/ccu/v2/purges/1234-456-7890',
'content': {
"estimatedSecond... | eef7a0325bf81a98339fa82ba022bd994675de8e | 44,665 |
import re
def should_filter(line, num):
"""Test the given line to see if it should be included. Excludes shebang
lines, for now.
"""
# Filter shebang comments.
if num == 0 and line.startswith('#!'):
return True
# Filter encoding specification comments.
if num < 2 and line.startswit... | 3c82c67ce9b569d99c26fea37b37a4e1dbc51cd4 | 44,666 |
from typing import Tuple
def decode_seat_of(pass_: list, n_rows: int = 128, n_cols: int = 8) -> Tuple[int, int]:
"""Return row and column number from boarding pass information."""
row_range = [1, n_rows]
col_range = [1, n_cols]
for char in pass_[:7]: # decode row
if char == "F":
... | 65a5502ad4eea05db08b4127bb6af6db1ad41db2 | 44,667 |
def read_rrup_file(rrup_file):
"""Read rupture(?) file"""
rrups = dict()
with open(rrup_file) as f:
next(f)
for line in f:
station, __, __, rrup, rjbs, rx, ry = line.rstrip().split(",")
rrup = float(rrup)
rjbs = float(rjbs)
if rx == "X":
... | f6b00218b412ac08873fd089fcb34a8f57375736 | 44,668 |
def log_dir():
"""Nмя произвольного каталога."""
return r'D:\log_dir1' | 150744b1c11bb475f35a7d997ceafcc4556a0c7e | 44,669 |
import os
def build_image_list(path):
"""
Recursive function for building a list of image files (jpg and png) for the path specified. The function is
recursively invoked for each sub-directory.
:param path: the path from which to search for image files. Any directories found in the path will result i... | 9ec3a53c63471a3a1e73fc8c0bedaad4c02d6788 | 44,670 |
def get_country(countries):
""" Get country code as input from user and check if country code in the list of countries obtained from the preprocessed data. Return country code in uppercase.
:param countries: the list of country code
:type countries: list
:returns: the entered country code
... | a043198eaf0614c60397e7f3df875d3a2ac6e9ba | 44,671 |
def gen_composite_processor(*funcs):
"""Applies the each func on the metrics in a chain"""
def composite_processor(host, name, val, timestamp):
tmp = host, name, val, timestamp
for func in funcs:
tmp = func(*tmp)
if tmp is None:
break
return tmp
... | 9c0ee4a7f987fc458a309c9eccf4878c1f548ca5 | 44,672 |
def prepend(v, l):
""" Given a value, prepend it to an iterable or a list
Returns a concrete list if given a list and a generator otherwise.
Ignores None as l
"""
if isinstance(v, list):
tmp = v
tmp.extend(l)
return tmp
else:
def generator(): # pragma: no cove... | 1aa01f9d988a7e5b907e969ee36df6ec6e6998e9 | 44,673 |
def e_filter(e):
"""Filters out unwanted elements"""
ignore_tags=('sdfield',)
if e.tag in ignore_tags:
return True | cb14154bedee50e9913749d381cf2db2690d7843 | 44,674 |
import re
def is_valid_zcs_container_id(zcs_container_id):
"""
Validates Zadara Container Services (ZCS) container IDs, also known as the
ZCS container "name". A valid ZCS container name should look like:
container-00000001 - It should always start with "container-" and end with
8 hexadecimal cha... | 9b8ef0e6281def4d09e787123e9582c9c4be9c84 | 44,675 |
import torch
def simple_contrstive_loss(vi_batch, vi_t_batch, mn_arr, temp_parameter=0.1):
"""
Returns the probability that feature representation for image I and I_t belong to same distribution.
:param vi_batch: Feature representation for batch of images I
:param vi_t_batch: Feature representation fo... | 55c8973fce464e440540d7a67305b87f985e75e5 | 44,676 |
import struct
def int2vector_unpack(data, unpack = struct.unpack):
"""
Given a serialized int2vector, unpack it into a list of integers.
An int2vector is a type used by the PostgreSQL catalog.
"""
return unpack("!32h", data) | 0adcffbe71bf20d29169a545bf7679648f63323c | 44,677 |
import numpy
def _binary_image_to_grid_points(binary_image_matrix):
"""Converts binary image to list of grid points.
This method is the inverse of `_grid_points_to_binary_image`.
:param binary_image_matrix: See documentation for
`_grid_points_to_binary_image`.
:return: rows_in_object: Same.
... | 1b9c78e2aa0d48e003c399c21bfce22cf33ff641 | 44,679 |
def get_hmt_balance(wallet_addr, token_addr, w3):
""" Get hmt balance
Args:
wallet_addr: wallet address
token_addr: ERC-20 contract
w3: Web3 instance
Return:
Decimal with HMT balance
"""
abi = [
{
"constant": True,
"inputs": [{"name":... | 4f968d48908ed0739aa3ab5cc7316e756d51bdb2 | 44,680 |
from typing import List
def encode_varint(value: int) -> bytes:
"""Encodes a single varint value for serialization."""
b: List[int] = []
if value < 0:
value += 1 << 64
bits = value & 0x7F
value >>= 7
while value:
b.append(0x80 | bits)
bits = value & 0x7F
value... | 63a5428702c23e98e2d8bd82051d26e2b20cbf51 | 44,681 |
def recursive_merge_dicts(a, b):
"""Recursively merge two dictionaries.
Entries in b override entries in a. The built-in update function cannot be
used for hierarchical dicts, see:
http://stackoverflow.com/questions/3232943/update-value-of-a-nested-dictionary-of-varying-depth/3233356#3233356
Param... | c4ed405ae2de4b7c7567a68cb25fb2d62cc5a196 | 44,682 |
def bk_column_names():
"""Returns list of column names from test piecash books, that are needed in creation of several bokeh views."""
columns = ["Category", "MonthYear", "Price", "Product", "Date", "Currency", "Shop"]
return columns | 21fe96d4c85ec008a0a32631e207d1d554c4c8dd | 44,683 |
def double_char(s):
"""Return word with double characters."""
word = ''
for i in s:
word += i * 2
return word | 7460bf28267dafa68b776c4b24d32c9084272731 | 44,684 |
def formatString(s):
"""Add a predefined number of spaces after the ':' character."""
try:
index = s.index(': ')
s0 = '{:<20}'.format(s[0:index])
s0 += s[index:]
return s0
except ValueError: # can be thrown by string.index()
return s | c58fbe1a0208ef894bf95f029798885835c6a7da | 44,685 |
def _is_git_index_exists(repo_ctx, repo_local_cache_path):
""" Checks that a local git index exists at the repository cache path
Args:
repo_ctx: Repository context of the calling rule
repo_local_cache_path: Path of the repository cache folder
Returns:
Boolean in... | 8064cd6afedd429d6b8ff83bea7c0cdd6a906437 | 44,686 |
def is_path_like(obj, attr=('name', 'is_file', 'is_dir', 'iterdir')):
"""test if object is pathlib.Path like"""
for a in attr:
if not hasattr(obj, a):
return False
return True | 858cfc52144e19d539f4074d50776cf03281fcc4 | 44,687 |
def read_label_map(path_to_labels):
"""Read from the label map file and return a class dictionary which
maps class id (int) to the corresponding display name (string).
This functions expects a txt, not pbtxt file
"""
with open(path_to_labels,'r') as f:
return {i: c for i,c in enumerate(f.rea... | 9e7d1e3445cbc21b48389f0d0666a281e2b0eee2 | 44,688 |
import argparse
def parser(options=None):
""" Parser for auto VetRedRockGui
Parameters
----------
options
Returns
-------
"""
parser = argparse.ArgumentParser(description='Run the VetRedRockGUI on\
RedRock output')
parser.add_argument(
... | 92feda1a9095c984e1809539229c96d5e8ac4d45 | 44,690 |
from typing import List
def config_noisy(shots: int, optimization_level: int, transpiler_seed: int,
initial_layout: List[int], seed_simulator: int, private_config: dict
) -> dict:
"""The configuration loading for the noisy simulation.
Args:
shots: Number of shots to be used in the no... | 2937ee790e7c9f91874e3b6581b1345cfce52c7f | 44,692 |
def _draw_leg_bbox(ax):
"""
Draw legend() and fetch it's bbox
"""
fig = ax.figure
leg = ax.get_legend()
fig.canvas.draw()
return leg.get_frame().get_bbox() | 51c30cfb1f91bcf4ad0e53e8fddab404ff398e60 | 44,693 |
import torch
def sig(gain: float, offset: float, x: torch.Tensor) -> torch.Tensor:
"""Computes element-wise sigmoid function.
Args:
gain: The sigmoid function gain.
offset: The sigmoid function offset.
Returns:
The sigmoid function evaluated for each element in the tensor.
"""
... | 2fb626d5a75b5859003bf0960afbce4b6a9b5f52 | 44,694 |
import argparse
def get_args():
"""
Parse and return the inputs arguments.
"""
parser = argparse.ArgumentParser(
description='LCLS2 MPS RTM Test Application')
parser.add_argument(
'--yaml',
type=str,
required=True,
dest='yaml_file',
help='Path to th... | 76635d1bd5fbddec49f5fc1fc3de921d9adbfae3 | 44,695 |
def default_not_in_transformer(row, lhs, rhs):
"""
Performs the in check of the lhs is not in the rhs. If the lhs has an
`is_not_in` method this is used, if not the `not in` operator is used.
:param row: The row being checked (not used)
:param lhs: The left hand side of the operator
:param rhs:... | d0a1974a9f127a014acbd92ed64cbf8aea8181cb | 44,697 |
def get_list(env, name, default=None):
"""Get a list from the environment
The input is assumed to be a comma-separated list of strings.
If ``name`` is not found in ``env``, return ``default``. Note
that ``default`` is returned as-is, so you should usually specify it as a
list::
ALLOWED_HO... | efbab4f49b065293101b1f42aecac002a53ebf98 | 44,698 |
def find_pages_range(soup):
"""
:param soup: soup object search result page
:returns: max page number of results
"""
pages = soup.find("ul", {'class': "pages_ul_inner"})
if pages:
results = pages.find_all('a')
page_max = results[-1].string
elif pages is None:
page_max... | def07a17f42a50def8887b5197d12c7a0f650ce0 | 44,700 |
def list_salesforce_api_versions():
"""Helper function to return a list of supported API versions"""
return [
{
"version": "20.0",
"label": "Winter '11",
"url": "/services/data/v20.0"
},
{
"version": "21.0",
"label": "Spring '11... | 3eb434a106bfbed018071f889a56f2f0bf4281c2 | 44,701 |
def get_env():
"""
Get settings file directory.
"""
return 'settings.environment.local' | 660c66b21aaf6a2d671456450804838cf28a8e0d | 44,702 |
def filter_title(job):
"""Filter out job title and link to listing."""
job_title = job.find('a', attrs={'class': 'job-link'}).text
link = job.find('a', href=True).attrs['href']
job_link = 'https://stackoverflow.com{}'.format(link)
return(job_link, job_title) | cdda84b4e8dd35ba233b60bd76d2a190c583a5a8 | 44,704 |
def bytes_to_int(bs):
""" converts a big-endian byte array into a single integer """
v = 0
p = 0
for b in reversed(bs):
v += b * (2**p)
p += 8
return v | 275801405b629a68c77bd07e5ddd10db376c2963 | 44,706 |
def getcookies():
"""
Input:
raw_cookies(str): 豆瓣cookie
Return:
cookies(dict):豆瓣cookie
"""
while True:
try:
raw_cookies = input('\n--------------------\
\n\n请输入你的cookie(最后不要带空格):')
cookies = {}
for line i... | 2298c9034c8e32846581e5dcf3644bc9162c13a1 | 44,707 |
import subprocess
import shlex
def os_cmd(cmd):
"""
Wrapper around subprocess
@param cmd: command to be run
@return: exit code of the process and tuple of stdout and stderr of the process
"""
p = subprocess.run(shlex.split(cmd), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
return p.retu... | bdc2eae499ac0371e314c4bf66e5366f9d6a55d3 | 44,708 |
def zipl(*lists):
"""
Equivalent to python2 zip, return a list instead
of a generatory in python3
"""
return list(zip(*lists)) | 1e2d7fb73782b678e172fda6cb1ac5e9fce625d0 | 44,709 |
from datetime import datetime
def get_FY_short(the_date=datetime.now()):
"""Return 2-digit current fiscal year as integar"""
if the_date.month > 6:
return the_date.year - 2000
else:
return the_date.year - 2001 | 8bbd206f8e5ef0dfc10ea2c416c4e41a285ee9ab | 44,711 |
def to_download_url(path):
"""Returns an url to filebrowser views.py download function """
return '/filebrowser/option?name=download_resource&path=' + path | 3b7a8e88ec476906fec1294f690a4267f80da32c | 44,712 |
from typing import List
def half_range(data: List[float]) -> float:
"""
Calculates the absolute uncertainty associated with a set of data.
Parameters
----------
data
List/tuple of the data
"""
return (max(data) - min(data))/2 | d84ec375a0f3a5c8a29661a2d6c53cff15b7761f | 44,713 |
def get_available_summary_methods():
"""Output the available metrics for summarizing output scores"""
return ["mean", "median"] | cd982d66d241aa7cf8731214babc8689a8c9a74f | 44,714 |
def _isnan(num):
"""Determines whether a string or float is NaN
(1, sign, diagnostic info as string) => NaN
(2, sign, diagnostic info as string) => sNaN
0 => not a NaN
"""
num = str(num).lower()
if not num:
return 0
#get the sign, get rid of trailing [+-]
sign = 0
if nu... | 15e920fb45dcec819e5036444a1671b4f8fe7593 | 44,715 |
import csv
def read_employees(csv_file_location):
"""
Takes a CSV file, registers a dialect, reads the CSV file and returns an employee list
"""
with open(csv_file_location) as file:
csv.register_dialect('empDialect', skipinitialspace=True, strict=True)
reader=csv.DictReader(file,diale... | 795114273ddc1930a968a516397781801ae22ab1 | 44,716 |
def generate_all_ev_combinations():
"""Generate all possible stat investment combinations."""
combinations = {}
combinations["atk"] = []
combinations["spa"] = []
atk_combinations = []
atk_combinations.append((False, False))
atk_combinations.append((True, False))
atk_combinations.append(... | add6f1ece638bbe927e4164d7617084c3b9af75c | 44,717 |
def parsesummaryfilecontents(info):
"""
parse info from contents of summary file
input: info struct
output: info struct (with even more info)
"""
# for a start, just take the last five lines of the
# summary file (includes a final empty line)
data = open(info.path, 'rt'... | a0a560b590aaa685c03808dfd99183759b495fe2 | 44,718 |
def get_attribute(class_name, attribute):
"""
Magic method that will be used by the Metaclass created for Itop object.
The function will avoid raising an exception if the atrtibute requested does not exist but rather return None.
Parameters
----------
attributes: str
The attribute from ... | ec9dfd2a6235b484d00e9663f9954a9cd94b7974 | 44,721 |
def coll_types(coll):
"""
Return iterator over types in collection
"""
return coll.types() | eb66707a0c3397973aff16e4893c6d33b3b6c333 | 44,722 |
import os
def read_sequence(filepath):
"""
Read in a single sequence given a .fa file
"""
basename = os.path.basename(filepath)
name = os.path.splitext(basename)[0]
with open(filepath, "r") as f:
input = f.readlines()
seq = ''
for row, text in enumerate(input[1:]):
... | db3f9c18121721b32665405ddd288ebf05374322 | 44,723 |
def get_words_from_dictionary(lemmas):
"""
Get original set of words used for analysis.
:param lemmas: A dictionary where keys are lemmas and values are sets
or lists of words corresponding to that lemma.
:type lemmas: dict(str): list(str)
:return: Set of words that exist as values in the d... | 2ddf017811cbe91a5cfcf4fbc37730554ec77d2a | 44,725 |
import random
def get_random_lat_long():
"""
Return a tuple with random latitude and longitudes.
:param tuple(float, float): latitude, longitude
"""
return (random.uniform(-90.0, 90.0), random.uniform(-90.0, 90.0)) | fd60221ebbf807df349991d606049755ca24d01e | 44,726 |
import hashlib
def hash_list(argv, size=8):
"""
Proposes a hash for the list of arguments.
@param argv list of arguments on the command line.
@param size size of the hash
@return string
"""
st = "--".join(map(str, argv))
hash = hashlib.md5()
hash.update... | b9371185889fd37408ff9f46b41e874f8dd9a029 | 44,727 |
def get_first_timestamp(busses: list[int]) -> int:
"""Get the first timestamp"""
return NotImplemented | 465bd641e41cef1ff5207511d09d9512ab131386 | 44,728 |
def get_table_1():
"""表1 空気搬送ファンの比消費電力 f_SFP
Args:
Returns:
list: 表1 空気搬送ファンの比消費電力 f_SFP
"""
table_1 = (0.4, 0.2)
return table_1 | 20c833ff3b65ccef39adc69f3fd4f1bea314d8a3 | 44,730 |
from typing import Optional
import re
import time
def _generate_default_job_name(image_uri: Optional[str]) -> str:
"""
Generate default job name using the image uri and a timestamp
Args:
image_uri (str, optional): URI for the image container.
Returns:
str: Job name.
"""
if not... | 06d983299008652a503ba9dbf943502290016394 | 44,733 |
import json
def _get_example(line):
"""Extract relevant fields from json.
Args:
line: String for json line.
Returns:
example_id: integer.
question: string.
contexts: List of strings.
context_indices: List of (int32, int32) tuples.
"""
json_example = json.loads(line)
example_id = json... | f57cf475c55566bf5a4f19699aab63d54839535d | 44,735 |
from typing import List
from typing import Union
def make_it_fit(cell_list: List[str], limit: int) -> Union[None, List[str]]:
"""
This function attempts to shorten a list of strings by finding and
elimininating empty string elements from left to rigth. If succesfull
it will return the modified list. O... | 48884f977074b82f391c7fb989e08dab1d285bf7 | 44,736 |
import time
def _generate_container_name() -> str:
"""Generate a Docker container name for use in DockerPolicy."""
return 'ros2launch-sandboxed-node-{}'.format(time.strftime('%H%M%S')) | 28eb30dd5c4a49e4342feeec94d09dda9f3f4c53 | 44,737 |
def getSigGenIDN(sg):
"""
This function returns the Sig Gen IDN
Parameters:
sg : socket connection
Returns:
IDN : Sig gen IDN response as string
"""
sg.sendall(b'*IDN?\r\n') # Get system i... | a9478286a2273a6be1c17a5b06d3d83641d80f8f | 44,738 |
def get_ds(dc, name):
"""
Pick a datastore by its name.
"""
for ds in dc.datastore:
try:
if ds.name == name:
return ds
except: # Ignore datastores that have issues
pass
raise Exception("Failed to find %s on datacenter %s" % (name, dc.name)) | 964a4c997e46d2d655659962479baab53cbb765d | 44,739 |
import string
def plate2robot_loc(row_val, col_val, plate_type='96'):
"""Changing positioning from row (letter) and column (number)
to just numeric position (column-wise) on the plate,
which is needed for TECAN robot positioning.
Using index for identifying well number in plate
[args]
row_val... | 5b62f5a2d73842fc283cf871906d9bf46f4b33bb | 44,741 |
def server_url(http_server):
"""URL for accessing the http server."""
host, port = http_server.server_address
return f"http://{host}:{port}" | d98ed61cf5f2541740bafac1df2f135e4ff04758 | 44,742 |
def bins(hist):
"""
Get access to the bins of a histogram
the returned object can be indexed and iterated over,
the elements are of the appropriate dimensionality
"""
return hist.__bins__() | 8e887231e4b6349ac93f408f1ea61ae782a71bf6 | 44,743 |
from typing import Dict
def dauphin_info(dauphin_county_dict) -> Dict[str, str]:
"""
Returns a dict with basic info for Dauphin County, including its name and mailing list ID.
"""
return dauphin_county_dict["42043"] | 26b35449a0177171a5ce499dd7af340278a91209 | 44,744 |
from typing import Callable
from typing import Type
from typing import Optional
from typing import Tuple
def make_metaclass(metaclass_callback: Callable[[Type], None], exclude: Optional[Tuple[str, ...]] = None) -> Type:
"""
make a metaclass
:param metaclass_callback: called when a new class is made using... | 18193fb296215c77a8f385ba1bb3c4ce888eb866 | 44,746 |
def select_rep(df):
"""select a representative clv per cluster"""
mode_clv = df.clv.mode()
if mode_clv.shape[0] > 0:
# if one or multiple modes are found, return median
return mode_clv.median()
else:
# if no mode is found, then return median
return df.clv.median() | 8176a36d8f08e0550b2ac1a4a1f0ba9069684aab | 44,747 |
def layer_rows(layer):
"""
Given a layer return each row as a list.
"""
els = range((2*(layer-1)-1)*(2*(layer-1)-1) + 1, (2*layer-1)*(2*layer-1) + 1)
side_length = len(els) / 4
return [els[:side_length], els[side_length:2*side_length], els[2*side_length:3*side_length], els[3*side_length:]] | ecab272deb2f7d990b094c2b9a2036c0f8990855 | 44,748 |
import random
def get_random_speechcon():
"""Return speechcon"""
SPEECHCONS = ['hmm','awesome','ah']
text = ("<say-as interpret-as='interjection'>{} !"
"</say-as><break strength='strong'/>")
return text.format(random.choice(SPEECHCONS)) | 76cf14df8a094705ccf14914353a94f72f3685aa | 44,749 |
def grad_sp_solve_nl_parameters(x, parameters, a_indices, b, fn_nl):
"""
We are finding the solution (x) to the nonlinear function:
f = A(x, p) @ x - b = 0
And need to define the vjp of the solution (x) with respect to the parameters (p)
vjp(v) = (dx / dp)^T @ v
To do this (see Eq.... | 0fb77365fe90260f2658c030623a11370b24a485 | 44,750 |
def sample_mocked_geolocation(**params):
"""Create and return a sample mocked geolocation object"""
mock_data = {
'ip': '10.0.0.1',
'country_name':'Mars',
'region_code':'SOL512',
'city': 'RedSand',
'latitude':49.02342,
'longitude':40.34342,
'zip':'1052'
... | 8506bfd2f9b602e027660401b4fdeb2cea9e92b8 | 44,751 |
import torch
def dhinge_dz(z, t, margin=1.0, trunc_thresh=float('inf'), norm_by_size=True):
"""compute derivative of hinge loss w.r.t. input z"""
tz = z * t
dhdz = (torch.gt(tz, margin - trunc_thresh) * torch.le(tz, margin)).float() * -t
if norm_by_size:
dhdz = dhdz * (1.0 / tz.size()[0])
... | cbd57534f3bd3ba1a2ca1a690bd337d736b8bcf9 | 44,753 |
def community2name(community):
"""
Given a list of concepts (words), return a string as its name.
"""
return " ".join(community) | c2454a26704bd6930c3c7fdf3bf17619ede918c6 | 44,754 |
def readFile(filepath):
"""Gets string representing the path of the file to be processed
and returns it as a list. It will omit blank lines.
Parameters
----------
filepath : str
The path of the filename to be processed
Returns
-------
lines
a list that contains the ... | d1dc54b48f7012cbf0f253154af96d673cd00259 | 44,755 |
def drop_users_to_ignore(ignore, license_lists):
"""This function drops the users to ignore during the comparison from each license type list.
Parameters
----------
ignore (DataFrame) : Users to ignore during comparison
license_lists (dict) : dictionary of DataFrames, one for each license type
... | 3aaee5d9c49ee776f6fc5dbd2a8062e104c78845 | 44,756 |
def roundAndFormat1(xxx):
""" changes numbers xxx into string percentages that are nice integer numbers
it is a hack to make sure that numbers like 65.241 become 65, whereas numbers like 6.7 become 7
so its basically rounding to the nearest integer number and then formatting it nicely for legend
"""
... | 810a744f07e776f5b84aa278e0cce6e83557154d | 44,757 |
import pytz
from datetime import datetime
def generateDateTimeBasedKey():
""" Genera un numero entero basado en la fecha y hora"""
madrid = pytz.timezone("Europe/Madrid")
dtdt = datetime.now(madrid)
dt = dtdt.date()
tm = dtdt.time()
mdate = dtdt.date()
mtime = dtdt.time()
milisec = ... | 0ba3cd294deff5f28fd8e47190864bd948c76024 | 44,759 |
def delete_cookie(cookieName: str, url: str) -> dict:
"""Deletes browser cookie with given name, domain and path.
Parameters
----------
cookieName: str
Name of the cookie to remove.
url: str
URL to match cooke domain and path.
**Experimental**
"""
return {
... | ff233a7e1e4048a35b6ad13f804cbfe088b6a66c | 44,760 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.