content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def xf_screenname(name):
"""Insure user screen name is prefixed with '@'."""
return '@' + name if name[0] != '@' else name | 6229a22907c4b1c11b75f5cd0218e056d46111eb | 14,343 |
import ast
def p_pyatom_dict(p, kv_pairs=2): # [key: value, ...], [:]
"""pyatom : LBRACKET dictents RBRACKET
pyatom : LBRACKET COLON RBRACKET"""
if kv_pairs != ':':
keys, values = map(list, zip(*kv_pairs))
else:
keys, values = [], []
return lambda: ast.Dict(keys, values) | 81a50745298106c9919c080629851fb57b5f1d1f | 14,344 |
import torch
def separation_loss_p(x, delta):
"""Computes the separation loss.
Args:
xyz: [batch, num_kp, 3] Input keypoints.
delta: A separation threshold. Incur 0 cost if the distance >= delta.
Returns:
The seperation loss.
"""
bs = x.size(0)
num_kp_p = x.size(1)
t1_p ... | f277c84ecd14fe50b967937bb8b4f8d5f2b98118 | 14,347 |
def scan_object( uri, resource, partial_path ):
"""
Scans an object for a matching URI
Args:
uri: The URI to find
resource: The object to scan
partial_path: An array of strings containing the path discovered for the current resource
Returns:
True if there's a match; Fal... | f52d754b38da43ef345596353ae96009d9bf89fb | 14,349 |
import os
def get_editor(repo):
"""
Returns the editor from env vars.
"""
return (repo.git.config("core.editor") or
os.environ.get("GIT_EDITOR") or
os.environ.get("VISUAL") or
os.environ.get("EDITOR", "vi")) | af29d1e52afea67d90460c0727a742b7d8146a78 | 14,351 |
def json_return(code, message = '', data ={}):
"""
將資料轉換成dict作為API回傳的統一格式
:param code:
:param message:
:param data:
:return:
"""
return {'data': data, 'msg':message, 'code': code} | 70134c28c54d910c634c0ffd14b2416072ec730a | 14,352 |
def expected(player1, player2):
"""
Calculate expected score of player1 vs player2 given elo rankings.
Args:
player1 (BaseAgent): Agent for whom the score is being calculated.
player2 (BaseAgent): Agent against whom player1 played.
Returns:
The expected score of the matchup.
... | 90551b04b15ce62a1d2c5d7022d9402b3efdba60 | 14,354 |
from warnings import warn
from functools import reduce
def rreduce(fn, seq, default=None):
"""'readable reduce' - More readable version of reduce with arrity-based dispatch; passes keyword arguments
to functools.reduce"""
warn(DeprecationWarning(
"rreduce is deprecated and will be removed in futur... | bb82cdf712c87885103d61f7c37fa588e8bdac6b | 14,355 |
def get_predictors(results):
"""Get predictors for logistic regression."""
assert len(results) == 200
y = []
x = []
for (_, trial1), (_, trial2) in zip(results.iloc[:-1].iterrows(), results.iloc[1:].iterrows()):
transition = 2 * int(trial1.common) - 1
reward = 2 * trial1.reward - 1
... | 240a0d32221e32eda58b86568b5975cdcdd3c475 | 14,357 |
import re
def check_password_format(password):
"""校验密码格式
Args:
password (str): 密码
Returns:
boolean: 格式符合返回True,格式错误返回False
"""
pattern = re.compile('\w{8,16}')
if pattern.match(password):
if re.search('[0-9]', password) and re.search('[a-z]', password):
re... | b0923972f22b08298df8aa9c83314787ebefb8a8 | 14,358 |
def corpus(request):
"""
A utility fixture to merely execute the actual fixture logic as necessary.
Args:
request: The pytest indirect request object, which has a param object
for the underlying fixture argument.
Returns:
The value of the execution of the corpus fixture.
... | 3c6986296a17145bc3b40cc84e2b62acb5c8f00c | 14,359 |
from math import floor, log10
def findSizeInt(number):
"""
#EN-US:
→ Calculates the number of digits in a number.
:param number: the number to be calculated.
:return: the number of digits of the number entered.
#PT-BR:
→ Calcula a quantidade de dígitos em um número.
:param number: o n... | 8b174183520337f31f17bfb4163d5ed5ff90e896 | 14,360 |
import operator
def _get_operator(comp_str):
"""Returns the operator function corresponding to the given comparison.
Args:
comp_str: str. One of: '<', '<=', '=', '>=', '>'.
Returns:
callable. The binary operator corresponding to the comparison.
Raises:
ValueError. The compar... | 123ca1e2be8abf81387fb5d2ffa559082116b959 | 14,361 |
def clean_text_simple(string):
"""
Remove all \x19 from the string formatted with simple colors:
\x198
"""
pos = string.find('\x19')
while pos != -1:
string = string[:pos] + string[pos+2:]
pos = string.find('\x19')
return string | a067f164be5677f6fb2029d5b839849ca50a230e | 14,362 |
import math
def knn(pnts, p, k):
"""
Calculates k nearest neighbours for a given point.
:param points: list of points
:param p: reference point
:param k: amount of neighbours
:return: list
"""
s = sorted(pnts,
key=lambda x: math.sqrt((x[0]-p[0])**2 + (x[1]-p[1])**2))[0:... | 2da3d4481db78910548eee04e0532e701e4c4201 | 14,363 |
import requests
from bs4 import BeautifulSoup
def scrape(start, end, logging=True):
"""
Scrape all the reviews from dealerrater.com for the McKaig
Chevrolet Buick dealership.
Parameters:
start: the page of reviews to start scraping
end: the last page of reviews to scrape
Ret... | 03dfd059a82c4c56dec47d772ef2e6ade905fac7 | 14,364 |
import os
import sys
import six
import gzip
import shutil
def maybe_download(filename, data_directory, source_url):
"""Download the data from source url, unless it's already here.
Args:
filename: string, name of the file in the directory.
work_directory: string, path to working directory.
... | a48989a2b8d21aa7d4c56bbf16b6731de75b5df1 | 14,365 |
import re
def multiple_replace(string, replacements):
"""
Given a string and a dictionary of replacements in the format:
{ <word_to_replace>: <replacement>, ... }
Make all the replacements and return the new string.
From: http://stackoverflow.com/questions/2400504/
"""
pattern = re.co... | bdaf05f2f9c5de2c0742c12219e2984ed3e7699e | 14,366 |
import argparse
def get_args():
"""
--mode train/test/deploy
--cores 1/2/3/4/5/6/7/8
--load_model <path_to_model>
### only for train mode ###
--save_top 1/2/3/4/5/6
--batch_size
--epochs
--learning_rate
###########################
... | a508679f14943afd801b40562c0d9182326d5e44 | 14,370 |
from typing import Dict
from pathlib import Path
from typing import Optional
import csv
def write_results(
result_dict: Dict[str, Dict[str, str]],
trans_dict: Dict[str, str],
input_filepath: Path,
output_filepath: Path,
write_csv: Optional[bool] = False,
) -> Dict[str, Dict[str, str]]:
"""
... | a791f47c9d16b451db14cd599cf2f15f04f0637c | 14,371 |
def mass_function_abc(m, a, b, c):
"""The parametrized surpression function of the halo mass function"""
return (1 + (a / m)**b )**c | d4e0b1d39a67baa121a28fc644b75c9bfd714c5e | 14,373 |
def upload_album(
self,
photos,
caption=None,
upload_id=None,
from_video=False,
options={},
user_tags=None,
):
"""Upload album to Instagram
@param photos List of paths to photo files (List of strings)
@param caption Media description (String)
@param upload_id Uniq... | 8b9e0a92c973ea90018f1356c44fe6e9047229f3 | 14,374 |
def retain(foo):
"""This method is very important for live source code manipulation. It ensures, that every reference to an object's
method is going to change when the method has been edited (and therefore been overridden). If a reference to a
method is made by providing the method object without calling re... | f615cd295648bc0ef266e9e1f25e60985cc1a1d5 | 14,375 |
import json
def loadMetadata(fn):
"""
Load Metadata JSON File
Parameters:
-------------
fn : str - filename
Returns:
-------------
data : dict
"""
data = json.load(open(fn))
return data | 4fa9aceed53cab0c076d4bdc474a08ebccae5ef6 | 14,377 |
def update_tuple(origin_tuple, update_value, update_index):
"""Update tuple/namedtuple for specified update_index and update_value."""
# Namedtuple is inherit from tuple.
if not isinstance(origin_tuple, tuple):
raise ValueError("Only tuple/namedtuple supported. Origin_tuple type: "
"%s." ... | 1956777840fe30db01f1a4526e8e79d0ceac8534 | 14,378 |
def get_variation(variation_key, variations_dict, defaults_dict):
"""Convert a string to a tuple of integers.
If the passed variation_key doesn't follow this pattern '0 100', it will
return default values defined in defaults_dict.
This is currently used for defining the variation data of the A/B
e... | 24e069fabcb9bd4dbfbd3c1ea17e859f27fdcceb | 14,379 |
def standardize(train_data, test_data):
"""
Standardize Data Set
"""
train_mean = train_data.mean()
train_std = train_data.std()
train_data = (train_data - train_mean) / train_std
test_data = (test_data - train_mean) / train_std
return train_data, test_data | b66a363cd37f7ebc2accd021866b7d34c415f528 | 14,380 |
import torch
def spread_feature(container, learned_uv, feature, mask1c):
"""
:param container: B,C,R,R
:param learned_uv: B,2,H,W
:param feature: B,C,H,W aligned with latent uv map
:param mask1c: B,1,H,W used to mask latent uv and feature
:return: container
"""
assert float(mask1c.max(... | 38f7602124792bf3f0e3395cd8952aec428ab43e | 14,381 |
def init(id, cfg):
"""Previous version init function.
..note:: This function is still supported for backwards compatibility when
the init_standard function is missing. When init_standard is
present this function SHOULD be omitted to avoid confusion to the
reader.
"""
... | 8076f694908bbe8edb8e0297d62a35b26fc1afcb | 14,383 |
import math
def radiacion_solar_onda_larga(tmax, tmin, p_vapor_real, r_solar, r_solar_cielo_despejado):
"""
calcula la radiación neta de onda larga saliente en MJ/m2 y día
param: tmax : temperatura máxima
param: tmin : temperatura mínima
param: p_vapor_real ... | 5404500ff08e5a886f3e000fd8d301faec78cff7 | 14,384 |
def requirements(filename):
"""Reads requirements from a file."""
with open(filename) as f:
return [x.strip() for x in f.readlines() if x.strip()] | 81e5fa3d2a11b9152be6f55ab879b1875fd0b07d | 14,385 |
def branch_uptodate(branch, true_on_missing_origin=True):
"""Return True is branch is up to date with origin, otherwise False,
also returns True if no remote defined"""
if branch['upstream']:
if branch['ahead'] or branch['behind']:
return False
return True
if true_on_missing_... | 2c0db03ea469b6f75e94ab6a73ace360e73948a3 | 14,386 |
import hashlib
import base64
def encode(text):
"""[summary]
Base64 Encoder.
Args:
text (str): String to be encoded.
Returns:
str: base64.urlsafe_b64encode
"""
fill_up = hashlib.blake2s(f"{text}".encode("utf-8"), digest_size=8).hexdigest()
text = f"{ text }::{ fill_up }"
... | f9da7bf0ba9455fd37277c8617332d78b11223bd | 14,387 |
import argparse
def parse_arguments():
"""Parse command line arguments
Args:
Returns:
Command line arguments
Raises:
"""
parser = argparse.ArgumentParser(
prog='pypgmon',
)
parser.add_argument(
'-l',
'--logger',
default='pypgm... | d9f571335611b3170a78dfd03b349ecb56784157 | 14,388 |
def multiply_ith_dimension(Pi, i, X):
"""If Pi is a matrix, multiply Pi times the ith dimension of X and return"""
X = X.swapaxes(0, i)
shape = X.shape
X = X.reshape((shape[0], -1))
# iterate forward using Pi
X = Pi @ X
# reverse steps
X = X.reshape((Pi.shape[0], *shape[1:]))
retur... | 98edc89389910d4361232350b0ad440fd785f74a | 14,389 |
import six
import socket
import contextlib
def is_port_open(port_or_url, timeout=1):
"""Check if TCP port is open."""
if isinstance(port_or_url, six.string_types):
url = six.moves.urllib.parse.urlparse(port_or_url)
port = url.port
host = url.hostname
else:
port = port_or_ur... | ad8d6e80cc2eaee6a5955f4f5bc0e69cac8f60b2 | 14,390 |
import sys
def get_name(category, gender, choice):
"""
Gets the name of the file corresponding to the category, gender, and option requested.
:param category: Type of file. Can be "number", "reason", or "ending".
:param gender: 'm' or 'f'.
:param choice: Specifies the file being requested for.
... | db939f515ea9696e68ae12524b1a8b8783d2f150 | 14,392 |
def should_sync_locations(last_sync, location_db):
"""
Determine if any locations (already filtered to be relevant
to this user) require syncing.
"""
if not last_sync or not last_sync.date:
return True
for location in location_db.by_id.values():
if not location.last_modified or ... | d61612473f2842f69628d273198549a55abf66be | 14,393 |
def get_feature_dimensions(parameters):
""" Returns dimensions (`int`s) of all node features.
"""
n_atom_types = len(parameters["atom_types"])
n_formal_charge = len(parameters["formal_charge"])
n_numh = int(
not parameters["use_explicit_H"]
and not parameters["ignore_H"]
) * len(... | f1409d1dc2f4785bb2c2452b9bc08395a598f16d | 14,394 |
def removeGenesWithExcessiveReplicationVariance(df_X, max_var=None):
"""
Removes Genes with excessive variation in the variance of their
trinary values. Assumes a single digit replication.
Parameters
----------
df_X: DataFrame
index: str <instance>.replication-digit
ex: T10.2
max_var: floa... | e6b6950e2694792e03940caadbeda85c8e32717c | 14,395 |
def _py_lazy_and(cond, b):
"""Lazy-eval equivalent of "and" in Python."""
return cond and b() | 872f382ac72d8253c61043dfe146d05775b4748d | 14,397 |
def parse_id(hardware_id):
"""Parse Nuki ID."""
return hex(hardware_id).split("x")[-1].upper() | 483fb1c7a864242335288f53653c461a50eab638 | 14,399 |
from typing import Dict
from typing import Any
from typing import OrderedDict
def sort_dict(item: dict) -> Dict[str, Any]:
"""
Sort nested dict
Input: {"b": 1, "a": {"c": 1,"b": 2}, "c": "c_st[ring]"}
Output: OrderedDict([
('a', OrderedDict([('b', 2), ('c', 1)])),
('b', 1),
('... | 0f4c042df4ea2f00dbda249f9d2c7c3488824559 | 14,400 |
import json
def load_dict(filename):
"""
Loads a dictionary stored in JSON format
:param filename:
:return:
"""
data = json.load(open(filename))
return data | 88f286417bbdd43d4499e83750c92843a9f6231a | 14,401 |
def nWaveRiseTime(pmax, patm=101e3, csnd=341, lamb=6.8e-8):
"""
Calculate N-wave rise time
Parameters
----------
pmax -- N-wave overpressure amplitude in Pa
patm -- atmospheric pressure in Pa
csnd -- speed of sound in m/s
lamb -- air molecular mean free path in m
Returns
------... | cbcae9d8e3ddaeb6daab5a02a722cd7302ebf562 | 14,402 |
from typing import List
import inspect
def get_class_names(module) -> List[str]:
"""Get class names of a module."""
ans = []
for m in inspect.getmembers(module):
if inspect.isclass(m[1]):
ans.append(m[0])
ans.sort()
return ans | 4ae36e8823f28d00693eac3d70affe7f0591a745 | 14,404 |
import os
def get_int_filename(filename):
""" Get the integer value of a filename """
name = os.path.splitext(filename)[0]
try:
return int(name)
except ValueError:
return 0 | b10d19ad016411a78454bbd010855c6ffb0dac71 | 14,405 |
def find_address_of_type(host_elem, type_):
"""Return the host's address of the given type, or `None` if there
is no address element of that type.
"""
address_elem = host_elem.find('./address[@addrtype="{}"]'.format(type_))
if address_elem is not None:
return address_elem.get('addr') | ff821703d076865da3c6efe0d2d760c4fcb2c997 | 14,407 |
import re
def IsValidAtom(atom):
"""Test if an atom conforms to the JHM definition of an atom"""
return re.match("([_a-zA-Z][_\-a-zA-Z0-9]*)?",atom) | 218e846db1559bb91ab1ab47c5955d43b8274866 | 14,408 |
import re
def fuzzyfinder(user_input,collection):
"""
fuzzy matching, to obtain a fuzzy matched list.
>>>collection = [
"user_name",
"api_user",
"school",
"email"
]
>>>fuzzyfinder("user",collection)
... | db01f13f3caf5dc9a21cfb180776c22b589f1a28 | 14,409 |
def bq_token_file_path_exists_mock(token_path):
"""
Mock bq_token_file_path_exist to return True
"""
return True | 54958444c16c4244ab349d60b0add39723ba6d8b | 14,410 |
def masa_strugotine(volumen_strugotine, gustoca_materijala):
"""
"""
return 1e-9*volumen_strugotine*gustoca_materijala | 06e65566ff2a9c13fabe1316a7a290c1145a741c | 14,411 |
from datetime import datetime
def check_realistic_birth_date(date):
"""
Function to check if the inserted date of birth is not futurist.
"""
date = date.split("/")
today = datetime.strftime(datetime.now(), "%d/%m/%Y").split("/")
logic_1 = (
int(date[0]) > int(today[0]) and # Day
... | 3b92d322881b9f4dafac6678a1627cec90c8cd50 | 14,414 |
def getBoundingBoxCoordinates(box, height, width):
"""
returns coordinates of bounding box in pixels
:param box: a Tensor returned of tensorflow object detection prediction of 1 set of ymin, xmin, ymax, xmax
:param height: height of image
:param width: width of image
:return: ymin, xmin, ymax, x... | 14f6e94b68d62893d3235c73c0c4943e6edaf4d2 | 14,415 |
def calc_dh(eta):
"""Calculate the first derivative of the interpolation function
Args:
eta: the phase field
Returns:
the value of dh
"""
return 30 * eta ** 2 * (eta - 1) ** 2 | 557f3d932c0b380ad291f2af081d1ebe8fcd5baf | 14,416 |
def parse_http_response(data):
""" Parses HTTP response data into a tuple in the form (cmd, headers).
@param data: HTTP response data
@type data: string
@return: (cmd, headers) for the given data
@rtype: tuple
"""
header, payload = data.split('\r\n\r\n')
lines = header.split('\r\n')
... | da4680acd9dd429fdbffbe6927586ba23256286e | 14,418 |
def isChildUri(parentUri, childUri):
"""Return True, if childUri is a child of parentUri.
This function accounts for the fact that '/a/b/c' and 'a/b/c/' are
children of '/a/b' (and also of '/a/b/').
Note that '/a/b/cd' is NOT a child of 'a/b/c'.
"""
return parentUri and childUri and childU... | a28a386c38a4d6722f6b7c8bcbeafb8092dbbe77 | 14,419 |
def size(b):
"""
Returns the size in bytes of the first netstring in the provided bytes object.
WARNING: This function doesn't check for netstring validity.
THROWS:
ValueError if cannot determine size
"""
try:
slen = b[:b.find(b':')].decode('ascii')
return 2 + len(slen) + int(slen)
e... | 2b50a555e29c6d7cbdc419d3dfb336d60f907d0c | 14,420 |
import torch
def get_output_size(model, input_shape=(1, 3, 224, 224), device="cpu", dtype='float32'):
"""
Returns the shape of the convolutional features in output to the model.
Parameters
----------
model pytorch model,
neural network model.
input_shape: tuple of int,
shape o... | f9c4e79e2c38a424c723cfed6fc73fc63ddc3142 | 14,421 |
def str_function(connectable) -> str:
"""__str__ function for OutputBase and InputBase."""
infos = []
if connectable.owner:
infos.append('owner: %s' % connectable.owner)
if connectable.connected:
infos.append('connected')
else:
infos.append('not connected')
return '%s(%... | 5ed2ba8575314c0fdf9046988f3977ab262ff0af | 14,423 |
from typing import List
import os
import re
def find_all_matched_files(directory: str, patternStr: str) -> List[str]:
"""
List the paths of files that match patternStr under the specified directory.
"""
if patternStr == "*.*":
pattern = "\.*.*$"
else:
pattern = patternStr.replace("... | 362d74d199700a4c1934b1b6aad0423d327377e4 | 14,424 |
import ssl
def get_ssl_context():
"""Create an SSL context."""
context = ssl.SSLContext()
context.verify_mode = ssl.CERT_NONE
return context | 182b18996632f335b1cdf4d73e8dd502881b0f73 | 14,425 |
def split_order_book(order_book_id: str):
"""
对合约拆分成品种和年份俩个部分
:param order_book_id:
:return:
"""
return order_book_id[:-4], order_book_id[-4:] | 4692e95eb814de50f9effe7ed289f94712e265d6 | 14,427 |
def get_template_from_path(path: str) -> str:
"""Convert a normal path back to its template representation."""
# replace all path parts with the template tags
path = path.replace("\\", "/")
return path | 1a62acca2c0531563fb4493bc06708671a601cda | 14,429 |
import re
def check_email(email):
"""
Checks an email format against the RFC 5322 specification.
"""
# RFC 5322 Specification as Regex
regex = """(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"
(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0... | 522547471730c6975246c301492f5b7676032c75 | 14,430 |
import pandas
def getCumSumForIntervalData(actualTimeSeries, predictedValuesOnLaggedData, intervalSize=365):
"""
:param actualTimeSeries: Object of DataFrame TimeSeries
:param predictedValuesOnLaggedData: Object of DataFrame TimeSeries
:param intervalSize: Period or Seasonality
:return: Cumulative... | 3bcbca64aff1652239b32f2c2454e897d8968334 | 14,431 |
def calc_check_digit(number):
"""Calculate the check digit for the number."""
alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
cutoff = lambda x: x - 9 if x > 9 else x
s = sum(
cutoff(alphabet.index(n) * 2) if i % 2 == 0 else alphabet.index(n)
for i, n in enumerate(number[::-1]))
re... | 967d9ac7eae3e45b42c6bb4e366345fd34207d0d | 14,433 |
def calcul_positions_virages(coordonnees_du_personnage, orientation_du_personnage, profondeur_vision, liste_plan_du_labyrinthe):
"""
Prends en argument :
- La liste correspondant aux coordonnées du personnage, 'coordonnees_du_personnage';
- La chaîne de caractères correspondant à l'orientation du personnage, ... | 1fd818452750e98b0f24a269a19be324484fe6fc | 14,435 |
def unique_filename(name):
"""
Returns unique file name based on "name" argument.
"""
return name | 1145ec89e9bbadf5944bc787ff1fda2805bfde1b | 14,436 |
def left_child(node, new_node=None):
""" Set left child: left_child(node, new_left_child); Get left node: left_child(node). """
if new_node is not None:
node[1] = new_node
return node[1] | baabfbeb4acb7e8a2846b9a4a45b9d993619a1e4 | 14,437 |
from datetime import datetime
def prettify_timestamp(value: str) -> str:
"""
Returns a pretty version of a timestamp object.
Current format:
- %b short name of month like Mar, Jun
- %d day of the month from 1 to 31
- %Y year in 4 digit format
"""
return datetime.utcfromtimestamp(float(... | 82faefee2f98db33665c81c309e531d6dacab099 | 14,438 |
def contains(text, pattern):
"""Return a boolean indicating whether pattern occurs in text."""
assert isinstance(text, str), 'text is not a string: {}'.format(text)
assert isinstance(pattern, str), 'pattern is not a string: {}'.format(text)
#funny storytime! initially did not pass because I falsely reme... | 4eff4e8d69e7843e2a4e4043df29139d92ded772 | 14,439 |
def custom_subparser_builder(subparser, subparser_id, description, options_func, runner_func, setup_func, shutdown_func, error_handler_func):
"""
Util to add subparser options
:param options_func: Function that will add args and options to Parser instance F(subparser) -> None
:param runner_func: Functi... | 0d5914646e07be26792fae321c32f3338d6b467b | 14,440 |
from typing import List
def one_minus(data: List[float]) -> List[float]:
"""
return 1 - each element in list
"""
return list(map(lambda elem: 1 - elem, data)) | bb5c9a3d27866b408e519541778c7cdb8bd9ac13 | 14,441 |
def call_method(obj, methodName):
"""
Execute a method of an object using previously passed arguments with setarg filter
"""
method = getattr(obj, methodName)
if hasattr(obj, '__call_arguments'):
ret = method(*obj.__call_arguments)
del obj.__call_arguments
return ret
retu... | 7bd94cdf81f448a8b73bbf3bcdda47cf4f5580cd | 14,442 |
def get_bracketing_pattern_feature(dataset):
"""
Return bracketing_pattern feature (sorted tuple of adj_quantities seen).
"""
grouped = dataset.groupby(
['tube_assembly_id', 'supplier', 'quote_date'])
bracketing_pattern = [None] * len(dataset)
for t_s_q, indices in grouped.groups.iterite... | 9b262fcff8e227dc50ea769ac8953df0aeba62b7 | 14,443 |
def exercise_output(template):
"""Outputs the way specified in the exercise"""
result = """Marca: {0}
Modelo: {1}
Preco: {2}
Motor: {3}
Ano: {4}
Km: {5}
Combustivel: {6}
Cambio: {7}
Direcao: {8}
Cor: {9}
Ar-cond: {10}
Opcionais: {11}\n"""
return result.format(
template["Brand"],
template["Mo... | 0944b47d28c8b95c7eab32b799066af14b2b95ea | 14,444 |
def get_table(tables, var, phi):
"""
Table Searching function
"""
if phi>=50:
phi = 50
#First find phi index
idx=0
while(True):
if tables['phi'][idx]>=phi:
break
idx+=1
if(tables['phi'][idx-1]==phi):
return tables[var][idx-1]
else:
... | 55a0feae3d67c960f815a46bb0bc43f0ed7cf5a9 | 14,446 |
def _GetMetdataValue(metadata, key):
"""Finds a value corresponding to a given metadata key.
Args:
metadata: metadata object, i.e. a dict containing containing 'items'
- a list of key-value pairs.
key: name of the key.
Returns:
Corresponding value or None if it was not found.
"""
for item ... | e4ec468fe1e79605d3d7199a703981bae02bfaa3 | 14,447 |
import re
def match_is_ipv4_address(value):
"""Match given value as a valid dotted-quad IPv4 address."""
# Apply the dotted-quad pattern to the string and detect a mismatch
try:
match = re.search(r'^(\d+)\.(\d+)\.(\d+)\.(\d+)$', value)
except TypeError:
return u'{0} must be a string in... | d4573d5919d1811b83c26928f3e403d070c41f37 | 14,449 |
import math
def smooth(low, high, x):
"""Smoothly goes from low to high"""
return low + (high - low) * (1 + math.cos(math.pi * (1-x))) / 2 | 3278891277048a4d6a19f7a5450a0a8a5f1d0ad9 | 14,450 |
def _parse_header(path):
"""Parses all GAMMA header file fields into a dictionary"""
with open(path) as f:
text = f.read().splitlines()
raw_segs = [line.split() for line in text if ':' in line]
# convert the content into a giant dict of all key, values
return dict((i[0][:-1], i[1:]) for... | 93e512388f3c5c5f8ee0e9f0365fa5328b0ea864 | 14,452 |
def parse_trousers_input_args(s):
"""Parses Trspi family's input arguments.
Given a string from of input arguments of a trousers API, the input arguments
parsed into tokens and then convert to tuples. For example:
"BYTE *s, unsigned *len"
->
[("BYTE *", "s"), ("unsigned *", "len")]
Args:
s: String r... | 366edb8d3b8f1369b8c4b095e037a2192b056e0d | 14,453 |
def encode_color(rgb):
"""rgb to 8-color pallete"""
r = "1" if rgb[0] > 127 else "0"
g = "1" if rgb[1] > 127 else "0"
b = "1" if rgb[2] > 127 else "0"
for i in range(8):
if r + g + b == format(i, '03b'):
return i | 81c04e6307eb3d36459cd24c1780e26d792ea6ab | 14,455 |
from pathlib import Path
def make_unique_filename(name):
""" Creates filename that does not collide with existing files.
May add random stuff between name and extension to make filename unique.
Returns Path object.
May return original name when fails to construct a unique name.
"""
name = Path(name)
parent, st... | 6da56fc220ca7cea6f4dec9ab1c9fb760c174178 | 14,456 |
def columnsBySubmission(submissions, columns):
""" create map submissionName -> set(columnNames)
"""
columnsBySubm = {}
for submission in submissions.keys():
template = submissions[submission]
columnsBySubm[submission] = set(columns[template].keys())
return columnsBySubm | 8364faef492941fb31008e5b31ee570bd2d29a04 | 14,457 |
def useScaleGlyph(unicodeValue, glyphList):
""" Determines whether or not to use scaled glyphs for glyphs in passed glyph_list """
for i in glyphList:
if isinstance(i, tuple):
if i[0] <= unicodeValue <= i[1]:
return True
else:
if unicodeValue == i:
return True
return False | 37fc8ee07ccbf58520b558f0d48ba96f50ce3ae3 | 14,459 |
def is_password_valid_with_old_rules(dataset):
""" Validate password according to the old rules """
letter_count = dataset['password'].count(dataset['letter'])
return int(dataset['first']) <= letter_count and letter_count <= int(dataset['last']) | 99a63ece8e3b8520fd71028bd01bb3a1a7e677a7 | 14,462 |
import glob
import os
def get_img_path(dir_list):
"""
get all images for style transferring, raw images are .jpg files
:param dir_list: a list of path point to paths like [training/a/abbey, training/a/airfield, ...]
:return: a dict of paths of raw images, key is image name and value is original directory and path... | 0db59a81fc58ef6320b57f084c4f8ba241c3ac0e | 14,463 |
import os
def version():
"""
Service version endpoint
"""
return os.environ.get('VERSION'), 200 | 24ebb860f5ae5fa0ab5617835d0107fd6e1db7c1 | 14,464 |
def _f(x, t, s, cls):
"""Return True if x equals t,
or x is an instance of cls and x equals cls(t),
or x.lower().startswith(s)"""
return x == t or \
(isinstance(x, cls) and x == cls(t)) or \
(isinstance(x, str) and x.lower().startswith(s)) | 91d9c518b58528f01034ca67738c220a17f7f40d | 14,465 |
import threading
import functools
def synchronized(wrapped):
"""Simple synchronization decorator.
Decorating a method like so:
.. code-block:: python
@synchronized
def foo(self, *args):
...
ensures that only one thread will execute the foo method at a time.
"""
lock = t... | 85af7bbd8b7d72f13bfaecc5f1df459745358ab5 | 14,466 |
def solve(lists, n):
"""
Get the missing list.
Parameters
----------
lists : list of lists
2*n - 1 lists with integers
n : int
Returns
-------
strictly increasing list of n integers.
"""
numbers = {}
for list_ in lists:
for el in list_:
if el... | 001645ff1a9ae00169ab3565eaed5cb7764f0c7a | 14,467 |
def counter(countables):
"""
Counter for counting the values inside a particular list or dict.
This is just a scratch/vanilla version of collections.Counter
Args:
countables: List of countables to be counted.
"""
counts = dict()
for k in countables:
if not k in list(counts.keys(... | 42bcf22f000de70e0453f9f9078ea8d7c5f74db2 | 14,468 |
def get_alignment_pdb_id(alignment):
"""
Returns a string of the four letter PDB ID found in alignment
:param alignment:
:return: 'pdb id'
"""
pdb_chain_id = alignment.hit_def.encode('ascii').split()[0]
pdb_id = pdb_chain_id.split('_')[0].lower()
return pdb_id | 35a6abcd18e411328e5b7fb8c5a4f1dba8fe2391 | 14,470 |
def post_inner_loop_update(temp_storage, this_np):
"""
This function updates the storage at the end of a step of the outer-loop, i.e., after all steps in the inner loop.
:param temp_storage: (dictionary) the dictionary with all the information and storage required by the inner loop
:param this_np: (Num... | f07b931ed999e18d73741020614d5faafb1664c3 | 14,472 |
import socket
def str_to_inet(ip: str) -> bytes:
"""
Converts a string representation of IP address to binary representation.
:param ip: IP like - "123.45.67.89"
:return: 32 bit representation of "123.45.67.89" like - '{-CY'
"""
try:
return socket.inet_pton(socket.AF_INET, ip)
exce... | 3ab520701ec0271499d3512425a939803ac0adc9 | 14,473 |
import csv
def load_promoter_characterizations (filename, samples):
""" Load promoter characterization data from file
"""
pro_data_perf = {}
pro_data_full = {}
data_reader = csv.reader(open(filename, 'rU'), delimiter='\t')
# Ignore header
next(data_reader)
# Process each line
for row in data_reader:
cur_ch... | 2029c23d33768fb72bc0fb20e6a3dae7d0338887 | 14,474 |
import os
import fnmatch
def find(pattern, path):
"""
Looks for files that match a pattern
Parameters
----------
pattern: str;
Pattern to look for.
path: str;
Where to look.
Returns
-------
result: list;
A list containing the files found.
"""
re... | 668765169cd11da033565a20fa193af4524e3702 | 14,475 |
def get_r77_id(cookie):
"""
get a Room 77 id from a cookie
"""
try:
r77_id, _ = cookie.split('%3B') # URI-encoded semicolon
except ValueError:
raise ValueError('Invalid cookie') # no semicolon
return int(r77_id) | 8513f1080eee73d342fcfee03df5f7927aca1197 | 14,476 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.