content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import os
def get_all_source_files(arr=None, prefix="."):
"""Return source files."""
if arr is None:
arr = []
if not os.path.isdir(prefix):
# assume a file
arr.append(prefix)
return arr
for fx in os.listdir(prefix):
# pylint: disable=too-many-boolean-expressio... | 7dd0cf00e90b1e403ce34b8b158b3e37201b0822 | 702,419 |
def count_all_questions_yes(group_input: str) -> int:
"""count questions all group members answered with yes"""
list_of_sets = [set(line.strip()) for line in group_input.split("\n")]
return len(set.intersection(*list_of_sets)) | ba9ce06b4bdbd09ff871114a74de53ccdf60dab3 | 702,420 |
def get_cell_numbers(contained):
"""Retrieve non-overlapping cell numbers from the output of `get_overlapping`.
None may appear at the ends of the output, indicating that the corresponding
target cells are not overlapping with any source cells. These should be ignored
when regridding.
Cell numbers... | b0bf32676ec7bfa73e04d3afd7053675f95d4abd | 702,421 |
def get_mos(da, da_peak_times):
"""
Takes an xarray DataArray containing veg_index values and calculates the vegetation
values (time not available) at middle of season (mos) for each timeseries per-pixel.
The middle of season is the mean vege value and time (day of year) in the timeseries
at 80% t... | 510452f4e89e2e26107f4c8bc9cc7617f7b56b61 | 702,422 |
import re
def tag_validate(tags, case_ids, plan_id):
"""Tests tag checking func"""
error_msg = None
tag_id = re.findall('ID_\d+|id_\d+', str(tags))
if not tag_id:
error_msg = "Wrong Tag Format:\
\nPls add tag 'ID_case_id' to this case."
elif int(tag_id[0][3:]) not in case_i... | 3428426b480f2515ca08663f94dd0f8073ed8d18 | 702,423 |
def get_clean_urls(raw_urls):
"""
Known problems so far:
https vs http
https://www.test.de vs https://test.de
https://www.test.de/something vs https://www.test.de/something#something
https://www.test.de/something.html vs https://www.test.de/something.html?something
"""
cleaned_urls = []
... | 19e238ff382c7c3dc83b779d7d82c59ff82820e9 | 702,425 |
from importlib.util import find_spec
def _pytest_has_xdist() -> bool:
"""
Check if the pytest-xdist plugin is installed, providing parallel tests
"""
# Check xdist exists without importing, otherwise pytests emits warnings
return find_spec("xdist") is not None | 77cc6d04d21f76b35b183fc4e9ebc2bf6824b744 | 702,426 |
def makedist(dist_type, *pars, **kwards):
"""
Creates a distribution class from scipy continuous distributions
See https://docs.scipy.org/doc/scipy/reference/stats.html.
Parameters
----------
dist_type: String -> Type of the distribution (see the scipy documentation)
*pars and **kwards... | b9fb48e80d51cbeac5977d3e469ea14854f94def | 702,427 |
import importlib
def build_model(model_name, weights_file=None, **kwargs):
"""Build the desired model."""
mod = importlib.import_module("."+model_name, __name__)
model = mod.build_model(**kwargs)
if weights_file:
try:
model.load_weights(weights_file, by_name=True)
print("Loaded existing model:... | 23cb3d093b435dc32ecefa8b1415d2c5d4cbc4dd | 702,429 |
def solve(_n, tree):
"""
Given a list of list of tokens:
. (empty), or # (tree), compute the
number of trees one would encounter
if one traverses the 2D grid along
a slope of (3, 1).
:param _n: The number of rows in the
2D grid.
:param tree: The 2D grid as a list of list.
... | b4dbbc5c62d5b680242997e22c7a84d4ad583848 | 702,430 |
def _getNodeType(node): # {{{
""" return NodeType as String """
if node.nodeType == node.ELEMENT_NODE : return "ELEMENT_NODE"
elif node.nodeType == node.ATTRIBUTE_NODE : return "ATTRIBUTE_NODE"
elif node.nodeType == node.TEXT_NODE : return... | 70bda4da9f991f17602ba2992cb6c11f19141eac | 702,431 |
import math
def get_margin(home_team, away_team, home_team_score, away_team_score):
"""
Get the multiplier for the margin of victory
"""
goal_differential = home_team_score - away_team_score
return max(1, math.log(
abs(goal_differential - .85 * ((home_team.elo - away_team.elo)/100)) + math... | 0e54ff280e8a045230b221128539a9a6c054625f | 702,432 |
def create_scales(options):
"""
Creates the scales for imfil.m. Nothing much here right now, but
custom scales ... are in the near future.
dscal = create_scales(options)
C. T. Kelley, September 15, 2008
This code comes with no guarantee or warranty of any kind."""
custom_scales = options.custom_sca... | c0e42bec16761a83a532c7799622d9b35ee72367 | 702,433 |
def _sbtype_has_field(sbtype, field_name):
"""Recursive helper to have has_field search up the inheritance hierarchy."""
for f in sbtype.fields:
if f.name == field_name:
return True
for b in sbtype.bases:
if _sbtype_has_field(b.type, field_name):
return True
for b in sbtype.vbases:
if ... | 8f2ec709214c9080b96acf267c66f1671fa47da3 | 702,434 |
def t_s(n, costheta):
"""Fresneltransmittance for two interfaces.
**Arguments:**
- **n**: iterable with two entries for (n_0, n_1)
- **theta:** iterable with two entries for (theta_0, theta_1)
"""
i, j = 0, 1
a = 2 * n[i] * costheta[i]
b = n[i] * costheta[i] + n[j] * costheta[j]
... | ae74b459ce0bb9172ed5d66c657ddba3065f4dd7 | 702,435 |
import json
import os
import collections
def get_tf_config():
"""Get configuration from TF_CONFIG environment variable.
"""
tf_config = json.loads(os.getenv('TF_CONFIG', '{}'))
if not tf_config:
return None
task = tf_config['task']
cluster = tf_config['cluster']
task_type = task['type']
task_id = ... | 376d034fe6790482c2a26e355348d932d0f33f43 | 702,436 |
def bin_bucket_sort(arr):
"""
Binary bucket sort / 2-Radix sort
Time: O(NLog2N)
Space: O(N)
input: 1D-list array
output: 1D-list sorted array
"""
bucket = [[], []]
aux = list(arr)
flgkey = 1
while True:
for ele in aux:
bucket[int(bool(ele & flgke... | 8945ef31d5705d1462ce71ed6447bcc8d76e4665 | 702,437 |
def tonum(s):
"""Converts a string representation of a decimal, hexadecimal, or binary number to a number value or None."""
if type(s) in (int, float):
return s
if s is None:
return 0
base = 10
if isinstance(s, str):
if "x" in s:
base = 16
elif "b" in s:... | 4878a5619fcd96897f5bec6167bb8f0b4539588a | 702,438 |
import sys
def handle_response(response, display=False):
"""
Dispatch response based on scripting response or event.
"""
def handle_script_response(response, display=False):
if display:
sys.stderr.write(
u'Scripting request submitted with request id: {}\n'.form... | a254ffc5084d8b0d2eaef255bbd122a5a10ec8f2 | 702,440 |
import socket
def hostname():
"""
Check the system's hostname
:rtype: str
:return: system hostname
"""
return socket.gethostname().split('.')[0] | 438ccd56367565e0cf0c9e8783bc73cb4507e83b | 702,441 |
import csv
def import_data(file):
"""
Imports instruction data from a .csv file, at the specified filepath
:param file: file
File object, to be read by the CSV reader
:return: list
A list of dictionaries, per row in the file, with the keys specified in the headers list
below
... | 472f47c2e2111d5ce9a9d20e1ac447a504941aa2 | 702,442 |
import re
def filter_data(data_frame):
"""
Process string value
:param data_frame: raw data in data frame type
:return: data frame
"""
data_frame[data_frame.columns[len(data_frame.columns) - 2]] = \
data_frame[data_frame.columns[len(data_frame.columns) - 2]].apply(lambda x: int("".join... | 75e3a40c0c1d06db7da71e8b6ddb0001c5933634 | 702,443 |
from typing import Tuple
from typing import List
from typing import Any
def _extract_bracket_params(meta_type: str) -> Tuple[str, List[Any]]:
"""
Gets parameters from the string representation of the type
Args:
meta_type (str): The string name of the metadata type
Returns:
Tuple[str,... | 38fc3872c18bb788a54d50b09a36cf3f5925550e | 702,444 |
import hashlib
def calc_local_file_md5_sum(path):
"""
Calculate and return the MD5 checksum of a local file
Arguments:
path(str): The path to the file
Returns:
str: The MD5 checksum
"""
with open(path, "rb") as file_to_hash:
file_as_bytes = file_to_hash.read()
re... | 78020e86a6d9a6939de6b9050d34fca0d482aab4 | 702,445 |
def emit_compare(field_name, value, session, model):
"""Emit a comparison operation comparing the value of ``field_name`` on ``model`` to ``value``."""
property = getattr(model, field_name)
return property == value | a9ad880951f87f488b12c4ce7c38c5e0e463a798 | 702,446 |
def unsigned32(i):
"""cast signed 32 bit integer to an unsigned integer"""
return i & 0xFFFFFFFF | 1d4e06406d3ee7ce7d8f5cefd28955f135059917 | 702,448 |
import tkinter as tk
from tkinter import filedialog
import os
def ask_path(folder_flag=True, multiple_files_flag=False):
"""Makes a tkinter dialog for choosing the folder if folder_flag=True
or file(s) otherwise. For multiple files the multiple_files_flag should
be True.
"""
# This method is almos... | 675f36f34a97a3445d35d1e7a45ee71e60a7ea48 | 702,449 |
def has_and_not_none(obj, name):
"""
Returns True iff obj has attribute name and obj.name is not None
"""
return hasattr(obj, name) and (getattr(obj, name) is not None) | 0d68a9b01d56ba056768d06a88c68b4bd5bbd4d2 | 702,450 |
def _qname_matches(tag, namespace, qname):
"""Logic determines if a QName matches the desired local tag and namespace.
This is used in XmlElement.get_elements and XmlElement.get_attributes to
find matches in the element's members (among all expected-and-unexpected
elements-and-attributes).
Args:
... | 66aa9272fd6e4a6e281d39f03dd63acabad0bbe7 | 702,451 |
from typing import Optional
from typing import Union
import subprocess
def run_local(command: str, str_output: Optional[bool] = False) -> Union[int, str]:
"""Runs a command locally and captures output."""
print(command)
if str_output:
process = subprocess.Popen(
command,
s... | fc56e2106a4f4104c30ec2f4a3252b8e43e8bdf3 | 702,452 |
def get_chombo_box_extent(box, space_dim):
"""
Parse box extents from Chombo HDF5 files into low and high limits
Parameters
----------
box : List
Chombo HDF5 format box limits,
e.g. [x_lo, y_lo, x_hi, y_hi] = [0,0,1,1]
space_dim : int
Number of spatial dimensions
... | d72b409a96c8a1936f456d87a341fba22ee9f97e | 702,453 |
def get_raw_pdb_filename_from_interim_filename(interim_filename, raw_pdb_dir):
"""Get raw pdb filename from interim filename."""
pdb_name = interim_filename
slash_tokens = pdb_name.split('/')
slash_dot_tokens = slash_tokens[-1].split(".")
raw_pdb_filename = raw_pdb_dir + '/' + slash_tokens[-2] + '/'... | 084239659220ea65ae57a006c8ce28df73b2fd5e | 702,454 |
def array_offset(x):
"""Get offset of array data from base data in bytes."""
if x.base is None:
return 0
base_start = x.base.__array_interface__["data"][0]
start = x.__array_interface__["data"][0]
return start - base_start | b383a91790b06ffb1b5b976b9575efe637fa47a6 | 702,455 |
import os
import re
def get_flags(source):
"""Gets flags from a source file.
Args:
source (str): Path to the source file (could be any extension).
Returns:
list[dict[str, _]]: List of maps with keys "type", "name", "default", and "descr" for the
respective fields correspondin... | 7cb7dc28b333154904619887dba5d21140141809 | 702,456 |
def update_global_variable():
"""
修改全集变量(global关键字)
:return:
"""
global count
count = 10
return count | 69c91bce24fc77dc731e05178849528e59bae4ba | 702,457 |
def get_non_lib(functions):
"""
Get all non-library functions
@param functions: List of db_DataTypes.dbFunction objects
@return: a subset list of db_DataTypes.dbFunction objects that are not library functions.
"""
return [f for f in functions if not f.is_lib_func] | 7f536ff98d647ba5e497b8550bc2497ef45e814b | 702,459 |
def _check_duplicates(data, name):
"""Checks if `data` has duplicates.
Parameters
----------
data : pd.core.series.Series
name : str
Name of the column (extracted from geopandas.GeoDataFrame) to check duplicates.
Returns
-------
bool : True if no duplicates in data.
"""
... | 429ce8d092b3a39fc44eeca91d593db22fe7364d | 702,460 |
def _has_textframe(obj):
""" Check if placeholder has TextFrame """
return hasattr(obj, 'TextFrame') and hasattr(obj.TextFrame, 'TextRange') | 087e6df38e55d99637e8e7ea998257f323d6d141 | 702,461 |
def get_mapping(combinable_list):
"""Determine the mapping from acceptance_id to the register id that can be used
to index into an array.
"""
result = {}
array_index = 0
while len(combinable_list) != 0:
# Allways, try to combine the largest combinable set first.
k ... | 085f28c8d1263bc2e547a5671e115d86992af231 | 702,462 |
def clean_chamber_input(chamber):
""" Turns ambiguous chamber information into tuple (int, str) with chamber id and chamber name """
if type(chamber) == str:
if chamber == '1':
chamber = 1
elif chamber == '2':
chamber = 2
elif chamber == 'GA':
chamber ... | 0ad20c117fc90e523e85ef7061a548b20c68dc92 | 702,463 |
def search_for_letters(phrase: str = 'life, the universe, and everything', letters: str = 'forty two') -> set:
"""Display any 'letters' found in a 'phrase'."""
return set(letters).intersection(set(phrase)) | 36944391599abf971512d21819f88dee9af42f36 | 702,464 |
import yaml
def loadyaml(file, default={}):
"""Utility function to load from yaml file"""
try:
with open(file, "r", encoding="utf-8") as f:
t = yaml.load(f, Loader=yaml.FullLoader)
except FileNotFoundError:
t = default
return t | a6720094340b71039d2e53ec1f48493480e4e26a | 702,465 |
from pathlib import Path
import logging
import yaml
def params_from_yaml(args):
"""Extract the parameters for preparation from a yaml file and return a dict"""
# Check the path exists
try:
config_file_path = Path(args.config)
assert config_file_path.exists()
except Exception:
l... | 36beadd8fa4f27471c514a963838aac216aad434 | 702,466 |
from typing import List
from typing import Union
def list_or_first(x: List[str]) -> Union[List[str], str]:
"""
Returns a list if the number of elements is
greater than 1 else returns the first element of
that list
"""
return x if len(x) > 1 else x[0] | 82e86001b35ecd6542a22fac3c5dd7f7723966d6 | 702,467 |
import re
def parse_version(version_str):
"""'10.6' => [10, 6]"""
return [int(s) for s in re.findall(r'(\d+)', version_str)] | 16cfcfc292eb89b6231a266c687f9dfd8caa5a8d | 702,468 |
import requests
def display_selected_patient_info(MRI):
""" Get a patient's latest information and ECG trace image
As a very important functionality of the server, the function
sends a 'GET' request to the server, get a string that includes
all patient's latest info and ECG image b64 string. Then ... | d0a47848451801517e9125bbd7de3b40023cbd60 | 702,469 |
def contains_common_item_2(arr1, arr2):
"""
loop through first array and create dictionary object where the keys are the items in the array
loop through the second array and check if item in second array exists in the created dictionary
"""
array1_dict = {}
for item in arr1:
array1_dict[... | 83b4eafe7904d47fd65db3fc3e5a4d598a51efea | 702,470 |
def complex_function(z):
"""
The complex function to plot. *You can write any function here*.
:param z: a numpy 2d array of complex numbers.
"""
return (z - 1) / (z + 1) | 242f6b84c50dedbbf28edf52c558d572ab4c6c85 | 702,471 |
def stop(job_id, event, action, resource, _count):
"""App stop event type"""
job_name = '{}:event={}:action={}'.format(
resource, event, action
)
func_kwargs = dict(
job_id=job_id,
app_name=resource,
)
return job_name, func_kwargs | 56f1496c860396f76cee105e007803eb850ca679 | 702,474 |
def vector_add(v, w):
"""adds corresponding elements"""
return [v_i + w_i
for v_i, w_i in zip(v, w)] | ed85d5d1158e46109966b3c09f3d33d5acae8c98 | 702,475 |
def nexthop_is_local(next_hop):
"""
Check if next-hop points to the local interface.
Will be True for Connected and Local route strings on Cisco devices.
"""
interface_types = (
'Eth', 'Fast', 'Gig', 'Ten', 'Port',
'Serial', 'Vlan', 'Tunn', 'Loop', 'Null'
)
for type in interf... | fd74119d54998fafcb9400adaaa2c95b42671734 | 702,476 |
def logistic_expval(mu, tau):
"""
Expected value of logistic distribution.
"""
return mu | f6ac18144d5543d50c04f8e042bb8b5f8c8ea5ec | 702,477 |
def is_(var):
"""intuitive handling of variable truth value also for `numpy` arrays.
Return `True` for any non-empty container, otherwise the truth value of the
scalar `var`.
Caveat of the most unintuitive case: [0] evaluates to True, like [0, 0].
>>> import numpy as np
>>> from cma.utilities... | dd7be0e1535c6a616a1984b7d4b4cab3b03fbfbd | 702,478 |
import re
import tarfile
import io
def _check_open_tarball(testcase, response):
"""
Check http-response headers and open tar ball from content.
"""
testcase.assertTrue(re.search(r'attachment;\s*filename="[^"]*.tar.gz"',
response['Content-Disposition']))
testcase.a... | ffa0aa59f102fffb3c11664ee5f486f424b6acd8 | 702,479 |
def GetKDPPacketHeaderInt(request=0, is_reply=False, seq=0, length=0, key=0):
""" create a 64 bit number that could be saved as pkt_hdr_t
params:
request:int - 7 bit kdp_req_t request type
is_reply:bool - False => request, True => reply
seq: int - 8 sequence numb... | 7a56abb0f1ccbe1a7da1a9e0c6b70418e00ef0be | 702,480 |
import json
def save_items_list(drive_service, file_location):
"""
save cloud items list in a json file
:param file_location: location where file needs to be saved
:param drive_service: servive object for drive
:return: True if list successfully saved else false
"""
files = drive_service.f... | 9f5dc557bbbfa102bf4acfa3fb9af9014b229c83 | 702,481 |
import json
def craft_unknown_asset_message(
username, emoji, channel, launch_time, cloud_provider, vps_name, tags
):
"""Function to craft a nicely formatted Slack message using blocks
for cloud assets not found in Ghostwriter.
"""
UNKNOWN_ASSET_MESSAGE = {
"username": username,
"i... | fea3e96b93bfaba8971680fd0af52eccd543e0f0 | 702,482 |
def tilted_L1(u, quantile=0.5):
"""
tilted_L1(u; quant) = quant * [u]_+ + (1 - quant) * [u]_
"""
return 0.5 * abs(u) + (quantile - 0.5) * u | ff7a3fe97d79e4c848797c79a2a7c14b449ad6b6 | 702,484 |
def getId(collection):
""" Get the ImageCollection id.
**CLIENT SIDE**
:type collection: ee.ImageCollection
:return: the collection's id
:rtype: str
"""
return collection.limit(0).getInfo()['id'] | ad08535eb838cfa4d7153efd476b6dac14d118bc | 702,485 |
def bytes_to_human(size, digits=2, binary=True):
"""Convert a byte value to the largest (> 1.0) human readable size.
Args:
size (int): byte size value to be converted.
digits (int, optional): number of digits used to round the converted
value. Defaults to 2.
binary (bool, op... | 22367220a122e399658a0dd42b52083ccc29df6f | 702,486 |
import requests
import toml
def get_stellar_toml(domain, allow_http=False):
"""Retrieve the stellar.toml file from a given domain.
Retrieve the stellar.toml file for information about interacting with
Stellar's federation protocol for a given Stellar Anchor (specified by a
domain).
:param str do... | 665ff032834d3bb501e1ff9a8591d54d6d3bb5a8 | 702,487 |
def _validate_method(method, where):
"""Helper for get_params()"""
if method is None:
return None
if method not in ['signal', 'thread']:
raise ValueError('Invalid method %s from %s' % (method, where))
return method | dbf7194f50a43dc3fd944f8923ddfec5aed3bbe7 | 702,488 |
import pathlib
def parent(path: str) -> str:
"""Get path's parent
e.g
j.sals.fs.parent("/home/rafy/testing_make_dir/test1") -> '/home/rafy/testing_make_dir'
Args:
path (str): path to get its parent
Returns:
str: parent path.
"""
return str(pathlib.Path(path).parent) | 8ed409fde19dcd74d3fb2c169946680a0c46543b | 702,489 |
def _getText(nodelist):
""" returns collected and stripped text of textnodes among nodes in nodelist """
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc.strip() | 37548ebf34f0f26cc4166e95621ee1ec0f3a3f71 | 702,490 |
import re
def strip_html(text):
"""See http://stackoverflow.com/a/9662362"""
return re.sub('<[^<]+?>', '', text) | 94747883a5df06b70fb3513e82e610d981582bbb | 702,491 |
def from_json(json_data, key):
"""Extract values from JSON data.
:arg dict json_data: The JSON data
:arg str key: Key to get data for.
:Returns: The value of `key` from `json_data`, or None if `json_data`
does not contain `key`.
"""
if key in json_data:
return json_data[key]
... | 2e5a97176c771c1c363fd7fbf86d8bf7b598f4ab | 702,492 |
def weights_dask(weights):
"""
Weighting array by cosine of the latitude.
"""
return weights.chunk() | d1b4259b806665760506b43cf072ceb61fcb2d8d | 702,493 |
import os
import binascii
def get_secure_random_string(size):
"""
Return a string of ``size`` random bytes. Returned string is suitable for
cryptographic use.
:param size: Size of the generated string.
:type size: ``int``
:return: Random string.
:rtype: ``str``
"""
value = os.ura... | fde036e0183b4ec7920e1dffefc6097c93752d58 | 702,494 |
def project(a):
""" De-homogenize vector """
return a[:-1] / float(a[-1]) | 68074a4fb9c5021f7e727654e699d823d093c3a6 | 702,495 |
import os
def ospathjoin(*args, **kwargs):
"""
Simple ``o.path.join`` for a specific platform.
@param args list of paths
@param kwargs additional parameters, among them,
*platform* (win32 or ...)
@return path
"""
def build_... | 025c4f5dc352df00d3aa8586a2cde88c63518eaa | 702,496 |
def screen_aos(mol, active_atoms, den_mat_a, ovlp, trunc_lambda):
"""Screen AOs for truncation"""
include = [False] * mol.nbas
active_aos = []
for shell in range(mol.nbas):
aos_in_shell = list(range(mol.ao_loc[shell], mol.ao_loc[shell + 1]))
if mol.bas_atom(shell) not in active_atoms: ... | b4856265441d1a51d09d3c261b39ec655cf202e4 | 702,497 |
def spell_check(text, spell):
"""Fix misspelled words"""
suggestions = spell.lookup_compound(text, 2)
if suggestions:
return suggestions[0].term
else:
return text | 6ada77bbc6d691fa0e650f27f9a1e09885e70c14 | 702,498 |
from operator import inv
def n_clinic_to_unit_cube(x_array,box):
"""
---Inputs---
x_array : {2 mode numpy array}
array defining the "real" coordinate(s) at which to calculate values of
basis functions
shape (n_points, d)
dimension of first mode gives number of points
... | d55dd6f99047935df395dde174b4525a2f6b9bcd | 702,499 |
def dummies(data):
"""
Manually creates labels for property type. sklearn label encoder was breaking the model shape.
"""
data['Property_Area'] = data['Property_Area'].replace('Rural', 0, regex=True)
data['Property_Area'] = data['Property_Area'].replace('Semiurban', 1, regex=True)
data['Property... | 607da5c4a023c789a3a6da27d0ddfe4bfafa7d3a | 702,500 |
def assert_all_loaded(pairs, raise_=True):
"""
Returns True if all SleepStudy objects in 'pairs' have the 'loaded'
property set to True, otherwise returns False.
If raise_ is True, raises a NotImplementedError if one or more objects are
not loaded. Otherwise, returns the value of the assessment.
... | d211b77c2d16fafaff5555701af66d0144fb0b73 | 702,501 |
import os
def expand_params(params_to_env):
"""
Given a dictionary like:
{
"AwsAccessKeyId": "AWS_ACCESS_KEY_ID",
"AwsSecretAccessKey": "AWS_SECRET_ACCESS_KEY",
"KeyNukerOrg": "KEYNUKER_ORG",
}
Convert to a string like:
--param KeyNukerOrg default --param AwsAccessKe... | 37833e73a0f6375689cad5bfd114e1ce1431c47f | 702,503 |
def remote_shortname(socket):
"""
Obtains remote hostname of the socket and cuts off the domain part
of its FQDN.
"""
return socket.gethostname().split('.', 1)[0] | e52ec17a36800029a9889dc1b5e567567b9c9340 | 702,504 |
def formatParagraphLine(text, width):
"""
:return: array of rows
"""
words = text.split()
tail = words
result = []
buf = ''
while len(tail):
curWord, tail = tail[0], tail[1:]
if len(buf) + len(curWord) + 1 > width:
if buf == '':
row = curWord
... | 14672342e24706df117425d5e59f9d2c762faab2 | 702,505 |
def encodewrap(s):
"""改行コードを\nに置換する。"""
r = []
if not s:
return u""
for c in s:
if c == '\\':
r.append("\\\\")
elif c == '\n':
r.append("\\n")
elif c == '\r':
pass
else:
r.append(c)
return "".join(r) | a3486f3340d898751371fb4d4e29876120ec280b | 702,506 |
import urllib3
import json
def get_public_urls():
"""Get a list of available external tunnel URLs"""
urls = []
try:
http = urllib3.PoolManager()
req = http.request('GET', 'http://localhost:4040/api/tunnels')
data = str(req.data, 'utf-8')
obj = json.loads(data)
tunn... | d17e57cafe0833f35b4c5742a96901869dd8b7b1 | 702,507 |
def is_fragment(href):
"""Return True if href is a fragment else False"""
is_fragment = False
try:
if href[0] == '#':
is_fragment = True
except IndexError:
is_fragment = False
return is_fragment | da1899ac1b59b8a6a42034a46194ff0d09a8799d | 702,508 |
import os
def is_dir(path):
"""Is the path a directory"""
return os.path.isdir(path) | 3ea885ce332c37ba069a34a493d3fb07b4c6d976 | 702,509 |
def myocardialmass(myocardvol):
"""
Specific gravity of heart muscle (1.05 g/ml)
"""
return myocardvol*1.05 | ca12a23a27a3dc2cb3df96abe4bfe94424125b14 | 702,510 |
async def challenge(websocket, user):
"""Challenges a user.
"""
return await websocket.send(f'|/challenge {user}, gen8metronomebattle') | bee53e79d085ebc7f8a48e0091adb2e6605a2ac6 | 702,511 |
def create_character_ngrams(text_list, length):
""" Create character ngrams of the specified length from a string of text
Args:
text_list (list): Pre-tokenized text token to process.
length (int): Length of ngrams to create.
http://stackoverflow.com/questions/18658106/quick-implement... | 5df4dda2fe83a921c3b949fa3e9e7e843c333530 | 702,512 |
def air2vacMortonIAU(wl_air):
"""Take an input air wavelength in Angstroms and return the vacuum
wavelength.
Formula taken from
https://www.astro.uu.se/valdwiki/Air-to-vacuum%20conversion
"""
s = 1e4 / wl_air
n = 1 + 0.00008336624212083 + (0.02408926869968 / (130.1065924522 - s**2))\
... | 66823170493c3b7d8f63bd7d2e32364aa5efa78e | 702,513 |
import os
def verify_path(file_name, folder):
"""Ensures folders for checkpoints and network parameters exists.
:param file_name: Name of file.
:param folder: Name of folder
"""
folder_path = os.path.join(os.getcwd(), folder)
if not os.path.isdir(folder_path):
os.makedirs(folder... | 6f933651b25078873ac660cf655b113748bb418a | 702,514 |
def get_max_node(candidates, gr_values, column_prefix=""):
"""Given a set of candidate nodes, and return the one with the
highest Gain Ratio.
Args:
candidates (list): List of candidate nodes.
gr_values (dict): Dictionary with column names as keys and
the corresponding Gain Rat... | 5d64dad256784a932bcdc85265713d2b32c19c47 | 702,516 |
def tablefy(data, column=None, gutter=1, width=79):
"""
Convert a list of strings into being a table, displaying in a left-to-right
and top-to-bottom pattern. This does not sort the values.
:param data: list of strings
:param column: width of column, if None, detected
:param gutter: width of g... | d8aa63421578b9a0c4cb9c3fa106e7336de946d9 | 702,517 |
import functools
def once(func):
"""
Decorate func so it's only ever called the first time.
This decorator can ensure that an expensive or non-idempotent function
will not be expensive on subsequent calls and is idempotent.
>>> func = once(lambda a: a+3)
>>> func(3)
6
>>> func(9)
... | 60e6c4a9e26b322c27da74ca98e119056247b900 | 702,518 |
def _element_basis(string: str):
"""
Parse element and basis from string
Args: str
Returns: element, basis
"""
cut_list = string.split(".")
element = cut_list[0]
basis = " ".join(cut_list[1:])
return element, basis | c6be1c2a05832bb3bbc4577015b541136c724a08 | 702,520 |
def proportion_linear(time_right: float,
time_between: float,
time_step: float) -> tuple:
"""
:param time_right: right border in time
:param time_between: time between borders
:param time_step: step in time between borders
:return: _Iterable_(alpha, beta)
... | a2841baf2b3022e2be7f47111e63f1f6eb9e76e2 | 702,523 |
import requests
def getusercid(username):
"""
getusercid(string) -> string
tries to retrieve the CID of an avatar for a name to cid lookup
"""
getuser = 'http://www.imvu.com/catalog/web_av_pic.php?av=%s' % (username)
r = requests.get(getuser)
link = r.url
cid = link[link... | 3f296e82191290646bef5e0c6e209f5d47b273f7 | 702,524 |
def mr2rho(w,t,p):
"""rho = mr2rho(w,t,p)
w in g/kg
t in K
p in mb
This was provide by Holger Linne' from Max Planck Institute.
Dave Turner
Pacific Northwest National Laboratory
Currently at the University of Wisconsin-Madison
dave.turner@pnl.gov
"""
rho = w * (p * 0.3477) / t
return rho | 595cbb884a6824c7ec5fd28a1110a4dff1016417 | 702,525 |
def get_block_time():
"""
Returns block time
Currently hardcoded
"""
return 0.25 | 80b0a035403384c7dbf17b7ee5971fe83cbe96cf | 702,526 |
def satellite(isochrone, kernel, stellar_mass, distance_modulus,**kwargs):
"""
Wrapping the isochrone and kernel simulate functions.
"""
mag_1, mag_2 = isochrone.simulate(stellar_mass, distance_modulus)
lon, lat = kernel.simulate(len(mag_1))
return mag_1, mag_2, lon, lat | a9522074bc64722f0991e3ac5747abe8fe6b226d | 702,528 |
def check_negation(text, NEGATION_MAP):
"""
Utility function to check negation of an emotion
:param text: text chunk with the emotion term
:return: boolean value for negation
"""
neg_word_list = NEGATION_MAP
neg_match = False
for neg_word in neg_word_list:
if neg_word.strip() in ... | 020b7f692264754d8b76111c709cc31710ba6339 | 702,529 |
def latex_to_unicode(string):
"""Returns a unicode representation from latex strings used by pyFAI.
.. note:: The latex string could be removed from the pyFAI core.
:param str string: A latex string to convert
:rtype: str
"""
string = string.replace("$", u"")
string = string.replace("^{-2}... | 2ef821cfc99ea6241b3d6bea95109f36f6cb135f | 702,530 |
def _tree_to_json(clf, features, labels, node_index=0):
"""Structure of rules in a fit decision tree classifier
Parameters
----------
clf : DecisionTreeClassifier
A tree that has already been fit.
features, labels : lists of str
The names of the features and labels, respectively.
... | 02689b1d0ccd6b5fb39def7e69a07a87770afd5d | 702,531 |
def find_bean_by_name(jsn, nme):
"""
Extracts a bean of the given name from jmx metrics json object.
"""
if 'beans' not in jsn:
return None
else:
return next((b for b in jsn['beans'] if b['name'] == nme), None) | 826115bff5a5c1a4ee58560a55641ccf99c1541f | 702,532 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.