content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
from dateutil import tz
def local_time(dt):
"""
Convert a datetime.datetime object to a timezone-aware datetime.datetime
in the users local timezone.
:param dt: A datetime.datetime object.
:returns: A timezone-aware datetime.datetime object in the users local
timezone.
"""
i... | 73d66c916fe7c849184181faf781715535da3166 | 31,654 |
def test_generator_frame_cycle():
"""
>>> test_generator_frame_cycle()
("I'm done",)
"""
testit = []
def whoo():
try:
yield
except:
yield
finally:
testit.append("I'm done")
g = whoo()
next(g)
# Frame object cycle
eval('... | d965091e4347f636a9c2a93c5a00bdc96b3ddce5 | 31,656 |
def get_notes():
"""
:return: a list containing all notes
"""
with open('data/notes.txt') as file:
notes = [line[0] for line in file]
return notes | bf4a3ec34b484d5e945117252ecb51a63685cb34 | 31,657 |
def _lps(maxlen):
"""
Brute force regular expression pattern for a length prefixed domain name component.
"""
return BR'|'.join(BR'\x%02x[a-z0-9\-\_]{%d}' % (d, d) for d in range(1, maxlen + 1)) | 1a527e7466ea2fc9fd2a331b63ece0c610b39ba4 | 31,658 |
def read_xml_tree(elt):
""" return xml tree `elt` """
children = elt.getchildren()
if len(children):
children_dict = {}
for child in children:
children_dict[child.tag] = read_xml_tree(child)
return children_dict
else:
return elt.text | 7e9d951ca5bf346fc1b1e7c649d7e5570aa9df81 | 31,660 |
def check_build_success():
"""Check build is successful and there are no warnings."""
def check(status, warning):
assert "build succeeded" in status.getvalue()
warnings = warning.getvalue().strip()
assert warnings == ""
return check | 6f0affe4ff4bbf1781ef931bb139348b336f884a | 31,661 |
def _getattr(obj, attr):
"""Try to get the attribute as if the object is a Namespace, but if it
fails, get it as it if were a key from a dictionary. This allows us to
play nice with both Namespace objects (method='create') as well as
dicts (method='yaml')
"""
try:
return getattr(obj, att... | c6f46800ad5fa339fdb3a0924678ade4f77de785 | 31,662 |
def _aggregate_counts(child_counts):
"""Return aggregated node count as int."""
if not child_counts:
return 1
elif len(child_counts) == 1:
return child_counts[0]
elif len(child_counts) == 2:
return child_counts[0] * child_counts[1]
else:
raise ValueError | a4b691341d7283b0800bffd3bc926b9ff71e1bdb | 31,663 |
def clean_10x_adata_var(adata):
"""cleans up adata.var (drops feature types columns that is Gene Expression
for all, genome col, sets gene_ids to index and gene_symbols to a column of
adata.var, remove index name.)"""
columns_to_drop = [
col for col in ["feature_types", "genome"] if col in ... | 24887824acd497d0afc321ba3483a7240c969ceb | 31,666 |
def from_datastore(entity):
"""Formats data from datastore
Datastore typically returns:
[Entity{key: (kind, id), prop: val, ...}]
This returns:
[ name, description, pageCount, author, review ]
"""
if not entity:
return None
if isinstance(entity, list):
entity = ... | 45b7b4690258b380bf7c7e69c631cf4f520559e2 | 31,667 |
import math
def round_sample(input_dataframe, frac=0.1, min_samples=1):
"""Sample X ensuring at least min samples are selected."""
num_samples = max(min_samples, math.floor(len(input_dataframe) * frac))
return input_dataframe.sample(num_samples) | 1e6279a9e069929bdf9fef931b00d9d99a9b6f0c | 31,668 |
def r_e_KimKim(N_s):
""" effective drop radius """
r_e = (4*N_s)**(-0.5)
return r_e | 0c85c71f29e320809da42e071bccedfff4fbb703 | 31,670 |
import time
def time_sorting(sort_fxn, data):
""" Record the run times for each run of a sorting function
:param sort_fxn:
The sort function of form sort_fxn(vec) to call
:param data:
A list of vectors to sort
:returns:
A list of run times to sort each element in data
"""
... | 5d7f2e83ec2a74202264447e24fb43dbd03ab83c | 31,671 |
def null():
"""
return an empty generator
"""
def _null(input):
return iter([])
return _null | c1ac07f1270439105350e672c6238c2e0dde46b2 | 31,672 |
def GetLostDistributionArr(aprtNodes, bunch_lost):
"""
Function returns the array with [aptrNode,sum_of_losses]
The sum_of_losses is a number of particles or the sum of macro sizes if the
particle attribute "macrosize" is defined.
"""
lossDist_arr = []
aprtPos_arr = []
#--- first we will sort apertures accordi... | b239bdf94e779e9c5c67cf0d1b98ab5a64800158 | 31,673 |
import os
def get_file_extension(fname):
"""Returns the given file's extension as a string, . included"""
_, ext = os.path.splitext(fname)
return ext | c814410e91e354383d3274d48e1e8f42b63a7e7a | 31,675 |
def caffe_compute(transformed_image,
caffe_net=None, output_layers=None):
"""
Run a Caffe network on an input image after preprocessing it to prepare
it for Caffe.
:param PIL.Image pimg:
PIL image to be input into Caffe.
:param caffe.Net caffe_net:
A Caffe network ... | 09d6581a5db5e184092742ae4296cc3310122507 | 31,676 |
import os
def get_districts(root_path):
"""
Start from the directory containing all the districts. A district is assumed to be any
directory in root_path.
"""
return (os.path.join(root_path,directory) for directory in os.listdir(root_path) if os.path.isdir(os.path.join(root_path,directory))) | bb201a746fab9d2a64b5ef2efeeb80835639b40d | 31,677 |
def kstairs(n, k):
"""Give the number of ways to take n steps, given that at each step, you
can choose to take 1, 2, ... k-2, k-1 or k steps.
>>> kstairs(5, 2)
8
>>> kstairs(5, 5)
16
>>> kstairs(10, 5)
464
"""
if n == 0:
return 0
if n <= k:
return 2**(n-1)
... | 07484fe1186967ba892d3d4e3284962d93a36b91 | 31,678 |
import random
def rand(request):
"""agent item python.random[lower, upper]"""
if len(request.params) != 2:
raise ValueError('Invalid number of parameters')
l = int(request.params[0], 10)
u = int(request.params[1], 10)
if l > u:
raise ValueError('Incorrect range given')
return random.randrang... | fb1aa42eb3dbd3dea9615e5fe53fbcd21bcab62b | 31,679 |
def _compute_derived_var(var_key, derived_vars_dict, nc_file):
"""Call the first valid derivation from the derived_vars_dict dict."""
derived_vars = derived_vars_dict[var_key]
# store a list of all inputs visited, so if Exception, we get a good msg.
derived_var_inputs = []
# get the first function ... | a77253e33393a1515f58867a5a5e496d421804f7 | 31,680 |
def get_corr_reg_name(curr_name: str) -> str:
""" Function that corrects wrong regions names """
# Specjalny wyjatek, bo w danych PRG jest powiat "JELENIOGORSKI", a od 2021 roku powiat ten nazywa sie "KARKONOSKI",
# wiec trzeba to poprawic
if curr_name == "JELENIOGORSKI":
return "KARKONOSKI"
... | 7fb0709868e66e73a0d736f3a0860fefbb0d6cd0 | 31,681 |
def este_corect(expresie):
"""Verifică dacă toate parantezele sunt folosite corespunzător.
"""
stk = []
for char in expresie:
if char == '(' or char == '[':
stk.append(char)
else:
if not stk:
return 0
else:
alfa = stk.po... | a27881687b0afa69e2a0a8192f79b6b81b176de0 | 31,682 |
import os
def api_key():
"""the api key"""
return os.environ['DF_API_KEY'] | 3c9b58f9ddab3553fce8f701aa45f22f56e7364d | 31,684 |
def bin_names_to_coords_filepath(query_bin, ref_bin, results_dir):
"""
prepare a file path for results
:param query_bin: bin number 1 name/filepath (reference sequence)
:param ref_bin: bin number 2 name/filepath. (query sequence)
:return:string like Acidovora-69x_Ga0081644_to_Acidovorax-79_Ga008165... | 946b788acaf776322cc02aaa3b6740f198b61b4d | 31,685 |
from typing import Tuple
import re
def parse_hp_condition(hp_condition: str) -> Tuple[int, int, str]:
"""
HPと状態異常を表す文字列のパース
:param hp_condition: '50/200' (現在HP=50, 最大HP=200, 状態異常なし) or '50/200 psn' (状態異常の時)
:return: 現在HP, 最大HP, 状態異常('', 'psn'(毒), 'tox'(猛毒), 'par', 'brn', 'slp', 'frz', 'fnt'(瀕死))
"... | cbe9ec75efbae1b144836cc8129fdc3256e0dccf | 31,686 |
def genlen(gen, ldict, name):
"""A bit of a hack to get the length of a generator after its been run.
ldict = {}
list(genlen((i for i in range(3)), ldict, 'mylen')
assert(ldict['mylen'] == 3
"""
ldict[name] = 0
def f():
while True:
yield next(gen)
ldict[name... | 6d5ec86ed71b1fc97f796a8dc72db230f01af7c1 | 31,688 |
import win32api
import sys
def clear_dll_directory():
"""
Push current Dll Directory. There are two cases that
can happen related to setting a dll directory:
1: Project is using different python then Desktop, in
which case the desktop will set the dll directory
to none for the project's... | 28c052002a410f25d56359a54a46fa22bbb0717f | 31,689 |
from typing import List
from typing import Dict
def dictify(data, keys: List, val: Dict) -> Dict:
"""Turns a flat :class:`NodeTree` dictionary into a nested dictionary.
Helper function to generate nested dictionary from list of keys and value.
Calls itself recursively.
Arguments:
data (... | e7c0111f67b7755a6e28d6264d8f7b300e94273c | 31,690 |
def normalize(x, min_x, max_x):
"""
Goal of this function is to normalize passed data given the min and max of the data to fit in 0 - 1
:param x: Array Like structure: The data to be normalized
:param min_x: Float like: The minimum of the data set
:param max_x: Float like: The maximum of the data set
:return: A... | 4fbbaf06017cedd14eca3e7f0639d9002b231be4 | 31,691 |
import textwrap
import html
def pretty_text(data):
"""Unsescape the html characters from the data & wrap it"""
if data is not None:
return textwrap.fill(html.unescape(html.unescape(data)), width=60)
else:
return "" | f5baf58394b8578b26ad3cb95aff26867bc5f748 | 31,692 |
def calculate_assets(df, choice, transactions):
"""Calculate the worth of the portfolio
Args:
df ([type]): [description]
choice ([type]): [description]
transactions ([type]): [description]
Returns:
[type]: [description]
"""
close_column = "close_" + choice
quanti... | 85fea50cb8740799f675695cf836adb153090f6a | 31,693 |
def precision_at_position_1(sort_data):
"""
Evaluate precision
"""
score = 0
if sort_data[0][1] == 1:
score = 1
return score | bb07288836ef127c3122a8065a7cf14952c642aa | 31,694 |
def count_recursive(contents_per_bag, bag_list):
"""
Count number of nested bags from the given list
:param contents_per_bag: per-bag mapping
:param bag_list: list of bag to inspect
:return: number of bags
"""
nested_bag_qty = 0
for bag in bag_list:
nested_bag_qty += 1
... | d48e317ee73bf0f18021d27bc9857a3ad898759c | 31,697 |
def sort_list(doc_name: str, *vart):
"""Checks if a string contains the identifiers in vart. If it does return the initial string, if not return None."""
for var in vart:
if var.lower() in doc_name.lower() and "(old" not in doc_name and "~" not in doc_name:
return doc_name | 92caeaa253daa4dc1b9fac5acda4e38963a984bf | 31,699 |
def from_homogeneous(vectors, at_infinity):
"""Converts vectors from homogeneous (from point or direction)."""
if at_infinity:
return vectors[:-1,...]
else:
divided = vectors / vectors[-1,...]
return divided[:-1,...] | 002c7fe26fa5100f4b21a373b8506e4960081b4c | 31,700 |
def rotl(x, count):
"""Rotates the 64-bit value `x` to the left by `count` bits."""
ret = 0
for i in range(64):
bit = (x >> i) & 1
ret |= bit << ((i + count) % 64)
return ret | 6bba2bf109f9ddd0f9b4c202c3192e14a0cd625f | 31,701 |
from typing import Union
import re
def _header_line(line: str) -> Union[None, tuple]:
"""
If it is detected as header line, returns its header level and caption.
Otherwise returns `None`.
"""
m = re.match(r"^(#+)(.+)", line)
if m:
level = len(m.group(1))
caption = m.group(2)
... | 0704ff88623eb66caef6a0473047f17a152701f4 | 31,702 |
import random
def flip():
"""Flip a coin."""
return random.choice(['Heads!', 'Tails!']) | bced383b31c62fef758d8522ecf1fef49d4f5fc1 | 31,703 |
from typing import Optional
import re
def get_nb_query_param(nb_url_search: str, param: str) -> Optional[str]:
"""
Get a url query parameter from the search string.
Parameters
----------
nb_url_search: str
The URL search string
param: str
The parameter name to search for
... | 28b36c630879a16dbca38a9739fe92b1d54aa5ca | 31,704 |
def _create_padded_message(message):
"""Pad the message."""
fill_size = len(message) + 16 - len(message) % 16
return message.zfill(fill_size) | fce0e75c10eb7bb9f16513926535436c1337bdcc | 31,705 |
from typing import Tuple
def nmea_coord_to_lla(
lat_str: str, lat_cardinal: str,
lon_str: str, lon_cardinal: str,
alt_str: str
) -> Tuple[float, float, float]:
"""
converts the nmea quintuplet (4811.7605691,N,01137.1631304,E,494.6412) to decimal gps coordinates
:param lat_str: latitude in nmea... | 1f9a8dc6bb05309957e27eb9ed72df953abca386 | 31,706 |
import time
def UnixTimeCurrent():
"""
Retrun: float
現在時刻のUnixTime
"""
unixime = time.time()
return unixime | f045d94e64e9eb6bdd564f8773d92dbc410241fa | 31,707 |
def quick_sort(arr):
"""
Breaks down array into smaller sections
then swaps subsections into order
uses local partition() and sub_quick_sort(),
which assumes whole array should be sorted
"""
def partition(arr, low, high):
i = low - 1
pivot = arr[high]
for j in range(... | be060f8855d459b9cad0fc980675f035e81b00d9 | 31,708 |
def MinMaxAvg(data):
"""
Given a list of values, the MIN/MAX/AVG value is returned in a Dictionary
:param data: List of data of the same kind
:type data: int[] or float[]
:returns: a dictionary { 'min':min,'max':max,'avg':average }
:rtype: dictionary
.. seealso:: Stats
"""
min_val = data[0]... | 0373da1ab3dfa36453669d0f6f33b8541e33eb52 | 31,709 |
def ansi(code_r, bold=""):
"""ANSI Colours for printing (Because why not?)
Code can be 30-37. In order of colours,
these are black, red, green, yellow,
blue, magnenta, cyan, and white.
After every colour print, print ansi(0) to clear colour attributes.
(Copied from psilib.utils.ansi)
"""
... | 43bfedf6e1aba69f2b2bacd928701547bdd4c4ad | 31,710 |
def createGeoJSON(features):# [[coord1,cord2,cord3,...], row, column]
""" createGeoJSON(features)
From structure as [[coord1,cord2,cord3,...], row, column]
creates a new geoJSON used for Surface Unit
Parameters
----------
features : List
Structure as [[coord1,cord2,cord3,...], row, ... | 80c25e5c094d704d4c9d12f5ebdfe556fbe44f71 | 31,712 |
from pathlib import Path
def read_html_file(file_path):
"""Reads the contents of an HTML file."""
html_file = Path(file_path)
if html_file.exists() and html_file.is_file():
with html_file.open() as temp_file:
contents = temp_file.read()
return contents
return None | 260b56d895a42696ff04badf62d58268b4f24c0a | 31,713 |
def check_inclusion_4(s1: str, s2: str) -> bool:
"""
optimize method 2
"""
len1, len2 = len(s1), len(s2),
if len1 > len2:
return False
diff = [0] * 26
for i in range(len1):
diff[ord(s1[i]) - ord('a')] -= 1
diff[ord(s2[i]) - ord('a')] += 1
diff_count = 0
for cn... | d471dc1aca049ea07c1203c7c3bff472f6d6a4ac | 31,715 |
def rsa_encrypt(data: int, e: int, n: int) -> int:
"""
encrypt data with the rsa cryptosystem (rsa_fernet_encrypt is more secure and supports more data)
:param data: the plaintext
:param e: public key (e) of the other person
:param n: public key (n) of the other person
:return: the ciphertext
... | 58f39297a594a1ed224b0ea09b81e7f988c2fe54 | 31,716 |
from typing import List
def is_armstrong(number: int) -> bool:
"""Return True if the given number is an armstrong number."""
digits = list(map(int, str(number)))
exponent = len(digits)
powers: List[int] = [base ** exponent for base in digits]
return sum(powers) == number | 2c84a53e439368a403f75066e4fbdca119d68f2f | 31,718 |
def quote_identifier(identifier, sql_mode=""):
"""Quote the given identifier with backticks, converting backticks (`)
in the identifier name with the correct escape sequence (``) unless the
identifier is quoted (") as in sql_mode set to ANSI_QUOTES.
Args:
identifier (str): Identifier to quote.
... | c032e6e597795b74b3a25c8529074684fc4ab619 | 31,719 |
from typing import Counter
import re
def build_wordlist(input_file):
"""Build a wordlist Counter from lines of the corpus file"""
wordlist = Counter()
for line in input_file:
words = re.findall(r'\w+', line)
wordlist.update(words)
return wordlist | 575a6fb872750dc83ac8b6f8b66f4b779962b71d | 31,720 |
def check_max_amplitude(st, min=5, max=2e6):
"""
Checks that the maximum amplitude of the traces in the stream are ALL
within a defined range. Only applied to counts/raw data.
Args:
st (obspy.core.stream.Stream):
Stream of data.
min (float):
Minimum amplitude for... | 3043ac4e29904779578c52dfb1c7b79f1cf13ad1 | 31,721 |
def getvalsfromparams(cosmo, **params):
"""
TO DO
provide a general function to pass values into cosmo and params
"""
return None | 9ce20795bcfbac8ea78241701acab907af73b387 | 31,722 |
def _calc_corr(dbal, benchmark_dbal, window):
"""
Calculate the rollowing correlation between two returns.
Parameters
----------
dbal : pd.Series
Strategy daily closing balance indexed by date.
benchmark_dbal : pd.Series
Benchmark daily closing balance indexed by date.
windo... | 4ae0ec7184774a6500eecafa91467daee7800ca1 | 31,724 |
def iben_tutukov1984(history, al=1):
"""
CE formalism from
`Iben & Tutukov 1984, ApJ, 284, 719 <https://ui.adsabs.harvard.edu/abs/1984ApJ...284..719I/abstract>`_
Required history parameters:
- star_1_mass
- star_2_mass
- he_core_mass
- binary_separation
:param histo... | 6eef41463eef83668902c74f748258a39e8b919f | 31,725 |
import os
import re
def convert_frame_format(path):
"""Convert format like '%04d' into '####' padding format"""
head, tail = os.path.split(path)
def replace(match):
count = int(match.group(2))
return match.group(1) + "#" * count + match.group(3)
tail = re.sub("(.*)%([0-9]*)d(.*)", re... | 5764e3edc74554a14bb1632243469f59409bbb95 | 31,726 |
def _count_words(text):
"""
Count words in a piece of text.
"""
if isinstance(text, (list, tuple)):
text = "\n".join(text)
return len(text.split()) if text else 0 | 473b91262f27400b8ae7c95a819eb35288cb1dc4 | 31,727 |
def parse_monitors(monitors):
"""
Given a list of dictionaries, returns a list of hosts that
can be used in an ansible inventory. These host lines can include
host variables as well.
For example, monitors in this format::
[
{"host": "mon0.host", "interface": "eth0"},
... | 5fc05ca5713bb188c022b0f070bf63f97162174f | 31,729 |
import json
def template_json():
"""Return a Template JSON."""
return json.loads(
"""{
"name": "RVXXX1-T1-ID",
"subject": "Campaign 1",
"html": "<html>Body Test</html>",
"text": "Body Test"
}"""
) | 7d9208e30140c9c4d840e544305f60a59dc75573 | 31,730 |
import argparse
def parse_args():
"""Parse command-line arguments"""
parser = argparse.ArgumentParser()
parser.add_argument('-s', '--video-source', type=str, required=True,
help='Video stream source')
parser.add_argument('-t', '--requested-target', type=str, required=True,
... | f563dad7f27bcdfd35467e9b86f6ba5c95a3d371 | 31,731 |
def jump_stats(previous_jumps, chute_altitude):
"""Compare altitude when chute opened with previous successful jumps.
Return the number of previous jumps and the number of times
the current jump is better.
"""
n_previous_jumps = len(previous_jumps)
n_better = sum(1 for pj in previous_jumps if c... | f9b92c1355ca45b4bb8be77c0e446bc71cdae7fc | 31,733 |
from typing import Dict
import os
import json
def get_sample_cr(crd: str) -> Dict:
"""Get a dictionary with a sample of a CRD."""
valid_crd = ['robco_mission', 'robco_robot', 'robco_robottype']
if crd not in valid_crd:
raise ValueError('There is no sample for CRD "{}"'.format(crd))
path = os.p... | f48056719cf2a13b340d2c53425e36b75cdaf0af | 31,734 |
def random_string(stringLength=8):
"""
Generate a random string
Parameters
----------
stringLength : int, optional
length of the random string, by default 8
Returns
-------
str
random string
"""
strings = [
("PasséComposéquitue","Le PasséComposéquitue es... | 954c1e4481dc6584ccef40dfc1d52b8aaeede125 | 31,736 |
from operator import xor
def detect_secstruct_clash(i, j, secstruct):
"""
Detect if an EC pair (i, j) is geometrically
impossible given a predicted secondary structure
Based on direct port of the logic implemented in
choose_CNS_constraint_set.m from original pipeline,
lines 351-407.
Use ... | 2591bffd2f21266ace9371fee68f3ac729f3cc9d | 31,739 |
def _cg_update(d, x, Ap, p, r, rsold, eps):
"""
"""
# standard CG update
pAp = r.dtype.type(0.0)
for f in range(d):
pAp += p[f] * Ap[f]
# alpha = rsold / pAp
alpha = rsold / max(pAp, eps)
for f in range(d):
x[f] += alpha * p[f]
r[f] -= alpha * Ap[f]
rsnew = r... | e2002c5f1c1822984b94e3daf951c10850f980bf | 31,740 |
def gauss_sum(n):
"""Calculate sum(x for x in range(1, n+1)) by formula."""
return n * (n + 1) // 2 | 96d611e8975d163f1cc1cdf207f0930b5951d4a1 | 31,742 |
def _is_mobi(file_bytes: bytes) -> bool:
"""
Decide if a file is a MOBI/AZW3 file.
From ./se/vendor/kindleunpack/mobi_sectioner.py lines 49-53
"""
return file_bytes[:78][0x3C:0x3C+8] in (b"BOOKMOBI", b"TEXtREAd") | dcd1fb584b5a8c373fc5b453314ccbc9574b66ea | 31,743 |
def find_dataset(filename, dataset_id):
"""
:param filename : file containing dataset information.
:param dataset_id : dataset to be searched.
:returns: The path of the given dataset id.
"""
var_dict = {}
with open(filename) as l_file:
for line in l_file:
if not line.star... | 60ec4e70f893ef6fb13f3e33ba5bf01b69b6c05b | 31,744 |
from typing import Dict
from typing import List
import collections
import math
def calculate_tf_weight(tokens_dict: Dict[str, List[str]]) -> Dict[str, Dict[str, float]]:
"""Calculates tf weight"""
tf_dict: Dict[str, Dict[str, float]] = {x: {} for x in tokens_dict} # {doc_id: {token: tf}
for doc_id in tok... | 699d54a58403341fb82aca86a04c58c6c1735508 | 31,746 |
def remove_empty(rec):
""" Deletes sequences that were marked for deletion by convert_to_IUPAC """
for header, sequence in rec.mapping.items():
if all(char == 'X' for char in sequence):
rec.headers.remove(header)
rec.sequences.remove(sequence)
rec.update()
return rec | 57616d8fb35f6bf5c74d4271dfe709e87171932a | 31,747 |
def get_first(objs, default=""):
"""get the first element in a list or get blank"""
if len(objs) > 0:
return objs[0]
return default | 5932027019a52bc037b18fb3d594819c51ab3b75 | 31,748 |
import os
def get_default_pp_args():
"""Returns the default arg for the preprocessor in a format:
-I<path_to_the_fake_includes>
"""
this_file = os.path.realpath(os.path.dirname(__file__))
root_path = os.path.split(os.path.abspath(os.path.join(this_file)))[0]
include_path = os.path.join(root_p... | 510e1ec97479cb1d1f77b68f2c4180c8a26be0c5 | 31,751 |
import time
def timestamp():
"""
Returns a unix timestamp
:return:
"""
return int(time.time()) | 4e67a0ebce4d493405cd045e766962ee5d14bbeb | 31,753 |
def get_y_for_x(x: float, gradient: float, y_intercept: float) -> float:
"""
Linear equation, y = mx + c
"""
return (x * gradient) + y_intercept | f2e4226c159e74621ae8301d24ecc5bef85971f4 | 31,754 |
import os
import json
import logging
import sys
import subprocess
def getremote(override):
"""Get the remote server from ~/.pull-gitrc or the command line.
Verify that the remote is reachable, or quit.
The contents of ~/.pull-gitrc should look like this:
{"remote": "foo.bar.home"}
"""
if no... | 9652c49ccc5e014b85eb2824f46ac7f1f71aa5d9 | 31,755 |
def record(*fields):
"""Generate a class that only allows attr names contained in `fields`"""
class _Record(object):
def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
def __setattr__(self, name, value):
if name not ... | 869351e977a5d04dae6b593bec9760278aea94f0 | 31,756 |
from typing import Union
from typing import Dict
from typing import Any
from typing import List
import json
def deep_decode(j: Union[Dict[str, Any], List[Any], str]) -> Union[Dict[str, Any], List[Any], str]:
"""将str完全解析为json"""
if isinstance(j, dict):
j = j.copy()
for k, v in j.items():
... | 18700e2766d1d3d9266d8af2965e88dbbec30704 | 31,758 |
def open_bed_file(bed_file_name):
"""Open BED file of sequence overlaps"""
with open(bed_file_name) as f:
cores = [i.split() for i in f.readlines() if "CORE" in i]
return cores | be061068bc31215627919db46e9e86197c2e76a4 | 31,762 |
import math
def regularize(data):
"""Converts every non-numerical list value to zero which is useful for analysis later."""
for index, val in enumerate(data):
if math.isinf(val) or math.isnan(val):
data[index]=0
return data | ae38fa7a3a1f5bb6bfeba2ca4fbcfd5145f36ee8 | 31,763 |
import functools
def log(func):
"""
不带参数的装饰器
:param func: 被装饰的函数
:return: 增强(装饰)后的函数
函数也是对象,它有__name__等属性,但经过decorator装饰之后的函数,它们的__name__已经从原来的'now'变成了'wrapper'
内置的functools.wraps就是把原始函数的__name__等属性复制到wrapper()函数中
"""
@functools.wraps(func)
def wrapper(*args, **kwargs):
pr... | 3bd630339318afff62814466d966807541255d5b | 31,764 |
import re
def finditer_(log_file_path, regex, read_line=True):
"""
regex = '(<property name="(.*?)">(.*?)<\/property>)'
:param log_file_path:
:param regex:
:param read_line:
:param re_parse:
:return:
"""
with open(log_file_path, "r") as f:
match_list = []
if read_li... | 74f54279a71338ed3135a10a2caae11562bfc922 | 31,765 |
def _config_hint_generate(optname, both_env_and_param):
"""Generate HINT language for missing configuration"""
env = optname.replace('-', '_').upper()
if both_env_and_param:
option = '--' + optname.lower()
return ('Pass "{0}" or set the environment variable "{1}".'
.format(o... | 1a21ce609a4d209f06c6479eb848412be859a598 | 31,766 |
from typing import List
def padding_list(someList: List[str], N: int) -> List[str]:
"""Padding the list with <s> at the front and </s> behind
Args:
someList (List[str]): The list to be padded with
N (int): The amount of <s>, </s> to be padded
Returns:
List[str]: Padded list
"... | e8df315d715e5e1e4575b42da5f6ff1691107732 | 31,767 |
import logging
def get_logger():
"""
Configures and returns root logger.
"""
logger = logging.getLogger('root')
FORMAT = '[%(asctime)-15s %(filename)s:%(lineno)s] %(message)s'
logging.basicConfig(format=FORMAT)
return logger | 8910c417e6d15cf92ecfab1226c175a55b2e5108 | 31,769 |
import re
def split(re_, str_, flag=0, max_split=0) -> list:
"""支持正则分割
:param re_:正则表达式
:param str_:字符串
:param flag: re.search(re_, self.string, flag), 默认flag=0
:param max_split: 最大分割数量
"""
return re.split(pattern=re_, string=str_, maxsplit=max_split, flags=flag) | d1eb55819341a4c210069459aae6c200c401e83a | 31,770 |
import os
def resolve_file(dirname, basename, lookup):
"""
If a filename is unique, use it. If it is not,
check the parent directories until disambiguation is achieved.
"""
if basename not in lookup:
return None
reference_list = lookup[basename]
dirname_path = os.path.split(dirname... | 7f5b69d7ce4c2258f3f6a46c97107f8d8f068d3c | 31,771 |
import re
def _detect_base64(s):
"""Quite an ingenuous function to guess if a string is base64 encoded
"""
return (len(s) % 4 == 0) and re.match('^[A-Za-z0-9+/]+[=]{0,2}$', s) | 0c0e4d50c8687e70a4ac423ae88d57146f5f28cc | 31,772 |
from typing import OrderedDict
def create_message(message_id, sender, receivers, date_sent, subject, content):
"""
This method turns all the messages from the file into an ordered
list.
@param message_id The ID of the message
@param sender The sender of the message... | 11d6ce6b2ad0ef44405b3f68326c95812279eb2f | 31,773 |
def get_latent_and_log_weight_and_log_q(generative_model, guide, obs, obs_id=None, num_particles=1):
"""Samples latent and computes log weight and log prob of inference network.
Args:
generative_model: models.GenerativeModel object
guide: models.Guide object
obs: tensor of shape [batch_... | c37fcc7d028fddd48edd563eb5fcf75067bbcc95 | 31,774 |
def check_non_ascii(line):
"""Checks if a line contains a non ascii chars
Params:
line (unicode)
Returns:
true if line does not contain non ascii chars
"""
try:
line.encode('ascii')
return True
except UnicodeEncodeError:
return False | 9e9eebf5623000b27e3b2234ada4c2c5eaafad83 | 31,775 |
def az_rate(val):
"""Convert an integer value to a floating point angular rate."""
return val * 90. / 2**16 | 22dfd3cfcc04ec83dc5b6d845eb333de96cd5f7a | 31,776 |
def title():
"""Return a sample title string."""
return 'this is a title' | 1a1e9bf8024870812783d851994733f58de79a91 | 31,777 |
def cond(condition, expr1, expr2):
"""Marked for deletion.. Python2.5 provides this."""
if condition:
return expr1
else:
return expr2 | 2e46fe73a54ef87ba4e9ccf9071dcb73ebf360bf | 31,778 |
import os
def dsn_from_env():
"""Read DSN from test environment variables.
For testing postgresql configurations with passwords / nonstandard ports, you can set the environment variables:
* PGSU_TEST_HOST
* PGSU_TEST_PORT
* PGSU_TEST_PASSWORD
* PGSU_TEST_USER
* PGSU_TEST_databas... | 825a3dde56a93b9ac91cc306cb661bb2fd2f86b2 | 31,779 |
import token
import tokenize
def strip_docstrings(line_gen):
""" Strip comments and docstrings from a file.
Based on code from: https://stackoverflow.com/questions/1769332/script-to-remove-python-comments-docstrings
"""
res = []
prev_toktype = token.INDENT
last_lineno = -1
last_col = 0
... | ea5774377439484dd6e208521f18dc694eb991ac | 31,780 |
def getelasticpublicip(ip):
"""Gets the PublicIp address of the Elastic IP Address"""
return ip["PublicIp"] | 84e4f788cb4a9b765f4b5dfc1a0606004162a4ed | 31,781 |
def commands(ctx):
"""
Returns a string of Rimworld specific commands
Parameters:
ctx: The context of the message
Returns:
str: The list of commands
"""
response = ''
response = 'Rimworld Commands: !item, !event, !iteminfo, !eventinfo, !mods'
return response | 4fcb162740e97437f414f8925eff97d3032e5319 | 31,782 |
def add_timeout_arg(parser):
"""Add the timeout argument to a parser"""
def _validator(val):
"""Validate acceptable inputs for the timeout of the function"""
error = 'Value for \'timeout\' must be an integer between 10 and 900'
try:
timeout = int(val)
except ValueErro... | 2b96c763f579650e86e311a2081eab2313f6dc49 | 31,784 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.