content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def getMaximumNodeId(nodeset):
"""
:return: Maximum node identifier in nodeset or -1 if none.
"""
maximumNodeId = -1
nodeiterator = nodeset.createNodeiterator()
node = nodeiterator.next()
while node.isValid():
id = node.getIdentifier()
if id > maximumNodeId:
maxim... | 45306222d8b26cd4294e4c4fb91c34c2effc3d95 | 695,190 |
import math
def n(i,pv,fv,pmt):
"""Calculate the number of periods in an annuity"""
n = math.log((fv*i+pmt)/(pv*i+pmt)) / math.log(1+i)
return n | b7219ae4d69f059bf7c0b34e7101bcbcdb991914 | 695,192 |
import csv
def errorreader(filename):
"""
读取表格,将URLError的编码重新读取,输出一个列表
:param filename:
:return:
"""
codelist = []
try:
with open(filename, 'r') as csvfile:
reader = csv.reader(csvfile)
for data in reader:
if len(data) >= 1: # 非空行
... | 2b8c71f248a3a1bd472ecc60ccdbd6bcbb02cdd7 | 695,193 |
import six
def compress_literal_list(literals):
"""Uses repetition syntax to shorten a literal list.
>>> compress_literal_list([])
[]
>>> compress_literal_list(['true'])
['true']
>>> compress_literal_list(['1', '2', 'f*', '3', '3', '3', '5'])
['1', '2', 'f*', '3', '3', '3', '5']
>>> c... | 3427cd91ea5d499cc00211a13cb75c28ff33baf4 | 695,194 |
def _get_variables(formula, type_):
"""Finds all the variables in the formula of the specific pysmt type.
Args:
formula (FNode): The pysmt formula to examine.
type_: The pysmt type to find (e.g: REAL, BOOL).
Returns:
set(FNode): The set of all the variables in the formu... | 493a8ac1cb47f1d854acf92dda92ef71986113da | 695,195 |
from pathlib import Path
def ftype(fn: Path) -> str:
"""
returns file type i.e. 'dt0','dt1','dt2','dt3'
"""
return fn.stem.rsplit(".", 1)[-1] | f4ce4e9bd8e4ad6c7c236941f2bfa08403f21fc5 | 695,196 |
def prompt(prompt_message: str = "Enter a string", default: str = "") -> str:
"""
Prints a message and waits for user input.
Args:
prompt_message: string to be printed
default: string to be returned if no value is entered
Returns:
string entered or default value
"""
de... | 0b8de5d4c3886de947887525684ed40a952d200e | 695,197 |
def count_utf8(line):
"""
文字コードで解説とコードを見分けるいい加減な実装
"""
a, u = 0, 0
for c in line:
if c == '#' and u == 0: #コメント
break
if ord(c) > 128:
u+=1
else:
a+=1
return u / (a+u) | c3d46709b9fe77f0bc22fb1399d80fc6b1ccbd04 | 695,198 |
def loadTextCode(path):
"""
Charge du code en version texte.
Cette fonction charge le texte du fichier situer à
l'emplacement de l'argument « path ». La fonction retourne
ensuite le texte.
:example:
>>> saveTextCode("C:/test.asm", "mov 10 acc")
>>> loadTextC... | 78892c5b449103fa43365a3c43a671ca50b7a780 | 695,199 |
import copy
def makePhe(phes = [],ids=[]):
"""Create the null phenotype values and append them to the case id
phes is the (generator, headername) for each column
for a phe file, ids are the case identifiers for the phenotype file
res contains the final strings for the file
each column is derived b... | 65361813bf17abac42c13bf7c24a898979e40054 | 695,200 |
def detect_combiner(env):
"""Detect if mkdocscombine exe is detected on the system, or use user specified option"""
if 'Mkdocs_Combine' in env:
return env.Detect(env['Mkdocs_Combine'])
else:
return env.Detect('mkdocscombine') | 9ab1237d835d5c03ab232eb66e9f99cb8b8b35b3 | 695,201 |
from datetime import datetime
def generate_po_ref():
"""
Convert date and time to hexidecimal.
Returns
-------
hexNum : TYPE Hexidecial Number
DESCRIPTION. Last five characters of the current date and time in hexidecimal.
"""
now = datetime.now()
date_time = now.strftime("%... | 38b5e43356ad00e7e823fabed79dca308ecc2e7c | 695,202 |
def quote_string(string, repl): # real signature unknown; restored from __doc__
"""
quote_string(string: str, repl: str) -> str
Escape the string 'string', replacing any character not allowed in a URLor specified by 'repl' with its ASCII value preceded by a percent sign(so for example ' ' becomes '%20'... | db2ef8868012ff1c24961df76e59981a98b45157 | 695,203 |
def any_key_id_mode():
"""
Only key id mode 2.
"""
return 2 | d63c3513de3b18c16fe14a88fab21da38f91c9e9 | 695,204 |
def escape_html(string: str, quote=True) -> str:
"""
Replace special characters "&", "<" and ">" to HTML-safe sequences.
:param string: the string
:param quote: If the optional flag quote is true (the default), the quotation mark characters, both double quote (") and single quote (') characters are als... | a21a40e658cc09b4d24a94e00a54c97c6f135a80 | 695,205 |
def blank_if_zero(n):
"""Return str(n) unless n is zero, in which case return ""."""
if n == 0:
return ""
return str(n) | d2249e29c43a05efa9bee6b380b5c8636f4c0dd9 | 695,206 |
def extractTime(val):
"""
extract the size from the string returned by an ls -l|a command
"""
return val.split(' ')[1].split('T')[0] | a9b05ec5d34ebd9d2a8724cae8e7c08e76c54d0b | 695,207 |
def parse_args(parser):
"""Parse command line arguments."""
parser.add_argument('-w', '--workload', default='tpch', help="""The target workload to
run. Choices: tpch, tpcds. Default: tpch""")
parser.add_argument('-s', '--scale', default='', help="""The scale factor for the
workload. Default: the scal... | f6b3b10b4cc0ac855ddf9addb9ceebf0c99e3498 | 695,208 |
def remove_null_values(data):
""" Removed null value
Arguments:
data {dict}: data
Returns:
data {dict}: update data
"""
return {k: v for k, v in data.items() if v is not None} | 702c0c308aaf9b7926535121eea7de0383412634 | 695,209 |
def get_as_clause_multicol(columns_to_query_lst, update_param_list):
"""
get_as_clause will return tuple of column names of intermediate table c of postgresql query.
:param columns_to_query_lst: columns for where clause.E.g [col1]
:param update_param_list: new column names for columns to be ... | 7bb34c1ca9534877d3ae4a17fa5fdc1e28ddabfc | 695,210 |
def format_epoch_score(epoch: int, loss: float) -> str:
"""Formats the results obtained at the end of an epoch in
a string used for logging.
Args:
epoch (int): current epoch
loss (float): current associated loss
Returns:
str: formatted string
"""
return f"Epoch {epoch}:... | fc2c816ca32c7e6e9d899bc89757d9a5424e7f00 | 695,211 |
def create_stats(value_counts):
"""
@param pd.Series value_counts: the value counts of the field in question
@returns dict: the statistics to be output in markdown
"""
stats = {}
stats["Unique Values"] = len(value_counts)
if len(value_counts) > 0:
stats["Most frequently occurring va... | 947db7bbd7ec86cfad9e7afd9addf102e7e0e508 | 695,212 |
import unicodedata
def is_number(string: str) -> bool:
"""See if a given string is a number (int or float)"""
try:
float(string)
return True
except ValueError:
pass
try:
unicodedata.numeric(string)
return True
except (TypeError, ValueError):
pass
... | e71ecaa10b619b6eac34001cc2f964d3b1d993f8 | 695,213 |
from typing import Optional
def validate_opex_per_capacity(opex_per_capacity: Optional[float]) -> Optional[float]:
"""
Validates the opex per capacity of an object.
Opex per capacity is always optional.
:param opex_per_capacity: The opex per capacity of the object.
:return: The validated opex per... | a9297cd0bb20a0ddcd37d946152b032d9938cf66 | 695,214 |
def get_structure_from_prev_run(vasprun, outcar=None):
"""
Process structure from previous run.
Args:
vasprun (Vasprun): Vasprun that contains the final structure
from previous run.
outcar (Outcar): Outcar that contains the magnetization info from
previous run.
... | c6d272d2bff74b408e1a16e758db975837822e79 | 695,215 |
def newPage(doc, pno=-1, width=595, height=842):
"""Create and return a new page object.
"""
doc._newPage(pno, width=width, height=height)
return doc[pno] | f908615439b911805d98d45e164ebe41565b5a1a | 695,217 |
def get_query(params):
""" Choose correct query based on the origin and destination string length.
"""
## Here I'm using Psycopg capability automatically convert Python objects to the SQL literals
## (note %(origin)s and %(destination)s variables). Without this the code would be susceptible
## to th... | 1fa13426d07f301a20093db7f40e5dd0e7a42a13 | 695,218 |
def _nt_unicode_error_resolver(err):
"""
Do unicode char replaces as defined in https://www.w3.org/TR/2004/REC-rdf-testcases-20040210/#ntrip_strings
"""
def _replace_single(c):
c = ord(c)
fmt = u'\\u%04X' if c <= 0xFFFF else u'\\U%08X'
return fmt % c
string = err.object[er... | 67c0f2ea92379a91c67dcfeabc51c4eee9972df7 | 695,219 |
def twoSum(nums, target):
"""
인자형: List[int]
목표값의 형: int
반환형: List[int]
"""
chk_map = {}
for index, val in enumerate(nums):
compl = target - val
if compl in chk_map:
indices = [chk_map[compl], index]
print(indices)
return [indices]
else:
chk... | 975d4a855a6f95369a25447f9201d2b31a8b75a8 | 695,220 |
import win32serviceutil
import pywintypes
def get_winsvc_status(svcname):
"""Get Windows service status.
Args:
svcname (str): Service name to query.
Returns:
(str): Service Status string.
"""
try:
ret = win32serviceutil.QueryServiceStatus(svcname)
except pywintypes.e... | 7f2eccfaf2890c948aec2cc4478cda66d872d9ea | 695,221 |
import os
def abs_path(pathname: str) -> str:
"""Transform a script-relative path to an absolute path."""
directory = os.path.dirname(os.path.abspath(__file__))
return os.path.normpath(os.path.join(directory, pathname)) | 37e5f23d3ca181b9e378213d052f736c4f8da02a | 695,222 |
from typing import List
from typing import Dict
def find_values(item, keys: List[str]) -> Dict:
"""Find values for keys in item, if present.
Parameters
----------
item : Any
Any item
keys : List[str]
Keys whose value to retrieve in item
Returns
-------
Dict
Ma... | bab4c8a9695113390654e4eaf971559a98f4eb71 | 695,223 |
def _toList(qvar):
""" Make qvar a list if not."""
if type(qvar) != type([]): qvar = [qvar]
return qvar | 96644b04ee791d901a44731daddcb636ed549b46 | 695,225 |
import os
from warnings import warn
import subprocess
def make_bubble(reports_dir, out_dir, title):
"""Make bubble chart"""
fig_dir = os.path.join(out_dir, 'figures')
if not os.path.isdir(fig_dir):
os.makedirs(fig_dir)
cur_dir = os.path.dirname(os.path.realpath(__file__))
bubble = os.pa... | a401f023407abd3d1f20fbc953a50781cf6058c7 | 695,226 |
import os
import yaml
def load_remote_source(mirror=''):
"""
Loads config file with definition of the remote data sources and formats it according to the chosen mirror.
@return: loaded config dictionary
"""
my_path = os.path.dirname(os.path.realpath(__file__))
with open('{}/remote_sources.yml'... | 8fa18769feb0476d9d9a69a44acc000ae8c09754 | 695,227 |
def create_members_api_bp_from_app(app):
"""Create members api blueprint."""
ext = app.extensions["invenio-communities"]
# control blueprint endpoints registration
return ext.members_resource.as_blueprint() | b6899ab54fe26419b5ca10f747719555aa50d2de | 695,228 |
import re
def macs_species(genome):
"""Convert genome to macs2 species encoding"""
if re.match('^hg[0-9]+$', genome):
return 'hs'
elif re.match('^mm[0-9]+$', genome):
return 'mm'
raise Exception('Unknown species {}'.format(genome)) | ecacca48f7bb7cd1eaa5e21a58ea2efba00627ae | 695,229 |
from typing import List
from typing import Dict
import os
import json
def get_installed_versions(path: str) -> List[Dict[str,str]]:
"""
Returns all installed versions
"""
dir_list = os.listdir(os.path.join(path,"versions"))
version_list = []
for i in dir_list:
if not os.path.isdir(os.... | beba59898459d7a188b85930425c633d62983908 | 695,230 |
def compile_ingredients(dishes):
"""
:param dishes: list of dish ingredient sets
:return: set
This function should return a `set` of all ingredients from all listed dishes.
"""
return set.union(*dishes) | 2277c3f5dcba68bae257a975f69fdbd83bf327a9 | 695,231 |
import socket
def is_port_opened(port, hostname='127.0.0.1'):
""" Checks if the specified port is opened
:param port: The port to check
:param hostname: The hostname to check, defaults to '127.0.0.1'
"""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(... | 5b9e1a80988c99289d71cdf616cc36800dcf4848 | 695,232 |
import re
def get_html_url(content):
"""Takes a HTML tag and returns the href or SRC"""
href_q = re.search(r'<a.+href="(.+)">(.+)</a>', content)
src_q = re.search(r'src="(.+)"', content)
src_alt_q = re.search(r'src=.+alt=(".+").*>', content)
if href_q:
return href_q.group(1), href_q.group... | 742c31e21a6512e9c5c4f9186396f50f26ed2b53 | 695,233 |
def wait4(pid, options):
"""Similar to :func:`waitpid`, except a 3-element tuple, containing the child's
process id, exit status indication, and resource usage information is returned.
Refer to :mod:`resource`.\ :func:`getrusage` for details on resource usage
information. The arguments to :fun... | 83365bc9ece235a3a8e50f624f81bf60c8c41cfa | 695,234 |
import hashlib
def verify_file_hash(
file_path:str,
file_hash:str,
file_hash_algorithm:str
):
"""Return True if the calculated hash of the file matches the given hash, false else"""
md5_hasher = hashlib.md5()
sha1_hasher = hashlib.sha1()
sha256_hasher = hashlib.sha256()
with open(f... | b237c737d2416fb05c9a1e99d0c242e04dd57a21 | 695,235 |
def parse_filename(args, start_date):
"""Parse filename from args and start_date
Arguments:
args: the arguments provided to the script
Returns:
filename: the filename to use for the csv data
"""
if args.filename:
filename = args.filename
# depending on date args either ... | c68a3036ec43b4657b88c7f2f623c689c721cf43 | 695,236 |
def make_rmd_featurestat(project_name):
"""
Rmarkdown creation: Obtain proportion of no feature counts from htseq-count results
Separate here because of the htseq-count-specific feature
"""
rmd="\n"
rmd=rmd+"## HTSeq-count: No feature counts statistics\n\n"
rmd=rmd+"Numbers of reads that can... | 861fc179846827775841a57b3d2dba1770e87ebe | 695,237 |
def make_gauge(name, value, m_type='gauge'):
"""Return a dict for use as a gauge."""
return {
'name': name,
'value': value,
'type': m_type
} | f1c5b11a481ad17eaf23169f9401b08cdff674d3 | 695,238 |
def has_triple_string_quotes(string_contents: str) -> bool:
"""Tells whether string token is written as inside triple quotes."""
if string_contents.startswith('"""') and string_contents.endswith('"""'):
return True
elif string_contents.startswith("'''") and string_contents.endswith("'''"):
r... | 708d6848c8e7f58f8f93818f7f3a5095bf4e2fa3 | 695,239 |
def difficultyLevel(mychoice):
""" Assigns the difficulty level and answers
Args:
param1 (str): the user's difficulty choice
Returns: the user's dificulty choice in word form
"""
if(mychoice == "easy" or mychoice == '1'):
return "easy"
elif(mychoice == "medium" or myc... | 8257daa0e21adc4dedbd7c177e4f0baebd4713dd | 695,240 |
def check_managability(user, note, action):
"""
Determine if user can edit or delete this note. This note can be edited or deleted if at least one of the
following criteria is met:
- user is an admin
- user is the author of the note
- user is member of a group in groups AND note is p... | 2b7ab8dea97f0f0c4e67b3d3f212438a130e7b92 | 695,241 |
def ipow(a, b, N):
""" Returns a raised to the power b modulo N by squaring exponentiation """
res = 1
while b > 0:
if b % 2 == 1:
res = (res * a) % N
a = (a * a) % N
b >>= 1
return res % N | 9b2047cb35c9b76db1597377a8bd2de23c37b0e8 | 695,242 |
def normalized_probabilistic_similarity(lang_model, query_model):
"""
Returns the 'normalized probability' (invented by me) of a query text belongs to a language model
:rtype : float
:param lang_model: The model of a language (usually a dictionary of features and it's values)
:param query_model: Th... | 6ba9bbefa587756176672308006e2c429efbdd73 | 695,243 |
def get_interface_speed(speed):
"""Translates speed into bits/sec given the output from the API
Args:
speed (string): input should be from NX-API in the form of '10 Gb/s'-
param being sent should be "eth_speed" from output from
'show interface eth x/y' in NX-API
Returns:
... | 73b0ed1f91386cfb63277e59e9d618a616a6d569 | 695,244 |
def _is_tcp_syn(tcp_flags):
"""
Passed a TCP flags object (hex) and return 1 if it
contains a TCP SYN and no other flags
"""
if tcp_flags == 2:
return 1
else:
return 0 | 7072b33e641099a97bdba850bfd11c9aeccc1223 | 695,247 |
def scope2dom(name, no_css_selector=False):
"""Get the CSS selector/element name actually used in the front-end html page
:param str/tuple name: When it is str, it is regarded as the Dom ID name;
when tuple, the format is (css selector, element name)
"""
selector = '#'
if isinstance(name, tu... | 3716eea31f90a58e5914e2dcfda61a47524f990b | 695,248 |
def indexToWorld(flatmap_index, map_width, map_resolution, map_origin = [0,0]):
"""
Converts a flatmap index value to world coordinates (meters)
flatmap_index: a linear index value, specifying a cell/pixel in an 1-D array
map_width: number of columns in the occupancy grid
map_resolution: side lenght... | 210a4c730072d855d825f08f2b41fbc05dbf04c2 | 695,249 |
def addext(name_str, ext_str):
"""Add a file extension to a filename
:param name_str: The filename that will get the extension
:param ext_str: The extension (no leading ``.`` required)
:returns: The filename with the extension
"""
if not ext_str:
return name_str
return name_s... | 834484ac16e979dd221eed08c0c62bd8ca2a716a | 695,250 |
def indentify(stuff, rep = 1, indent = '\t'):
""" From http://code.activestate.com/recipes/66055-changing-the-indentation-of-a-multi-line-string/#c4 """
lines = [(rep * indent) + line for line in stuff.splitlines()]
return "\n".join(lines) | 53497ce2539e637295b41f97da7b3ac54fc4e485 | 695,251 |
def roll(image, delta):
"""Roll an image sideways."""
xsize, ysize = image.size
delta = delta % xsize
if delta == 0: return image
part1 = image.crop((0, 0, delta, ysize))
part2 = image.crop((delta, 0, xsize, ysize))
image.paste(part1, (xsize - delta, 0, xsize, ysize))
image.paste(part2... | 28e212e7309749f9a93d6d51587ae939c51ae082 | 695,252 |
def elt0(list, context):
"""return first member of reduction"""
return list[0] | 43015dcad789f1e9f8bc0d87f42d947ce53505a4 | 695,253 |
def tagnum(line):
"""
returns the current event count
"""
return int(line[line.find('=') + 1:line.find(')')]) | 2ea8111d44bcb9a9273e1a93629a60f574231c51 | 695,254 |
def get_factorial(num: int):
""" Returns the factorial of `num` """
answer = 1
for i in range(num, 0, -1):
answer *= i
return answer | 8dbdeb545c76fa4860240d80059a46c82a032202 | 695,255 |
import sys
def validate_input(text: str) -> bool:
"""ensure the game gives back the initial string to begin"""
if len(text) != 4:
print('Input string must be 4 characters long', file=sys.stderr)
return False
return True | 45727a485dff50a7b2ff71236490bb5fd025ec4c | 695,258 |
from typing import List
from typing import Dict
import json
def construct_pod_dict(node_info_file: str,
pod_types: List[str]) -> Dict[str, List[str]]:
"""Constructs a dict of pod names to be queried.
Args:
node_info_file: The file path contains the pod names to query.
... | bb9bd23013649d73ac8cfaa182159ac2b1ce9edc | 695,259 |
def rflink_to_brightness(dim_level: int) -> int:
"""Convert RFLink dim level (0-15) to 0-255 brightness."""
return int(dim_level * 17) | 8924a7de8892b0d1e339c5917ae25ff6b29e7f2b | 695,260 |
import os
def get_include():
"""Return the directory of framework header files.
Returns
-------
str
The include directory.
"""
core_root = os.path.dirname(os.path.dirname(__file__))
return os.path.join(os.path.dirname(core_root), 'include') | 68d37816087161b9382a06f50a6a800edd691c14 | 695,261 |
import logging
def MergeDictionaryValues(old_dict, new_dict):
"""Attempts to merge the given dictionaries.
Warns if a key exists with different values in both dictionaries. In this
case, the new_dict value trumps the previous value.
Args:
old_dict: Existing dictionary.
new_dict: New dictionary.
R... | 2836386f78363a1a0cede442ac0d6e81e3cd71e4 | 695,263 |
import re
def strip(path):
"""
:param path: 需要清洗的文件夹名字
:return: 清洗掉Windows系统非法文件夹名字的字符串
"""
path = re.sub(r'[?\\*|“<>:/]', '', str(path))
return path | 0e5988a857e8645ab9a80cb2b9276c630e3d0e6a | 695,264 |
def make_pounds(coins, bill):
"""
Find how many ways there are to make bill from the given list of coins
:param coins List of coins
:type coins list
:param bill Coin/note to make change for
:type bill int
:return: Number of ways to make change for the given currency
:rtype: int
"""
... | c1cb1e82bdb50e4ada3b4d02b3ff7b692bb91f5a | 695,266 |
def bytes_identical(a_bytes, b_bytes):
"""Return a tuple
(bytes a == bytes b, index of first difference)"""
if len(a_bytes) != len(b_bytes):
return False, min([len(a_bytes), len(b_bytes)])
elif a_bytes == b_bytes:
return True, 0 # True, dummy argument
else:
pos = 0
... | 258471bfa76a58bb236ca0a18833324d3f4576e4 | 695,267 |
import configparser
import os
def extract_endpoint(profile="default"):
""" A simple utility to extract the endpoint from an S3 configuration
file, since it's not currently supported in the boto3 client (see
https://github.com/aws/aws-cli/issues/1270 ."""
config = configparser.ConfigParser()
# Path... | 1ce101b396b79153d6f9c9223ce97adb5f261729 | 695,268 |
def find_shablons(key_word, array):
"""
Receive the `key_word` as string shablon, find all words in `array`
which contain it and return list of those words
Parameters
----------
key_word : str
array: list
Returns
-------
list
"""
result_list = []
key_wo... | fe959369e204910723a9c32caeaa9f8712590bce | 695,269 |
def iso_string_to_sql_date_mysql(x: str) -> str:
"""
Provides MySQL SQL to convert an ISO-8601-format string (with punctuation)
to a ``DATE``, just by taking the date fields (without any timezone
conversion). The argument ``x`` is the SQL expression to be converted (such
as a column name).
"""
... | 6798578e8633e819e7e55622e53b2cd2be583fc5 | 695,270 |
def check_proximity(xy1, xy2):
"""
>>> check_proximity((10,10), (10,10))
False
>>> check_proximity((11,11), (11,12))
True
>>> check_proximity((0,0), (0,0))
False
"""
if type(xy1) is not tuple or type(xy2) is not tuple: return False
if len(xy1) != 2 or len(xy2) != 2: return False
if xy1 == xy2: return False
... | f94c2767a0c4c8f2eb11266647ad7663bd0db71e | 695,271 |
import os
def exists_file(filename):
"""
Check whether a file exists or not.
:param filename: (string) the filename.
:return: True, if the file exists; False, otherwise.
"""
dirname = os.path.dirname(filename)
dirname = dirname if len(dirname) != 0 else os.path.curdir
filepath = os.pat... | 3318e3e424948475d1f474aceb3d93154a5e1ab6 | 695,273 |
def unique(iterable):
"""Return unique elements.
Note
====
Always returning a list for consistency was tempting,
however this defeats the purpose of creating this function
to achieve brevity elsewhere in the code.
@return: iterable with duplicates removed, as C{set} if possible.
@rtype... | 330fa2a729d86134d2745d668a0fa690e8c56618 | 695,274 |
from typing import Dict
def get_config_input(user_cfg: Dict[str, dict]) -> Dict[str, dict]:
"""
Get the input configuration
:param user_cfg: user configuration
:type user_cfg: dict
:return cfg: partial configuration
:rtype cfg: dict
"""
cfg = {}
if "input" in user_cfg:
c... | bbcaf21c3c337b14e33ac9ce6469368987eaac4b | 695,275 |
from datetime import datetime
def ctime():
"""Returns current timestamp in the format of hours-minutes-seconds."""
return datetime.now().strftime("%H:%M:%S") | c48271101866e8cf6f7907668895ea6cf934624d | 695,276 |
from typing import Dict
from typing import List
def prepare_data_for_markdown_formatting(scans: Dict) -> List[List[str]]:
"""Method responsible for formatting the data into the correct form for the MarkdownTableWriter.
Args:
scans: Dictionary containing the scans, from the virustotal api response.
... | 89c1560b40579cc1944bde8c04be8fcdf28a64ad | 695,277 |
def docstring(docstr, sep="\n"):
"""
Decorator: Append to a function's docstring.
"""
def _decorator(func):
if func.__doc__ == None:
func.__doc__ = docstr
else:
func.__doc__ = sep.join([func.__doc__, docstr])
return func
return _decorator | 21bbd5e158a183ebda28e313e8b4180ba3928233 | 695,278 |
def link_easy(sid):
"""
Creates an html link to a dataset page in Easy.
:param sid: a dataset id
:return: link to the page for that dataset
"""
prefix = 'https://easy.dans.knaw.nl/ui/datasets/id/'
return '<a target="_blank" href="{}{}">{}</a>'.format(prefix, sid, sid) | f329ac256e459bf79572b8686a1b6be003efccae | 695,279 |
import base64
def _get_signed_query_params(credentials, expiration, string_to_sign):
"""Gets query parameters for creating a signed URL.
:type credentials: :class:`oauth2client.client.AssertionCredentials`
:param credentials: The credentials used to create a private key
for signin... | 6f7fd8d24240ee604fdfe3b5d63ff8638e601f77 | 695,280 |
def is_closed(request):
"""Check if the request is closed."""
return request.is_closed | a2949d8f185f56f52e5b637066353ce935df28c3 | 695,281 |
import csv
def read_subjects_file(subjects_file, has_header_line=False, index_of_subject_id_field=0, **kwargs):
"""
Read a subjects file in CSV format that has the subject id as the first entry on each line. Arbitrary data may follow in the consecutive fields on each line, and will be ignored. Having nothing ... | 9722d3a6d86306cf7b441ad46f9f7932213c7c46 | 695,282 |
def get_dataset_params(dataset):
"""
Get the capacities to test for the particular dataset.
:param dataset: string of dataset
:return: list of capacities
"""
if dataset == 'cub200':
capacity_list = [2, 4, 8, 16]
else:
raise NotImplementedError('Dataset not supported.')
re... | a8e859da52085233426957397d8d0fc50628d5b8 | 695,283 |
import math
def sched_cos(start, end, pos):
"""Cosine scheduler."""
return start + (1 + math.cos(math.pi * (1 - pos))) * (end - start) / 2 | d20afee0f5d11b792bc926b4f13d1353e0208619 | 695,284 |
import re
def replace_aea_fetch_statements(
content: str, old_string: str, new_string: str, type_: str
) -> str:
"""Replace statements of the type: 'aea fetch <old_string>'."""
if type_ == "agents":
content = re.sub(
fr"aea +fetch +{old_string}", f"aea fetch {new_string}", content
... | 0bd3838d642c4a6120e2b1fcad4fe8995ab7425f | 695,285 |
def bigquery_serialize_date(py_date):
"""
Convert a python date object into a serialized format that Bigquery accepts.
Accurate to days.
Bigguery format: 'YYYY-[M]M-[D]D'
https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types
Args:
py_date (datetime.date): The date to... | b730fdfe6696011601d466ad65010b5b566749e7 | 695,286 |
def get_model(obj):
"""
Finds model root element for the given object.
"""
p = obj
while hasattr(p, 'parent'):
p = p.parent
return p | d61bc104296db17fe178307503a8494e19c9718b | 695,287 |
import torch
def focal_loss(input_values, gamma):
"""Computes the focal loss"""
p = torch.exp(-input_values)
loss = (1 - p) ** gamma * input_values
return loss.mean() | 7246eade4f4175065c845386dbeb0e26b4f63b81 | 695,289 |
def correct_timing(offset, stimuli):
"""Correct Timing.
Given the offset and stimuli array, return
an array of data with stimuli corrected to the offset!
"""
print('Calculating the correct trigger times in relation to offset... \n')
new_stimuli = []
for stim in stimuli:
# Th... | 58b1f264e7cf85a859a171f18efb33b3ee1f519a | 695,290 |
import click
def main(args=None):
"""Console script for flowsym."""
click.echo("Welcome to FlowSym, a Python API used to simulate flow "
"cytometry data!"
"\n\n"
"If you don't see any warning messages above then you're "
"all set!")
click.echo("S... | 46dbe0ebde8f896a7113bc4c8a415003b44e9553 | 695,291 |
from typing import Tuple
from typing import Union
def is_secret_key(key: str) -> Tuple[bool, Union[str, None]]:
"""Check if the Airflow Flask webserver secret key is valid.
:param key: Key to check.
:return: Validity, and an error message if not valid.
"""
key_bytes = bytes(key, "utf-8")
mess... | 77327659da0935da96be5597b296cce7173d7bf2 | 695,292 |
def correct_img_dimension(width, height, threshold_w, threshold_h):
"""
return a new width and height that is as close as to the thresholds, while keeping
aspect ratio same
:param width:
:param height:
:param threshold_w:
:param threshold_h:
:return: tuple of new width and height
""... | 30b3b30bff06004b3df19e036972be71c05e3ff1 | 695,294 |
def check_dummy_variables(df, dummy_list):
"""
Checks that all missing variables where added when encoding, otherwise
adds the ones that are missing
"""
for var in dummy_list:
if var not in df.columns:
df[var] = 0
return df | 1c96c9963605a082f678c2ce3129f83aebcc9948 | 695,295 |
def format_schema(schema):
"""Convert Schema to fixture format.
"""
return {
"fields": {
"name": schema.name,
"datastore_id": schema.datastore_id,
"workspace_id": str(schema.workspace_id),
"created_at": str(schema.created_at),
"updated_at":... | cbb310f7e6d8dfac43eecc153138fbbbe7c6f274 | 695,296 |
def grep(pat,list,case=1):
"""Simple minded grep-like function.
grep(pat,list) returns occurrences of pat in list, None on failure.
It only does simple string matching, with no support for regexps. Use the
option case=0 for case-insensitive matching."""
# This is pretty crude. At least it should i... | 00e073adf85ed0f08fa76d09b61c82cc0cfaaf93 | 695,297 |
def file_to_list(filename):
"""
Read lines of text file to a list.
@param filename: path to file
@type filename: string
@return list of lines
"""
with open(filename) as fil:
meat = fil.readlines()
return [i.strip() for i in meat] | 7d5db114798470e75e2f9e750a666cee57520820 | 695,298 |
def ssl_config(module):
"""
Creates a ssl config dictionary to be used for ssl auth.
"""
ctx = module.params['ssl_auth']
try:
return {
'cert': ctx['cert'],
'serverca': ctx['serverca'],
'no_ssl_verify': ctx.get('verify', True),
'authtype': 'ssl'
}
except KeyError as e:
modu... | 2581d58acb25fb5d0c6bb1bfc877619c3c6ed52c | 695,299 |
def c(x, y):
"""
Convert ECMA-48 character notation to 8-bit form
```python
>>> c(0,0)
0
>>> c(1,11)
27
>>> c(15,15)
255
```
"""
return (x << 4) + y | de9028b1ac244c23f13ffe2fe30c2a8a64d3b80a | 695,300 |
import os
def get_hash_from_name(file_path):
"""
Please note that there is absolutely no error checking in this function.
All paths are assumed to end in 'file_name.extension'. It is also assumed
that the file_name is, in fact, the hash and not some other name.
"""
return os.path.basename(fil... | be117cf56a20ae2aba9d3d05a03d647de5dfe82e | 695,301 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.