content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
from typing import List
from typing import Dict
from typing import Tuple
from typing import Callable
def enum_options(values: List[Dict]) -> Tuple[List[str], int, Callable]:
"""Enumerate options of a enum parameter for display in a select box.
Returns a 3-tuple containing a list of option value, the list inde... | c1214f319847b40705f425e529420a5916debe6e | 703,994 |
def bits_to_netmask(bits):
""" Convert bits to netmask
Args:
bits ('int'): bits to converts
ex.) bits = 32
Raise:
None
Returns:
Net mask
"""
mask = (0xffffffff >> (32 - bits)) << (32 - bits)
return (str( (0xff000000 & mask) >> 24) ... | 33897b357d99027d6f96fc5fb63f38989dbbe930 | 703,995 |
def find_elements(node, xpath, allow_zero=True, allow_multiple=True):
"""Attempt to find child elements in a node by xpath. Raise exceptions if conditions are violated. Return a
(possibly empty) list of elements."""
all_elements = node.findall(xpath)
if (len(all_elements) == 0 and not allow_zero) or (le... | 2255fcd63f35837c647dd6dca81ab648d59addc8 | 703,996 |
def largest_rectangle_area(heights):
""" return largest rectangle in histogram """
stack = [-1]
max_area = 0
for i in range(len(heights)):
# we are saving indexes in stack that is why we comparing last element in stack
# with current height to check if last element in stack not bigger t... | fefb750d57a250c322a6464be250fe2cb3a9a2df | 703,997 |
import subprocess
def kill_lines(path):
"""
Will run sed on all files in path and remove leftovers from commented out cookie cutter code ` # - ` or ` // - `
"""
re = '^\s*(#|//) -\s*$'
for escape in "()/|":
re = re.replace(escape, fr"\{escape}")
sed_command = f"/{re}/d"
print(f"rem... | 19bd97900ff2be10528eed93a0a42f9984d404a6 | 703,998 |
def generateMessage(rotation, tiltRight, tiltLeft, eyeLeft, blinkLeft, blinkRight, eyeRight):
"""
"""
messageToSend = []
messageToSend.append(int(rotation))
messageToSend.append(int(tiltRight))
messageToSend.append(int(tiltLeft))
messageToSend.append(int(eyeLeft))
messageToSend.append(i... | fcda9d537cda1fd7dc6fbc1e888d2a1af598104c | 704,000 |
def app_metadata_json():
"""Create metadata.json content for a test app."""
return {
"description": "A test app that does not really exist.",
"title": "Test App",
"version": "1.0.0",
"authors": "aiidalab",
"logo": "img/logo.png",
"state": "development"
} | a07c21259c43980e51e0a8e115e589b02e493d04 | 704,001 |
def get_text(original, token, replace):
"""Convenience function for getting the text to use for a match when
formatting.
If ``replace`` is False, returns the part of ``original`` between
``token.startchar`` and ``token.endchar``. If ``replace`` is True, returns
``token.text``.
"""
if repla... | b0e2e53611cb5b26b04d0e8350f1ae88a6b56056 | 704,002 |
def calc_Ti(Te, Tg, n):
"""Calcuate the infectious period."""
return (Tg - Te) * 2.0 * n / (n + 1.0) | 7ba0176b821032e4f69ff7fe368393c2773c7d0d | 704,003 |
def _get_indent(line):
"""Return the indentation in front of a line"""
indent = line.replace(line.lstrip(), '')
return indent | 6a5dd97d4c5702a55b8b1ddaad91c5ecb99458fa | 704,004 |
def _GetRegionalSetRequest(client, health_check_ref, replacement):
"""Returns a request for updating the health check."""
return (client.apitools_client.regionHealthChecks, 'Update',
client.messages.ComputeRegionHealthChecksUpdateRequest(
healthCheck=health_check_ref.Name(),
he... | ec47ac791fcf912ba7c05077b34f2f62e0949691 | 704,005 |
def problems(mod, msg):
"""Ansible module exist with an error."""
return mod.exit_json(changed=False, failed=True, msg=msg) | 3ec1a8c8843ba9b33d47e61d1b775aadb32ab45e | 704,006 |
def to_sql_name(name):
"""
Ensure ``name`` is a valid SQL name.
"""
return name.lower().replace(' ', '_') | f3157d9444793d0af05e27317fdab2aa55531b84 | 704,007 |
import os
import json
def get_setting(key):
"""Get the secret variable or return explicit exception."""
try:
base_dir = str(os.path.dirname(__file__))
print("BASE DIR: " + base_dir)
with open(base_dir.join("/config.json")) as f:
config_json = json.loads(f.read())
... | 20cae220942c087f3d372444399f79e68aa49263 | 704,008 |
def polygon_to_points( poly ):
"""
Plotting helper, which rearranges polygon vertices into lists
of X and Y coordinates. The first point is duplicated at the end
of each list, to make a closed path.
:Parameters:
poly: tuple of ((x1,y1),(x2,y2),...)
The coordinates of t... | 958621cb7ff2d4fe22c4482e07a6a7ba614f9fc1 | 704,009 |
import re
def alphanumerical(string):
"""
A function to filter a string to only allow alphanumerical characters.
"""
pattern = re.compile('[^a-zA-Z0-9]+')
return pattern.sub('', string) | 3acd64f629e601c72421ac73955a61c1426d3a9d | 704,010 |
def helper_parse_UniProt_dump_other_functions(list_of_string):
"""
e.g. input
[['EMBL; AY548484; AAT09660.1; -; Genomic_DNA.'],
['RefSeq; YP_031579.1; NC_005946.1.'],
['ProteinModelPortal; Q6GZX4; -.'],
['SwissPalm; Q6GZX4; -.'],
['GeneID; 2947773; -.'],
['KEGG; vg:2947773; -.'],
... | 292cd9eca3636ba3cd6813df574de3bdd54aa48f | 704,011 |
import numpy
def normalise_signal_minmax(signal: numpy.ndarray) -> numpy.ndarray:
""" """
return numpy.interp(signal, (signal.min(), signal.max()), (-1, 1)) | 266cb3c86fa5f48c997bb8f18e42cc38b2d05d7e | 704,012 |
import os
def parallel():
"""
Returns 'mpi', if this code runs with MPI, else returns 'seq'
:return:
"""
return 'mpi' if 'OMPI_COMM_WORLD_SIZE' in os.environ else 'seq' | 7a5212a1b563f2bd95130ee6b6381397a4ef2edd | 704,013 |
def decode_dbkey(dbkey):
""" Decodes dbkey and returns tuple ( username, dbkey )"""
if isinstance(dbkey, str) and ':' in dbkey:
return dbkey.split(':')
else:
return None, dbkey | de2a076b36e4ea82412478384b65845af225b1ab | 704,014 |
def get_case_related_entities(st, related_cases):
"""Returns the all the entities featured in the related cases without duplicates.
INPUT: Storage unit, related cases.
OUTPUT: All the entities and their types contained in the related cases without duplicates"""
existing_ners = {}
for c in related_ca... | 7ecc8927720a22d5dc05c948b9abbae458aee426 | 704,015 |
import random
def get_documents_words(news_files, corpus_news):
"""
Given a set of documents it will return the dictionary with their
respective categories
:param news_files: List of raw news file names
:param corpus_news: PlainTextCorpusReader object
:return: Dictionary with words and categor... | ad189bf0e00118bebbb21794d959d903242ca10c | 704,016 |
def question_first_sentence(database_connection, question):
"""
return the id, answer, and first sentence of questions in a set of categories
"""
c = database_connection.cursor()
command = 'select raw from text where question=%i' % question
c.execute(command)
for ii, in c:
return ii | 730e3c3825a47f66418a3c9decbd0e38755b6775 | 704,017 |
def sum_of_vals(vals):
"""
:param vals: an iterable such as list
:return: sum of the values from the iterable
"""
sum = 0
for val in vals:
sum += val
return sum | aecc28e505acbea02f5ec41aec03b2db7bc3baad | 704,018 |
def time_sa_to_s(t, clock_freq):
"""
convert from time in samples to time in seconds
"""
return float(t / clock_freq) | eabf76cda8529dc9c9ad0acc6466c5037062b295 | 704,019 |
def mod(ctx, arg):
"""
"""
action = ctx.copy_last_action()
return action | e9007ffab406df13ddf01c6d65d58deaa713799c | 704,020 |
def kdcompare(r, p, depth):
"""
Returns the branch of searching on a k-d tree
Input
r: root
p: point
depth : starting depth of search
Output
A value of -1 (left branch), or 1 (right)
"""
k = len(p)
dim = depth%k
if p[dim] <= r.point[dim]:
return -1
... | c11aa24718b8a2d8d9e39852ca53e09118d3c215 | 704,021 |
def _has_class(domElement, className):
"""
Helper function to test if the provided element has the provided class
"""
return className in domElement.get_attribute('class').split(" ") | 9a20557cc8d3e3dc91ac33764a6d94139b70f6f2 | 704,022 |
def format_datestamp(datestamp):
"""Format datestamp to an OAI-PMH compliant format.
Parameters
----------
datestamp: datetime.datetime
A datestamp.
Return
------
str:
Formatted datestamp.
"""
return datestamp.strftime('%Y-%m-%dT%H:%M:%SZ') | f050dd4f18691034c0414a4d9fa51629b0208d6a | 704,023 |
import base64
def encode_base64(data: bytes) -> bytes:
""" Creates a url safe base64 representation of an input string, strips
new lines."""
return base64.urlsafe_b64encode(data).replace(b"\n", b"") | 472ff045dc1df4ad5fe2a0e3001477a4d1c738fd | 704,025 |
def yellow_bold(payload):
"""
Format payload as yellow.
"""
return '\x1b[33;1m{0}\x1b[39;22m'.format(payload) | 2ae528c9dcc5a4f9b5f685f201f4d6696387a256 | 704,026 |
def add_trial_name_as_number(warm_up_data_df):
"""add column where trial_name is converted to number and before-/after-correction is added"""
warm_up_data_df.insert(
warm_up_data_df.shape[1], "trial_name_corrected_by_before_and_after", float(100)
)
offset = 0
for index, row in warm_up_data_d... | 160907c14f377cae0c2067dac1dd898f4e343056 | 704,027 |
def normalize(rendered):
"""Return the input string without non-functional spaces or newlines."""
out = ''.join([line.strip()
for line in rendered.splitlines()
if line.strip()])
out = out.replace(', ', ',')
return out | 02a87a7a5e596b45d15bb2559403e92cb69a2f1d | 704,028 |
import aiohttp
import asyncio
async def test_download_speed(session: aiohttp.ClientSession, url: str) -> int:
"""Count the amount of data successfully downloaded."""
result = 0
try:
async with session.get(url) as resp:
while True:
chunk = await resp.content.read(56)
... | c6ca9504f90cbb9091051931054f12f8498b8535 | 704,029 |
def compare_nodal_prices(df_dcopf, df_mppdc):
"""Find max absolute difference in nodal prices between DCOPF and MPPDC models
Parameters
----------
df_dcopf : pandas DataFrame
Results from DCOPF model
df_mppdc : pandas DataFrame
Results from MPPDC model
Returns
... | 2368bb7f8534ac466ab7858fa1056e3fe5f48f16 | 704,030 |
def add(a, b):
"""A dummy function to add two variables"""
return a + b | 4914b8d73e6808d93e8e8ee98902ad3b093f1ce6 | 704,031 |
def truncate(s, eps):
"""
Find the smallest k such that sum(s[:k]**2) \geq 1-eps.
"""
mysum = 0.0
k=-1
while (mysum < 1-eps):
k += 1
mysum += s[k]**2
return k+1 | fc9b5984316e969961b496fd54425e4f52f025ff | 704,032 |
def list_to_str(items):
"""
:param items:
:return:
"""
mystr = ''
for item in items:
mystr += item
return mystr | 6530a33641f261888094d4ecb6fff469a97d6c10 | 704,033 |
import torch
def to_minmax_form(boxes):
"""
:param boxes: (n, 4) tensor, (xmin, ymin, xmax, ymax) form.
:return: (n, 4) tensor, (cx, cy, w, h) form
"""
xmin = boxes[:, 0] - boxes[:, 2] / 2 + 0.5
ymin = boxes[:, 1] - boxes[:, 3] / 2 + 0.5
xmax = boxes[:, 0] + boxes[:, 2] / 2 - 0.5
ymax... | f00f703c78db7926bbea684147facc6fa553ac67 | 704,034 |
def compute_mean_nutrient_intake(nutrient_intake):
"""Compute mean nutrient intake"""
nutrient_totals = nutrient_intake.sum()
total_count = nutrient_intake.count()
carb_mean = (nutrient_totals[0]/total_count)
fiber_mean = (nutrient_totals[1]/total_count)
fat_mean = (nutrient_totals[2]/total... | ff79f816162a8f555d5deb582eb9647f1cef66b9 | 704,035 |
import os
def delete_outputs(config, outcfg):
"""
Remove pipeline outputs to save memory
after running the job
Parameters
----------
config : dict-like
Input configuration of job. Uses
config["management"]["delete"] (list of key
used to index outcfg) to determine
... | 1edf02ae14a755f77899c6d3be05ff11a2d6bcf3 | 704,036 |
import csv
def get_outputs(output_file):
"""
Parse ``output_file`` which is a csv file and defines the semantics of the
output of a neural network.
For example, output neuron 1 means class "0" in the MNIST classification
task.
"""
outputs = []
mode = "rt"
with open(output_file, mo... | b001942bc270952c9bb82537d0b5033c9ee968ff | 704,037 |
def get_io_functions_from_lib(lib, load_func_name='load', dump_func_name='dump', load_kwargs={}, dump_kwargs={}):
"""Helper to create loader and dumper functions for libraries"""
def loader(input_stream, args):
return getattr(lib, load_func_name)(input_stream, **load_kwargs)
def dumper(output, outpu... | 1d81031c7e5421f190f8c8936d92f2a5a2d999bf | 704,039 |
import sys
def is_piped_output():
"""
Checks the piped output.
This function checks if this script
is being executed with a piped output.
E.g.: python dnsrato.py -d domain.com --format json > outfile.json
Returns
-------
bool
True if the is a piped output, False otherwise.
... | 4f59a6abc6bfaac47340434afd07c62aaf8a5ddc | 704,040 |
def list_zeroes(line):
"""
Takes a list of integers and removes all non-zero elements.
"""
zeroes = []
for item in line:
if item == 0:
zeroes.append(item)
return zeroes | f10d6a59f8a6f00cb22d5f6ee6ce2087a4969b8e | 704,042 |
def ObjectToDict(obj):
"""Converts an object into a dict."""
keys = [ k for k in dir(obj) if not k.startswith("__") ]
return { k : getattr(obj, k) for k in keys } | f2679daab84d5cee2c7f319d1d34f3c669971cd6 | 704,043 |
def ortho(subj_coord, obj_coord, subj_dim, obj_dim):
""" It returns a tuple of 3 values: new dim for combined array,
component of subj_origin in it, component of obj_origin in it. """
if subj_coord > obj_coord:
return (subj_coord + (obj_dim - obj_coord), 0,
subj_coord - obj_coord)
... | 36a3127b0721ac87e81259432823eab26fc015e9 | 704,044 |
def _unravel(nodes,tets,index):
"""Returns a list containing the node coordinates of the tet
stored in the 'index' position in the 'tets' list."""
return [nodes[tets[index][0]],nodes[tets[index][1]],nodes[tets[index][2]],nodes[tets[index][3]]] | e8428de351db2a84a4875a81b47d07b03a67efd9 | 704,045 |
def visdom_image(vis, image,win_name):
"""
eg :
visdom_image(vis=vis, image=drawn_image, win_name='image')
:param vis: 由 setup_visdom 函数创建
:param image: 单幅图片张量,shape:[n,w,h]
:param win_name: 绘图窗口名称,必须指定,不然会一直创建窗口
:return:
"""
vis.image(img=image, win=win_name)
... | 145ad236c0e07a79195a573b562ffd9a8654be96 | 704,046 |
def file_num2size(num_size, h=True):
"""文件大小数值变为 MB 的显示
:param num_size: 文件大小
:param h: 是否 human 显示
:return: {'value': 数值,'measure': 单位,'str': 字串, 'org_size': 原始大小}
"""
measure_list = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
fsize = num_size
i = 0
while (fsize >= 1) and (i < len(measure... | f3cf060b4015831381ab5d5b3ed236d8519746cc | 704,047 |
import types
import asyncio
def loop_apply_coroutine(loop, func: types.FunctionType, *args, **kwargs) -> object:
"""
Call a function with the supplied arguments.
If the result is a coroutine, use the supplied loop to run it.
"""
if asyncio.iscoroutinefunction(func):
future = asyncio.ensure... | d77a70540237f690e712e30b93b53b363907b678 | 704,049 |
def zipmap(keys, vals):
"""
Return a ``dict`` with the keys mapped to the corresponding ``vals``.
"""
return dict(zip(keys, vals)) | a058e5a4e462416f48d83b3c288a0cd8d6b000ef | 704,050 |
def _create_thingy(sql_entity, session):
"""Internal call that holds the boilerplate for putting a new SQLAlchemy object
into the database. BC suggested this should be a decorator but I don't think
that aids legibility. Maybe should rename this though.
"""
session.add(sql_entity)
#Note t... | 4d50da3a15606c7adf61e2c9c09a4a3a9898edf9 | 704,051 |
def maxsubarray(list):
"""
Naive approach to calculating max subarray
Iterating all possible subarrays
Complexity (n = list size)
Time complexity: O(n^2)
Space complexity: O(1)
"""
maxStart = 0
maxEnd = 0
maxSum = list[0]
for i in range (len(list)):
currentSum = 0
... | 71b4a12d02fab45fc14890ae4a34a0dc50d6a7b4 | 704,052 |
from typing import Sequence
def is_sequence(obj):
"""Is the object a *non-str* sequence?
Checking whether an object is a *non-string* sequence is a bit
unwieldy. This makes it simple.
"""
return isinstance(obj, Sequence) and not isinstance(obj, str) | 06129c6122fec0290edb34cadc75b68199738435 | 704,053 |
def getAxisList(var):
"""
Returns a list of coordinates from: var
"""
return [var.coords[key] for key in var.dims] | eae9b971bcbf021ef2203dd6cb21df6343d0f19a | 704,054 |
def skip_nothing(name, dirpath):
"""Always returns :obj:`False`.
"""
return False | 9e846b7060af43b2c4165e6530fcabc66415615b | 704,056 |
import os
import subprocess
import re
def get_version_number(klocwork_path):
"""This function determines the Klocwork version number.
Inputs:
- klocwork_path: Absolute path to the bin directory of the Klocwork installation [string]
Ouputs:
- version_number: The version number of the Kloc... | 08f919420a1f2465895b3cab26d062fc78b58b95 | 704,057 |
import os
import sys
def credentials():
"""Retrieves credentials"""
username = os.environ.get('OS_USERNAME')
password = os.environ.get('OS_PASSWORD')
tenant_name = os.environ.get('OS_TENANT_NAME')
auth_url = os.environ.get('OS_AUTH_URL')
if not all((username, password, tenant_name, auth_url)... | 6ac966762db6bb8c9079502d4adcfbf94ec753e8 | 704,058 |
def centtoinch(cents):
"""Cents to inch."""
return .3937*cents | 517142a29242246721abd05638c8ecbefcd888cb | 704,059 |
def get_top_element_count(mol, top):
"""
Returns the element count for the molecule considering only the atom indices in ``top``.
Args:
mol (Molecule): The molecule to consider.
top (list): The atom indices to consider.
Returns:
dict: The element count, keys are tuples of (elem... | f7293c1d154346c955052ceff0ee59483538bdc3 | 704,060 |
def at_least_one_shift_each(cur_individual):
""" checks if there is at least one of each shift: 01, 10, 11 """
num_entrega = 0
num_recogida = 0
num_dual = 0
while cur_individual:
shift = cur_individual[:2]
cur_individual = cur_individual[2:]
if shift == '01':
num_... | 070fe16e779ab30bcee7873ec01876962f30ec91 | 704,062 |
from datetime import datetime
import pytz
def get_aware_utc_now():
"""Create a timezone aware UTC datetime object from the system time.
:returns: an aware UTC datetime object
:rtype: datetime
"""
utcnow = datetime.utcnow()
utcnow = pytz.UTC.localize(utcnow)
return utcnow | b0b102b8d7d49e0d7d4041a476502cdd683dc8af | 704,063 |
from typing import Optional
from typing import Callable
from typing import Iterator
from typing import Any
import inspect
def iterpoints(resp: dict, parser: Optional[Callable] = None) -> Iterator[Any]:
"""Iterates a response JSON yielding data point by point.
Can be used with both regular and chunked respons... | 000c2c873ab38378bb42945ed3304213b254061a | 704,064 |
def convert_output_key(name):
""" Convert output name into IE-like name
:param name: output name to convert
:return: IE-like output name
"""
if not isinstance(name, tuple):
return name
if len(name) != 2:
raise Exception('stats name should be a string name or 2 elements tuple '
... | d5c59766c615e0e7b45f173948692050a7b890e3 | 704,065 |
def in_polygon(point, polygon):
"""Simple wrapper on the within method of shapely points
Params: point (POINT) a shapely point object
polygon (POLYGON) a shapely polygon object (the target overlap area)
Returns: (bool) whether or not the point is within polygon expressed as a boolean
"... | 0a26d023672162a53affddfe23a89361d900d9a0 | 704,066 |
import typing
def parse_patter(pats: typing.List[str]) -> typing.Tuple[typing.List[str], typing.List[str]]:
"""
分析匹配项
========
/xx/ # 只匹配根目录下文件夹
xx/ # 匹配所有的文件夹
/xx # 只匹配根目录下文件
xx # 匹配所有的文件
!xx # 除xx之外
=========
/xx/ => xx + xx/**
xx/ => xx + xx/... | 17eca544b157fe2ad406e1c4385c49acc53ff0d7 | 704,067 |
import os
def is_downloaded(folder,path_):
"""[check if the .html file exists]
Args:
folder ([folder in which is placed the book]): [description]
path_ ([type]): [path of the .html page]
Returns:
[type]: [description]
"""
if not os.path.exists(folder):
os.maked... | 1d480fedb13429baa4bc3234f7a42cafe8dba93c | 704,068 |
def set_spines(ax, plot_params):
"""
Sets spines of the shift graph to be invisible if chosen by the user
Parameters
----------
ax: Matplotlib ax
Current ax of the shift graph
plot_parms: dict
Dictionary of plotting parameters. Here `invisible_spines` is used
"""
spines ... | 4e74ce30f52d465e9470f608cd8c909dfae4d0a5 | 704,069 |
def matches(G, queue):
"""
If the sequence in 'queue' correspond to a
node in 'G', return the sequence id,
otherwise return False
"""
if not queue:
return False
seq = 0
for a in queue:
try:
seq = G[seq][a]
except KeyError:
return False
... | 859f43f6457b4add4cda88495a8dc6c4a559e5d5 | 704,071 |
def getPortList(chute):
"""
Get a list of ports to expose in the format expected by create_container.
Uses the port binding dictionary from the chute host_config section.
The keys are expected to be integers or strings in one of the
following formats: "port" or "port/protocol".
Example:
po... | eb97568befca72f6d9cb6c455d8d9ad03b13eebf | 704,072 |
def get_datasets_dbpedia(subset, limit):
"""
Loads dbpedia data from files, split the data into words and generates labels.
Returns split sentences and labels.
"""
datasets = dict()
data = []
target = []
target_int =[]
target_names = []
filename = 'data/dbpedia/'+subset+'.cs... | 03f567e814b3ca0227b558177feb8a2165256cfc | 704,073 |
import glob
import sys
import os
def recursive_glob(path):
"""Version-agnostic recursive glob.
Implements the Python 3.5+ glob module's recursive glob for Python 2.7+.
Recursive glob emulates the bash shell's globstar feature, which is enabled
with `shopt -s globstar`.
Args:
path: A path that may cont... | 6a738db431a0230c186f14f6739f1beb20e1ff97 | 704,074 |
import re
def camelcase_to_snakecase(value: str) -> str:
"""
Convert a string from snake_case to camelCase.
>>> camelcase_to_snakecase('')
''
>>> camelcase_to_snakecase('foo')
'foo'
>>> camelcase_to_snakecase('fooBarBaz')
'foo_bar_baz'
>>> camelcase_to_snakecase('foo_bar_baz')
... | 05fe02739e8152bc64ab35bd842162b5d7c3ab4c | 704,075 |
def best_archiver(random, population, archive, args):
"""Archive only the best individual(s).
This function archives the best solutions and removes inferior ones.
If the comparison operators have been overloaded to define Pareto
preference (as in the ``Pareto`` class), then this archiver will form ... | 20d606f5ea4d76b1c6bd2acfd6bf1017e694f026 | 704,076 |
def elk_index(hashDict):
""" Index setup for ELK Stack bulk install """
index_tag_full = {}
index_tag_inner = {}
index_tag_inner['_index'] = "hash-data"
index_tag_inner['_id'] = hashDict['hashvalue']
index_tag_full['index'] = index_tag_inner
return index_tag_full | 9adcc529b88b319180e223ba9e47bda51e628478 | 704,078 |
import uuid
def generate_unique_str(allow_dashes=True):
"""
Generate unique string using uuid package
Args:
allow_dashes (bool, optional): If true use uuid4() otherwise use hex that will skip dash in names. Defaults to True.
"""
if allow_dashes:
unique_str = str(uuid.uuid4())
... | 9a08364837ea719454b885fcb344631005e7a610 | 704,079 |
def import_atm_mass_info():
"""
Funtion to load dictionary storing atomic mass information by atom type.
dict
dictionary of atomic mass by atom name
"""
massdict = {'H': 1.00797,
'HE': 4.0026,
'LI': 6.941,
'BE': 9.01218,
... | c470495f30d77b41642bfd07f52a82b7a060ffb5 | 704,080 |
def remove_batch_from_layout(layout):
"""
The tf-mesh layout splits across batch size, remove it.
Useful for prediction steps, when you no longer want large batches.
:param layout: string describing tf-mesh layout
:return: layout minus batch dimension
"""
layout = layout.split(',')
ret_... | 44d032504055e1133a6dc97ea040ff44ea2ac327 | 704,081 |
def _knapsack01_recur(val, wt, wt_cap, n):
"""0-1 Knapsack Problem by naive recursion.
Time complexity: O(2^n), where n is the number of items.
Space complexity: O(n).
"""
if n < 0 or wt_cap == 0:
return 0
if wt[n] > wt_cap:
# Cannot be put.
max_val = _knapsack01_re... | 88f73b2e2f577b5e17a4ba235699ad542dfc7f0d | 704,082 |
def matchElements(e1, e2, match):
"""
Test whether two elements have the same attributes. Used to check equality of elements
beyond the primary key (the first match option)
"""
isMatch = True
for matchCondition in match:
if(e1.attrib[matchCondition] != e2.attrib[matchCondition]):
... | 1aa57a3a9a3123445e0234efa506f95616f90ef8 | 704,083 |
def auc_step(X, Y):
"""Compute area under curve using step function (in 'post' mode)."""
if len(X) != len(Y):
raise ValueError(
"The length of X and Y should be equal but got " + "{} and {} !".format(len(X), len(Y))
)
area = 0
for i in range(len(X) - 1):
delta_X = X[i... | 886f410a35a49a7098c1f2dcd145b54d1b54d423 | 704,084 |
def calculate_num_modules(slot_map):
"""
Reads the slot map and counts the number of modules we have in total
:param slot_map: The Slot map containing the number of modules.
:return: The number of modules counted in the config.
"""
return sum([len(v) for v in slot_map.values()]) | efbb82a54843f093a5527ebb6a1d4c4b75668ebb | 704,085 |
def df2dicts(df):
"""
df to dicts list
"""
dicts = []
for line in df.itertuples():
ll = list(df.columns)
dicts.append(dict(zip(ll, list(line)[1:])))
return dicts | f63520c22766a2454e52f17d539a876d1eea4fa5 | 704,087 |
import filecmp
def files_differ(path_a, path_b):
"""
True if the files at `path_a` and `path_b` have different content.
"""
return not filecmp.cmp(path_a, path_b) | ea0382e619228cd0fc042a9003c34f33bd53f313 | 704,089 |
def m2(topic_srs, topic_vol, sharpe, ref_vol, cum=False, annual_factor=1):
"""Calcs m2 return which is a port to mkt vol adjusted return measure.
The Sharpe ratio can be difficult to interpret since it's a ratio, so M2
converts a Sharpe to a return number.
Args:
topic_srs (Pandas DataFram... | 8b05b0419db895d1de756cfb8751b9311cd43eca | 704,090 |
def helper(n, largest_digit):
"""
:param n: int, a number
:param largest_digit: int,
:return: int, the largest digit
"""
if n == 0: # base case
return largest_digit
else:
if n < 0: # convert negative n into positive if any
n = n * -1
if n % 10 > largest_digit:
largest_digit = n % 10
return help... | 557a6ce39a31f7edd2438bea43be9d8abfec47c5 | 704,091 |
import networkx
def do_to_networkx(do):
"""Return a networkx representation of do"""
terms = do.get_terms()
dox = networkx.MultiDiGraph()
dox.add_nodes_from(term for term in terms if not term.obsolete)
for term in dox:
for typedef, id_, name in term.relationships:
dox.add_edge(... | 97c27a5e6ec3c0467fe42f34325aac5b565f5be3 | 704,092 |
def find_largest(line: str) -> int:
"""Return the largest value in line, which is a whitespace-delimited string
of integers that each end with a '.'.
>>> find_largest('1. 3. 2. 5. 2.')
5
"""
# The largest value seen so far.
largest = -1
for value in line.split():
# Remove the tra... | 95ceb1e79812e9ef9c7338f393e9d22224eb5a03 | 704,093 |
def _shot_id_to_int(shot_id):
"""
Returns: shot id to integer
"""
tokens = shot_id.split(".")
return int(tokens[0]) | 59d0ecabf874841d616a72ebea1ebac6e6dc3947 | 704,094 |
import ctypes
def get_native_pointer_type(pointer_size: int):
"""
:return: A type that can represent a pointer.
"""
return {
ctypes.sizeof(ctypes.c_uint32): ctypes.c_uint32,
ctypes.sizeof(ctypes.c_uint64): ctypes.c_uint64,
}[pointer_size] | 2364bde2f7bfb7ce2b743d8958551156c847f847 | 704,095 |
from typing import Union
from typing import List
def trim_name(names: Union[List[str], str]) -> Union[List[str], str]:
"""Trims the name from the web API, specifically from IFTTT (removes extra "the ")"""
# Single name
if isinstance(names, str):
trimmed_name = names.lower().replace("the", "").str... | ee0bf0dcb9353fcad1b4af5f50bf2ff208c1dbe2 | 704,096 |
def compare(Target, Population):
"""
This function takes in two picture objects and compares them.
:param Target: target image
:type Target: Picture object
:param Population: The population of the current generations
:type Population: A list of picture objects
:return: Two best members of... | 4456141d1c980c5ca008d614ced05e1ec2efc062 | 704,097 |
def strify(iterable_struct, delimiter=','):
""" Convert an iterable structure to comma separated string.
:param iterable_struct: an iterable structure
:param delimiter: separated character, default comma
:return: a string with delimiter separated
"""
return delimiter.join(map(str, iterable_struc... | 3c8337691c9008449a86e1805fe703d6da73a523 | 704,098 |
def generate_pattern_eq_ipv4(value):
"""
makes a pattern to check an ip address
"""
return "ipv4-addr:value = '" + value + "'" | 36b4a09363512709c3bdf8046ea52f8ba14aa8e7 | 704,099 |
import requests
import sys
def print_server_info(ip, user, password):
"""
Fetch and print servers info
@params:
ip - Required : the ip of the server (Str)
user - Required : the administrator username (Str)
password - Required : The administrator password (Str)
"""
try... | 77280b61a71f58f827e879a09f8e72f984d759d9 | 704,100 |
def sanitize_df(df, d_round=2, **options):
"""All dataframe cleaning and standardizing logic goes here."""
for c in df.columns[df.dtypes == float]:
df[c] = df[c].round(d_round)
return df | cb411b0019112155311a926ec145becc0f8c4ce9 | 704,101 |
import torch
def undo_imagenet_preprocess(image):
""" Undo imagenet preprocessing
Input:
- image (pytorch tensor): image after imagenet preprocessing in CPU, shape = (3, 224, 224)
Output:
- undo_image (pytorch tensor): pixel values in [0, 1]
"""
mean = torch.Tensor([0.485, 0.456, 0.406]).v... | 57d4cfc365c4e6c2dcfd37c8a2c500465daa421a | 704,102 |
def collapse(html):
"""Remove any indentation and newlines from the html."""
return ''.join([line.strip() for line in html.split('\n')]).strip() | a5a55691f2f51401dbd8b933562266cbed90c63d | 704,103 |
def get_pagination_request_params():
"""
Pagination request params for a @doc decorator in API view.
"""
return {
"page": "Page",
"per_page": "Items per page",
} | 8ceb2f8ead3d9285017b595671f02817d098bc40 | 704,104 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.