content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def _dir(obj):
"""Verb: print dir(obj)"""
print(dir(obj))
return obj | 257fd71e4ba66a13f7ceed2f5fd429adda23ffb2 | 22,498 |
def build_tdbank_config_param(
group_id,
task_name,
rt_id,
topic,
tasks,
master,
bid,
table_name,
kv_splitter,
field_splliter,
):
"""
生成tdbank任务配置
:param group_id: 集群名
:param rt_id: rt_id
:param topic: 数据源topic
:param tasks: 消费并发数
:param master: tdbank... | 1861ca8ba5423ebdfd32a1cf50bb40aafbeb6a29 | 22,502 |
def getListItem(inputtext='',inputlist=[]):
"""Prompts the user for a value.
Values are accepted if they can be found in a predefined list.
Other values prompt the user to re-enter a response.
*inputtext defines the text preceding the user interaction
*inputlist defines the values acceptable as a user response
## *... | a2b567c78fdd5adba5b137f3509cf4115ebae15d | 22,503 |
def to_applescript(num):
"""
Convert a Python number to a format that can be passed to Applescript.
A number doesn't need coerced to print to stdout, but it's best to be
thorough and explicit.
"""
return str(num) | 7d4fe31e276267668078cedc0b5fa6c5f97dc035 | 22,504 |
def button(url, title, style, _method="get", **context):
"""
A single button like [EDIT]
:param url: Action this button goes to.
:param title: Title of the button.
:param style: Style of the button (if applicable): primary|danger|info|warning|success
:param _method: (optional) A method. If "get"... | 5b48e1b76d8df98f55ba198002e6ad4cf3f00313 | 22,505 |
import random
def sample(population, k, seed=42):
"""Return a list of k elements sampled from population. Set random.seed with seed."""
if k is None or k > len(population):
return population
random.seed(len(population) * k * seed)
return random.sample(population, k) | 0f087c675e87fef721426229f570e95ae84b10bc | 22,507 |
def increment(value, list_):
"""
This updates the value according to the list. Since we seek 4
consecutive numbers with exactly 4 prime factors, we can jump
4 numbers if the last doesn't have 4 factors, can jump 3 if
the second to last doesn't have 4 factors, and so on
"""
if list_[-1] != 4:... | cae8e71c052aa0121a677304c45d4d6261d757d5 | 22,509 |
from pathlib import Path
def _get_all_entries(entry_list, keep_top_dir):
"""
Returns a list of all entries (files, directories) that should be copied.
The main purpose of this function is to evaluate 'keep_top_dir' and in case
it should not be kept use all the entries below the top-level directories.
... | 71add58859cd4880fb46f4657ee6e0e9938a4d5f | 22,510 |
import argparse
def parse_args(argv=None):
""" Parses command line arguments.
:return: args
:rtype: Namespace
"""
parser = argparse.ArgumentParser(description="Plot PK models using 2 or 3 compartment models")
parser.add_argument('-d', '--data_root', type=str, required=False, help="Path to loc... | 26e5cd995b0f09019c99109407832a4ebb5df0d8 | 22,511 |
def convertBinaryToDecimal(num: str) -> int:
"""
Converts a binary string to a decimal number
"""
multiplier: int = 1
decimalNum: int = 0
for c in reversed(num):
decimalNum += (int(c) * multiplier)
multiplier *= 2
return decimalNum | 6ae6ee26f8f66347284c4db4a6a0e76dd88f749f | 22,512 |
def dataInit():
"""
初始化数据和属性集。
Returns: (数据, 属性集)
"""
Data = [['青绿', '蜷缩', '浊响', '清晰', '凹陷', '硬滑', 0.697, '好瓜'],
['乌黑', '蜷缩', '沉闷', '清晰', '凹陷', '硬滑', 0.774, '好瓜'],
['乌黑', '蜷缩', '浊响', '清晰', '凹陷', '硬滑', 0.634, '好瓜'],
['青绿', '蜷缩', '沉闷', '清晰', '凹陷', '硬滑', 0.608, '好瓜... | 3adbc5b70440660918c363d1d451dcd4da87d73c | 22,513 |
import mimetypes
def get_content_type(filename):
"""
Uses mimetype's guess functionality to take a shot at guessing the provided filename's mimetype.
:param str filename: name of the file, should include extension
:return: the guessed value or `application/octet-stream` by default
:rtype: str
... | 7bc7c33763157ba3104de854dde9106d93db0205 | 22,514 |
def change_soup(adventuredoc, section):
"""Create the HTML for the provided file contents!
Should maybe have the callback....
Returns:
BeautifulSoup: --
"""
soup = section.soup
total_number_of_sections = len(adventuredoc.sections)
# Section Progress/Position
progress = secti... | b0af5ee299d641778edd8b7766d841b72e3c59c8 | 22,515 |
import pytz
from datetime import datetime
def get_caption():
""" Returns a human readable string based on the current time. """
timezone = pytz.timezone('America/New_York')
return f"{datetime.now(timezone).strftime('%A, %b %d %Y @ %l:%M:%S %p')}" | 05fde430464063341198796262f6e4d1faed130a | 22,516 |
def dict_list_eq(l1, l2):
"""Compare to lists of dictionaries for equality.
"""
sorted_l1 = sorted(sorted(d.items()) for d in l1)
sorted_l2 = sorted(sorted(d.items()) for d in l2)
return sorted_l1 == sorted_l2 | 3f873598ba7a6f60eca4fa7524ca87992ce63528 | 22,518 |
import os
import pickle
def load_mnist(data_dir, use='train'):
"""
Load preprocessed mnist and normalize it to [-1, 1]
parameter
- data_dir: directory path where mnist pickles exist. default MNIST_PATH
- use: load 'train' or 'test'
return: normalized images and labels
"""
pr... | bb4765ac65f67c2bbfefa9e00812bbc38517632c | 22,519 |
def acceptance_probability(previousConfigCost, newConfigurationCost, NumberOfSteps):
"""
e = previous config
e' = new config
T = NumberOfSteps
* Implementation of P(e, e', T).
* The probability of making a transition from the current state s
* to a candidate state ... | ea56f38830f00115e567fc426961e6eafe42695e | 22,522 |
def adcm_credentials():
"""
Provides ADCM username and password by default
Examples:
login(**adcm_credentials)
"""
return {'username': 'admin', 'password': 'admin'} | c8a9822f047aaeb9853b4e26e67fba5bd1cd910b | 22,525 |
def multiple_split(source_string, separators, split_by = '\n'):
"""
This function allows the user to split a string by using different
separators.
Note: This version is faster than using the (s)re.split method (I tested it
with timeit).
Parameters:
* source_string: string to be splitted
* separators:... | 0310d60a225fe156f86d6c0b4ce02781773750de | 22,526 |
def base36decode(base36_string):
"""Converts base36 string into integer."""
return int(base36_string, 36) | 66da9d391705cd0748e0e7c0ea5c69be2366ed4e | 22,527 |
from typing import Any
def xml2dict(xml: Any) -> Any:
"""Convert xml to dict."""
data = {}
for child in list(xml):
if len(list(child)) > 0:
data[child.tag] = xml2dict(child)
else:
data[child.tag] = child.text or ""
return data | 9cba1d08813b24581a173b77e4a92d46a31ae5c9 | 22,528 |
def get_topic_data(topics_with_summaries):
"""
This function takes in a list of ranked topic objects
and returns a dictionary of the data.
Keys are document object and values are list of tuples of (sent, set of nouns)
for each sent in the doc. {doc_obj: [(sent_index, sent_noun_set)]... | b0abf8ba28bc4359c2453050cb1a24340ac21158 | 22,529 |
def decode(symbol_list, bit_count):
""" Decodes the value encoded on the end of a list of symbols.
Each symbol is a bit in the binary representation of the value, with more significant
bits at the end of the list.
- `symbol_list` - the list of symbols to decode from.
- `bit_count` -... | f7cbfe783b32db099713d357fc6a20a7deff7e9f | 22,530 |
import requests
import json
def make_post_request(url, payload, headers=None):
"""Wrapper for requests.post"""
return requests.post(url, data=json.dumps(payload), headers=headers) | 3d02fe19bfd8c3c80d0f181679b563d4d2429a6a | 22,533 |
def newman_conway(num):
""" Returns a list of the Newman Conway numbers for the given value.
Time Complexity: O(n)
Space Complexity: O(n)
"""
if num == 0:
raise(ValueError)
if num == 1:
return "1"
if num == 2:
return "1 1"
answer = [None, 1, 1]
i ... | 57d8f5465884e34d4db0e977e53518086eb605d7 | 22,535 |
import json
def format_entry_as_json(entry):
"""
Return a blog entry in a JSON format
:param entry: input blog
:return: JSON format of the entry
"""
if entry:
entry_as_json = {"subject": entry.subject, "content": entry.content,
"date": entry.created.strftime('%... | c057c317db40322ecea24098d231c6591ae99453 | 22,536 |
def make_scoped_name(*args):
""" Convert a series of strings into a single string
representing joined by points. This convertion represents
Pythons scope convention.i.e. pkg.subpkg.module
Args:
*ags: list of string. The strings will
joined in FIFO order.
Returns:
str: stri... | 39895772eb6d4cb8b0c63b54f8f2cfd4c83964c9 | 22,537 |
def AND(p: bool, q: bool) -> bool:
"""
Conjunction operator used in propositional logic
"""
return bool(p and q) | 5e166eff3b1b998490fd5ed1c9e6e034de1efea0 | 22,538 |
import copy
import os
def _compute_paths_to_names(env):
"""
Single-environment version of conversion of filepath(s) to name(s).
This is similarly motivated by allowing tests' assertions about
equality between Mappings to be independent of Project instance's
effort to ensure that filepaths are abs... | 613920c946a9379199ff6ce3f700f90eb0ebed08 | 22,540 |
def compare_tree_to_dict(actual, expected, keys):
"""Compare parts of lxml.etree objects to dicts."""
for elem, data in zip(actual, expected):
for key in keys:
if elem.get(key) != data.get(key):
return False
return True | 45d9d2784ed559cc0bba8f69ad12e1662379eb09 | 22,542 |
from typing import Sequence
import difflib
def did_you_mean(message: str, user_input: str, choices: Sequence[str]) -> str:
"""Given a list of choices and an invalid user input, display the closest
items in the list that match the input.
"""
if not choices:
return message
else:
res... | f3400d27dc31d3d56f90511afacf290d24c60c7e | 22,544 |
import torch
def calculate_assignment_probabilites(assignments, num_clusters):
"""
Just counts the occurence of each assignment to get an empirical pdf estimate
"""
assignment_counts = torch.bincount(assignments, minlength=num_clusters)
empirical_density = assignment_counts.float()/assignment_counts.sum().... | 1b04d9978b91f230eca9487e8bd31cdc16b33e8d | 22,545 |
def array_to_string(array, delimiter=" ", format="{}", precision=None):
"""
Converts a numeric array into the string format in mujoco.
Examples:
[0, 1, 2] => "0 1 2"
"""
if precision is not None and format == "{}":
return delimiter.join([format.format(round(x, precision)) for x in a... | 8b308b41d5b6f82d58a8b9a4afd529fc7cbf7408 | 22,546 |
import argparse
import os
def parse_args(args):
"""Parse list/tuple of arguments with argparse module
- **Parameters** and **returns**::
:param list args: arguments to be parsed
:returns namespace: parsed arguments
"""
parser = argparse.ArgumentParser(description='jumpdir')
subpar... | ca5c977fc6568b545fa8e5add087f8742af531f5 | 22,547 |
import json
def json_roundtrip(data: dict) -> dict:
"""Input `data` is returned after JSON dump/load round trip."""
return json.loads(json.dumps(data)) | 2e15814d1e975f5f3e845196365de5b521e60cd8 | 22,548 |
def is_apple_os(os_):
"""returns True if OS is Apple one (Macos, iOS, watchOS or tvOS"""
return str(os_) in ['Macos', 'iOS', 'watchOS', 'tvOS'] | 77b85f8e4fec837c5009fff3d8e8446c9f1d0d58 | 22,550 |
def getTZLookup(tzfname='cities15000.txt'):
"""Returns a mapping from gps locations to time-zone names.
The `tzfname` file is read to map gps locations to timezone names.
This is from: http://download.geonames.org/export/dump/cities15000.zip
Returns a list of `((lat, lon), timezone)` pairs.
"""
... | 3dcb3b297be72eb55c2d75ffc0bf269e27775232 | 22,553 |
def pages_to_article(article, pages):
"""Return all text regions belonging to a given article."""
try:
art_id = article['m']['id']
print("Extracting text regions for article {}".format(art_id))
regions_by_page = []
for page in pages:
regions_by_page.append([
... | 2ae0105eaf60f57482e2ab5646318408eba8862a | 22,556 |
def format_with_default_value(handle_missing_key, s, d):
"""Formats a string with handling of missing keys from the dict.
Calls s.format(**d) while handling missing keys by calling
handle_missing_key to get the appropriate values for the missing keys.
Args:
handle_issing_key: A function that t... | 957b851dcacfc98c5bcdb5f1c76850014f8262f5 | 22,559 |
from operator import mul
def dot(A, B):
"""
Computes dot product between input 1-D list 'A'
and 2-D list B.
"""
arr = []
for i in range(len(B)):
val = sum(map(mul, A, B[i]))
arr.append(val)
return arr | 18ed7e4333190421d8abe25748e0dcfa244b7701 | 22,562 |
def remove_backslash(path):
"""Removes all the backslashes from a path and replace them with spaces
Returns a new path without backslashes
Parameters
----------
path: a path (str)
a string that represents a path that leads to a valid dir
"""
if '\\ ' in path:
path = path.r... | ab978a77e0c8e8980d1220eb96898ed2b1fd648a | 22,563 |
def check_duplicate_codewords(C):
"""Check if there are two codewords in C"""
duplicate_list=[]
n=0
for w in range(len(C)):
for w2 in range(len(C)):
if w < w2:
if w is not w2:
if (C[w] == C[w2]).all():
print('Duplicates dete... | bb4027cfe235338e6e04ce5c01ff079e1d7dd7fb | 22,564 |
def sum_combinations(numbers):
"""Add all combinations of the given numbers, of at least one number"""
combinations = [0]
for element in numbers:
new_combinations = list(combinations)
for element2 in combinations:
new_combinations.append(element + element2)
combinations =... | 193f3c7285f70f13435e971844288cb6faeb1d98 | 22,565 |
import json
def load_json(filepath):
"""
Load a json file
Inputs
filepath: string, path to file
Outputs
data: dictionary, json key, value pairs
Example
path = "~/git/msc-data/unity/roboRacingLeague/log/logs_Sat_Nov_14_12_36_16_2020/record_11640.json"
js = load_json(path)
... | bca35e8e10da33ac599a8895e8495fb5eec829e0 | 22,566 |
def parse_cfg_args(arg_list):
"""Parse command-line style config settings to a dictionary.
If you want to override configuration file values on the command
line or set ones that were not set, this should make it simpler.
Given a list in format [section.key=value, ...] return a
dictionary in form { ... | 96e4a0ce5af3c6e9085e8674ce77a3119d3e0dc1 | 22,567 |
from math import log
def idf(term, corpus):
"""
computes inverse document frequency. IDF is defined as the
logarithm of the total number of documents in the corpus over the
number of documents containing the search term:
log(all documents/documents containing the search term)
Note that if *no... | 15ca03e272a0e535500f38e3bb73bab342e42390 | 22,569 |
def special_cases():
"""Returns the special cases which are not handled by other methods"""
charactersSet = set()
# Cyrillic
charactersSet.add((0x0401, "\u0415")) # CYRILLIC CAPITAL LETTER IO
charactersSet.add((0x0451, "\u0435")) # CYRILLIC SMALL LETTER IO
# Symbols of "Letterlike Symbols" U... | 0679077141d573a4f841edf76d0b48afa0fc371f | 22,570 |
def get_points_dict(encounters, applied=None):
"""given a queryset contain encounter objects, return a dictionary of
tagids and thier associated lat-longs. The order of the lat-long
should appear in chronological order that is consistent/determined
by observation date.
returns dictionary of the fo... | 48bae54fa4f2956afedd6910977bab286a6ef092 | 22,573 |
def hot_fix_label_issue(measurements: list) -> list:
"""
Aligns measurement labels with upper and lower case letters.
:param measurements: List of measurements that could contain labels with upper case letters.
:return: List of measurements only containing labels with ... | 7635838dbc4cae00d3803bb3d9ddcccf7872037f | 22,574 |
def two_oldest_ages(ages):
"""Return two distinct oldest ages as tuple (second-oldest, oldest)..
>>> two_oldest_ages([1, 2, 10, 8])
(8, 10)
>>> two_oldest_ages([6, 1, 9, 10, 4])
(9, 10)
Even if more than one person has the same oldest age, this should return
two *distinct*... | 38944082fdf1ca44ff1813b9570dcb0377f40960 | 22,578 |
def replace_pad(l, new_symbol='-'):
"""<pad> refers to epsilon in CTC replace with another symbol for readability"""
new_l = []
for x in l:
if x == "<pad>":
new_l.append(new_symbol)
else:
new_l.append(x)
return new_l | 94671a5d035a4ce2fae1f26e65c52ad55e4dba6c | 22,579 |
import random
import string
def get_random_string(digit=8):
""" for Cache Control Hash """
return ''.join([random.choice(string.ascii_letters + string.digits) for i in range(digit)]) | df504710188be247ebad0c144ce8b8f6954c3423 | 22,580 |
def getLemma(line):
"""
retreves the second word in a line in the coha corpus, or nothing if
given an empty line
"""
if line == "":
return ""
s = line.split("\t")
return s[1] | 34c51925d6a9d3908bf8b3114256e50ae3712467 | 22,581 |
from typing import Optional
import os
def get_template(
path: Optional[str] = None,
platform: Optional[str] = None,
command: Optional[str] = None,
yang: Optional[str] = None,
misc: Optional[str] = None,
):
"""
Function to locate template file and return it's content
**Attributes**
... | 35336707920339021e7443fba3a4d6a733cef498 | 22,582 |
import re
def _regex_search(pattern: str, string: str, group: int):
"""Shortcut method to search a string for a given pattern.
:param str pattern:
A regular expression pattern.
:param str string:
A target string to search.
:param int group:
Index of group to return.
:retur... | c703ac3eed3cbb981586b5a950f071c8535f32a5 | 22,583 |
import json
def jsonString(obj, pretty=False):
"""Creates a json object, if pretty is specifed as True proper
formatting is added
Args as data:
obj: object that needs to be converted to a json object
pretty: Boolean specifying whether json object has to be formatted
Returns:
JS... | 7fb621029ee509240dfd46bc641dcde34c87170c | 22,584 |
def calculateConsensus(u, d, t, U_sum, D_sum):
""" Calcluate consensus score. This is a heuristic for the percentage
of the community who finds a term useful. Based on the observation
that not every user will vote on a given term, user reptuation is
used to estimate consensus. As the number of vot... | fddf0708ba8ed2bba7c6351f8b2b1451c56caee9 | 22,585 |
def newStats():
"""Allocate and initialize an new stats object.
Returns:
Status array for tabulation."""
return {
'emailID': None,
'type': None,
'recipients': 0,
'opened': 0,
'clicked': 0,
'converted': 0,
'unsubscribed': 0,
'numberOfL... | 70dbcbf91caf6b3978155c4d896253d8fb7b60d3 | 22,586 |
import struct
def read_plain_int96(fo):
"""Reads a 96-bit int using the plain encoding"""
tup = struct.unpack("<qi", fo.read(12))
return tup[0] << 32 | tup[1] | 39d924fe211a17192b4b3158340d40b3f28948d1 | 22,587 |
import typing
def _simple(item: typing.Any) -> bool:
"""Check for nested iterations: True, if not.
:param item: item to check for repr() way
:type item: typing.Any
:return: use repr() iver item by default
:rtype: bool
"""
return not isinstance(item, (list, set, tuple, dict, frozenset)) | c02443c0bf75de321f5af68b1e4c45a1348113c0 | 22,588 |
def get_common_date_pathrow(red_band_name_list, green_band_name_list, blue_band_name_list):
"""
:param red_band_name_list:
:param green_band_name_list:
:param blue_band_name_list:
:return:
"""
red_date_pathrow = [ '_'.join(item.split('_')[:2]) for item in red_band_name_list]
green_date_... | a5ede92c0d8d8ca95d173e23179e4c3ec0d4c1c5 | 22,589 |
def computeAirProperties(T, p, pInhPa=False):
""" Calculates air density in kg/m3 and viscosity in m2/s given pressure
in mmHg and temperature in deg C. Can also specify pressure in hPa with the flag."""
mmHgTohPa = 1.3332239
if pInhPa:
p = p/mmHgTohPa
# from engineering toolbox:
# ... | 645db891cc775bbd1702a8ee437a2fa1fe9b62a3 | 22,590 |
import re
def tags_to_dict(doc):
"""Process the tags from a single document and return a dict.
Assumes a tag schema with the fields in `fields`. Boolean values are represented as '0' and '1'.
Also retrieves the `country` and `language` fields as tags if they are present in the document.
"""
# Ini... | a7e40a669b3f59a9226cef97e79b47adb69e7474 | 22,591 |
def check_default_attack_params(args_):
"""
This function is responsible for setting the default parameters of the
adversarial attacks if no values are provided. A full description of the
default parameters can be found in the supplementary of our paper.
"""
# Model
if args_.replicate:
... | 3ca98d2713cf1ff18d6c596bd71d307e046796e2 | 22,592 |
def load_card(data, schema):
"""Validate that the card is correctly formed.
Parameters
----------
data : `dict`
raw card data
schema : `dict`
card schema dictionary
Returns
-------
`dict`
card dictionary
Raises
------
ValueError
if data is m... | 236e3aca87b14fa0bb8792a11a94b7852d0c5678 | 22,593 |
def getSpkrs(comboSplitSegs, name_type):
"""
This function returns the list of ground truth speakers.
Inputs:
- comboSplitSegs: list of ground truth and diarization segments after all iterations have reduced it to
non-overlapping segments with a constant number of speakers in each... | 0279a30bbd12b41672a608d0a68d35e013b185e5 | 22,594 |
def readonly(label, value):
"""Return HTML markup for a readonly display like a form input."""
return {"label": label, "value": value} | c153ae42b074dea68101ca2e3abce03d1ed6c552 | 22,596 |
def course_str(course):
"""Format course as a string."""
return (
f"[{course['pk']}] {course['name']} "
f"{course['semester']} {course['year']}"
) | a9b1d6663ab18da220eceedc3c2319f9da80a08c | 22,599 |
import functools
def loss_function_for_data(loss_function, X):
""" Get a loss function for a fixed dataset
Parameters
----------
loss_function : function
The loss function to use. The data parameter for the function must
be `X`
X : coo_matrix
coo_matrix of data to apply l... | 782d050ed313146d9cdae38b7e63ed9dd287e3cc | 22,600 |
import numpy
def cov_flat2polidx(cvc, parity_ord=True):
"""
Convert flat array covariance matrix (visibilities) to polarization
component indexed array covariance matrix.
Parameters
----------
cvc : array_like
Covariance cube to be converted. Shape should be (..., 2*N, 2*N),
w... | 8cbac455141693bb0b8261c4a52ad9e83f509583 | 22,602 |
def get_app_specific_information(json_list_of_transactions):
"""Function that extracts the application through which the venmo
transaction was made (ie iPhone app, desktop, etc) and stores
each type in a table in the venmo transactions database."""
apps = []
# Only extracting app information
... | 96610d947d11965b12935a29f86c56dd0b57b740 | 22,603 |
import typing
def encoded(string: typing.Union[str, bytes], encoding='utf-8') -> bytes:
"""Cast string to bytes in a specific encoding - with some guessing about the encoding.
:param encoding: encoding which the object is forced to
"""
assert isinstance(string, (str, bytes))
if isinstance(string,... | d00a1b857dd80533d1f269a5ef3961cb98e68095 | 22,606 |
def bin2dec(x):
"""
Returns the binary input into a valid decimal number
Parameters
----------
x : Integer
Data in the binary format
"""
# print(type(x))
dec = 0
for i,j in enumerate(x):
dec += j<<i
return dec | 624ac298487a89bc2822f7fc1442a4d89af4f6b3 | 22,607 |
def get_nested_h5_field(h, fields, resolve_value=True, is_matrix=False):
"""
Meant to be a replacement for _extract_time_from_disk
Attributes
----------
h : HDF5 group
fields : list or string
"""
if not isinstance(fields, list):
fields = [fields] # string to list
for key... | b7656734bcd67e15b4ef9fcc68d267a613a3fdc1 | 22,608 |
import os
import subprocess
def _download(target_path, name, url):
"""
Downloads the playlist `name` found at `url`.
Returns the path to the directory that the playlist
was downloaded to.
Note that this function makes no guarantees
at all that it actually managed to do this.
"""
path ... | f04f30b55500b1df198538d9f999960dad0ea27d | 22,609 |
def time_duration_formatter(x):
"""Format time duration in seconds
"""
mm, ss = divmod(x, 60)
hh, mm = divmod(mm, 60)
dd, hh = divmod(hh, 24)
res = ''
if dd:
res += '%dd ' % dd
if dd or hh:
res += '%dh ' % hh
if dd or hh or mm:
res += '%dm ' % mm
res += '... | a0b28b2dd6cd81cb297b2b1dbbc184ff1be896b8 | 22,611 |
def get_keys_from_post(request, *args):
"""Get a tuple of given keys from request.POST object."""
return tuple(request.POST[arg] for arg in args) | f504a784849470405dbb6022bc0b7ce877caceda | 22,612 |
async def some_async_function(value):
"""A demo async function. Does not do any actual I/O."""
return value | 9324669acd9955095e12c28acc09cf0b7d68d767 | 22,613 |
import json
import hashlib
def compute_caching_hash(d):
"""Generate a hash from a dictionary to use as a cache file name
This is intended to be used for experiments cache files
"""
string = json.dumps(d, sort_keys=True, ensure_ascii=True)
h = hashlib.sha1()
h.update(string.encode('utf8'))... | 140a68c2f349fb5f3db6d48a24c16cc22a215bb0 | 22,614 |
def slopeFromVector(v):
"""
Return the slope of a vector from a QVector2D object.
"""
if v.x() == 0.0:
return v.y()
return v.y() / v.x() | 26d33063f84b889ee80868758eb7d15d9abf7dae | 22,615 |
def abstract_class_property_A(**kwargs):
"""
Decorator function to decorate objects with abstract
class properties. Leaves behind another decorator
that takes a class as its input.
"""
def abstractor(WrappedClass):
class PropertyWrapper(WrappedClass):
"""
A Wra... | 3c548e81b706e4cc3c78f1a49f513e5e206da0e2 | 22,616 |
import re
def uncamelcase(s,separator=" "):
"""
EXAMPLES::
sage: sage.categories.category_with_axiom.uncamelcase("FiniteDimensionalAlgebras")
'finite dimensional algebras'
sage: sage.categories.category_with_axiom.uncamelcase("JTrivialMonoids")
'j trivial monoids'
sage... | d550489954cbced9970b5973fcdef1c9c060a623 | 22,617 |
import random
def rnd_start(seq,murate,inrate,delrate):
"""Random mutation/indel start points for Poisson and Guassian processes"""
_l=len(seq)
if murate>0:
if _l>(1/murate):
_mustart=max(0, round((1/murate)*random.random()))
else:
_mustart=0
else:
_mustart=float('Nan')
if inrate>0:
if _l>(1/inrat... | e768a5f146510f157fd1e0dc367370c1c45a8303 | 22,618 |
import os
def ignorable_name(fn):
"""Filter out recognized pseudo-file names."""
if fn is None:
return False
return os.path.basename(fn) in [".", "..", "$FAT1", "$FAT2", "$OrphanFiles"] | d8bb710490d1d31eda5a0050aeb0a7789aa6f6bf | 22,619 |
def validation(model, val_fn, datagen, mb_size=16):
""" Validation routine for speech-models
Params:
model (keras.model): Constructed keras model
val_fn (theano.function): A theano function that calculates the cost
over a validation set
datagen (DataGenerator)
mb_size... | 14b1465ec9934f95b96f2f019cc83a42e8c25cc7 | 22,620 |
def sumevenfib(N):
"""
N is a positive number
This function will add up all even fibonacci numbers that do not exceed N
We use the convention that F_0 = 0, F_1 = 1,...,F_3 = 2
Note that F_3k is the subsequence of even Fibonacci numbers
"""
F1 = 1
F0 = 0
S = 0
while F0 <= N:
S += F0
F3 = 2*F1 + F0
F1 =... | 7b1949fa72e4595265bad5d5b2354f25c8a83bbc | 22,622 |
import collections
def _append_cell_contents(notebook):
"""Appends prior cell contents to a later cell dependent on labels
This function will iterate through a notebook and grab all cells that have a
label and add them to any cell that references that label (i.e., has the label
in its ref_labels list). Each ... | fc9d15d9c351e55a36201aae889e08b044c0ca9b | 22,624 |
import socket
def get_local_addrs():
"""Return all of the local IP Addresses."""
return [addr[4][0] for addr in socket.getaddrinfo(socket.gethostname(), None)] | 870114f53fdbbc631f992c731a9e75c2755d5326 | 22,625 |
def change_op(instructions, i, new_op):
"""
Return a copy of the `instructions` where the operation at index `i` is changed to `new_op`
"""
# Store the value of the argument at index `i` in the instructions
_, arg = instructions[i]
# Make a copy of the instructions list
modified = instructio... | 3a2d6f690a341b2941a9feb20e8a060bb04cec04 | 22,626 |
def _intersection(A,B):
"""
A simple function to find an intersection between two arrays.
@type A: List
@param A: First List
@type B: List
@param B: Second List
@rtype: List
@return: List of Intersections
"""
intersection = []
for i in A:
if i in B:
... | ad0be8b29900d7238df93309f5b9ad143e60ba0f | 22,629 |
def scan_ioat_copy_engine(client, pci_whitelist):
"""Scan and enable IOAT copy engine.
Args:
pci_whitelist: Python list of PCI addresses in
domain:bus:device.function format or
domain.bus.device.function format
"""
params = {}
if pci_whitelist:
... | 0723727cc9fe94e707aa323da498d90d99c15104 | 22,631 |
import os
def get_mysql_config():
"""Return the the parsed connection string as dict. I.e. can be used in MySQLConnectionPool as:
mysql_config = dblib.get_mysql_config('DATA_QUALITY')
mysql_pool = MySQLConnectionPool(pool_size=1, **mysql_config)
"""
# Return a configuration dict configurations
... | 33641d6b10945b4436f3fcc14c7d88fca1883b5b | 22,632 |
from typing import List
import os
import subprocess
def bamfilter(bam:str, regions:List[str],outputdir:str):
"""
从bam文件中抽提出比对到ref:start-end的read信息
:param bam:需要过滤的bam文件路径
:param regions:提取区域列表
例如:['edge1:0-10000','edge2']
:return: 过滤后的Sam文件路径
"""
outfile=os.path.join(outputdir,'tmp.sam... | 95c494b4f371125032e0b0eb643568a5bf304fd7 | 22,633 |
def compound_score(text, sia):
"""
This function computes VADER's compound score
of some text
Arguments:
text : (string)
sia: nltk.SentimentIntensityAnalyzer() object
Returns:
float between -1 and 1
"""
return sia.polarity_scores(text)['compound'] | 5cdf5b2f5cc87ef28c80dbea1f53eafda6286acf | 22,635 |
def even(n):
"""Builds a set of cycles that a graph with even vertices."""
assert n % 2 == 0
# Base case for complete graph such that V = {1, 2, 3, 4}.
cycles = [[1, 2, 3], [2, 3, 4], [3, 4, 1], [4, 1, 2]]
for i in range(6, n + 1, 2):
a, b = i, i - 1
# Use edges (a, 1), (a, 0), (b... | 38792c058c8f8d045eeac2bb08d7d78abda12868 | 22,637 |
def _replaceRenamedPairMembers(kerning, leftRename, rightRename):
"""
Populate the renamed pair members into the kerning.
"""
renamedKerning = {}
for (left, right), value in kerning.items():
left = leftRename.get(left, left)
right = rightRename.get(right, right)
renamedKernin... | cdfa789f1f903276cacb798ee039181847b4922e | 22,638 |
def api_url(query_type):
"""
Method Will return appropriate URL based on query type
"""
type_url_mapping = {'Email Sender': 'bademail', 'Email Recipient': 'bademail', 'Domain': 'baddomain', 'IP Address': 'v2.0/ip'}
return type_url_mapping[query_type] | d9fd0057f9ba3dfa1526ddc6c15a7aafdaeab496 | 22,639 |
def recursively_split_version_string(input_version: str, output_version: list = []):
"""
Splits a version/tag string into a list with integers and strings
i.e. "8.0.0.RC10" --> [8, '.', 0, '.', 0, '.RC', 10]
Input:
input_version (str): a version or tag i.e. "8.0.0.RC10"
output_versio... | b5e8be1d88d5113591e8199bbb39c89f803a20ea | 22,640 |
def get_dict(size, key_prefix, value_preix):
"""
Creates a dictionary with size numbers of keys.
:type size: int
:type key_prefix: str
:type value_preix: str
:rtype: dict[str, str]
:param size: The amout of keys the dictionary must contain.
:param key_prefix: A value to be added before... | ead26cf740f9e4f0f9a17cd748bf13acb6277183 | 22,642 |
import types
import importlib
def import_pickle() -> types.ModuleType:
""" Returns cPickle module if available, returns imported pickle module otherwise """
try:
pickle = importlib.import_module('cPickle')
except ImportError:
pickle = importlib.import_module('pickle')
return pickle | 5d876a41f875e8b57c526a271c94b92a36d991ca | 22,643 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.