content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def devices_to_string(devices):
"""
Format device list to string
:param devices: list of devices
:type devices: int or str or list
:return: string of device list
:rtype: str
"""
if isinstance(devices, str):
return devices
if isinstance(devices, int):
devices = [devic... | 3b9879f7726fc3b42cda4e656689ff584dbc6719 | 46,132 |
def dict_encode(dict, encoding='cp1251'):
"""Encode dict values to encoding (default: cp1251)."""
encoded_dict = {}
for key in dict:
encoded_dict[key] = dict[key].encode(encoding)
return encoded_dict | adfc1f9217ff48d20d44df5af4220f58e73419f4 | 46,134 |
def convert_pyr_coeffs_to_pyr(pyr_coeffs):
"""this function takes a 'new pyramid' and returns the coefficients as a list
this is to enable backwards compatibility
Parameters
----------
pyr_coeffs : `dict`
The `pyr_coeffs` attribute of a `pyramid`.
Returns
-------
coeffs : `lis... | 6b7ab3c4a6a85d05b7628cd7d31c46a62e549afc | 46,135 |
def is_ganache(ethereum_network):
"""true if we're using ganache"""
return not ethereum_network | e21a01190b92b95e2399542fef596d22db1baa5e | 46,136 |
def format_resp(number, digits=4):
"""
Formats a number according to the RESP format.
"""
format_string = "%%-10.%dE" % digits
return format_string % (number) | 6fe34c4431b9bfd7156e8e6062fdb35f909b1028 | 46,137 |
import torch
def relative_time_to_absolute(batch, relative_lens, rate):
"""Converts SpeechBrain style relative length to the absolute duration.
Operates on batch level.
Arguments
---------
batch : torch.tensor
Sequences to determine the duration for.
relative_lens : torch.tensor
... | 88caf837d49dd46d14106e0df6011f22415cb73b | 46,140 |
def _escape(st):
"""Escape Strings for Dot exporter."""
return st.replace('"', '\\"') | 0fe5af78a9e8a36c918f040a197cf92624271d07 | 46,141 |
def get_good_qa_ints_to_keep_l2cloud():
"""
https://ecostress.jpl.nasa.gov/downloads/psd/ECOSTRESS_SDS_PSD_L2_ver1-1.pdf for qa flag bits
"""
cloud_mask_flag = ["0", "1"] # 1 is determined, 0 is not determined
cloud_flag = "0" # 0 is no 1 is yes, either bit 2 3 or 4 set
thermal_brightness_tes... | 8b992234604d1e2287760fad472303e2cf2a62d8 | 46,142 |
def multiply(x, y):
"""Multiplies two numbers. Equivalent to a * b but curried"""
return x * y | 21ddc96142998879669d30f6c03abba22dc0ba08 | 46,143 |
from typing import List
def find_dup(numbers: List) -> int:
"""
Solution: Iterate through the list and store items in a set. When an item is found that already exists in the set
return that item.
Complexity:
Time: O(n) - Iterate through our list once
Space: O(n) - We could potentially store each item found
"... | 94620fc5ceb565b417bcf1f0de6f6d7af23968ed | 46,144 |
import argparse
import os
def get_args():
"""Parses command line arguments.
Configures and runs argparse.ArgumentParser to extract command line
arguments.
Returns:
An argparse.Namespace containing the arguments parsed from the
command line
"""
parser = argparse.ArgumentParser... | 5b228c82aa6a0cf1f5bfc0cd10bd0c8d515b2c9c | 46,145 |
def conjugate(x: complex) -> complex:
"""
Returns the conjugate of a complex number
"""
return x.real - x.imag * 1j | 6cacee436e7ca74d586364a4f578b745c08768d2 | 46,146 |
import math
def radians(degrees):
"""
Converts degrees to radians, which is used in math functions.
"""
return math.pi / 180.0 * degrees | 9925b4f10b097ddad384c7ed34668a6127296bff | 46,147 |
def to_lower_camel(s: str) -> str:
"""
Convert a snake-case string into lower camel case.
"""
parts = s.split("_")
return parts[0] + "".join([p.title() for p in parts[1:]]) | d937d70a9a1914079a377edd2d8d3e3d0a78bcb5 | 46,148 |
def get_export_options(defaults=None):
"""code export related options
"""
if defaults is None:
defaults = {}
options = {
# ID of the model to generate a local model
'--model': {
'action': 'store',
'dest': 'model',
'default': defaults.get('mo... | c72288e49f673e42a44d1f4dc97bebbf2a636962 | 46,149 |
import logging
def _setup_text_logger(name, stream, level):
"""Setup a text logger."""
res = logging.getLogger(name)
handler = logging.StreamHandler(stream)
handler.setFormatter(logging.Formatter(fmt="%(message)s"))
res.addHandler(handler)
res.setLevel(level)
return res | 54373e2c7d5e9337a6dd7ed321eefd6fd2d55f96 | 46,150 |
def normalize_ipam_config_key(key):
"""Normalizes IPAM config keys returned by Docker API to match Ansible keys.
:param key: Docker API key
:type key: str
:return Ansible module key
:rtype str
"""
special_cases = {
'AuxiliaryAddresses': 'aux_addresses'
}
return special_cases... | 24c85ed68f284baf96fbc805b6217cca2e0d7221 | 46,151 |
import yaml
def fetch_mapping(filepath: str) -> dict:
"""Returns a dictionary from a YML file"""
with open(filepath, "r") as stream:
map = yaml.safe_load(stream)
return map | 8a228d6474e0d474eb7a441f068adc711926b433 | 46,152 |
def upcase(val: str) -> str:
"""Make all characters in a string upper case."""
return val.upper() | f96247fa0b46daca4bc35420d8b218c2ee22f25a | 46,154 |
from typing import Union
from pathlib import Path
import wave
def empty_wav(wav_path: Union[Path, str]) -> bool:
"""Check if a wav contains data"""
with wave.open(str(wav_path), 'rb') as wav_f:
return wav_f.getnframes() == 0 | 7ae5fa1a01138314ace682c636001b087aa61818 | 46,156 |
def _blockdevice_volume_from_datasetid(volumes, dataset_id):
"""
A helper to get the volume for a given dataset_id.
:param list volumes: The ``BlockDeviceVolume`` instances to inspect for a
match.
:param UUID dataset_id: The identifier of the dataset the volume of which
to find.
:r... | a520cf9795fa5cad5ff92dea8b378d2c43009419 | 46,157 |
def kebab_case_to_human(word):
"""Should NOT be used to unslugify as '-' are
also used to replace other special characters"""
if word:
return word.replace("-", " ").title() | 9d101d7cbddda8ca183d61002dc65613d1388517 | 46,158 |
import os
import logging
def get_l3energy(job, par, bls=0):
"""
Get the L3, single-point energies.
This is not object oriented.
"""
if bls:
key = par['barrierless_saddle_single_point_key']
else:
key = par['single_point_key']
if par['single_point_qc'] == 'molpro':
... | c142d4c91f06c77aeb085650ce76287a606af4ef | 46,159 |
import os
def count_files(root_folder):
"""
Count files in source folder.
:param root_folder:
:return:
"""
print('Contagem de arquivos ... Aguarde')
file_counter = 0
for root, dirs, files in os.walk(root_folder):
for _ in files:
file_counter += 1
print('Total de... | 1d25bef151839eb8dcae20a4d341c379496d8297 | 46,160 |
import torch
def batch_diag1(A):
"""
A :(t,d,d)
returns : (t,d)
"""
t = A.shape[0]
sollist = [torch.diag(A[i,:,:]) for i in range(t)]
result = torch.stack(sollist,dim=0)
return result | 1b3f136a937e9a6f6ad371c3fe0b00cbf7a5f3ef | 46,161 |
def parse_word_expression(expr):
"""
Parses a word expression such as "thermoelectric - PbTe + LiFePO4" into positive and negative words
:param expr: a string expression, with " +" and " -" strings separating the words in the expression.
:return: Returns a tuple of lists (positive, negative)
"""
... | 9872e05f7ce86f2973efec8c5e0d5306d718419a | 46,162 |
import re
def __modify_name_replace(file_name, string, replace_string, position):
"""
Core method to replace a string inside the base name of a file.
"""
file_newname = ""
if position == "any":
file_newname = file_name.replace(string, replace_string)
elif position == "prefix":
... | da6b5998cb712369bb7814e974ec4523f38cb65c | 46,163 |
import random
import string
def rand_string(count=12):
"""Return random string of length count with letters and numbers, mixed case. Uses Python randomness."""
return ''.join(random.choice(string.ascii_letters + string.digits) for x in range(count)) | bc800528c6b45a7cc468ec2727ee1ce00136238d | 46,164 |
from typing import Union
from typing import Sequence
from typing import Tuple
def parse_vspace(
ncols: int,
vspace: Union[Sequence[int], bool] = False,
) -> Tuple[bool, Sequence[int]]:
"""
:param ncols:
:type ncols: int
:param vspace:
:return:
:rtype:
"""
if isinstance(vspace, Sequence):
add_vspace... | 3b9149e282260dbdb3c12c6a45407e3aa00ba9ee | 46,165 |
def setBits( lst ):
"""
set the bits in lst to 1.
also set bits 18, 20, 22, 24, and 28 to one (since they should always be set)
all other bits will be 0
"""
res = 0
for b in lst + [18,20,22,24,28]:
res |= (1 << b)
return res | 645509278a7f974c6da163935b3ee3e2e3724a06 | 46,168 |
def predicate(printer, ast):
"""Prints a predicate."""
return f'{printer.uppaal_c_printer.ast_to_string(ast["expr"])}' | bf46fe1b9d7b2dfd214e787ab1ae41b65fa621f3 | 46,170 |
import string
import random
def set_xrf():
"""
Create XRF key used to prevent cross site request forgery
"""
characters = string.ascii_letters + string.digits
return ''.join(random.sample(characters, 16)) | 9932f9d94b29ac8e27f1d9833621620aa662246c | 46,172 |
from typing import List
from typing import Callable
def create_matcher(queries: List[str], query_type: str) -> Callable[[str], bool]:
"""
Create a matcher for a list of queries
Parameters
----------
queries : list
List of queries
query_type: str
Type of query to run: ["or"|"a... | cc7cb37cab30728a70ac03446ed985ed0f71b9fc | 46,174 |
def reverseSentence(s):
"""i am a student. -> student. a am i"""
s = s[::-1]
sNums = s.split(' ')
for i in range(len(sNums)):
sNums[i] = sNums[i][::-1]
return " ".join(sNums) | 25e74f96182d94dd9031627e46d0a89235ffb796 | 46,175 |
async def format_embed_description(records: dict, format_str: str):
"""Formats an embed description to use.
Args:
records (dict): records to convert to description
format_str (str, optional): the format string to use;
do not pass a F-String!
Returns:
str: the formatted ... | 27ba27becb490bd5d2243db5be8f26133ad50caa | 46,176 |
def remove_suffix(s: str, suffix: str) -> str:
"""Remove the suffix from the string. I.e., str.removesuffix in Python 3.9."""
# suffix="" should not call s[:-0]
return s[: -len(suffix)] if suffix and s.endswith(suffix) else s | 17474d37726249dc84aa89f0861fe43db43bf1e9 | 46,177 |
import re
def split_camel_cased(text: str) -> str:
"""Split camelCased elements with a space.
Arguments:
text:
The text to be processed.
Returns:
The text with all camelCased elements split into different elements.
"""
return re.sub("(?!^)([A-Z][a-z]+)", r" \1", text) | 4ecc9e30bd50fb9898c23955917c953b3827b9a3 | 46,178 |
from bs4 import BeautifulSoup
import re
def default_db_connection(publish_settings):
""""Takes PublishSettings looks for Azure default db connection, returns default db connection string for local environment and SQL to add user to local db"""
username, password = '', ''
soup = BeautifulSoup(publish_settings... | 37351f7f41c6dfd037fd33c5bc94faf18fa40fcd | 46,179 |
import torch
import pathlib
def migrate_180826_models(f_folder: str, f_glob: str) -> int:
"""
inside <EXPERIMENT>/compressor/
provide f_glob -> '*.torch'
Converts the old *.torch files containing
'codebooks' to 'components'
"""
p_glob = pathlib.Path(f_folder).glob(f_glob)
old_key ... | 60acaec4cd9956d1ce09ae0b37c8d732ee832fcd | 46,181 |
import math
def triangle(v):
"""
Return a value corresponding to a triangle wave
"""
return (2 * abs(v - math.floor(v + (1/2)))) - 1 | 85b5824a5686b56a0ab2455d8aaba60ee0c45d6d | 46,182 |
def get_datatypes(xml_data_model, tag_name='nodeset', data_type='type', max_str=None):
"""
:param xml_data_model: data model list read from ODK config (read_odk_data_model)
:param tag_name: column name containing the tag names of the data model
:param data_type: column name containing the data type bel... | 47f3ee6c1ab192ad87c23147458ae6d22ffd3c3c | 46,183 |
def filter_tagged_vocabulary(tagged_vocabulary, vocabulary, split="|"):
"""Filters tagged_vocabulary (tokens merged with tags) for tokens
occurring in vocabulary.
Parameters
----------
tagged_vocabulary : collection
vocabulary of tokens (can be merged with tags)
vocabulary : collection
... | a84ded5b44db2a4075591fd56847dc9529eefc7a | 46,184 |
def _f(X, y, clf):
"""Returns the flattened coefficients of a fitted classifier.
This function exists at the module level instead of as an anonymous or
subordinate function so that it is importable by `multiprocessing`.
Parameters
----------
X : array
Design matrix.
y : array
... | 209d60f77168d39b541e3b091a8d342ed8c7fead | 46,185 |
def load_languages(language, languages_dict):
"""loads the language from the string-dict loaded from the config
Args:
language (str): selectbox choice for the language model from the user
languages_dict (dict): dict containing to-evaluate strings of the language
Returns:
tfhub lang... | 3f7d945ab5154a44249755a067fc53d7ff7c4d9f | 46,187 |
def get_data_symptom(driver, options):
""" Returns record with selected symptom """
return {"symptom": options[1].text.strip()} | 828077ed1dd6bb230990e9499cf4ec7c82dcdb06 | 46,188 |
def inputthis(question='-> ', expected_tuple=('Y', 'N'), error='ERRO! Resposta inesperada!'):
"""
:param question: Input text
:param expected_tuple: Tuple containing all the options from wich the user should choose from
:param error: Error message for when the input isn't cointained in the tuple
:re... | 36c3d47f0ba0c73d12a1323241e1d6173aecd621 | 46,189 |
def standardize_json_string(json_string):
"""
Replace " with ' if they occur within square brackets
eg {"key":"["Key":"value"]"} => {"key":"['Key':'value']"}
"""
inside_brackets_flag = False
standard_json_string = ""
for i in range(0, len(json_string)):
if json_string[i] == '[':
... | cba3311fca294d39ee80666c989228d5b56db056 | 46,190 |
from typing import Any
import ctypes
def di(id_: int) -> Any:
"""
Hacky inverse for id
"""
return ctypes.cast(id_, ctypes.py_object).value | ea3fd2e6199e3505d9a6bd56ac5d18ff97ef9716 | 46,191 |
def get_default_model_settings():
"""Return some default settings for a DeepSphere model."""
model_settings = {"pretrained_model_name": None,
"model_name_prefix": None,
"model_name": None,
"model_name_suffix": None,
# Arc... | 68a63a06edd30cbc737e1d11b862ded10b7add03 | 46,193 |
def _find_match(needle: dict, haystack: list, keys: list):
"""Find a dictionary in a list of dictionary based on a set of keys"""
for item in haystack:
for key in keys:
if item.get(key) != needle[key]:
break
else:
return item
return None | 4cc009583cd3238bba3b4e3da94257229ee37894 | 46,194 |
def _extract_params_from_i0(only_variable_parameters, parameters_with_variability, initial_conditions_with_variability):
"""
Used within the distance/cost function to create the current kinetic parameter and initial condition vectors
to be used during that interaction, using current values in i0.
This ... | bdda0afa34a1b825558bed632ae06e800f167fed | 46,195 |
def handler(mocker, aws_request_id):
"""
this fixture provides a way to call the function handlers so as
to insert a canned context (which is assumed by the logger setup)
"""
def _handler(func_module, event, context=None):
if context is None:
context = mocker.Mock(aws_request_id... | 55440de29bc5070ae111547db687c97be531a178 | 46,196 |
import os
def getOutputFileName(originalFileName, outputExtension, index=None):
"""
Return a filename which is the same as C{originalFileName} except for the
extension, which is replaced with C{outputExtension}.
For example, if C{originalFileName} is C{'/foo/bar.baz'} and
C{outputExtension} is C{... | f544f440c0cca050670aa3b70f935570129628f8 | 46,197 |
def classify(instruction):
"""Classify instruction.
Return name of instruction handler and arguments.
"""
if instruction in (0x00e0, 0x00ee):
return f"op_{instruction:04x}",
opcode = instruction >> 12
if 0 <= opcode <= 2:
return f"op_{opcode}nnn", instruction & 0x0fff
if 3... | 1e639c426221bda290ac1e8adfc03b36cab9af5c | 46,198 |
def get_cached_stickers(context, fuzzy=False):
"""Return cached search results from a previous inline query request."""
query_id = context.inline_query_id
cache = context.tg_context.bot_data[query_id]
if fuzzy:
results = cache["fuzzy"]
offset = context.fuzzy_offset
else:
res... | c3399ac727d4f412f35b4442390c10abc7eb1ad5 | 46,199 |
from typing import List
from typing import Tuple
def find_two_smallest(L:List[float]) -> Tuple[int, int]:
""" (see above) """
# Find the index of the minimum and remove that item
smallest = min(L)
min1 = L.index(smallest)
L.remove(smallest)
# Find the index of the new minimum item in the list... | 6847fc028d01fa5539b3fd4a3e8de416089150ab | 46,201 |
def get_attribute(name):
""" Gets the value of the element's attribute named ``name``. """
def evaluator(element):
return element.attrib.get(name)
return evaluator | 8ffc06ae088f09284509d3a47ef85f32175385f3 | 46,202 |
import requests
def get_attd_as_json():
"""
We can fetch the attendance 4PM report via the
SODA api using the requests library, as the
SODA api is REST-ful. The data updates every
day, and includes previous data, so we only
need to fetch this on a daily basis after 4
in the afternoon.
... | 382b8fa9389450a5211e5d4ac8ee8a0fc2b11264 | 46,203 |
from typing import Counter
def unique_words_by_tag(tokens, tag_value='N/A'):
"""Return a counter of the tokens with the given tag value."""
nouns = []
for word, tag in tokens:
if tag.startswith(tag_value) or tag_value == 'N/A':
nouns.append(word.lower())
return Counter(nouns) | b56dc9dbcdcb25b8d81fe2ebc79784008d848d23 | 46,204 |
def total_per_person(single_plan):
"""Returns total cost per person
Parameter
single_plan: single plan from database
Returns: total cost per person"""
costs = single_plan.cost_set.all()
if costs:
total_cost = 0
for cost in costs:
cost_per_person = round(cost.cost /... | 0019267cfa754e4a64631b812f026fcd8534f8b8 | 46,205 |
def writeable(doc):
"""
Return a writeable tuple for doc.
writeable tuple is any 2-tuple of `output_path`, `bytes`.
`lettersmith.write` knows how to write these tuples to disk.
"""
return doc.output_path, doc.content.encode() | 186580eee94dc537968b3c6edac1f5a755f858ed | 46,207 |
def coco_valid_joints(jointsx, jointsy, jointsv, dims):
"""
coco_valid_joints: Function to decide which joints are valid. Each dataset
has different criteria, so can't have a single function. Boo.
jointsx: ndarray joints x cood
jointsy: ndarray joints y coord
dims: (width, hei... | 5bd20838c4b309b854cf0c93da68929f8f4226b3 | 46,208 |
def fsm_submit_button(transition):
"""
Render a submit button that requests an fsm state transition for a
single state.
"""
fsm_field_name, button_value, transition_name = transition
return {
'button_value': button_value,
'fsm_field_name': fsm_field_name,
'transition_name... | e4fedef1a489dd96e573027639f0eec2cbf13711 | 46,209 |
def get_attrs():
"""get attrs."""
attrs = {
"enable_feature_library": True
}
return attrs | f5bd40f44f3565e421cb2c72cebbed1982ad2b41 | 46,211 |
def pointOnTrianglePlane(P, A, B, C):
"""
Projects the point P onto the plane containing traingle A, B, C
"""
N = (B - A).cross(C - A).normalize()
return P + (-(P - A).dot(N))*N | c70c02c31905208fa8a0942df7a12d33316f0afa | 46,212 |
def clean(code):
"""
Removes characters other than eight language commands.
"""
return filter(lambda x: x in ['.', ',', '[', ']', '<', '>', '+', '-'], code) | 8eeed2e5948a001639c1b935da196f30a156b9da | 46,213 |
def get_analysis_type(normal, umi):
""" return analysis type """
return "paired" if normal else "single" | d0da541419c2d7c3509d29e256431639cb20e87b | 46,214 |
import argparse
import os
def get_cleaner_ArgumentParser(clean_func):
"""Get an ArgumentParser instance for clean up functions.
Parameters
----------
clean_func : str
The name of the cleaner function to get arguments for. Must be one of:
"wrapper", "output", "logs".
Returns
-... | 78a49bc36dbe75b8fbde50e933d007d30f5f1ce0 | 46,216 |
def list_to_ol(input_list):
"""
Creates a html list based on input list
@param input_list: list of items
@return: html for list of items
"""
return '<ol>{}</ol>'.format('\n'.join(['<li>%s</li>' % cell_type for cell_type in input_list])) | c0c59f07ab65760911977aa10d408b7e1dd6b59f | 46,217 |
from typing import Dict
from typing import Tuple
from typing import List
from typing import Any
def _traverse_foreign_key_tree(
tree: Dict[str, Dict[Tuple[str, ...], dict]], name: str, fields: Tuple[str, ...]
) -> List[Dict[str, Any]]:
"""Traverse foreign key tree.
Args:
tree: Foreign key tree (s... | 37bafd03fed849031939159fab03bf5708ebffb7 | 46,219 |
from typing import List
from typing import Dict
def generate_currency_endowments(
agent_addresses: List[str], currency_ids: List[str], money_endowment: int
) -> Dict[str, Dict[str, int]]:
"""
Compute the initial money amounts for each agent.
:param agent_addresses: addresses of the agents.
:param... | 0dbf36a09c88eb3cdb1278862bdb37b2927fcec0 | 46,220 |
def key_to_hump(key):
"""
将变量转化为驼峰命名
:return: 返回驼峰命名变量
"""
return key.lower().title().replace("_", "") | b495a3c1d4a219134122a0c35c11eea0c485bac9 | 46,221 |
def constrained_domain(**namespace):
""" Returns e.g. periodic domain. """
return None | 7a5ee9981629ef159919f72f01d02314e91c170d | 46,222 |
def sort_list_by_other(to_sort, other, reverse=True):
"""Sort a list by an other."""
return [el for _, el in sorted(zip(other, to_sort), reverse=reverse)] | 9672bd28349fe0f3cc0d8d122f59724965d53f35 | 46,224 |
import plistlib
def uid_convert(obj):
"""To JSON uid convertor"""
if isinstance(obj, plistlib.UID):
return "UID(" + str(obj.data) + ")"
# return obj | ecdc8a0100d990809601636ded3d7368a423aba7 | 46,225 |
import random
def _uniq_id():
"""
Create a random 64-bit signed integer appropriate
for use as trace and span IDs.
XXX: By experimentation zipkin has trouble recording traces with ids
larger than (2 ** 56) - 1
"""
return random.randint(0, (2 ** 56) - 1) | 5e9b48fd15e07777f09ed21cbe53fec83dc3af50 | 46,227 |
def update_analyze_button(disabled):
"""
Updates the color of the analyze button depending on
its disabled status
:param disabled: if the button is disabled
"""
if not disabled:
style = {"width": "100%", "text-transform": "uppercase",
"font-weight": "700", "background":... | 5a0056879fd5ecde05b7b4fbadbeb7e3aeb1d679 | 46,228 |
import json
def add_environment_endpoint(app, config):
"""
Create a /_environ endpoint.
This creates a /_environ endpoint where expose some variables used in the
application to verify if they are ok.
:param app:
:param config:
:return: A json file that expose the configuration variables ... | d492094cd2941a81f19062bf15e66081c797af47 | 46,229 |
from typing import Tuple
from pathlib import Path
import subprocess
def walksat(input_dimacs: str,
solver_exe: str = "binary/walksat_linux",
) -> Tuple[bool, list, float]:
"""
WalkSAT v56 (https://gitlab.com/HenryKautz/Walksat)
:param input_dimacs: Correctly formatted DIMACS file ... | c349cc67b674e1373ff6a47fb01a08d276aea9a8 | 46,230 |
def format_id(ident):
"""
Convert a message ID to its canonical string form
"""
return '%016X' % ident | 633ce965ca74ff3dac2b7bf9910186c88e892111 | 46,232 |
import sys
import imp
def main_is_frozen():
"""
Returns whether or not it is frozen in an executable
#http://www.py2exe.org/index.cgi/HowToDetermineIfRunningFromExe
:rtype : bool
"""
return (hasattr(sys, "frozen") or # new py2exe
hasattr(sys, "importers") # old py2exe
... | 0f68a07a0de3254ac8d3941ee04587ed7babeafe | 46,233 |
def catch_all(path):
"""
Redirect arbitrary pages to homepage.
"""
return "we gotta help the pope" | cd1e76ac2c8bbaea724f7f96a8d7c538b22fb282 | 46,234 |
def read_classes(classes_path):
"""Reads classes from file.
Args:
classes_path (str):
Path to file containing names of all classes.
Returns:
list: List containing names of all classes.
"""
with open(classes_path) as f:
class_names = f.readlines()
cla... | fcfcd3f7391e096fd71a7091eb33e4a9c8a21581 | 46,235 |
import torch
def generate_sparse_one_hot(num_ents, dtype=torch.float32):
""" Creates a two-dimensional sparse tensor with ones along the diagnoal as one-hot encoding. """
diag_size = num_ents
diag_range = list(range(num_ents))
diag_range = torch.tensor(diag_range)
return torch.sparse_coo_tensor(
... | 3a71c72acfca4fe9fbfe1a6848519e9726fe72d9 | 46,237 |
def __is_prefix(pref, word):
"""
SUMMARY
returns whether a string is prefix of another
PARAMETERS
pref: the string we check whether is prefix
word: the string we search the prefix in
RETURNS
boolean: True if <pref> is prefix of <word> otherwise False
"""
if word... | 4480f1efad3ba1eb8d5ae4ca7ebf369a336ca481 | 46,238 |
from typing import Optional
from typing import List
from typing import Dict
def generate_info_json(
prev_photo: Optional[str], next_photo: Optional[str], exif: List
) -> Dict:
"""Generate the content of the story metadata file."""
data = {
"title": {"en": "", "fi": "", "fr": ""},
"descript... | b0ef5e1a78966014003311c87328d1c96a684cce | 46,239 |
def catGram(mp, categories):
""" Selects the grammatical categories of the minimal pairs """
pairs = mp[mp.cgram_1.isin(categories) & mp.cgram_2.isin(categories)]
return pairs | 761b93eb9e10695259697ca409f53944acd93da5 | 46,240 |
def splev_wikipedia(k: int, x: int, t, c, p: int):
"""Evaluates S(x).
Arguments
---------
k: Index of knot interval that contains x.
x: Position.
t: Array of knot positions, needs to be padded as described above.
c: Array of control points.
We will look at c[k-p .. k]
p: Degree o... | 9a12eabc1cc64b8e1829d1af2f3866ae3aa00bf7 | 46,243 |
def merge_sort(arr):
""" Implementation of a merge_sort algorithm using recursion.
"""
def _merge(a, b):
""" This will be recalled recursevly.
Takes in two pre-sorted arrays and returns a single sorted array.
"""
i = 0
j = 0
k = 0
r = [[] for _ in... | 12aee6e95346e4ac291edbdcec7e11c69ed2c154 | 46,245 |
import os
def get_folder_path(folder_name):
"""
Get path for temp folder with folder name.
"""
folder_path = os.path.join(str("."), str(folder_name))
if not os.path.exists(folder_path):
os.mkdir(folder_path)
return folder_path | 45f7e380727fd02f5d544f9b1d0105c5e9ff66d7 | 46,248 |
def split_string_by_fields(string, fields):
"""
Helper function to split a string by a set of ordered strings,
primarily used for Maccor metadata parsing.
>>>split_string_by_fields("first name: Joey last name Montoya",
>>> ["first name:", "last name"])
["Joey", "Montoya"]... | 7722f5fd80a581a113c18495d2ad21d1af41748d | 46,250 |
def footer(id1, id2 = None):
"""
Build SMT formula footer
Args:
id1 (str): ID of policy 1 in SMT formula
id2 (str, optional): ID of policy 2 in SMT formula. Defaults to None.
Returns:
str: SMT footer
"""
smt = '(assert {}.allows)\n'.format(id1)
if id2:
smt... | c9af2ad7453282e1611e7b2010f4269ca8ac0bc0 | 46,252 |
def area_square(length):
"""
Calculates the area of a square.
Parameters
----------
length (float or int) length of one side of a square
Returns
-------
area (float) - area of the square
"""
return length ** 2 | 122ce824bc47651aa56f424618b1b18c7fd0aa19 | 46,253 |
def select(func):
"""
select :: (a -> Bool) -> [a] -> [a]
Grab elements based on a filter function
Similar to builtins.filter()
"""
def imap(data):
if not isinstance(data, list):
return list(filter(func, [data]))
return list(filter(func, data))
return imap | 119dfc50027c329d64f23f33ad1984076d73da87 | 46,254 |
def create_final_conv(image_sizes, h_out = 1, w_out = 1):
"""
This function generates a convolution with h,w = 1. Used the formula from
here :https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html#torch.nn.Conv2d
----------
image_sizes : the h,w of the output of each convolution layer in a l... | f8dd86db1d6449d3e948cc8bde7fb7e8dca27f0b | 46,255 |
def calculate_time(cents_per_kWh, wattage, dollar_amount):
""" Returns the time (in hours) that it would take to reach the monetary price (dollar_amount)
given the cost of energy usage (cents_per_kWh) and power (wattage) of a device using that energy.
"""
return 1 / (cents_per_kWh) * 1e5 * dollar_am... | 86c261d8b72089d39935468dd349eef8e9611cdd | 46,257 |
def flatten(filenames):
"""Takes a list which may contain other lists and returns a single,
flattened list
Args:
filenames (list): list of filenames
Returns:
flattened list of filenames
"""
flat_filenames = [file for i in filenames for file in i]
return flat_filenames | 5a81b0c3d9395142c4991052cf494226b3516bc3 | 46,258 |
def vals_vec_from_lmfit(lmfit_params):
"""Return Python list of parameter values from LMFIT Parameters object."""
vals = [value.value for value in lmfit_params.values()]
return vals | 6fac3ac8dd364dca3ae19a6cac36be072e32fdb7 | 46,259 |
def _get_yaml_path(path, parameter):
"""Compose the parameter path following the YAML Path standard.
Standard: https://github.com/wwkimball/yamlpath/wiki/Segments-of-a-YAML-Path#yaml-path-standard
"""
yaml_path = []
if path:
yaml_path.extend(path)
if parameter:
yaml_path.append(... | 7b4c8807cbc8a030ad2b541bb21dc59e3204324f | 46,260 |
import os
import warnings
def filter_valid_images(df, img_directory, x_col, img_format):
"""Keep only dataframe rows with valid filenames
# Arguments
df: Pandas dataframe containing filenames in a column
x_col: string, column in `df` that contains the filenames or filepaths
# Returns
... | df3f6e4c2d9f1edd58d58b4808ebe634e93ffd71 | 46,261 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.