content stringlengths 39 14.9k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def num_arrows(soln):
"""Return the number of arrows in the solution."""
return sum(1
for reactor in soln.reactors
for waldo in reactor.waldos
for arrow, _ in waldo.instr_map.values()
if arrow is not None) | 5695a83ced47725c15b77b0f53fa89a762b86609 | 104,162 |
import types
def className(obj, addPrefix=False):
"""Return human-readable string of class name."""
if isinstance(obj, str):
class_str = obj
# don't add prefix -- it's unknown
prefix = ""
elif isinstance(obj, type):
class_str = obj.__name__
if addPrefix:
... | a5a9d7fb0be0b01700a4f9d02d6532e758d662bd | 104,163 |
def gen_topline_employment_change(shortened_dv_list):
"""Create variables for the topline employment change for the current and
previous months."""
topline_employment_change = round((shortened_dv_list[11] - shortened_dv_list[10]) * 1000)
prev_topline_employment_change = round((shortened_dv_list[10] - s... | 5afea158ffc75558cd4d615dacdf7e9945189741 | 104,167 |
def _create_url_rule(func):
"""Creates the URL rule for a function.
:param function func:
The MicronMethod to create the route for.
:returns:
The URL rule: "/<function name>"
"""
name = func.__name__.split('.')[-1]
return '/' + name | 8982e5a18ce07326d9f118bbcbc2252b21cdc5dd | 104,172 |
def sampling_map(data, n_req, n_step):
"""
Creates a list containing 3-tuples where each element can be used to
index a specific sequence and then index start and end positions for
a sample of that sequence. Each sample will be n_req in length which
should be long enough to create a batch. We sampl... | 5fba1b7bd86f4674c98d550eba38d71232da8034 | 104,180 |
import itertools
def leading(predicate, iterable, start=0):
"""Returns the number of leading elements in the iterable for which
the predicate is true.
:param predicate:
Predicate function of the form::
f(x) -> bool
:param iterable:
Iterable sequence.
:param start:
Start index. ... | 01f0ac8aa3d7361a61bc8186ba3774f0d9b9dd1d | 104,182 |
import re
def get_host_from_url(url_path):
"""Given a smrtlink job url, return host (e.g., 'http://smrtlink-alpha')"""
return re.sub(r'https', 'http', ':'.join(url_path.split(':')[0:2])) | 21a9a5c83546bfb14c8fa437177825a8c01f374f | 104,183 |
def collocation_order(request):
"""Order of collocation method."""
return request.param | 35bed240a6d505d4c469b9de54559305b0db3daa | 104,186 |
def array(n):
"""Return array declaration for rank n"""
return ", ".join([":"] * n) | 946d9b3cfcbe5eda64545dae8d6ae96ab3483737 | 104,188 |
def get_dev_input4() -> list:
"""Build a maze for development purposes."""
form1 = (
"""oooooo+--+oooooo
o+--+o|oo|o+--+o
o|oo+-+oo+-+oo|o
o++oooooooooo++o
oo+-+o+--+o+-+oo
oooo|o|oo|o|oooo
o+--+o+--+o+--+o
++oooooooooooo++
|oooooooooooooo|
+--------------+
oooooooooooooooo
o+-+oo+--+xx+-+o
++o|oo|oo|oo|o++
|oo... | 40a7e1220dc23cc5ff0c85b50ca9eab01e7904aa | 104,193 |
def create_db_links(txt_tuple_iter, link_format):
"""
From an iterable containing DB info for records in DB or 'not in DB' if no
records were found, returns info formatted as url links to detail pages of
the records.
:param txt_tuple_iter: an iterable of strings and tuples where the 0
... | 4cb393382aa6bf21481e1cd2a60d2746188811f9 | 104,195 |
def GetPersistentDeviceList(file_name):
"""Returns a list of devices.
Args:
file_name: the file name containing a list of devices.
Returns: List of device serial numbers that were on the bot.
"""
with open(file_name) as f:
return f.read().splitlines() | aa68d4a4f7eaea79f74e0c2ca6e44e49fab3aae9 | 104,198 |
def is_list_of(seq, check_type):
"""
check if the `obj` is a list of `check_type` data.
"""
if not isinstance(seq, list):
return False
else:
for item in seq:
if not isinstance(item, check_type):
return False
return True | 443191f33cbee519af3770721063da5763ebfd4b | 104,199 |
from warnings import warn
def warning(*args, **kwargs):
"""
Issues a warning.
Parameters
----------
\*args : \*
Arguments.
\*\*kwargs : \*\*
Keywords arguments.
Returns
-------
bool
Definition success.
Examples
--------
>>> colour.utilities.wa... | 3133ebdbaabb212f62b9118e81bc245bd7d6fb30 | 104,203 |
def get_time_seconds(string):
"""Returns Slurm-compatible time string as seconds
"""
while (len(string.split(":")) < 3):
string = "00:" + string
return sum(secs * int(digit) for secs,digit in zip([3600, 60, 1], string.split(":"))) | fedbb7b4666f2396028b221342da68bc3fce5878 | 104,207 |
def date2epoch(dt):
"""
Convert list of datetime objects to epoch time
Parameters
----------
dt : datetime.datetime
Single or list of datetime object(s)
Returns
-------
time : float
Datetime converted to epoch time (seconds since 1/1/1970 00:00:00)
"""
if not i... | 1d13af15d856ca9d8f45fcda5f37d7a7eaff284a | 104,210 |
def BooleanFromString(s):
"""Interpret 's' as a boolean and return its value. Raise
ValueError if it's not something we can interpret as true or
false."""
s = s.lower()
if s in ("true", "t", "1", "on", "yes", "y"):
return True
if s in ("false", "f", "0", "off", "no", "n"):
return False
raise Valu... | 0b1bf77f113da032ea6677f2f56e610b2384cf8a | 104,211 |
def print_dataframe_memory_usage(df):
""" df: a Pandas.DataFrame such as curr_active_pipeline.sess.spikes_df
Usage:
from pyphocorehelpers.print_helpers import print_dataframe_memory_usage
print_dataframe_memory_usage(curr_active_pipeline.sess.spikes_df)
>> prints >>:
==... | d74f8579a89ec8ef17ecf3a10f1c17bb66269201 | 104,214 |
import requests
from bs4 import BeautifulSoup
def getLinks(url):
"""
Receive a URL and return a BeautifulSoup object
"""
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36"}
try:
html = requests.... | 018ccede3109942d51f6f59cedc87da0efc59f93 | 104,215 |
def image_size(data):
"""
Parameters
----------
data : numpy.ndarray
Image data.
Returns
-------
tuple (int, int)
Image width and height.
"""
image_shape = data.shape
return (image_shape[0], image_shape[1]) | 011c8a3385fc04c407f8b76b48cc7833f58d7df6 | 104,217 |
import json
def decode_json(s):
"""
Compatible with JSON format that incorrectly uses '\' escape character.
Such as \" \'
See http://stackoverflow.com/questions/7921164/syntax-error-when-parsing-json-string for details.
JSON online verification:http://jsonlint.com/
"""
result = No... | c49838cd18aea94647e67ba91ce4496f20322051 | 104,222 |
from typing import Optional
import torch
def get_spectrogram(
waveform,
*,
n_fft: int = 2048,
hop_length: Optional[int] = None,
win_length: Optional[int] = None,
window: Optional[torch.Tensor] = None,
center: bool = True,
pad_mode: str = "reflect",
power: Optional[float] = None,
):... | 17ee54cd5e909c72f99a97648c3d911f1a1b7508 | 104,225 |
def get_cloud_directive(key, task_directives, cloud_args_key='cloud_args'):
"""
Helper function to get a directive one layer undernearth ``cloud_args``
:param key: str Directive key
:param task_directives: dict The dictionary of task directives
:param cloud_args_key: str Key for the first level... | 70d97d8d3f7edb6c1a3eebebd0fc50adbdc4b42a | 104,232 |
def hex_colour(color: int) -> str:
"""Converts an integer representation of a colour to the RGB hex value."""
return f"#{color:0>6X}" | 422c84cad5721445c1ce38afa4f9c2e241f9a4a3 | 104,233 |
def title_or_url(node):
"""
Returns the `display_name` attribute of the passed in node of the course
tree, if it has one. Otherwise returns the node's url.
"""
title = getattr(node, 'display_name', None)
if not title:
title = str(node.location)
return title | 7a2a90dc683a77490ed005b66d2666151421f940 | 104,234 |
def remap_to_range(x, x_min, x_max, out_min, out_max):
"""convert x (in x_min..x_max range) to out_min..out_max range"""
if x < x_min:
return out_min
elif x > x_max:
return out_max
else:
ratio = (x - x_min) / (x_max - x_min)
return out_min + ratio * (out_max - out_min) | 0e6c7a755ea3dc4651fbf5abf2cc313b33be7db1 | 104,241 |
import random
import string
def get_testdir(length):
""" This function creates a random string that is used as the testing
subdirectory.
"""
return ''.join(random.choice(string.ascii_lowercase) for _ in range(length)) | 08aa9fa3767792006ef7ad3bfc421546756e2d27 | 104,242 |
import queue
def read_file(file, file_encoding='utf-8'):
"""读取文件内容,注意文件是UTF-8的格式且不是BOM格式
:param file: 读取的文件
:param file_encoding: 文本编码
"""
queues = queue.Queue(maxsize=0)
with open(file, encoding=file_encoding) as fp:
for line in fp:
queues.put(line)
return queues | 2225f2c130147945579896197699a47b5aee2103 | 104,243 |
def cm2inch(value: float) -> float:
""" Conversion function from centimeters to inches. """
return value / 2.54 | 5ac8f72210ab3b19ebd3171d6f8badf0042db691 | 104,248 |
def forward_box(box):
"""Increase box level (max 4)
Parameters
----------
box: int
question box level
Returns
-------
int: updated box
"""
if box < 4:
box += 1
return box | ae0de5b0821e8bde81063471f1f3768022d1856e | 104,249 |
def _number_to_3digits(number):
"""
Transform a number smaller than 1000 (0-999) to a string representation with
three characters (000, 001, ..., 021, ..., 089, ..., 123, ..., 999).
"""
# Make sure the value we transform is under 1000 and is positive.
mod_number = number % 1000
if mod_n... | fa5e6f76114ca89ea5ee954b46e32f6cf71cd60f | 104,250 |
def filter_raw_data(df, min_entities=1, max_entities=10000000):
"""
Removing sentences with 'min' and 'max' labels other than 'O'.
Args:
df: pd.DataFrame containing all sentences of the data.
min_entities: int representing the min number of labels other than
'O'.
max_entitie... | ce91d1ee0464408b930c347eba131c1c29dd93c4 | 104,255 |
import difflib
def get_book_id(book_title, metadata):
"""
Gets the book ID for a book title based on the closest match in the metadata dataframe.
"""
existing_titles = list(metadata['title'].values)
closest_titles = difflib.get_close_matches(book_title, existing_titles)
book_id = metadata[meta... | c2a860960fc34c11fc759856852b60dc31779740 | 104,256 |
def convert_condition(cond):
"""Convert a condition from auto-libm-test-out to C form."""
conds = cond.split(':')
conds_c = []
for c in conds:
if not c.startswith('arg_fmt('):
c = c.replace('-', '_')
conds_c.append('TEST_COND_' + c)
return '(%s)' % ' && '.join(conds_c) | 96361f0a3e6f3f9c84aca64d140ad82cbb1c2676 | 104,257 |
def top_markets_by_property(property_data_frame, number_of_markets, dimension):
""" A function which returns the top number_of_markets per dataframe
I: dataframe, the number of markets to return
O: list of the top markets sorted by number of observations"""
markets = property_data_frame.groupby([dimens... | 6799d9ce3cb343a0827aa23733ca44345420aeb0 | 104,262 |
def PlaceHolders(sql_args):
"""Return a comma-separated list of %s placeholders for the given args."""
return ','.join('%s' for _ in sql_args) | bd24cf36514e23cbe7d5ca3d0981c38930aa6b4a | 104,264 |
import math
def round_up_to(x: int, base: int) -> int:
"""Round ``x`` up to the nearest multiple of ``base``."""
return int(math.ceil(x / base)) * base | b3001b6575df26c3aabcf02d5bb27129c2c5a364 | 104,265 |
def toBytes(s):
"""
Method aimed to convert a string in type bytes
@ In, s, string, string to be converted
@ Out, response, bytes, the casted value
"""
if type(s) == type(""):
return s.encode()
elif type(s).__name__ in ['unicode','str','bytes']:
return bytes(s)
else:
return s | fb5253027efc0f98fc8da803a4982b49fd9af533 | 104,266 |
from pathlib import Path
import yaml
def is_app_based_tracing_intervention(intervention=None, intervention_conf=None):
"""
Determines if the intervention requires an app.
Args:
intervention (str): name of the intervention that matches a configuration file in `configs/simulation/intervention`. Def... | beb00bab70bca479742536b630164240d9e9f17e | 104,267 |
def _calculate_positives_negatives(target_details):
"""
Takes expected and actual target values, generating true and false positives and negatives,
including the actual correct # of positive and negative values.
"""
true_positive = 0
true_negative = 0
false_negative = 0
false_positive =... | 43314d34e98c4e9fa959426666f17d1a7d71af44 | 104,269 |
import torch
def get_device(gpu_list=None):
"""Get a Pytorch device corresponding to one of the GPU indices listed
in gpu_list. If gpu_list is empty, get the device corresponding
to the CPU instead. If gpu_list is None (the default), enumerate
the available GPU indices and pick one as though the lis... | d183d3b807b38f47cc83ae00397bdcd924f6e0dd | 104,272 |
def CreateSQSQueueSubscription(*, session, queuearn, topicarn):
"""Use SQS queue to subscribe to the SNS topic
:param session: Session to use for AWS access
:type session: boto3.session.Session
:param queuearn: ARN of the queue
:type queuearn: str
:param topicarn: ARN of the SNS topic to subscribe to
:ty... | 122ce9623bb760f56e9e3f9de8dc911f208d2357 | 104,274 |
from pathlib import Path
def find_db_files(s_db_path: str):
"""Find all csv files in a given directory and store them in a list.
Args:
s_db_path: A string with the data path to the database folder.
Returns:
files: A list with db (.csv) files in the folder.
"""
s_data_path = P... | 408748ed200a5e03c51f8b46669b3bb62e0586f5 | 104,287 |
def _to_flat_dict_key(keys):
"""Converts a list of nested keys to flat keys used in state.as_dict().
Args:
keys: List of keys from outmost to innermost.
Returns:
Corresponding flat dictionary for the given list of keys.
"""
return '/' + '/'.join(keys) | 271fe3fe89a83a1160f8c9203984ec01ffdf4358 | 104,289 |
def _get_trailing_whitespace(marker, s):
"""Return the whitespace content trailing the given 'marker' in string 's',
up to and including a newline.
"""
suffix = ''
start = s.index(marker) + len(marker)
i = start
while i < len(s):
if s[i] in ' \t':
suffix += s[i]
e... | 5a5e5d88accc105334c7cec74a8dbcd51c03e184 | 104,298 |
import codecs
def normalise_encoding_name(option_name, encoding):
"""
>>> normalise_encoding_name('c_string_encoding', 'ascii')
'ascii'
>>> normalise_encoding_name('c_string_encoding', 'AsCIi')
'ascii'
>>> normalise_encoding_name('c_string_encoding', 'us-ascii')
'ascii'
>>> normalise_e... | 150f0c7b754ebfd74e3ec719f16c1d1102cb1af7 | 104,300 |
def _nevergrad_ask_tell(optimizer, ob_func, no_bias=False):
"""Exposes the Nevergrad Optimizer ask and tell interface
Parameters
----------
optimizer: nevergrad.Optimizer
Nevergrad Optimizer instance to perform optimization routine
ob_func: nevergrad.MultiobjectiveFunction
Nevergrad... | e75e8828bf14176ae267ab628213f733478a3ffc | 104,307 |
def mock_endpoint_factory(mock_endpoint):
"""
Fixture that yields a factory function used to create a USB endpoint at the given address.
"""
def factory(address):
mock_endpoint.getAddress.return_value = address
return mock_endpoint
return factory | c21a60887a1f4f3daef10a3c3c918e081921dcfa | 104,308 |
def node_offsets_formatter(node):
"""
Returns a terminal node's original character offsets.
"""
return "%d:%d" % (node.start_token.start_char, node.end_token.end_char) | 23ca0c602597080e0368e3b24364ab38b8cf24c2 | 104,309 |
def root_to_list(root):
"""takes in etree root node, parses it to a depth-first ordered list
Arguments: root [element] : root element to be converted to list
Returns: [list] List of element objects in depth-first order
"""
return list(root.iter()) | a6861ba73352582cba2ef8d79528df840bf13609 | 104,312 |
from typing import IO
from typing import Dict
from typing import List
import csv
def parse_package_to_repos_file(input_file: IO[str]) -> Dict[str, List[str]]:
"""Parse CSV file mapping package names to repositories.
:param IO[str] input_file: CSV file to parse.
The file needs to contain a column `pac... | 25b36a3d965aa00fa6428fc9045ed5c99bb8e253 | 104,316 |
def create_station_id(loc_name, vs30, z1p0=None, z2p5=None):
""" Creates a projects station id based on if Z1.0/Z2.5 values were specified or not"""
station_id = f"{loc_name}_{str(vs30).replace('.', 'p')}"
if z1p0 is not None and z2p5 is not None:
station_id += f"_{str(z1p0).replace('.', 'p')}_{str(... | b833f6abfb39843cc136346deaa9762f1dee4bbb | 104,319 |
def safe_delete_key(dictionary, key):
"""
Safely delete a key from a dictionary only if it exists
:param dictionary: the dictionary
:param key: the key to delete
:return: the dictionary
"""
try:
del dictionary[key]
except:
pass
return dictionary | bc58b2a23281634291eb2b2587a550f0a7da206a | 104,320 |
import hashlib
def create_hashname(id1, id2, bins, bins_col, direction, ops):
"""
Helper function to generate a hash name for the cached filename
:param id1:
:param id2:
:param bins:
:param bins_col:
:param direction:
:param ops:
:return:
"""
name = str(id1) + '_' + str(id2) + '_' + str(bins) + ... | c896b71b1cc513307e0c5a57c6d6450332d70a16 | 104,322 |
def strip(input_string):
"""Strip trailing whitespace, single/double quotes."""
return input_string.strip().rstrip(";").strip('"').strip("'") | 8278395cd8bcfc5fe700dfe593957410e79d174f | 104,325 |
import re
def parse_regexp(regexp, string, json_key_list):
"""
Parse a regular expression and return the result as dictionary object
:param regexp: A regular expression to parse
:param string: A string to parse
:param json_key_list: A list of JSON keys to extract from the regular expression and... | efc05390504c48bf8068f0c44a33b5acfa1c5fb7 | 104,326 |
def add_frame(img, c, b=40):
"""Add a colored frame around an image with color c and thickness b
"""
img = img.copy()
img[:, :b] = img[:b, :] = img[:, -b:] = img[-b:, :] = c
return img | 63b00fd6e47347baf49c28a38b74829aef158b98 | 104,330 |
import json
def annotation_to_GeckoJSON(annotation, distances={}, colors={}):
"""
Parameters:
-----------
annotation: `pyannote.core.Annotation`
proper pyannote annotation for speaker identification/diarization
distances: `dict`, optional
in-cluster distances between speech feature... | 2df1a0937d8b2aa5957b06b2237b7cfe7ed9454b | 104,331 |
def binaire_vers_decimal(bits):
"""
Transforme un tableau de bits en entier
:param bits: Le tableau de bits
:return: L'entier représentant la valeur binaire
"""
nb = 0
for bit in bits:
nb = (nb << 1) | bit
return nb | e837f35161b631634c62852adbf03b8b18065635 | 104,332 |
def bbox_parse(annotation, gt_bboxes, gt_labels, gt_bboxes_ignore, cat2label):
"""
Parse ground-truth box in an annotation dict. There is no return in this
function, because the `gt_bboxes`, `gt_labels`, `gt_bboxes_ignore` are
lists, and if they have append element in this function, the change will
... | 51e1cd9ced94c8e976d651caa26825eb3df0ee40 | 104,333 |
from bs4 import BeautifulSoup
def remove_html_tag(text):
"""
Removes the html tags from the text to clean the data
:param text: (str) The text document
:return text: (str) Returns the text document free of html tags
"""
text = BeautifulSoup(text, 'html.parser').get_text()
return text | 81e8babc7b2dbfc39052cbb096071f75997fff62 | 104,334 |
def path_3d(quad_path,
ax3d,
planned_path=None,
waypoints=None,
quad_lw=1.0,
path_size=3.5,
wp_size=6.0):
""" Plots the path of a quad on a matplotlib axes.
Only use if you want to modify the look of the plots, otherwise use plot_path_3d ... | 75cc67013a752779baa71b1a2b68540b453cc351 | 104,337 |
from typing import Any
import types
import functools
def is_callable(func: Any) -> bool:
"""
Return ``True`` if ``func`` is callable.
:param func: Function object
:return: ``True`` if function
"""
# noinspection PyTypeChecker
return isinstance(func, (types.FunctionType, types.BuiltinFunct... | 7eaa9f439c3464df44cd82d63a4f0f9e9d6ad928 | 104,345 |
def pull_field(cursor, field):
"""
Wrapper function to return dictionary key-val pair being accession-field
"""
field = ["`" + field + "`"]
result = cursor.execute("SELECT `accession`, ? FROM SEQUENCES;", field)
field_dict= dict(result.fetchall())
return field_dict | 3eb477fe3399e1d61ca6f6ce0b3fb9ac1bff2a21 | 104,349 |
def lazyprop(fn):
"""
Instead of having to implement the "if hasattr blah blah" code for lazy loading, just write the function that
returns the value and decorate it with lazyprop! See example below.
Taken from https://github.com/sorin/lazyprop.
:param fn: The @property method (function) to implem... | a38bf3c2f4b9833a24137fc1d103973abbc040d8 | 104,350 |
def create_filters(filter_dict):
"""
Converts a dict to a list of boto3 filters. The keys and value of the dict represent
the Name and Values of a filter, respectively.
"""
filters = []
for key in filter_dict.keys():
filters.append({'Name': key, 'Values': filter_dict[key]})
return f... | 6f734b2be22fa7789783351e3e75b1f64072c0ed | 104,353 |
from pathlib import Path
import logging
def check_arg_output_plot(output_file: str, create_parent_dir: bool = True) -> bool:
"""Return True of the output_plot has the expected format (deduced from the file extension).
Accepted extensions are: svg and png.
If the parent directory of the output file does ... | 39ca0976dedf96d8bed6e863b83e5081d45e0ed0 | 104,354 |
def filing_1550126(get_fixture):
"""
Returns the file path for 1550126.fec
"""
return get_fixture("1550126.fec") | 5e28bbe2553d4b14596b0de8ced0f4935a36b387 | 104,355 |
import fnmatch
def GetTestsFromDevice(runner):
"""Get a list of tests from a device, excluding disabled tests.
Args:
runner: a TestRunner.
"""
# The executable/apk needs to be copied before we can call GetAllTests.
runner.test_package.StripAndCopyExecutable()
all_tests = runner.test_package.GetAllTes... | 89c575bfca9b03983354be84df00100da49ab41e | 104,356 |
def square(x):
"""
Calculate the square of a number
Parameters
----------
x : a number (int, float, complex...) or numpy array
Outputs
-------
The number squared,
.. math::
x^2
Example
-------
>>> square(5)
25
"""
return x**2 | 2298d40f69c1ca70f225fc0c2ae9947b854cfeeb | 104,362 |
def filter_non_src_files(files):
"""
Filters out all files which don't contain prefix Inst
i.e. all files that aren't pymod dicts for TestComponent
"""
src_files = []
for file in files:
if file[:4] == "Inst":
src_files.append(file)
return src_files | d94310dc144c107bc99e17e964db9c26663cf3de | 104,366 |
def is_valid_directed_joint_degree(in_degrees, out_degrees, nkk):
""" Checks whether the given directed joint degree input is realizable
Parameters
----------
in_degrees : list of integers
in degree sequence contains the in degrees of nodes.
out_degrees : list of integers
out degre... | c144816f286894e6e4df9adb107d02be630576f2 | 104,367 |
def try_read_until(fp, pattern, chunk_size=16384):
"""
Perform buffered read of `fp` until pattern, and return all data accumulated and ends with pattern.
If read failed (no pattern found), file position is backtracked.
Else: file cursor will be at position right after pattern.
:returns: None, if EOF reached... | 1135827dba5f6cbb1fb29f410a99a6dfc2c3f794 | 104,372 |
def cbany(callback, iterable):
"""Return True if any callback(row) of the iterable is true. If the iterable
is empty, return False
:param callback: callable
:param iterable: Sequence
:returns: bool
"""
for v in iterable:
if callback(v):
return True
return False | 95e7ed255eb00ead6652188d65771903f3c4ab72 | 104,373 |
def groups(hand, numwildcards=0):
"""Checks for pairs, threes-of-a-kind, fours-of-a-kind,
and fives-of-a-kind
Inputs: list of non-wildcards plus wildcard count
2,3,4, ... 10, 11 for Jack, 12 for Queen,
13 for King, 14 for Ace
Hand can be any length (i.e. it works for seven card g... | d9b80b39d91aaa521bd092704a70922a757af88f | 104,375 |
def find_factorial(number: int) -> int:
"""Return factorial for specified number."""
if number > 0:
return number * find_factorial(number - 1)
elif number == 0:
return 1
else:
raise ValueError("Negative number") | 6071ac6909c2161a068694c0da85172198b3266f | 104,378 |
def mfacebookToBasic(url):
"""Reformat a url to load mbasic facebook instead of regular facebook, return the same string if
the url don't contains facebook"""
if "m.facebook.com" in url:
return url.replace("m.facebook.com", "mbasic.facebook.com")
elif "www.facebook.com" in url:
return u... | 26b55c23048bd8febe6ef93f15b0c4bbfd434e36 | 104,381 |
import curses
def keypending( scr ):
""" return true if getch is going to return a real key """
ch = scr.getch()
if ch >= 0:
curses.ungetch(ch)
return (ch >= 0) | 435b8f83717405f12843d1e54c02b3431a94a8ca | 104,387 |
def app_model_or_none(raw_model):
"""
Transforms `raw_model` to its application model. Function can handle `None` value.
"""
return raw_model.get_app_model() if raw_model is not None else None | fdaa53876e4d0eba6260b4d8b5ecf90c5e8a33aa | 104,390 |
def get_offer_address(html_parser):
"""
This method returns the offer address.
:param html_parser: a BeautifulSoup object
:rtype: string
:return: The offer address
"""
try:
address = html_parser.find(class_="address-text").text
except AttributeError:
return
else:
... | f8de5c7d30ed78016ebb246454c64e5b37913c28 | 104,394 |
def get_destination_from_obj(destination):
"""Helper to get a destination from a destination, event, or tour.
For events and tours, return the first related destination, if any."""
if hasattr(destination, 'first_destination'):
# tour with related destination(s); use the ordered first
retur... | 025bee5615793aad61e81d5723bd3df43d43115d | 104,399 |
import requests
def get_url(url):
""" Get a url, return it's contents. """
headers = {"User-Agent": "dftools"}
resp = requests.get(url, headers=headers)
if resp.status_code == requests.codes.ok:
return resp.content, resp.status_code
else:
return None, resp.status_code | 6a67f273277605979fb114031760e07253dbd565 | 104,404 |
import functools
import math
def get_factors(n):
"""return all factors of an integer
Parameters
----------
n: int
integer to factorize
Returns
-------
factors: list
List of all factors
"""
step = 2 if n % 2 else 1
ret = list(
set(
functools... | 67ca23f94bf17ff2321ad654c1d4bb6eb6feb977 | 104,406 |
import time
def formatDatetime(date):
"""
It return the timestamp of a concret date.
Args:
date: A datetime object.
Returns:
An integer containing the timestamp of a concrete date.
"""
return int(time.mktime(date.timetuple()))*1000 | e22bd2f63776c96c3bccad3eb38fccc9eb780aa6 | 104,408 |
def power(n,r):
""" Return n^r """
return n**r | d1ed5d802a5975ed100e40f18c739fd39653beaf | 104,413 |
import inspect
def parameters(only=None, exclude=None, ignore='self'):
"""Returns a dictionary of the calling functions
parameter names and values.
The optional arguments can be used to filter the result:
only use this to only return parameters
from... | d582fb95d03accc5216c1fd78c95ab2af733f128 | 104,417 |
import re
def _parse_ffmpg_results(stderr):
""" Extract number of channels and sample rate from
the given FFMPEG STDERR output line.
:param stderr: STDERR output line to parse.
:returns: Parsed n_channels and sample_rate values.
"""
# Setup default value.
n_channels = 0
sample_rate = ... | 4dc49194e5a07bc3914c5d8c2decdb65ee348cd0 | 104,418 |
def weighted_choice(weights, prng):
"""Samples from a discrete distribution.
Parameters
----------
weights : list
A list of floats that identifies the distribution.
prng : numpy.random.RandomState
A pseudorandom number generator object.
Returns
-------
int
"""
... | 0ff2dc3c669f128a97d4bca1d34f36f1d5bb6482 | 104,421 |
def beta(mu,phi):
"""Transforms beta function parameters from average and variance form to
the alpha & beta parameters"""
a = mu*phi
b = (1-mu)*phi
return a, b | 5948b130455276f783969387a059ffc283bf6753 | 104,422 |
def get_request_ips(request):
"""
Get the chain of client and proxy IP addresses from the request as
a nonempty list, where the closest IP in the chain is last. Each
IP vouches only for the IP before it. This works best if all proxies
conform the to the X-Forwarded-For header spec, including whateve... | 8aafda8ea790e7d6eea01f08e128cf1f70310dd1 | 104,423 |
def protege_data(datas_str, sens):
"""
Used to crypt/decrypt data before saving locally.
Override if securit is needed.
bytes -> str when decrypting
str -> bytes when crypting
:param datas_str: When crypting, str. when decrypting bytes
:param sens: True to crypt, False to decrypt
"""
... | b7e8bad20ca6825dd68552a435920c45cd582a30 | 104,425 |
from typing import List
def string_of_single_to_list_of_ints(input_string: str) -> List[int]:
"""
Split a string on `split_string` and return a list of integers
:param input_string: String to split
:return: List of integers
"""
list_of_ints = list(map(int, input_string))
return list_of_in... | a6c9de29cce4c96ea86f77a7f17aa330960ad77f | 104,428 |
def canUnlockAll(boxes):
"""
- boxes is a list of lists
- A key with the same number as a box opens that box
- You can assume all keys will be positive integers
- The first box boxes[0] is unlocked
- Return True if all boxes can be opened, else return False
"""
canUnlockAll = False
k... | 439d5694a442342626d960fce716fce930512b28 | 104,433 |
def defaults_override(dictionary, overrides):
"""override and append values from defaults to dictionary"""
for key in overrides:
dictionary[key] = overrides[key]
return dictionary | 9d98ebd347527f57bf3f03435673abb8de825af0 | 104,435 |
def report_exit(combined_test_report):
"""The exit code of this script is based on the following:
0: All tests have status "pass", or only non-dynamic tests have status "silentfail".
31: At least one test has status "fail" or "timeout".
Note: A test can be considered dynamic if its name cont... | f3fa40a42c8f6b61f8d2729abdb0e10321cc50f0 | 104,436 |
def generate_resource_url(
url: str, resource_type: str = "", resource_id: str = "", version: str = "v1"
) -> str:
"""
Generate a resource's URL using a base url, the resource type and a version.
"""
return f"{url}/{resource_type}/{resource_id}" | 350a0c07813153107f2d103cca5e3df6bc197f68 | 104,440 |
import math
def Gamma2(z: float) -> float:
"""Gamma Function. Gergő Nemes version.
Gamma(n) == fact(n-1)
>>> import math
>>> round(Gamma2(2),1)
1.0
>>> round(Gamma2(3),1)
2.0
>>> round(Gamma2(4),1)
6.0
>>> round(Gamma2(5),1)
24.0
>>> round(Gamma2(.5), 7) # Not quite r... | a998aa7e8188a61e23fac36a2cc8e243e8878925 | 104,450 |
def generate_default_hostname(instance_id):
"""Default function to generate a hostname given an instance reference."""
return str(instance_id) | 006f6ea820d91a5ad1c5fb07ce7c0a44ee1644d7 | 104,453 |
import hashlib
def get_hash(value):
""" Return a 32-byte hash of value as a hex string"""
return hashlib.sha256(value).hexdigest() | ced272a574c339c713d1354d665d225367784188 | 104,455 |
def strip_domain_strings_wrapper(subset):
"""wraps a function to strip results_type, subset, and domain_frac text"""
def strip_domain_strings(text):
"""Strip the string"""
text = text.strip('*')
text = text.replace('results_', '')
text = text.replace(subset, '')
text = t... | 9055f51ad7023735dbbc12a7034ecf7be78fa16c | 104,462 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.