content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def resource_name_for_asset_type(asset_type):
"""Return the resource name for the asset_type.
Args:
asset_type: the asset type like 'google.compute.Instance'
Returns:
a resource name like 'Instance'
"""
return asset_type.split('.')[-1] | 00604d1285e8e275976a026aaf0e7afb200ba1c8 | 35,667 |
def get_merged_gaps(gaps):
"""Get gaps merged across channels/streams
Parameters
----------
gaps: dictionary
contains channel/gap array pairs
Returns
-------
array_like
an array of startime/endtime arrays representing gaps.
Notes
-----
Takes an dictionary of gap... | 59c6c04ca20800040eaa2a4909708b4880fcb11f | 35,668 |
def get_lrmost(T, segs):
"""
Finds the leftmost and rightmost segments of segs in T
"""
l = []
for s in list(T):
if s in segs:
l.append(s)
if len(l) < 1:
return None, None
return l[0], l[-1] | a0af5055292b3253cd27300181e7aee9e0b9653a | 35,669 |
def overall_dwelling_dimensions(
area,
average_storey_height
):
"""Calculates the overall dwelling dimensions, Section 1.
:param area: A list of the areas of each floor.
The first item is the basement, the second the ground floor etc.
See (1a) to (1n).
:ty... | 72408ae8c0aa782b6a6b2f86dd5635f9c9e984c9 | 35,670 |
def speedx(clip, factor = None, final_duration=None):
"""
Returns a clip playing the current clip but at a speed multiplied
by ``factor``. Instead of factor one can indicate the desired
``final_duration`` of the clip, and the factor will be automatically
computed.
The same effect is applied to t... | e6bf9595bc958cd0fc39bab95bef31fe6fba6ba6 | 35,672 |
def check_groups(dashboard, request):
"""
Check groups authorization for a dashboard
"""
if dashboard.public is True:
return True
if request.user.is_superuser is True:
return True
groups = dashboard.groups.all()
user_groups = request.user.groups.all()
for group in groups:... | e4ab46d443f3cbb1513242101792de4d411d993e | 35,673 |
def binarize_worker(document):
"""Binarizes a BOW document.
Parameters
----------
document : list of (int, float)
A document.
Returns
-------
binarized_document : list of (int, float)
The binarized document.
"""
binarized_document = [(term_id, 1) for term_id, _ in ... | eadf535337dec095b9f287b422541fe5de8ae932 | 35,674 |
import networkx as nx
def split_graph(G):
"""splits graph(s) on interactions and return a dictionary of graphs with interaction as keys."""
# Find all interactions to split the graph on
split_by = "interaction"
split_list = list()
for u, v, d in G.edges(data=True):
split_list.append(d[spl... | 4ac596e472afb57cb3f6094fb0f4166aca4b1a2a | 35,675 |
def CheckForNewSkipExpectations(input_api, output_api):
"""Checks for and dissuades the addition of new Skip expectations."""
new_skips = []
expectation_file_dir = input_api.os_path.join(input_api.PresubmitLocalPath(),
'gpu_tests',
... | dcd4dceb38fc745f10c58980fb56cf8730ee3e03 | 35,676 |
def test_trainable_parameters_changed(trainer):
"""Performs a training step and verifies that at least one parameter
in every trainable layer has changed."""
print("At least one parameter changed in the trainable layers", end="")
passed, msg = True, ""
trainer.fit(epochs=1, max_steps=1, max_eval_s... | 29a0b0ffab55b62e9cb5ff5d4b29f1b655e99ad9 | 35,677 |
def get_free_space_network(free_nets, used_nets):
"""Return list of free subnets."""
for excluded_net in used_nets:
temp_net_list = list(free_nets)
free_nets = []
while temp_net_list:
temp_net = temp_net_list.pop()
used_nets = []
try:
... | 4b1e59bf9afbb8adf37db250248619824320af37 | 35,678 |
def get_game_name(filename: str):
"""
retrieves game name from pbp file
:param filename: path to pbp file
:return: game name or False
"""
gamename = b''
with open(filename, 'rb') as eboot:
eboot.seek(0x24)
pbp_verification_offset = eboot.read(4)
eboot.seek(int.from_by... | 379e46d427feabba3f33dd3757ce34c34ff6780c | 35,679 |
def sbt(bees):
"""Sanitize bees types"""
return [tuple(b) for b in bees] | 6410e7aa4b8f7a575041a8d0d02d29ba1b06feaf | 35,680 |
def i_simple(r,m):
"""
variables:
r=nominal interest rate
m=number of periods in a year
Ex. annually = 1
semianually = 2
quaterly = 4
"""
return r/m | df534b93e2fed16de099697217ad79b36a796c01 | 35,681 |
def strategy(history, memory):
"""
Tit for Tat, but it only defects once in a row.
"""
choice = 1
if (
history.shape[1] >= 1
and history[1, -1] == 0
and memory is not None
and 1 == memory
):
choice = 0
return choice, choice | ec4a016acd66374c56b57bbeb1d0e54813edd829 | 35,682 |
def _pixel_to_coords(col, row, transform):
"""Returns the geographic coordinate pair (lon, lat) for the given col, row, and geotransform."""
lon = transform[0] + (col * transform[1]) + (row * transform[2])
lat = transform[3] + (col * transform[4]) + (row * transform[2])
return lon, lat | f610340b5eb2ea652774d753920076f59a6faccd | 35,684 |
def round_to_factor(num: float, base: int) -> int:
"""Rounds floating point number to the nearest integer multiple of the
given base. E.g., for floating number 90.1 and integer base 45, the result
is 90.
# Attributes
num : floating point number to be rounded.
base: integer base
"""
ret... | 3679b884523253cec51659ceaf6f78292f87a401 | 35,685 |
def quaternary_spherical(rho, phi):
"""Zernike quaternary spherical."""
return 252 * rho**10 \
- 630 * rho**8 \
+ 560 * rho**6 \
- 210 * rho**4 \
+ 30 * rho**2 \
- 1 | 7a7e211ae02d024955087a5da4f1b4e4c0b5de3c | 35,686 |
def get_doc_content(content):
"""
Return the doc fields from request (not auth-related fields).
"""
return {
"title": content.get("title"),
"link": content.get("link"),
"tags": content.get("tags"),
"authors": content.get("authors"),
"year": content.get("year"),
... | ffd5037aee65dcc1cc104e8fc47df708fd5e7c64 | 35,687 |
def join_strings(lst):
"""Join a list to comma-separated values string."""
return ",".join(lst) | fbbc195a53d2d4b15012861251d676dbf9369cde | 35,688 |
def l_system(depth, axiom, **rules):
"""Generate L-system from axiom using rules, up to given depth"""
if not depth:
return axiom
# Basic, most straight-forward implementation
# Note 1: it doesn't matter if axiom is a string or a list
# Note 2: consider the difference between .extend()... | ed59af25848c5074be7b1da1a796dcdb0422e87e | 35,689 |
def call_with_ensured_size(method, max_size, arg):
"""
Breaks a list of arguments up into chunks of a maximum size and calls the given method on each chunk
Args:
method (function): the method to call
max_size (int): the maximum number of arguments to include in a single call
arg (an... | e31dfbd03de5e4caabb46241957b98d1b76eee1a | 35,690 |
import numpy
def gtsolh(a, b):
"""Starting solution."""
c = 0.95 * b
for _ in range(5):
gamma = b / a
kappa = c / b
k2 = kappa ** 2
gk2 = (gamma * kappa) ** 2
fac1 = numpy.sqrt(1.0 - gk2)
fac2 = numpy.sqrt(1.0 - k2)
fr = (2.0 - k2) ** 2 - 4.0 * fac1... | f8b4c7081262a49848572222a2ba6c5501e18127 | 35,691 |
def safe_str(maybe_str):
"""To help with testing between python 2 and 3, this function attempts to
decode a string, and if it cannot decode it just returns the string.
"""
try:
return maybe_str.decode('utf-8')
except AttributeError:
return maybe_str | f9713f98b4d32558855d46d82c2f5cc9bce568ee | 35,692 |
import os
def _get_win_drives():
"""Returns a list of paths for all available drives e.g. ['C:\\']"""
assert os.name == "nt"
drives = [letter + u":\\" for letter in u"CDEFGHIJKLMNOPQRSTUVWXYZ"]
return [d for d in drives if os.path.isdir(d)] | 9ef95f3dca0acce1a370d39a671210187da6b139 | 35,693 |
def args_priority(args, environ):
"""
priority of token
1) as argumment: -t
2) as environ variable
priority of as_user
1) as argument: -a
2) as environ variable
"""
arg_token = args.token
arg_as_user = args.as_user
slack_token_var_name = "SLACK_TOKEN"
if slack_token_va... | b2e0a114c477ae9e09aa8beb2516bfc7f5c60c8a | 35,695 |
def get_snapshot(ec2, snapshot_name: str):
"""Returns a snapshot by its name."""
res = ec2.describe_snapshots(Filters=[
{'Name': 'tag:Name', 'Values': [snapshot_name]},
])
if len(res['Snapshots']) > 1:
raise ValueError('Several snapshots with Name=%s found.' % snapshot_name)
snapsh... | cd6076e04fd2c83e50b3a0ac7bc117793c92731d | 35,697 |
import uuid
def get_file_name():
"""
"""
return uuid.uuid4().hex | 7495447e9ec49536db1bb9c8cda9f822f2e71b90 | 35,698 |
from datetime import datetime
def get_datetime_from_timestamp(timestamp):
"""Return datetime from unix timestamp"""
try:
return datetime.fromtimestamp(int(timestamp))
except:
return None | 553d24a532681d139845777cd71ca54fc3e16f96 | 35,701 |
def mock_athlete():
"""Mock athlete."""
athlete = {
"first_name": "Test",
"last_name": "USER",
"yearborn": 1900,
}
return athlete | 1d8d911cd889c1b728104475dcbfff14737b603f | 35,702 |
def cns_representer(dumper, data):
"""
Represents Configuration as dict
Parameters
----------
dumper :
YAML dumper object
data :
ConfigurationNameSpace object
Returns
-------
yaml dumper representation of Configuration as dict
"""
return dumper.represent_dic... | a4586b205e968d493854d2c37c3bd39ab3c96c6b | 35,703 |
import zlib
def compress(data):
"""
info: will compress data
:param data: bytes
:return: bytes
"""
return zlib.compress(data) | 23039a3382c10bc6b4cb15325443aa5b9e816028 | 35,704 |
def get_pubmed_id_for_doc(doc_id):
"""Because our doc_id is currently just the PMID, and we intend to KEEP it this way, return the doc_id here"""
return doc_id | a1d9241406b9655553d008ff7839c1f2b730f994 | 35,705 |
def generate_onehot_dict(word_list):
"""
Takes a list of the words in a text file, returning a dictionary mapping
words to their index in a one-hot-encoded representation of the words.
"""
word_to_index = {}
i = 0
for word in word_list:
if word not in word_to_index:
word_... | 1408cfbf8360134b4d9a95165e693a972cc4f4e3 | 35,706 |
def get_rp_dict(data, context=None):
"""
Get a label and value dictionary from the request POST
"""
all_dict = {}
for key, item in data["results"].items():
"""
All Responses is a category base for responses that are free text
and not options. If not all All Responses, the la... | ffeab44e031e6237ce4da69aecbad0d68d082a9c | 35,708 |
def get_sale_location(match):
"""Convert address strings into a list of address components."""
sale = {
'consignor_city': match.group('city').strip(),
'consignor_state': match.group('state'),
}
return sale | 803bd7f9375efdf8695f787d781faf2dc0deef25 | 35,713 |
def valid_file(path: str) -> bool:
"""
Check if regressi file is valid
:param path: path to the file to test
:return: whether the file is valid or not
"""
with open(path, 'r') as file:
if file.readline() == "EVARISTE REGRESSI WINDOWS 1.0":
return False
else:
... | 81e407fd24a830b32a0ba55bb4e912a2d32d61ef | 35,714 |
import os
def get_short_name_with_ext(path):
""" get file short name without ext, for example: "c:/1.txt" will return "1.txt" """
return os.path.basename(path) | b260d7d9e57b4dd6398be6383eef0f4e0bbec708 | 35,715 |
import time
def _date_to_posix(date):
""" date: datetime.datetime object """
posix = time.mktime(date.timetuple())
return str(int(posix)) | e41a7d10b3aa9d4ca35b7f72d09ae284cc5ca95e | 35,717 |
def owners_to_string(owners, queryset=False):
"""
Args:
owners: [{"user": {"username": "jack"}}, ...] OR
[models.Profile] (if queryset=True)
Returns:
['<Profile.user.username', ...]
"""
if queryset:
new_owners = [i.user.username for i in owners]
else:
... | 8463b36dfd1cf34af9d6d62ab2a1843247e048cc | 35,718 |
import re
def alphanum_key(s):
""" Key func for sorting strings according to numerical value. """
return [int(c) if c.isdigit() else c for c in re.split('([0-9]+)', s)] | c9147a41cad775700db280e92efe500fb6d8469e | 35,719 |
def get_something():
"""A session scope fixture."""
return "Bubu was here" | 54361255ffa6fe6a48b2db00a70a309d4bab0e98 | 35,720 |
from typing import Any
import json
import yaml
def repr_arg_value(val: Any) -> str:
"""Return the value's string representation.
The representation can be used by `libwampli.parse_arg_value` to retrieve
the value.
"""
try:
return json.dumps(val)
except ValueError:
return yaml.... | 82508250cc46d2ef21af08d68024b224b290f27f | 35,721 |
def var_name_from_file_name(name):
"""var name is camelCase, file name is snake_case"""
no_ext = name[:-3]
if '_' not in no_ext:
return no_ext
segments = no_ext.split('_')
return ''.join([segments[0]] + [x.capitalize() or '_' for x in segments[1:]]) | 8d547f568fd0d7ff76876cb9592b3b2646aa6023 | 35,722 |
import os
def get_vcf_paths_hs37d5(phased, chroms = None, sample = None):
""" Get list of paths for HS37D5 vcfs. If not phased, then a whole-genome vcf will be returned. If phased
and chromosomes provided, a list of phased vcfs are returned. If sample is HG002, a single GIAB whole-genome phased
vcf is r... | 1072fac3301d3a39c60ff45e5eac4ac9ed5152ed | 35,723 |
def handle_command(command, old_service):
"""
1. identify the OLD from the command
{'acked': True,
'id': 'cbcfb97d-6f72-4851-997d-173560c6173d',
'old_id': 'd9d5563d-a29a-46b3-85f2-6a3a1104f7fa'}
"""
return None | f6737829f43e70b22bbb2fd8d2952c8332580f87 | 35,724 |
def format_default_groups(default_groups: list) -> list:
"""
Formats the default groups
to execute in prowler
"""
formatted_groups = []
for group in default_groups:
formatted_group = group.rsplit("_")
formatted_groups.append(formatted_group[1])
return formatted_groups | 065102e96b0ba7e4fb547cc76616dfd55c4a41f2 | 35,725 |
def change_ohlcv_time(df, period):
""" Changes the time period on cryptocurrency ohlcv data.
Period is a string denoted by 'time_in_minutesT'(ex: '1T', '5T', '60T')."""
# Set date as the index. This is needed for the function to run
df = df.set_index(['date'])
# Aggregation function
ohlc_d... | e95872b2047f2367bcb69aa411c382ce69cc8d19 | 35,726 |
def value_or_default(value, default):
"""
Returns the supplied value of it is non None, otherwise the supplied default.
"""
return value if value is not None else default | d3fdf1cee4029c5617623e2834a6f05d962b2e94 | 35,727 |
import re
def charge(q_layer,p_layer):
"""
@param q_layer: q layer string
@param p_layer: p layer string
@return: charge
"""
global_charge = 0
if(q_layer != ""):
q_components = q_layer.split(';')
for q_component in q_components:
if(q_component!=""):
... | 6da9565d3f3bc4ccb6ed064d66a1a0d28242f74f | 35,728 |
import re
def parse_k(msg):
"""Parse create keypoint message and return keypoint number"""
if not re.search(r"KEYPOINT NUMBER", msg):
res = re.search(r"(KEYPOINT\s*)([0-9]+)", msg)
else:
res = re.search(r"(KEYPOINT NUMBER =\s*)([0-9]+)", msg)
if res:
result = int(res.group(2))... | 92f45ea09a7c9e1eecf48664c49218657687a217 | 35,729 |
def confirm(prompt=None, response=False):
"""Prompts for a yes or no response from the user
Arguments
---------
prompt : str, default=None
response : bool, default=False
Returns
-------
bool
True for yes and False for no.
Notes
-----
`response` should be set to th... | 4e60be0b9973de67ee718eb255c10efdbd7666aa | 35,730 |
import random
def generate_colour():
"""generate random colours"""
#from colorutils import random_web
#return random_web()
r = lambda: random.randint(0,255)
return "#%02X%02X%02X" % (r(), r(), r()) | b7980eeba42b5b14548348f7050111b052be9f1d | 35,731 |
def count_single_char(line):
"""
统计单字词
"""
return sum([1 for word in line if len(word) == 1]) | c26696d29164c98f5a34217596ed9c947350d4d5 | 35,732 |
def READ_RECORD(SFI:int, record:int) -> dict:
"""READ_RECORD(): generate APDU for READ RECORD command
"""
return {'CLA' : '00', 'INS' : 'B2', 'P1' : F"{record:02X}", 'P2' : F"{SFI*8+4:02X}", 'Le' : '00'} | 746e09d86b42eb822b197ebb3ff8f4bb36ad018a | 35,733 |
import os
def get_train_event_log(base_dir):
"""
Args:
base_dir: Path to model training directory
Returns:
(str) Path to train tensorboard data
"""
tb_str = os.path.join(base_dir, 'tensorboard/train/')
return tb_str | 3f8a1f96f8d7e1fcd478d5ead8326ded8b154301 | 35,734 |
import os
def folder_is_hidden(p):
"""
Removes hidden folders from a list. Works on Linux, Mac and Windows
:return: true if a folder is hidden in the OS
"""
if os.name == "nt":
attribute = win32api.GetFileAttributes(p)
return attribute & (win32con.FILE_ATTRIBUTE_HIDDEN | win32con.... | 3b4f15d6a7b656d62d1f3d03dc115193a5ec0a5d | 35,735 |
import random
def get_most_frequent_referent(seen_coref, ref_dict, tok_line):
"""Takes care of indexes that were never instantiated"""
# first check if we have instantiated variables that were never referred to
line = " ".join(tok_line) # put line back
most_freq = ''
score = -1
for item in... | 108220ea3761a18e1f13f7a7c1a158d3e7172d36 | 35,736 |
from typing import List
import subprocess
def _call_pytest(files: List[str]) -> int:
"""
Args:
files (list(str)): The files on which to call pytest
Returns:
The maximum of return codes of calls to pytest on `files`
"""
result = 0
for file_ in files:
cmd = ["pytest", fil... | 7c5f5b6f3666455e315057bdc41cb0fbb047459d | 35,737 |
def is_capitalized(text: str):
""" Given a string (system output etc.) , check whether it is lowercased,
or normally capitalized.
"""
return not text.islower() | 1a1404ea4a4a109711755644c20c6ce19f70b5ae | 35,738 |
def get_trials():
""" Return trials for taskA and B (combined) in trial-time
(equivilant to 3 TRs). """
return [1,1,4,4,6,0,4,2,4,1,0,0,0,0,5,4,5,1,5,5,3,6,6,0,0,2,2,3,
3,1,3,2,4,2,2,6,0,5,3,1,2,2,0,4,3,0,0,6,5,6,6,5,1,0,0,
5,5,2,2,6,2,0,0,0,6,6,5,0,0,0,0,4,6,4,5,6,4,0,0,0,0,3,... | 7dae3e9f02bc974544795da63e7c680e3a0af811 | 35,739 |
def transform_vertex(u, phi):
"""
Given a vertex id u and a set of partial isomorphisms phi.
Returns the transformed vertex id
"""
for _phi in phi:
if _phi[0] == u:
return _phi[1]
raise Exception('u couldn\' be found in the isomorphisms') | d35d0a819d795098190f8578b115b04231a53902 | 35,740 |
def write_normal(fname,triplets,na,angd,agr):
"""
Write out ADF data in normal ADF format.
"""
outfile= open(fname,'w')
outfile.write('# 1:theta[i], ')
for it,t in enumerate(triplets):
outfile.write(' {0:d}:{1:s}-{2:s}-{3:s},'.format(it+2,*t))
outfile.write('\n')
for i in range(n... | d12e858060dad0f398beb139aaf9a4edda255807 | 35,741 |
import six
def restruct_for_pack(obj):
"""Recursively walk object's hierarchy."""
if isinstance(obj, six.text_type):
return obj
if isinstance(obj, (bool, six.integer_types, float, six.binary_type)):
return obj
elif isinstance(obj, dict):
obj = obj.copy()
for key in obj:... | 500fe6c3127fa7daa6b4fd99d2ba41f6ecbf6b74 | 35,742 |
import random
def bomber(length, width, bomb, m, n):
"""
Place bombs randomly (position of first click and its surroundings cannot be bombs)
:param length: length of the board
:param width: width of the board
:param bomb: number of bombs
:param m: horizontal position of first click
:param ... | 52591fe68d7d03e29559072148a945700b6aad06 | 35,743 |
import os
def get_violations_reports(report_path, violations_type):
"""
Finds violations reports files by naming convention (e.g., all "pep8.report" files)
"""
violations_files = []
for subdir, _dirs, files in os.walk(os.path.join(report_path)):
for f in files:
if f == "{violat... | e1209300c71a32bb4f7ad6d86217aae90f075204 | 35,744 |
import os
def game_id():
""" Caches and returns the SteamAppId as """
return os.environ.get('SteamAppId') | 573b7fb5da7abd1c551b9f2fa764799e83329206 | 35,745 |
def format_example_name(example):
"""Formats an example command to a function or file name
"""
return '_'.join(example).replace('-', '_').replace(
'.', '_').replace('/examples/', '')[1:] | 223301709fb52aac98e2622c7df760fd3d7056e1 | 35,747 |
def value(card):
"""Returns the numeric value of a card or card value as an integer 1..13"""
prefix = card[:len(card) - 1]
names = {'A': 1, 'J': 11, 'Q': 12, 'K': 13}
if prefix in names:
return names.get(prefix)
else:
return int(prefix) | 534681894f67dc626173d952e7eddb0ecd8da20d | 35,748 |
def dirInfoGet(in_dir, mid_dir):
"""
将输入目录、输出目录改为固定的目录
:param in_dir: 输入目录
:param mid_dir: 输入目录
:return:
"""
dirInfo = [in_dir + r'/ObsData', in_dir + r'/SatNcData', mid_dir + r'/RetData']
return dirInfo | b9a1e20ee7f78ff294b08af6a2d8535dd932866a | 35,750 |
from textwrap import dedent
def rs256_private_key():
"""
This fixture provides a pre-generated private key for RS256 hashing.
"""
return dedent(
"""
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAw408+QDZ10idz4ytJtwFQE4YgmrjvCoEXjtTUWQ3H4nWAAYQ
+oE9xpr/gosNiFMuyRburvXT... | c730d6070e9872f3401fdd020429d3e5afb775aa | 35,751 |
import re
def make_command(name):
"""Convert a string into a space-less command."""
name = re.sub('[^\w]', ' ', name) # Replace special characters with spaces
name = name.strip().lower()
while " " in name: name = name.replace(' ', ' ') # Replace duplicate spaces
name = name.replace(' ', '-') ... | e1f154f89e0e54ead76a4492325fb1c547043cea | 35,752 |
def convertMappingDict(mdict):
""" This method converts a mapping proxy object to
a dict object. mapping proxies create read-only dicts
but we don't have that concept in transcrypt yet.
"""
ret = {}
for k in mdict.keys():
ret[k] = mdict[k]
return(ret) | 8a1ea786dadceb7707b75a258372925447dbd1c2 | 35,753 |
import re
def _remap_by_name(stations):
"""Remaps channel numbers based on the callsign and uses subchannels to
for each additional. For example, if the first CBS channel got 5.1,
the next encountered one would get 5.2, and so on
"""
callsigns = []
callsignSubchannels = {}
for stati... | 94edc3483cfa4b4be7b369ef0e0a7c045bf192ef | 35,754 |
import subprocess
def upload_kaggle_titanic_submission_via_api(filename, message):
"""Upload CSV to Kaggle Titanic Competition via Kaggle API.
Arguments:
filename {str} -- CSV filename that you want to submit to Kaggle.
message {str} -- The message that you want to include in the
... | df371b157049721fb229fd39450bb15f5c739000 | 35,755 |
def _get_name(param) -> str:
"""Checks if signature.Parameter corresponds to *args or **kwargs type input."""
if param.kind in (param.VAR_POSITIONAL, param.VAR_KEYWORD) and param.default is param.empty:
return str(param)
else:
return param.name | 1a8c054d42e081ff3abdb53dd56cdeafea05e781 | 35,756 |
import subprocess
def on_cluster(cmds=["sbatch"]):
"""Used to check if we are on a cluster
:return: True is a clsuter commands is found
Currently, checks for slurm commands only
"""
def cmd_exists(cmd):
result = subprocess.call(
"type " + cmd, shell=True, stdout=subprocess.... | 15b3a5ee9d30631b333c6429e8093ba5eb0423b8 | 35,757 |
def merge(left, right):
"""Merge function used for merge sort"""
lPoint = 0
rPoint = 0
result = []
# Use two pointer method to build sorted list
while lPoint < len(left) and rPoint < len(right):
if left[lPoint][0] > right[rPoint][0]: # Sort by min radius in descending order
... | 9fda9f6ac322ccdf61508791a18a9d8440283c57 | 35,758 |
import time
def now_sec():
"""Timestamp in seconds since 1970"""
now = time.time()
return int(now) | f5dd857040f7bb40d6b0aa0dc5f10a415f4eb0da | 35,760 |
def add_prefix(name, prefix=None, split='.'):
"""Add prefix to name if given."""
if prefix is not None:
return '{}{}{}'.format(prefix, split, name)
else:
return name | b22ab3ce8a286716579892a4bf9627674aea1f62 | 35,761 |
import sys
def is_in_virtualenv():
"""
Returns ``True`` if we are in a virtualenv.
"""
return hasattr(sys, 'real_prefix') or hasattr(sys, 'base_prefix') | f213414831f80496d5c80536b605ec4f11c3a476 | 35,762 |
def lpmerge(L, R):
"""In place left precedent dictionary merge.
Keeps values from `L`, if the value in `R` is :const:`None`."""
set = L.__setitem__
[set(k, v) for k, v in R.iteritems() if v is not None]
return L | 739b999cc9fbbec6d26448131c74b27c961a460c | 35,763 |
import torch
def f_get_raster_image(cfg,
images,
history_weight=0.9):
"""
Creates single raster image from sequence of images from l5kit's AgentDataset
Args:
cfg {dict}: Dictionary config.
images: (batch_size, 2*(history_num_frames+... | aff05d51041c909a73a93c9dbef2970e302677b1 | 35,764 |
import json
def sub_string_to_json(pre_text):
"""
将字符串处理成json格式返回 , 这里返回的是原生类型dict
:param pre_text:
:return:
"""
pre_text = pre_text[pre_text.find('{'): len(pre_text) - 1]
if pre_text.endswith(")"):
pre_text = pre_text[:len(pre_text) - 1]
# 将str转成json, 这里会成为原生类型,即dict
json_... | 667960b24491ca3696f06b596aee2262a33ce208 | 35,765 |
def a_send(text, ctx):
"""Send text line to the controller."""
ctx.ctrl.send(text)
return True | 7a5b8412f5099138afedc892c893f413ab4eba21 | 35,766 |
def path_info_split(path_info):
"""
Splits off the first segment of the path. Returns (first_part,
rest_of_path). first_part can be None (if PATH_INFO is empty), ''
(if PATH_INFO is '/'), or a name without any /'s. rest_of_path
can be '' or a string starting with /.
"""
if not path_info:... | 2b8429767feee1d271f8370684dddd34362390af | 35,768 |
import os
def get_img_path(dir: str):
"""
get the list of image paths from a certain directory dir
"""
img_path_ls = []
for image in os.scandir(dir):
if image.path.endswith('.jpg') or image.path.endswith('.png') or image.path.endswith(
'.JPEG') and image.is_file():
... | fc73af86395a79e06861fad4c41c9c11a06903a9 | 35,769 |
def update_package_db(module, xbps_path):
"""Returns True if update_package_db changed"""
cmd = "%s -S" % (xbps_path['install'])
rc, stdout, stderr = module.run_command(cmd, check_rc=False)
if rc != 0:
module.fail_json(msg="Could not update package db")
if "avg rate" in stdout:
retu... | 686a8c87fa8348c748b968813b0bb85320381bd0 | 35,770 |
def readline_mock(src):
"""Line reader for the given text.
This is meant to be used with Python's tokenizer.
"""
curr = -1
src = bytes(src, encoding="utf8")
lines = [line + b"\n" for line in src.split(b"\n")]
def readline():
nonlocal curr
curr = curr + 1
if curr >= ... | af37541695d67931d99762ffc91d5447d5bb7bc9 | 35,772 |
def py_fn(f, args=None, kwargs=None):
"""
Rem codes: py_fn f args kwargs
python intepreted as: f(*args, **kwargs)
"""
if not args:
args = ()
if not kwargs:
kwargs = {}
return f(*args, **kwargs) | 6bc2906757bcf1d0d2f21ba024c7abab8f81cb7e | 35,773 |
import time
def unixtime(dt_obj):
"""Format datetime object as unix timestamp
:param dt_obj: datetime.datetime object
:returns: float
"""
return time.mktime(dt_obj.utctimetuple()) | 7b2e6a923be2c05abed0ad8d324e818646e8f0c1 | 35,774 |
def star_wars(x, y, elem, neighbours):
"""Star Wars preset of the Generations family. (345/2/4)"""
red_count = 0
for neighbour in neighbours:
if neighbour == 3:
red_count += 1
if elem == 3: # The cell is alive
if red_count in [3,4,5]:
return 3
else:
... | b9929d132b42744439052600019b852833e2c032 | 35,776 |
def pwd():
"""
后台密码修改
"""
return 'pwd' | 9c2dfa12ca49b20f5ac34904149f5705f81cae44 | 35,777 |
import json
def construct_event_json(event, data):
"""
Helper function to construct a payload for sending to clients
"""
return json.dumps([event, data], ensure_ascii=False).encode('utf8') | 0693dacbf3592a6965fda925d8b3eab9c11dddf0 | 35,778 |
def number_unit(disc):
"""
Return the number of units with the given discriminant.
"""
if disc < -4:
return 2
elif disc == -4:
return 4
elif disc == -3:
return 6
else:
raise ValueError | abc19d49a036f952e897f9cc1426d34ce5237371 | 35,779 |
def is_private(message) -> bool:
"""Whether message is private."""
# See "type" at https://core.telegram.org/bots/api#chat.
return message.chat.type == 'private' | d45dca82c3a46d25997b1dbde2803fb50d08c871 | 35,780 |
import calendar
def to_timestamp(date):
"""Convert a datetime object into a calendar timestamp object
Parameters
----------
date : datetime.datetime
Datetime object e.g. datetime.datetime(2020, 10, 31, 0, 0)
Returns
-------
cal : calendar.timegm
Calendar timestamp corresp... | 514ea392268dc94aa0a14b1dd5ce04425d1ed3bb | 35,782 |
def title_getter(node):
"""Return the title of a node (or `None`)."""
return node.get('title','') | 0825f4a2d6360d4845b3379ba9ade7a8e5fa11dc | 35,783 |
import struct
import socket
def next_ip(ip):
"""Return the next IP address following the given IP address.
It needs to be converted to an integer, then add 1,
then converted back to an IP address
"""
ip2int = lambda ipstr: struct.unpack('!I', socket.inet_aton(ipstr))[0]
int2ip = lambda n... | 883d88ea35aaed0d2a506f3ea4fc404f83ac4cea | 35,784 |
def get_palette(num_classes):
"""
功能:获得画板颜色
"""
n = num_classes
palette = [0]*(n*3)
for j in range(0, n):
lab = j
palette[j*3+0] = 0
palette[j*3+1] = 0
palette[j*3+2] = 0
i = 0
while (lab > 0):
palette[j*... | b59614cfc014a3ad72003a68b969270ca90a8ea1 | 35,786 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.