content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def kill_process(device, process="tcpdump"):
"""Kill any active process
:param device: lan or wan
:type device: Object
:param process: process to kill, defaults to tcpdump
:type process: String, Optional
:return: Console ouput of sync sendline command after kill process
:rtype: string
"... | 8b892b79c07feff586ddd0576cc18ab92551c322 | 20,336 |
def mock_get_globus():
"""Mock get_globus()"""
class MockGlobusAuth:
def __init__(self):
self.authorizer = None
return MockGlobusAuth() | a823d43b9ddd5d6761819b5f83b4dd035e97bf2e | 20,337 |
def to_wgs84(gdf):
"""Reprojects a GeoDataFrame to WGS84 reference system (EPSG:4326).
Args:
gdf (GeoDataFrame): The GeoDataFrame object to be exported.
Returns:
The transformed GeoDataFrame.
"""
if not ('init=epsg:4326' in gdf.crs.to_string()):
gdf = gdf.to_crs({'i... | 02505da7e0d4a7cb3d78b3ae60633d0dc1af1433 | 20,338 |
import json
def read_test_file(path):
"""Read a test file.
Parameters
----------
path : str
The path to a test file.
Returns
-------
typing.Tuple[str, typing.List[str]]
"""
with open(path) as f:
dct = json.load(f)
return dct['text'], dct['sentences'] | a416a4031ff355134004dde233d741899a35b28b | 20,339 |
import csv
def test_csv(data):
"""Test data to correct csv format."""
data.seek(0)
try:
_foo = csv.Sniffer().sniff(data.read(), delimiters=';')
return True
except csv.Error:
return False | 0807c6340bcaa3f0cea2d5399152d4a7bcf462f9 | 20,340 |
def make_xml_name(attr_name):
""" Convert an attribute name to its XML equivalent by replacing
all '_' with '-'. CamelCase names are retained as such.
:param str attr_name: Name of the attribute
:returns: Attribute name in XML format.
"""
return attr_name.replace('_', '-') | f1463c4592edd40c20f030cbd9add83a3cf93577 | 20,342 |
import typing
def query_bt_info(
start: typing.Dict[str, typing.Any],
composition_key: str,
wavelength_key: str,
default_composition: str = "Ni"
) -> dict:
"""Query the necessary information for the PDFGetter."""
if composition_key in start:
composition = start[composition_key]
... | 520f006a9fdf479089230f6af123b2a9e8838de9 | 20,343 |
def other(player):
""" Returns the given player's opponent.
"""
if player == 'X':
return 'O'
return 'X' | e23ed765c5331ae47d284e71835b6c0897612b5c | 20,345 |
def get_module(module_name: str):
"""
Retrieves a module.
"""
try:
# import importlib
# module = importlib.import_module(module_name)
# requiring parameter `fromlist` to get specified module
module = __import__(module_name, fromlist=[''])
return module
except ... | 76d9ebd5b7a8a2450f4a740720152f85bf56ef76 | 20,346 |
import re
def check_package_name(package_name):
"""Check that package name matches convention
Args:
package_name: The package name to validate
Returns:
A boolean determining whether the package name is valid or not
"""
m = re.match('[a-z0-9_]{3,30}', package_name)
return (m != None and m.group(0... | 28d22f69d3926152aabbb835ada8bb8d31553a01 | 20,347 |
import random
def random_distr(l):
"""function that can be used to simulate the terminal symbol of an n-gram given
the previous values.
"""
r = random.uniform(0, 1)
s = 0
for item, prob in l:
s += prob
if s >= r:
return item
return l[-1] | 88db100e09370da0bf5e9689a763316e6c822840 | 20,348 |
import random
def gen_ipaddr(ip3=False, ipv6=False, prefix=()):
"""Generate a random IP address.
You can also specify an IP address prefix if you are interested in
local network address generation, etc.
:param bool ip3: Whether to generate a 3 or 4 group IP.
:param bool ipv6: Whether to generate... | 173551883ab17f033f043dbbf5fe7f2c8e87c2ff | 20,349 |
import aiohttp
async def msg_port(msg, blog, cid, time_code):
"""上传消息,包括文字、图片、混合消息"""
url = blog
data = {'token': 'qq',
'time_code': time_code,
'msg_type': 'text',
'mediaId': '1',
'content': msg,
'cid': cid,
'action': 'send_talk'}
... | 225d765b9b62af45b29554c313aea8345b290fe9 | 20,350 |
def is_composite(_):
"""
Always returns 'N'
"""
return "N" | a55cee38e26ab74c9e3b07fdce19cfc7f5b93f0a | 20,352 |
def get_event_types(client, method, token):
"""
Call the client module to fetch event types using the input parameters
:param client: instace of client to communicate with server
:param method: Requests method to be used
:param token: server access token
:return: alert event types
"""
eT... | 6a9c382dc702d9545b8d6c27760e221a6baaea7a | 20,355 |
import sys
import os
def run_platform_cmake():
"""Runs cmake build configuration
"""
if sys.platform == 'win32':
vs_version_year = '2015'
if 'VSVERSION' in os.environ:
vs_version_year = os.environ['VSVERSION']
if vs_version_year == '2015':
vs_version_numeral... | ffa69cb7463cd39b483f63aef7d58e258cfd6270 | 20,356 |
def determine_layers_below_above(layers, values, elevation):
"""Determine the layers below and above the current elevation
Args:
layers [<str>]: All the pressure layers to load for each parameter
values [<LayerInfo>]: All the interpolated layers information
elevation <float>: The elevat... | bc0b0846037fd9a415c091264213684ee088174c | 20,357 |
def get_suffix_side(node, matcher):
"""Check if (not) adding char node to right syllable would cause creating word suffix.
Return 1 if char node should be added to right,
-1 if to left,
0 if cannot determine."""
if node.next.syllable is None or node.next.syllable.is_last() is False:
return 0... | c46ed8605c0eef77059804802e7151b75b0388b0 | 20,358 |
import os
def dataset32(user_factory, post_factory, dataset32_model):
"""
Provides the dataset:
- 2 users as authors
- 2 posts, each post authored by each user
Each object has random shared hash assigned to dataset:
- author:
- username: user_{hash}
- password: user_{hash}
... | eae6c3a76c137517712e11c907a1689329afac6e | 20,359 |
def _sanitize_git_config_value(value: str) -> str:
"""Remove quotation marks and whitespaces surrounding a config value."""
return value.strip(" \n\t\"'") | 8945955e6ac4811a637d9df6eac0f7f29a5e55eb | 20,360 |
def binpack(articles,bin_cap):
""" Write your heuristic bin packing algorithm in this function using the argument values that are passed
articles: a dictionary of the items to be loaded into the bins: the key is the article id and the value is the article volume
bin_cap: the capacity of ea... | 8c4714e8358462d20342ac3d9206b7b0791ce2c4 | 20,361 |
def _get_statvfs(fh, result):
"""
Returns a tuple (f_type, f_bsize, f_blocks, f_bfree, f_bavail, f_files,
f_ffree, f_fsid, f_namelen, f_frsize)
The statvfs structure is given in the lines following the current line. If the
lines contain the information needed, the lines are read and the in... | 81b984c54cae16f7975df4047f4c9620acf6a1bb | 20,363 |
import os
import zipfile
def download_data(competition: str = "nlp-getting-started") -> list:
"""To download and unzip from kaggle competition data.
Args:
competition (str, optional): Competition name of which data needs to
be downloaded. Defaults to "nlp-getting-started".
Returns:
... | f551bb3a3b6b5d39e74a94c84f962a0d25278730 | 20,364 |
def is_urn(s: str):
"""Test if is uuid string in urn format"""
return type(s) == str and s.startswith("urn:uuid:") | 7f5bbf7dad8e86a687230c29a50f3218198a8286 | 20,366 |
def numdim(l):
"""
Returns number or dimensions of the list, assuming it has the same depth
everywhere.
"""
if not isinstance(l, (list, tuple)):
return 0
if not isinstance(l[-1], (list, tuple)):
return 1
else:
return 1 + numdim(l[-1]) | e5e35e968e944d29b81261781959350eab900b78 | 20,367 |
import os
import sys
import json
def getProblemSet(ds, n_solutions_th, max_n_problems):
"""
Get list of problems satisfying required criteria:
- number of solutions is not less than threshold
- number of problems is not more than required
Parameters:
- ds - directory with tokenized... | 6932924075996f437db8a2e442ecdb30593c5f8b | 20,368 |
def recommended_spacecharge_mesh(n_particles):
"""
! --------------------------------------------------------
! Suggested Nrad, Nlong_in settings from:
! A. Bartnik and C. Gulliford (Cornell University)
!
! Nrad = 35, Nlong_in = 75 !28K
! Nrad = 29, Nlong_in = 63 !20K
! Nrad =... | 432689a85c26873cb9d255b7f119ccf06fc5301d | 20,369 |
def integration_service(config, pin, global_service_fallback=False):
"""Compute the service name that should be used for an integration
based off the given config and pin instances.
"""
if pin.service:
return pin.service
# Integrations unfortunately use both service and service_name in thei... | 6d4b39f96672cdf0d903f2faca8e776f579ec7e1 | 20,370 |
def valid(brd, num, pos):
"""
Compares the suggested value against the row, column, and 3x3 grid to identify if entry is valid. If the number is
observed in either of these categories, the entry is invalid and the test fails. At that point, a new value is
determined and the process repeats. If the entry... | 3efd7daa532fda71a0e8cd7521eae2f33b80b0b5 | 20,371 |
def get_snirf_measurement_data(snirf):
"""Returns the acquired measurement data in the SNIRF file."""
return snirf["nirs"]["data1"]["dataTimeSeries"][:] | 2781c241aac66167e94f6873492d62a200081688 | 20,372 |
import json
def parse_sw(sw_file):
""" Parse stopword config. """
with open(sw_file, "r", encoding="utf-8") as sw_stream:
sw = json.load(sw_stream)
assert isinstance(sw["wordlist"], list)
for word in sw["wordlist"]:
assert isinstance(word, str)
stopword = sw["wordlist"]
retur... | 8dc46a61c195f0ff47bbc825dd816c780ef6f0b5 | 20,373 |
def num_ints(lst):
"""
Returns: the number of ints in the list
Example: num_ints([1,2.0,True]) returns 1
Parameter lst: the list to count
Precondition: lst is a list of any mix of types
"""
result = 0 # Accumulator
for x in lst:
if type(x) == int:
result = resul... | cba6c06bc1618dae1b7a6f515e7f9b42ca88187b | 20,375 |
def _escapeQuotes(key, _dict):
"""
Safely escape quotes of each item that goes in a row
@param key: The key of the dictionary to pull from.
@param _dict: The target dictionary holding the data
@return:
"""
value = _dict.get(key, '')
# if the key exists but has a None value, just use the ... | 681920670e06098f9b0f43a61c838044593b42c8 | 20,376 |
def without_keys(d: dict, *rm_keys):
"""Returns copy of dictionary with each key in rm_keys removed"""
return {k: v for k, v in d.items() if k not in rm_keys} | 256597224426708c38369ba635b4fa1df15591be | 20,377 |
def assemble_CohorteFromFile(fileName):
"""
-> Assemble discrete cohorte from cytokine data
-> fileName is the name of the dicrete reduce matrix file
(e. g DATA/CYTOKINES/RA_quantitativeMatrix_discrete.csv)
-> add diagnostic in vectors
-> Write index variable file in PARAMETERS folder
-> add "pX" prefix to sc... | 8f51cbfe71790fb757dc514635e7b0773b1a2e58 | 20,378 |
def retry_if(predicate):
"""
Create a predicate compatible with ``with_retry``
which will retry if the raised exception satisfies the given predicate.
:param predicate: A one-argument callable which will be called with the
raised exception instance only. It should return ``True`` if a retry
... | e02401ba7eb9af88565e06c0013135bfcf711521 | 20,379 |
def list_diff(list1, list2, identical=False):
"""
API to get the differece in 2 lists
:param list1:
:param list2:
:param identical:
:return:
"""
result = list()
for value in list1:
if identical:
if value in list2:
result.append(value)
else:... | e5ff6369b07514c91333330676afdf25a81377ad | 20,382 |
import itertools
from functools import reduce
def rank_compounds(compounds, nst_model, stats_lexicon):
"""Return a list of compounds, ordered according to their ranks.
Ranking is being done according to the amount of affixes (the fewer the higher)
and the compound probability which is calculated as follo... | 341e02131f708b67e91d5c8de26a77517dc04689 | 20,385 |
def format_value(value):
"""Handles side effects of json.load function"""
if value is None:
return 'null'
if type(value) is bool:
return 'true' if value else 'false'
if type(value) is str:
return f'\'{value}\''
if type(value) is dict \
or type(value) is list:
r... | ccf3383d39fd1f745a505811b2cf7da335da1ae9 | 20,386 |
import requests
def twitter_api_request(url, parameters, token):
"""Returns a list of tweets"""
res = requests.get(
url,
params=parameters,
auth=token
)
tweets = res.json().get('statuses')
return tweets | 67a9a901cca478ac94251165ab76ed1d00b54f42 | 20,387 |
def next_pow2(n):
""" Return first power of 2 >= n.
>>> next_pow2(3)
4
>>> next_pow2(8)
8
>>> next_pow2(0)
1
>>> next_pow2(1)
1
"""
if n <= 0:
return 1
n2 = 1 << int(n).bit_length()
if n2 >> 1 == n:
return n
else:
return n2 | a94ee5064ae2f3540b65b03b85ab82290c26addd | 20,388 |
def merge_annotations(interaction_dataframe, columns):
"""Merges the annotations for a protein-protein interaction.
Given two columns of a protein-protein interaction dataframe, each of
which contains a type of annotation data, this function returns the merged
set of those annotations.
E.g. Column... | e5dcacc645e1110c1515f5630cd9197a8b7656bd | 20,389 |
def Conjoin( matrix, stays, goes ):
""" Given a matrix and a row that stays and a row that goes
Condense the matrix
"""
#Each item in the matrix will have one spot that stays and one spot that goes.
# Take the average of item[stays] and item[goes] and store it in item stays
for i in range(... | d83b20cd2bf778adf193506b8ab2fda2c8f4b936 | 20,390 |
import re
def policy_set_pattern(policy_set: str) -> re.Pattern:
"""Return a regexp matching the policy set's name."""
final = policy_set.rsplit("/", maxsplit=1)[-1]
return re.compile(rf"^{final}_\d+$") | 78c278ddf6cd98e4a69c248806334a7190cad1cd | 20,392 |
def get_start_end_interval(ref, query, i = 0, j = -1):
"""
Return the start and end points in the query where the ref contig matches.
"""
#print 'start find interval'
#print ref
#print i,j
if i >= len(query):
return i, j
#print query[i][1] + '\tlen: ' + str(len(query))
... | 5490f5bde09fae861661d90eb903bb705d85e4f5 | 20,393 |
import math
def angle_between(pos1, pos2):
""" Computes the angle between two positions. """
diff = pos2 - pos1
# return np.arctan2(diff[1], diff[0])
return math.atan2(diff[1], diff[0]) | ee69333fbd188fe977ac64f91275962b34246ed4 | 20,394 |
async def handle_update_identity(request, identity):
"""
Handler for updating an Identity. The request is expected to contain at
least a partial JSON representation of the Identity model object.
"""
id = request.match_info["id"]
identity.id = id
await identity.save()
return 200, {"data":... | 74712d4381c82395f9b31d194e2bcc1f5600b3ac | 20,395 |
from pandas import DataFrame
def _is_aligned(frame, other):
"""
Helper to check if a DataFrame is aligned with another DataFrame or Series.
"""
if isinstance(other, DataFrame):
return frame._indexed_same(other)
else:
# Series -> match index
return frame.columns.equals(othe... | 8381ff297a858d32f539f1deeef57f32d9ab0c4d | 20,396 |
def concat_url(num_of_pics,item_type,org):
"""[summary]
This concats our full API url
Args:
num_of_pics ([INT]): [How many pictures wanted, the hitsPerPage in our case]
item_type ([STR]): [This is what type of item we want from request]
org ([STR]): [The org we want pictures from]
... | 3214b98e387731251fbe9e4d9cd01e248f2f8b62 | 20,397 |
def not_none(elem):
"""Check if an element is not None."""
return elem is not None | f91a28efc42e3d50515bb783d3f16a64cdcf9490 | 20,398 |
def format_weather_header_for_HELP(itype, iunits, city, lat=None):
"""
Prepare the header for the precipitation, air temperature and
global solar radiation input weather datafile for HELP. The format of the
header is defined in the subroutine READIN of the HELP Fortran source code.
"""
fheader =... | 7d848481b7316cef4094c2d24b9978665a1c2e1d | 20,399 |
import os
def is_c_file(fn):
"""
Return true iff fn is the name of a C file.
>>> is_c_file("a/b/module.c")
True
>>> is_c_file("a/b/module.h")
True
>>> is_c_file("a/b/module.c~")
False
>>> is_c_file("a/b/.module.c")
False
>>> is_c_file("a/b/mod... | 5a106c70f034b89737d46261a0973670305f1631 | 20,400 |
import os
def get_case_name(case_path, inst_path):
"""extract case name from case path."""
return case_path.replace(os.path.join(
inst_path, "cases"), "")[1:].replace("\\", "/") | f585f1ceb469664ac7c5407e69ce1387cd59ecb2 | 20,401 |
def __TeardropLength(track, via, hpercent):
"""Computes the teardrop length"""
n = min(track.GetLength(), (via[1] - track.GetWidth()) * 1.2071)
n = max(via[1]*(0.5+hpercent/200.0), n)
return n | 6f2e0f9980e5d47e4c52b1a7bf4b6f20d62d2e94 | 20,402 |
import numpy
def spikelist2spikematrix(DATA, N, N_time, dt):
"""
Returns a matrix of the number of spikes during simulation.
Is of the shape of N x N.
The spike list is a list of tuples (rel time, neuron_id) where the
location of each neuron_id is given by the NEURON_ID matrix, which
is in a... | f179f69149ba6a57a6e8c01615ceb16988596b7b | 20,404 |
def decode_selected_indices(decode_fn, features):
"""Decode selected indices from features dict."""
inputs = features.get("inputs", None)
selected_ids = features.get("selected_ids", None)
num_inputs = features.get("num_inputs", None)
if inputs is None or selected_ids is None or num_inputs is None:
raise V... | 3e09c349551a740bf994055205463cedf1d25cdd | 20,406 |
def wilight_to_hass_hue(value):
"""Convert wilight hue 1..255 to hass 0..360 scale."""
return min(360, round((value * 360) / 255, 3)) | 5a9021185f7bbb9bf1351b2df55207063ee49f9a | 20,407 |
def convert_triggers(events, return_event_ids=False):
"""Function to convert triggers to failed and successful inhibition.
Trigger codes:
stop_signal: 11,
go: 10,
response: 1,
stop_signal_only: 12,
failed_inhibition_response: 2,
failed_inhibition: 37,
successful_inhibition: 35
... | 69eca81afe81c4f161ee69e3a02f2e5706c1c5ee | 20,408 |
import random
def intRndPct(n, pct=20):
"""
Randomize an integer
Parameters
----------
n : int
pct : int, optional
Randomization factor in %. The default is 20.
Returns
-------
int
Randomized integer
"""
return int(n * (100.0 + random.uniform(-pct, pct)) ... | 5ef784b83d7e9e5c033932ec41d5426b775ece35 | 20,410 |
def kind(o):
"""
returns a suitable table name for an object based on the object class
"""
n = []
for c in o.__class__.__name__:
if c.isalpha() or c == '_':
if c.isupper() and len(n):
n.append('_')
n.append(c.lower())
return ''.join(n) | 420041fd2369fdcdee48ac433a81be2dc07c1563 | 20,412 |
def user_index_by_id(slack_id, users):
"""
Returns index of user in users list, based on it's Slack id
:param slack_id:
:param users:
:return: Index in users or False
"""
found_users = [user for user in users if user['id'] == slack_id]
if len(found_users) == 0:
#... | ec5fb9b382f71f1df4fa7778285679307c634c39 | 20,413 |
def isoformat(date):
""" Convert a datetime object to asmx ISO format """
return date.isoformat()[:-3] + "Z" | c2c94c1957f251622998af723aab354116b7fd55 | 20,415 |
from pathlib import Path
import json
def load_json(path: Path):
"""
Loads authentification keys/tokens.
:param path: JSON file to load the keys from
:return: Dictionary containing the key-file information
"""
with open(path, mode='r', encoding='utf8') as file:
return json.load(file) | e7368431970682451669603098d56c1c991750a5 | 20,416 |
def normalize_md(txt):
"""Replace newlines *inside paragraphs* with spaces.
Consecutive lines of text are considered part of the same paragraph
in Markdown. So this function joins those into a single line to make the
test robust to changes in text wrapping.
NOTE: This function doesn't attempt to b... | 3d3383607c7b5957ce75888266326f03f7dc7be2 | 20,417 |
def find(node):
"""
Find the UFSet of given node by return the root of this UFSet
With path compression
"""
if node.parent != node:
node.parent = find(node.parent)
return node.parent | 5c671b02cf8a7c7df82480a16eab3006139b1d8e | 20,418 |
import json
def parse_station_info_json(station_info_json):
"""
解析沿途停靠站点信息
:param station_info_json: 车站信息json
:return: [简略火车车次, 起点站名, 终点站名]
"""
json_text = json.loads(station_info_json)
data = json_text['data']['data']
start_station_name = data[0]['start_station_name']
station_trai... | a9d80a47db9864662c33fadbf623218af2ece04e | 20,419 |
def process_data(df, stable=True):
"""Process raw data into useful files for model."""
# Fix the category for both
bat_hand = {'R': 1, 'L': 0, 'B': 2}
df['bats'] = df['bats'].map(bat_hand)
pit_hand = {'R': 1, 'L': 0, 'S': 0}
df['throws'] = df['throws'].map(pit_hand)
df = df.dropna(subset... | 90d6f91821420b22341ef542f71f9a0521fbb5f8 | 20,420 |
def validate_key_parse(data):
"""
Validate key is a numerical value string and parse it.
:param dict data: Data to be validated
"""
validated_data = {int(key): str(value) for key, value
in data.items() if key.isdigit()}
return validated_data if len(validated_data) == len(... | 79c973b2892caabd6249366423bc229384f80f5a | 20,421 |
import re
def tsv_string_to_list(s, func=lambda x : x, sep='|^|'):
"""Convert a TSV string from the sentences_input table to a list,
optionally applying a fn to each element"""
if s.strip() == "":
return []
# Auto-detect separator
if re.search(r'^\{|\}$', s):
split = re.split(r'\s*,\s*', re.sub(... | 3bc223b7d685a0245d4dad98eeac81c39a315a77 | 20,422 |
def resource_count(entries=[]):
"""
Count for each type of resource
count = [{resourceType: instances}, ...]
:param entries:
:return: counts: dictionary of counts
"""
count = {}
for e in entries:
if "resourceType" in e:
if e['resourceType'] in count:
... | 2518f016fbdd515e25e005905948b84fdc923c60 | 20,424 |
def replicate_config(cfg, num_times=1):
"""Replicate a config dictionary some number of times
Args:
cfg (dict): Base config dictionary
num_times (int): Number of repeats
Returns:
(list): List of duplicated config dictionaries, with an added 'replicate' field.
"""
# ... | 8b4d43002c22d20c6d2238c2309086a21d560c5c | 20,425 |
import torch
def gradient(func, idx, tensors):
"""Take the gradient of func
w.r.t. tensors[idx].
func is
Args:
func (Callable):
assumed to be the function of *tensors.
idx (int):
index of the tensor w.r.t which
the gradient is taken
tenso... | a537186507101e63fb47bee9e62b56de309ebb60 | 20,427 |
def count_items(column_list):
"""Function to consolidade the count by user type
Args:
column_list: The list to perform the consolidation
Returns:
Lists with user types and count items
"""
type_count = {}
for type in set(column_list):
type_count[type] = column_list.count(type... | e3872c88145aa259402ced51c3783b9a4ea1bab3 | 20,428 |
import shutil
def header(overrides) -> str:
"""Create header for experiment."""
# Get terminal number of columns
try:
columns, _ = shutil.get_terminal_size((80, 20))
except Exception: # pylint: disable=broad-except
columns = 80
# Join key-values and truncate if needed
content... | d870bc643c65b9a717e2a8004c6381e3e743e676 | 20,429 |
def get_best_algorithm_hyperparameter_onestep(results_df):
"""
Combines get_best_algorithm_hyperparameter() and
get_best_hyperparam_all() into one function.
Parameters
==========
results_df : DataFrame
DataFrame containing pipeline_ML results.
"""
# Set up
average_group_c... | 8065a6f51d2b4be557d6fc8816783bb2b18d6ce3 | 20,430 |
def get_user_config():
"""Reads the project configuration from the user.
Returns:
tuple: Returns a tuple, containing (project_name, is_flask_service)
"""
project = str(input("""Please give your project name: """))
flask_service = str(input(
"""Should "%s" contain a Flask service? (... | 48f89636741887a103ecaa900d749068ac77cb24 | 20,431 |
def places(net):
""" build place vector definition """
_places = {}
offset = 0
for place in net.places:
_places[place] = {
'offset': offset,
'position': net.places[place].position,
'initial': net.places[place].marking
}
offset += 1
ret... | 8ed3c3db0bfe77afb4028c68898b535057d1fc88 | 20,432 |
def gen_mock_env_info(*args, **kwargs) -> str:
"""构造并返回 mock 的 exec_command 查询到的 env_info"""
return "env1=xxx\nenv2=xxx\nenv3=xxx" | f7b3835ed151825969e8752ce6a975fe86708f7e | 20,433 |
import argparse
def init_argparse():
"""
Initialize all possible arguments for the argument parser.
Returns:
:py:mod:`argparse.ArgumentParser`: ArgumentParser object with command line arguments for this script.
"""
argparser = argparse.ArgumentParser()
argparser.add_argument('--input',
help='Relation ... | 98018f46668d8e87aa3571fbdcb22ca2381d4433 | 20,434 |
def in_order(tree):
"""
Function to which performs inorder for a tree iteratively.
Parameters:
tree (BinTreeNode) ; the tree for which inorder is to be performed.
Returns:
sortedArr (list); list of all elements in ascending order.
"""
sortedArr = []
current... | 2d61a691854a5901b4140f3a22d689709cac7640 | 20,435 |
def create_table_sql(tablename, fields, geom_type, geom_srid):
"""
Create a SQL statement for creating a table. Based on a geoJSON
representation. For simplicity all fields are declared VARCHAR 255
(not good, I know, patches welcome)
"""
cols = []
for field in fields:
cols.append("%s... | 1df5ff0472a0333f6dcc872030e3f253e4aeb940 | 20,436 |
import os
import sys
import stat
def get_stdin_data():
""" Helper function that returns data send to stdin or False if nothing is send """
# STDIN can only be 3 different types of things ("modes")
# 1. An interactive terminal device (i.e. a TTY -> sys.stdin.isatty() or stat.S_ISCHR)
# 2. A (named) p... | 604adcd395e48038caaa9d01bedbdf9b3efb90cf | 20,437 |
def inherit(cls, *bases):
""" Inherits class cls from *bases
@note: cls needs a __dict__, so __slots__ is tabu
@param cls: The class to inherit from *bases
@type cls: C{class}
@param bases: The base class(es)
@type bases: C{list}
"""
newdict = dict([(key, value)
... | 96fdbd3bf0fbf669d8f25b4f1338c50fbf10de79 | 20,438 |
import math
def math_degrees(x):
"""Implement the SQLite3 math built-in 'degrees' via Python.
Convert value X from radians into degrees.
"""
try:
return math.degrees(x)
except:
pass | 19ce54220c093b2b10de5f101dd11c4221a413fe | 20,440 |
def extract_bold_bins(dataf):
"""
Returns the dataframe filtered to only rows with a BOLD BIN id, i.e.
excluding NaN values
:param dataf: Input dataframe
:return: Filtered dataframe
"""
return dataf.loc[dataf.bold_id==dataf.bold_id] | 42637ae77bdc3966a3c95612eced79dd6c9358a8 | 20,442 |
import click
def _validate_count(value):
"""
Validate that count is 4 or 5, because EFF lists
only work for these number of dice.
:param value: value to validate
:return: value after it's validated
"""
# Use `set` ({x, y, z}) here for quickest result
if value not in {4, 5}:
r... | 79f17c061af41e71f0f2f82d4a6a21fe2e09abfa | 20,443 |
def get_vplex_device_parameters():
"""This method provide the parameters required for the ansible
device module on VPLEX
"""
return dict(
cluster_name=dict(type='str', required=True),
geometry=dict(type='str', required=False, default='raid-1',
choices=['raid-0', 'ra... | f6d0e5892f3b1e770f1ef10b78ec290e14d33e76 | 20,444 |
def totalSeconds(td):
"""totalSeconds(td) -> float
Return the total number of seconds contained in the given Python
datetime.timedelta object. Python 2.6 and earlier do not have
timedelta.total_seconds().
Examples:
>>> totalSeconds( toLocalTime(86400.123) - toLocalTime(0.003) )
86400.12
... | 20ef54d7107ec910582a0fb904902788d93a2de4 | 20,445 |
import typing
def read_data_from_txt_file(txt_path: str) -> typing.List[str]:
"""从单个txt文本中按行读取,并返回结果
"""
with open(txt_path, 'r', encoding='utf-8') as f:
contents = [i.strip() for i in f]
return contents | 725d4566198c61b383b2ef973dd1f0f66b627ff8 | 20,446 |
async def get_ladders(database, platform_id, ladder_ids):
"""Get platform ladders."""
query = 'select id, platform_id, name from ladders where platform_id=:platform_id and id = any(:ladder_ids)'
values = {'platform_id': platform_id, 'ladder_ids': ladder_ids}
return list(map(dict, await database.fetch_al... | b1bbdbd51b72c45dd14ac696b3c4b841b39e72e9 | 20,447 |
def NLSYMBNDRY(NSPV,ISPV,VSPV,GLK,GLKG,NDF=4):
"""Establish the boundary condition in the global matrices
Args:
NSPV (int): Number of primary boundary conditions
ISPV (array): Position of primary boundary conditions
VSPV (array): Value of primary boundary conditions
GLK (array): Global stiffness ma... | e379a73e93b0d02db7c91d2d69ad55105abc8339 | 20,448 |
import torch
def compute_content_loss(a_C, a_G):
"""
Compute the content cost
Arguments:
a_C -- tensor of dimension (1, n_C, n_H, n_W)
a_G -- tensor of dimension (1, n_C, n_H, n_W)
Returns:
J_content -- scalar that you compute using equation 1 above
"""
m, n_C, n_H, n_W = a_G.sha... | 51894aedd2a7cfce5db3be3b43f8689ecdf78bf6 | 20,449 |
def id_sort_key(entity):
"""
Sort key for ``DiscordEntity``-s.
Parameters
----------
entity : ``DiscordEntity``
The discord entity to get identifier of.
Returns
-------
entity_id : `int`
The entity's identifier.
"""
return entity.id | 320468d39064f49c9a118ca5a3591e68227d9bbe | 20,450 |
def filter_table_from_column(table,column,value):
"""
Return a view into the 'table' DataFrame, selecting only the rows where
'column' equals 'value'
"""
return table[table[column] == value] | 2b0642d8a2a7959614ef99f1fdc12148ddd294f7 | 20,451 |
def strip_specific_magics(source, magic):
"""
Given the source of a cell, filter out specific cell and line magics.
"""
filtered=[]
for line in source.splitlines():
if line.startswith(f'%{magic}'):
filtered.append(line.lstrip(f'%{magic}').strip(' '))
if line.startswith(f'... | 3c2722b86b6fc8e40c8dd51edd06d7edb28e2945 | 20,452 |
def build_docker_package_install(package, version):
"""Outputs formatted dockerfile command to install a specific version
of an R package into a docker image
Parameters
----------
package : string
Name of the R package to be installed
version : string
Version numbe... | 3d323377ce22225fdeea767550eedc57542631df | 20,453 |
def recall_powerlaw_fits_to_full_models():
"""fits may be recomputed by evaluating the .ipynb associated with fitting powerlaws to the full models.
here, w=M*q**m, and Delta_X is the maximum disagreement one could expect to observe with 95% confidence.
here, we observe Delta_X concerns disagreements between... | 441177ede4f5a9b093522ce8dc799307e714ee0d | 20,455 |
def center_crop(im):
"""assumes im.shape = (x, y, colors)"""
im_dim = min(im.shape[:2])
im_x0 = int((im.shape[0] - im_dim)/2)
im_y0 = int((im.shape[1] - im_dim)/2)
return im[im_x0:im_x0+im_dim, im_y0:im_y0+im_dim] | 29251fd1a000c5c6ff5d81a6688685d7ac010a76 | 20,456 |
def fatorial(num=1, show=False):
"""
-> Calcula a fatorial de um número.
:param num: Número a ser calculado fatorial.
:param show: (opcional) Mostrar ou não a conta.
:return: valor da fatorial do número.
*Desenvolvido por Lucas Souza, github.com/lucashsouza *.
"""
fat = 1
for cn... | 39245c46ae6d9551dcd1fdd9c161575c8e5c21dd | 20,457 |
def get_column_from_file(data_path, column_index, sep=None):
"""
:param data_path:
:param column_index:
:param sep:
:return:
"""
with open(data_path, 'r', encoding="utf8") as f:
contents = f.readlines()
data = []
sep_data = []
for content in contents:
content = c... | a7aa673f594a2f4bd4939330c30971e3f60c7aa4 | 20,458 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.