content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def template_check(value):
"""Check if a rendered template string equals true.
If value is not a string, return value as is.
"""
if isinstance(value, str):
return value.lower() == "true"
return value | 3733db5c107068e815bac079fdef1a450f7acdc9 | 280 |
def return_npc(mcc, mnc):
"""
Format MCC and MNC into a NPC.
:param mcc: Country code.
:type mcc: int
:param mnc: Network code.
:type mnc: int
"""
return "{0}{1}30".format(str(mcc).zfill(3), str(mnc).zfill(3)) | 0ae5952fd7b026c2c90c72046f63ca4d08dacf06 | 281 |
def _get_capacity():
"""Return constant values for dam level capacities.
Storage capacity values are measured in million cubic metres
i.e. Megalitres or Ml.
Source: https://en.wikipedia.org/wiki/Western_Cape_Water_Supply_System
@return capacity: Dict object containing maximum capacities of Wester... | 01d1a5e7470d578296e285e2e00cd44eaf00d15c | 282 |
def prod_non_zero_diag(x):
"""Compute product of nonzero elements from matrix diagonal.
input:
x -- 2-d numpy array
output:
product -- integer number
Not vectorized implementation.
"""
n = len(x)
m = len(x[0])
res = 1
for i in range(min(n, m)):
if (x[i][i] != 0):
... | 13e9f6cc9ea22e7901d454b23297a2e9c5da3a3a | 283 |
def build_query(dct):
"""Build SQL with '?' and value tuples from clause dictionary"""
if (dct is not {}):
str_clauses = ''
tpl_values = ()
bln_start = True
#print dct
for str_field, dct_op_val in dct.iteritems():
if (str_field is not None):
if... | ac49014c8e629d2fdc12472f2b8b345cbee8ce18 | 286 |
from typing import Callable
import click
def with_input(func: Callable) -> Callable:
"""
Attaches a "source" argument to the command.
"""
return click.argument(
"source", type=click.Path(exists=True), required=True
)(func) | 3117f183ac4e4d459a718b59fc9a3ba00b36e291 | 287 |
def check_loop_validity(inst_list):
""" Given a list of instructions, check whether they can form a valid loop.
This means, checking for anything that could create an infinite loop.
We are also disallowing double loops right now"""
for i, c in enumerate(inst_list):
if c in [5, 6, 16, 25]:
... | a58923e014947d1406165a831a57b73fcb9ab226 | 288 |
def calc_high_outlier(values) -> float:
"""Calculates the high outlier from a pandas Series"""
q1, q3 = [values.quantile(x, 'midpoint') for x in (0.25, 0.75)]
return q3 + 1.5 * (q3 - q1) | 8ee929aec1cb4af9a90d04893f8f94444d00ad22 | 289 |
import re
def diff_re(a, b, fromfile='', tofile='',
fromfiledate='', tofiledate='', n=3, lineterm='\n'):
"""
A simple "diff" of two sets of lines when the expected lines
are regular expressions. This is a really dumb thing that
just compares each line in turn, so it doesn't look for
c... | 802dd3287502c3d3fe85242ba51043e4b5769cd5 | 290 |
from typing import Union
from typing import Dict
from typing import Tuple
from typing import Any
def serialize_framework_build_config(dict_: Union[Dict[str, str], str]) -> Tuple[Any, ...]:
"""Serialize a dict to a hashable tuple.
Parameters
----------
dict_: Dict[str, str]
Returns
-------
... | 365b413ff21bf4fb7f5d153dbe74801ee125108f | 291 |
def get_confidence(imgfilename):
"""
1003_c60.jpg -> c6
"""
if not imgfilename:
return ''
return 'c' + imgfilename.split('/')[-1][0:1] | 7c98f2abd2119b41d7e2501823985a894da5a1a1 | 292 |
def min_max_median(lst):
""" a function that takes a simple list of numbers lst as a parameter and returns a list with the min, max, and the median of lst. """
s = sorted(lst)
n = len(s)
return [ s[0], s[-1], s[n//2] if n % 2 == 1 else (s[n//2 - 1] + s[n//2]) / 2] | 59b1ceef5796d77cc039a42593ddb3d1d2244bd7 | 293 |
def _enzyme_path_to_sequence(path, graph, enzymes_sites):
"""Converts a path of successive enzymes into a sequence."""
return "".join(
[enzymes_sites[path[0]]]
+ [graph[(n1, n2)]["diff"] for n1, n2 in zip(path, path[1:])]
) | a3de9de5dc37df641e36d09d07b49c402fa17fd1 | 295 |
import string
def simple_caesar(txt, rot=7):
"""Caesar cipher through ASCII manipulation, lowercase only."""
alphabet = string.ascii_lowercase # pick alphabet
shifted_alphabet = alphabet[rot:] + alphabet[:rot] # shift it
table = str.maketrans(alphabet, shifted_alphabet) # create m... | eb8d86d37d8a8902663ff68e095b3b822225859c | 296 |
def _is_url_without_path_query_or_fragment(url_parts):
"""
Determines if a URL has a blank path, query string and fragment.
:param url_parts: A URL.
:type url_parts: :class:`urlparse.ParseResult`
"""
return url_parts.path.strip('/') in ['', 'search'] and url_parts.query == '' \
and ... | 4bad1f230adfa77df019519db276a181d57682dd | 299 |
import re
def dir_keys(path):
"""A function to take a path, and return a list of all the numbers in the path. This is
mainly used for sorting
by the parameters they contain"""
regex = '[-+]?[0-9]+(?:\.[0-9]+)?(?:[eE][-+]?[0-9]+)?' # matching any floating point
m = re.findall(regex, path)
... | c2c32772771c9bae23a1fcc949a509eaaf36d602 | 300 |
def get_colours_extend(graph_size, start_set, end_set, source, target, reachable=None):
"""
Get colours for nodes including source and target nodes.
Blue nodes are those in the source set.
Orange nodes are those in the start set, not in the source set.
Green nodes are those reachable from the sourc... | d366ed6c4c387d0b4de4440d34d358d5a142661a | 301 |
def load_file(file_location):
"""
Opens a given file and returns its contents.
:param str file_location: The absolute path to the file
:rtype: str
:return: The contents of the file
"""
with open(file_location, 'r') as file_contents:
contents = file_contents.read()
return conte... | 61b78432cffa4c22adc9af31bbad63bf8777737b | 302 |
def travel_time_without_Rebalancing(tnet, i, j, exo=0):
"""
evalute the travel time function for edge i->j
Parameters
----------
tnet: transportation network object
i: starting node of edge
j: ending node of edge
Returns
-------
float
"""
return sum(
[tnet.fcoe... | 00ae58356d1a808d34a559267134cb52fc8b0dc5 | 305 |
import numpy
import math
def enhance_with_function(images, labels, ratio, enhance_func):
"""
:param images:
:param labels:
:param ratio: the ratio of max input class. for example, highest sample count is 1000, ratio is 3, the result
will be around 1000 * 3 * how_many_classes
:param enhance_fun... | d16b7d3726902653bce94c11dba808da1ee88d09 | 306 |
import uuid
def uuid1_():
"""用于生成GUID"""
return str(uuid.uuid1()) | 8b1bf00c2c76429499a4300cc7f75fd075a0bf1c | 308 |
import os
def get_tmp_filepath(_file):
"""生成一个针对_file的临时文件名"""
_path = os.path.dirname(_file)
_tmp_filename = os.path.basename(_file)
if not _tmp_filename.startswith('.'):
_tmp_filename = '.' + _tmp_filename
_tmp_filename += '_tmp'
_tmp_filepath = os.path.join(_path, _tmp_filename)... | f566825dec9c3a6330ba5e1578f74c2a171e4296 | 309 |
def upperLeftOrigin( largeSize, smallSize ):
"""
The upper left coordinate (tuple) of a small rectangle in a larger rectangle (centered)
"""
origin = tuple( map( lambda x: int( ( (x[0]-x[1])/2 ) ), zip( largeSize, smallSize )) )
return origin | bda31fc5eb021f40a62b00949ced940ef171005f | 310 |
def is_square_inside(row, col, rows, cols):
"""Check if row and col is square inside grid having rows and cols."""
return row not in (0, rows - 1) and col not in (0, cols - 1) | f0cdcbc6d9bee6a41fd0cc84b16ffaf0638a522c | 311 |
def clean_repository_clone_url( repository_clone_url ):
"""Return a URL that can be used to clone a tool shed repository, eliminating the protocol and user if either exists."""
if repository_clone_url.find( '@' ) > 0:
# We have an url that includes an authenticated user, something like:
# http:/... | c1d274e907d73aceaa5f1e2c52336edf1638cd8a | 312 |
def add(n1, n2):
"""Adds the 2 given numbers"""
return n1 + n2 | ca670819dab8230e355e1b236d9cc74ed0b3b868 | 314 |
def kwarg_any(kwarg_functions):
"""Resolve kwarg predicates with short-circuit evaluation. This optimization
technique means we do not have to evaluate every predicate if one is already
true.
"""
return any(kwarg_function() for kwarg_function in kwarg_functions) | 3303e1a871bb41920ba0f41e4928e05b6d876c1e | 315 |
from typing import Tuple
from typing import Optional
def _get_build_to_download(build: str) -> Tuple[str, Optional[str]]:
"""Get the build version to download.
If the passed value is not an explict build number (eg. 15.0) then
the build for the current day of that major/minor will be downloaded.
:p... | 96215d80af60c25877da3eb7ff65147b2652a592 | 316 |
import torch
def kl_reverse(logu: torch.Tensor) -> torch.Tensor:
"""
Log-space Csiszar function for reverse KL-divergence D_f(p,q) = KL(q||p).
Also known as the exclusive KL-divergence and negative ELBO, minimizing
results in zero-forcing / mode-seeking behavior.
Args:
logu (torch.Tensor... | fcc9035de183cb6d5b51e169dd764ff92ab290aa | 317 |
def reload() -> bool:
"""Gracefully reloads uWSGI.
* http://uwsgi.readthedocs.io/en/latest/Management.html#reloading-the-server
"""
return False | f020356774d0a500b6755d53d548a804392c39d3 | 319 |
import re
def predict_imagen(titulo=None,
grados=None,
ano_lanzamiento=None,
paginas=None,
codbarras=None):
""" Predictor for Imagen from model/5a143f443980b50a74003699
Created using BigMLer
"""
tm_tokens = 'tokens_only... | ecee556bf9eb563cb40bf759bb6c4bfdf74922a0 | 320 |
def construct_item(passage: str, labels):
"""
根据输入的passage和labels构建item,
我在巴拉巴拉...
['B-ASP', 'I-ASP', 'I-ASP', 'I-ASP', ..., 'I-OPI', 'I-OPI', 'O']
构造结果示例如下:
{
'passage': '使用一段时间才来评价,淡淡的香味,喜欢!',
'aspect': [['香味', 14, 16]],
'opinion': [['喜欢', 17, 19]]
}
:return:
... | b4a31b67df7c82b56e0eb388e964422f257a9293 | 321 |
def getStartingAddress(packet):
"""Get the address of a modbus request"""
return ((ord(packet[8]) << 8) + ord(packet[9])) | 83dc55585d67169b0716cc3e98008574c434213b | 322 |
import numbers
def is_number(item):
"""Check if the item is a number."""
return isinstance(item, numbers.Number) | 6c3fb6817a0eda2b27fcedd22763461dceef6bc1 | 323 |
def from_list(commands):
"""
Given a list of tuples of form (depth, text)
that represents a DFS traversal of a command tree,
returns a dictionary representing command tree.
"""
def subtrees(commands, level):
if not commands:
return
acc = []
parent, *commands... | 39dad022bf81712e074f6e8bb26813302da9ef9f | 324 |
def buildGeneMap(identifiers, separator="|"):
"""build map of predictions to genes.
Use an identifier syntax of species|transcript|gene. If none is
given, all transcripts are assumed to be from their own gene.
"""
map_id2gene, map_gene2ids = {}, {}
for id in identifiers:
f = id.spli... | e854639142bd600338563ffc1160b43359876cdd | 325 |
def checkdnsrr():
"""Check DNS records corresponding to a given
Internet host name or IP address"""
return NotImplementedError() | 7fda596230cc5f61e946e8a0949c67f365cf5563 | 327 |
def xml_attr_or_element(xml_node, name):
""" Attempt to get the value of name from the xml_node. This could be an attribute or
a child element.
"""
attr_val = xml_node.get(name, None)
if attr_val is not None:
return attr_val.encode('utf-8').strip()
for child in xml_node.getchildren()... | 4ec061a9a865291d8d26d8de474141175d5aab28 | 328 |
import numpy
def kmeans_init_centroids(x_array, num_centroids_K):
"""
This function initializes K centroids that are to be used in K-means on the dataset x_array.
Parameters
----------
x_array : array_like
The dataset of size (m x n).
num_centroids_K : int
The number of clust... | 2e310dd3fe9eb6dd32999e32f583fc4a7fd0bbf0 | 329 |
def get_coinbase_candle_url(url, timestamp_from, pagination_id):
"""Get Coinbase candle URL."""
start = timestamp_from.replace(tzinfo=None).isoformat()
url += f"&start={start}"
if pagination_id:
url += f"&end={pagination_id}"
return url | a1bb4e975060ba5e3438b717d1c2281349cd51f1 | 330 |
def part2():
"""This view will be at the path ``/part2``"""
return "Part 2" | 92a8789b669a66989a74be2c2126e8958e4beece | 331 |
def subplot_index(nrow, ncol, k, kmin=1):
"""Return the i, j index for the k-th subplot."""
i = 1 + (k - kmin) // ncol
j = 1 + (k - kmin) % ncol
if i > nrow:
raise ValueError('k = %d exceeds number of rows' % k)
return i, j | 2d2b7ef9bf9bc82d06637157949ca9cb3cc01105 | 333 |
def _split_keys(keypath, separator):
"""
Splits keys using the given separator:
eg. 'item.subitem[1]' -> ['item', 'subitem[1]'].
"""
if separator:
return keypath.split(separator)
return [keypath] | 2f67a35a2e08efce863d5d9e64d8a28f8aa47765 | 334 |
def spacify(string, spaces=2):
"""Add spaces to the beginning of each line in a multi-line string."""
return spaces * " " + (spaces * " ").join(string.splitlines(True)) | 7ab698d8b38a6d940ad0935b5a4ee8365e35f5da | 336 |
import math
def calc_dif_mod_cn (x, y):
""" Check if the difference between the modulus of consecutive numbers is a prime number """
modx = math.sqrt(x.real ** 2 + x.imag ** 2) # modulus of the first complex number
mody = math.sqrt(y.real ** 2 + y.imag ** 2) # modulus of the second complex number
d... | 88e353e4a948c3b6adc65b91265a5f6d2e68a1c1 | 339 |
def frohner_cor_3rd_order(sig1,sig2,sig3,n1,n2,n3):
"""
Takes cross-sections [barns] and atom densities [atoms/barn] for
three thicknesses of the same sample, and returns extrapolated
cross section according to Frohner.
Parameters
----------
sig1 : array_like
Cross section of the ... | d6f0b39368c19aeda899265eb187190bb4beb944 | 343 |
def nodeInTree(root, k):
"""
Checks if the node exists in the tree or not
"""
if root == None:
return False
if root.data == k or nodeInTree(root.left, k) or nodeInTree(root.right, k):
return True
return False | 14db01c8d2370bfaa01220d3608798165ea1a096 | 344 |
def split_and_filter(intermediate_str, splitter):
"""
Split string with given splitter - practically either one of "," or "/'".
Then filter ones that includes "https" in the split pickles
:param intermediate_str : string that in the middle of parsing
:param splitter
:return: chunk of string(s) a... | a4b800df1aca89ca1e8eedfc65a5016a995acd48 | 345 |
import os
def verify_image(filename):
"""Verifies whether the file exists"""
image_extensions = ['tif', 'jpg', 'gif', 'png', 'jpeg']
if type(filename) is str:
extension = filename.split('.')
if len(extension) == 2:
if extension[1].lower() in image_extensions:
re... | 84e9845ab3e146d94f2ba3e0a2fb3ecd458b822f | 346 |
import copy
import random
def entries():
""" Basic data for a test case """
return copy.deepcopy(
{"arb_key": "text", "randn": random.randint(0, 10),
"nested": {"ntop": 0, "nmid": {"list": ["a", "b"]},
"lowest": {"x": {"a": -1, "b": 1}}},
"collection": {1, 2, 3}}) | 5d6cde325b69e43598f9d0158ae5989a4d70b54c | 348 |
def count_ref_alleles(variant, *traits):
"""Count reference allels for a variant
Parameters
----------
variant : a Variant as from funcgenom
the variant for which alleles should be counted
*traits : str
the traits for which alleles should be counted
Returns
-------... | 10ea3468f5de8f2b77bb97b27b888af808c541b7 | 349 |
import random
def random_in_range(a: int, b: int) -> int:
""" Return a random number r with a <= r <= b. """
return random.randint(a, b) | 611c2754ace92eac4951f42e1e31af2f441ed0c2 | 351 |
def km_miles(kilometers):
"""Usage: Convert kilometers to miles"""
return kilometers/1.609 | 5480c065f904dfc1959691e158653fd0e6bb67e6 | 353 |
def strategy(history, memory):
"""
Tit-for-tat, except we punish them N times in a row if this is the Nth time they've
initiated a defection.
memory: (initiatedDefections, remainingPunitiveDefections)
"""
if memory is not None and memory[1] > 0:
choice = 0
memory = (memory[0], m... | bf8d09417c246f9f88a721dfcc4408f49195fd1a | 354 |
import torch
def get_cali_samples(train_data_loader, num_samples, no_label=True):
"""Generate sub-dataset for calibration.
Args:
train_data_loader (torch.utils.data.DataLoader):
num_samples (int):
no_label (bool, optional): If the dataloader has no labels. Defaults to True.
Ret... | 297ea0384b1e7f0a6ea51fc37325e57eb1cb8afa | 355 |
def _swap_endian(val, length):
"""
Swap the endianness of a number
"""
if length <= 8:
return val
if length <= 16:
return (val & 0xFF00) >> 8 | (val & 0xFF) << 8
if length <= 32:
return ((val & 0xFF000000) >> 24 |
(val & 0x00FF0000) >> 8 |
... | 4b3b879ad04e43e9454b904ba65420a8d477b629 | 358 |
def about(template):
"""
Attach a template to a step which can be used to generate
documentation about the step.
"""
def decorator(step_function):
step_function._about_template = template
return step_function
return decorator | 7c00256e39481247857b34dcd5b7783a39b0a8bd | 359 |
import torch
def _extend_batch_dim(t: torch.Tensor, new_batch_dim: int) -> torch.Tensor:
"""
Given a tensor `t` of shape [B x D1 x D2 x ...] we output the same tensor repeated
along the batch dimension ([new_batch_dim x D1 x D2 x ...]).
"""
num_non_batch_dims = len(t.shape[1:])
repeat_shape = ... | 7ee1d0930f843a9d31bcc4934d675109f3b2df9b | 360 |
def split_component_chars(address_parts):
"""
:param address_parts: list of the form [(<address_part_1>, <address_part_1_label>), .... ]
returns [(<char_0>, <address_comp_for_char_0), (<char_1>, <address_comp_for_char_1),.., (<char_n-1>, <address_comp_for_char_n-1)]
"""
char_arr = []
for addres... | f4f3dd59378a689e9048cee96b8d6f12e9d8fe21 | 361 |
import getpass
def get_ssh_user():
"""Returns ssh username for connecting to cluster workers."""
return getpass.getuser() | 166048aa258bd0b2c926d03478e8492a405b0f7e | 364 |
def adjacency_matrix(edges):
"""
Convert a directed graph to an adjacency matrix.
Note: The distance from a node to itself is 0 and distance from a node to
an unconnected node is defined to be infinite.
Parameters
----------
edges : list of tuples
list of dependencies between n... | b8743a6fa549b39d5cb24ae1f276e911b954ee5a | 365 |
def estimate_Cn(P=1013, T=273.15, Ct=1e-4):
"""Use Weng et al to estimate Cn from meteorological data.
Parameters
----------
P : `float`
atmospheric pressure in hPa
T : `float`
temperature in Kelvin
Ct : `float`
atmospheric struction constant of temperature, typically 10... | b74dd0c91197c24f880521a06d6bcd205d749448 | 366 |
def connection_type_validator(type):
"""
Property: ConnectionInput.ConnectionType
"""
valid_types = [
"CUSTOM",
"JDBC",
"KAFKA",
"MARKETPLACE",
"MONGODB",
"NETWORK",
"SFTP",
]
if type not in valid_types:
raise ValueError("% is not a... | cc2ed6096097c719b505356e69a5bb5cdc109495 | 368 |
def add_sibling(data, node_path, new_key, new_data, _i=0):
"""
Traversal-safe method to add a siblings data node.
:param data: The data object you're traversing.
:param node_path: List of path segments pointing to the node you're creating a
sibling of. Same as node_path of traverse()
:param new_key: The sibling... | 4bc11315eab686659edc9f7eb8479508d3ca37fb | 371 |
import re
def strip_characters(text):
"""Strip characters in text."""
t = re.sub('\(|\)|:|,|;|\.|’|”|“|\?|%|>|<', '', text)
t = re.sub('/', ' ', t)
t = t.replace("'", '')
return t | 763ddc837ef9be19aa067e362c312ebd88632ed7 | 372 |
def publications_classification_terms_get(search=None): # noqa: E501
"""List of Classification Terms
List of Classification Terms # noqa: E501
:param search: search term applied
:type search: str
:rtype: ApiOptions
"""
return 'do some magic!' | 6633c91d59a5df7805979bd85a01f8eb1c269946 | 374 |
def _card(item):
"""Handle card entries
Returns: title (append " - Card" to the name,
username (Card brand),
password (card number),
url (none),
notes (including all card info)
"""
notes = item.get('notes', "") or ""
# Add car... | fc7d5e4b960019b05ffe7ca02fd3d1a94d69b303 | 375 |
def get_width_and_height_from_size(x):
""" Obtains width and height from a int or tuple """
if isinstance(x, int): return x, x
if isinstance(x, list) or isinstance(x, tuple): return x
else: raise TypeError() | 581c9f332613dab5de9b786ce2bac3387ee1bd3b | 377 |
def remove_stopwords(lista,stopwords):
"""Function to remove stopwords
Args:
lista ([list]): list of texts
stopwords ([list]): [description]
Returns:
[list]: List of texts without stopwords
"""
lista_out = list()
for idx, text in enumerate(lista):
text = ' '.joi... | edca74bb3a041a65a628fcd3f0c71be5ad4858df | 378 |
def get_users_report(valid_users, ibmcloud_account_users):
"""get_users_report()"""
users_report = []
valid_account_users = []
invalid_account_users = []
# use case 1: find users in account not in valid_users
for account_user in ibmcloud_account_users:
# check if account user is in va... | a96f8835496f82d8b6f8cd4f248ed8a03676795b | 379 |
def get_natural_num(msg):
"""
Get a valid natural number from the user!
:param msg: message asking for a natural number
:return: a positive integer converted from the user enter.
"""
valid_enter = False
while not valid_enter:
given_number = input(msg).strip()
i... | 77bed94bf6d3e5ceb56d58eaf37e3e687e3c94ba | 381 |
import types
def copy_function(old_func, updated_module):
"""Copies a function, updating it's globals to point to updated_module."""
new_func = types.FunctionType(old_func.__code__, updated_module.__dict__,
name=old_func.__name__,
argdefs=old_func._... | e09022f734faa1774a3ac592c0e12b0b007ae8e3 | 382 |
import random
def get_random_color():
"""
获得一个随机的bootstrap颜色字符串标识
:return: bootstrap颜色字符串
"""
color_str = [
'primary',
'secondary',
'success',
'danger',
'warning',
'info',
'dark',
]
return random.choice(color_str) | 898814996aa5ada8f4000244887af382b8b9e1bc | 383 |
def neighborhood(index, npoints, maxdist=1):
"""
Returns the neighbourhood of the current index,
= all points of the grid separated by up to
*maxdist* from current point.
@type index: int
@type npoints: int
@type maxdist int
@rtype: list of int
"""
return [index + i for i in ran... | 98166d810daa6b99862a4c9f6d1629fdfa571bd0 | 384 |
def data_check(data):
"""Check the data in [0,1]."""
return 0 <= float(data) <= 1 | b292ef07a024e53d82e706f0d88d50d6318d6593 | 385 |
def decentralized_training_strategy(communication_rounds, epoch_samples, batch_size, total_epochs):
"""
Split one epoch into r rounds and perform model aggregation
:param communication_rounds: the communication rounds in training process
:param epoch_samples: the samples for each epoch
:param batch_... | 3a743208af50d7c7865d5d5f86a4f58b0ba98a4d | 387 |
def create_config_file_lines():
"""Wrapper for creating the initial config file content as lines."""
lines = [
"[default]\n",
"config_folder = ~/.zettelkasten.d\n",
"\n",
"def_author = Ammon, Mathias\n",
"def_title = Config Parsed Test Title\n",
"def_location_spec... | d0d1057c3f450636279a8df9d4a39977f1eeef42 | 388 |
def get_recipes_from_dict(input_dict: dict) -> dict:
"""Get recipes from dict
Attributes:
input_dict (dict): ISO_639_1 language code
Returns:
recipes (dict): collection of recipes for input language
"""
if not isinstance(input_dict, dict):
raise TypeError("Input is not typ... | e710d9629d10897d4aae7bf3d5de5dbbe18196c5 | 389 |
def split(text):
"""Turns the mobypron.unc file into a dictionary"""
map_word_moby = {}
try:
lines = text.split("\n")
for line in lines:
(word, moby) = line.split(" ", 1)
map_word_moby[word] = moby
except IOError as error:
print(f"Failed due to IOError: {... | ba051724f0399e918949c3e8b7fb010e2d87c9f9 | 391 |
def report(key_name=None, priority=-1, **formatters):
""" Use this decorator to indicate what returns to include in the report and how to format it """
def tag_with_report_meta_data(cls):
# guard: prevent bad coding by catching bad return key
if key_name and key_name not in cls.return_keys:
... | 3830135de40bdc2a25bd3c6b6cecc194c6dbebac | 392 |
def lerp(a,b,t):
""" Linear interpolation between from @a to @b as @t goes between 0 an 1. """
return (1-t)*a + t*b | 12cb8690ba5e5f2a4c08c1cd29d3497513b63438 | 394 |
def generate_annotation_dict(annotation_file):
""" Creates a dictionary where the key is a file name
and the value is a list containing the
- start time
- end time
- bird class.
for each annotation in that file.
"""
annotation_dict = dict()
for line i... | f40f210075e65f3dbe68bb8a594deb060a23ad8b | 395 |
def extract_jasmine_summary(line):
"""
Example SUCCESS karma summary line:
PhantomJS 2.1.1 (Linux 0.0.0): Executed 1 of 1 SUCCESS (0.205 secs / 0.001 secs)
Exmaple FAIL karma summary line:
PhantomJS 2.1.1 (Linux 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.21 secs / 0.001 secs)
"""
# get tota... | f795ff015555cc3a2bd2d27527ae505a6dde9231 | 396 |
def degrees_of_freedom(s1, s2, n1, n2):
"""
Compute the number of degrees of freedom using the Satterhwaite Formula
@param s1 The unbiased sample variance of the first sample
@param s2 The unbiased sample variance of the second sample
@param n1 Thu number of observations in the first sample
@pa... | 5f076e33584c61dca4410b7ed47feb0043ec97cb | 397 |
import os
def get_requires_file(dist):
"""Get the path to the egg-info requires.txt file for a given dist."""
return os.path.join(
os.path.join(dist.location, dist.project_name + ".egg-info"),
"requires.txt",
) | f0fc66abc15fcba133240cc1783059d5694a08f6 | 398 |
def get_range_to_list(range_str):
"""
Takes a range string (e.g. 123-125) and return the list
"""
start = int(range_str.split('-')[0])
end = int(range_str.split('-')[1])
if start > end:
print("Your range string is wrong, the start is larger than the end!", range_str)
return range(sta... | a88d9780ac2eba1d85ae70c1861f6a3c74991e5c | 399 |
import io
import traceback
def _format_exception(e: BaseException):
"""
Shamelessly stolen from stdlib's logging module.
"""
with io.StringIO() as sio:
traceback.print_exception(e.__class__, e, e.__traceback__, None, sio)
return sio.getvalue().strip() | d80f60634a9862ca282b1c7ccf63ae8e945ffdc9 | 400 |
def annealing_epsilon(episode: int, min_e: float, max_e: float, target_episode: int) -> float:
"""Return an linearly annealed epsilon
Epsilon will decrease over time until it reaches `target_episode`
(epsilon)
|
max_e ---|\
| \
| \
| \
mi... | fab650085f271f1271025e23f260eb18e645a9ba | 402 |
def pad_seq(seq, max_length, PAD=0):
"""
:param seq: list of int,
:param max_length: int,
:return seq: list of int,
"""
seq += [PAD for i in range(max_length - len(seq))]
return seq | bb61677bc658e22b317e3d5fb10f7c85a84200d0 | 403 |
def pytest_funcarg__testname(request):
"""
The testname as string, or ``None``, if no testname is known.
This is the parameter added by the test generation hook, or ``None`` if no
parameter was set, because test generation didn't add a call for this test.
"""
return getattr(request, 'param', No... | 87444cda36635b21c27d260835f96670d6b2d215 | 404 |
def find_opposite_reader(card_reader_list, find):
"""Returns the card reader on the opposite side of the door for the card reader in find"""
for c in card_reader_list:
if c.room_a == find.room_b and c.room_b == find.room_a:
return c
raise (Exception("No reader on opposite side found")) | 8a70b9b35174be62f3ca816f385b4c29a6ebebe8 | 405 |
def extractYoloInfo(yolo_output_format_data):
""" Extract box, objectness, class from yolo output format data """
box = yolo_output_format_data[..., :6]
conf = yolo_output_format_data[..., 6:7]
category = yolo_output_format_data[..., 7:]
return box, conf, category | ff28a5ce5490c61722ca06b0e09b9bd85ee7e111 | 408 |
def replace_umlauts(s: str) -> str:
"""
Replace special symbols with the letters with umlauts (ä, ö and ü)
:param s: string with the special symbols (::)
:return: edited string
"""
out = s.replace('A::', 'Ä').replace('O::', 'Ö').replace('U::', 'Ü').replace('a::', 'ä').replace('o::', 'ö') \
... | 8fad1f1017a3fd860d7e32fd191dd060b75a7bb8 | 410 |
import json
import base64
def read_amuselabs_data(s):
"""
Read in an amuselabs string, return a dictionary of data
"""
# Data might be base64'd or not
try:
data = json.loads(s)
except json.JSONDecodeError:
s1 = base64.b64decode(s)
data = json.loads(s1)
ret = {}
... | f9c2fb2807d1003261bec7b58e4ba025aac65a6a | 411 |
import os
import sys
import configparser
def update_site_config(site_name, parameters):
"""Update the site config to establish the database settings"""
site_directory = os.path.join('web', 'sites', site_name)
if not os.path.isdir(site_directory):
print('site directory {} missing'.format(site_direc... | 8dce45257189cb5c4830f18fc1bcad388a193252 | 412 |
import torch
import math
def sample_random_lightdirs(num_rays, num_samples, upper_only=False):
"""Randomly sample directions in the unit sphere.
Args:
num_rays: int or tensor shape dimension. Number of rays.
num_samples: int or tensor shape dimension. Number of samples per ray.
upper_... | 7f7657ff66d0cffea6892dffdf49ba6b52b9def9 | 414 |
def date_handler(obj):
"""make datetime object json serializable.
Notes
-----
Taken from here: https://tinyurl.com/yd84fqlw
"""
if hasattr(obj, 'isoformat'):
return obj.isoformat()
else:
raise TypeError | 741867e05e1b5f3e9d0e042b3b1576fb61ab0219 | 415 |
def has_type(typestmt, names):
"""Return type with name if `type` has name as one of its base types,
and name is in the `names` list. otherwise, return None."""
if typestmt.arg in names:
return typestmt
for t in typestmt.search('type'): # check all union's member types
r = has_type(t, n... | d534331df62f76efdcbb93be52eb57ee600a7783 | 416 |
import base64
import struct
def tiny_id(page_id):
"""Return *tiny link* ID for the given page ID."""
return base64.b64encode(struct.pack('<L', int(page_id)).rstrip(b'\0'), altchars=b'_-').rstrip(b'=').decode('ascii') | 1a37b814ff9845949c3999999b61f79b26dacfdc | 417 |
def getSpectra(dataframe, indices):
""" Returns the files for training and testing
Inputs
-----------
dataframe: pd.DataFrame object from which we need to get spectra
indices: row values for which we need the spectra
Returns
-----------
spec_vals: pd.DataFrame object ... | 606757ffdde39c0847dd0402342441931d66a081 | 418 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.