content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
import numpy
def add_param_starts(this_starts, params_req, global_conf, run_period_len, start_values_min, start_values_max):
"""Process the param starts information taken from the generator, and add it to
the array being constructed.
Inputs:
this_starts: a tuple with (starts_min, starts_max),... | b50f538b9d5096fe6061b4b990ccb9ad6ba05ef6 | 1,489 |
def codegen_reload_data():
"""Parameters to codegen used to generate the fn_ansible_tower package"""
reload_params = {"package": u"fn_ansible_tower",
"incident_fields": [],
"action_fields": [u"ansible_tower_arguments", u"ansible_tower_credential", u"ansible_tower_hosts",... | 49dee7d9a1dc297ff31f51e4583740c353831cd9 | 1,490 |
import os
def gen_dir(download_dir, main_keyword):
"""Helper function | generates a directory where pics will be downloaded"""
if not download_dir:
download_dir = './data/'
img_dir = download_dir + main_keyword + '/'
if not os.path.exists(img_dir):
os.makedirs(img_dir)
return img_d... | 2a8fe841ac4c2afdf64cd91f6dae1842e2c3c51d | 1,491 |
def is_valid_page_to_edit(prev_pg_to_edit, pg_to_edit):
"""Check if the page is valid to edit or not
Args:
prev_pg_to_edit (obj): page to edit object of previous page
pg_to_edit (obj): page to edit object of current page
Returns:
boolean: true if valid else false
"""
try:
... | ce594804f105b749062f79d63fc3021296631c1b | 1,492 |
import shutil
import os
def if_binary_exists(binary_name, cc):
"""
Returns the path of the requested binary if it exists and clang is being used, None if not
:param binary_name: Name of the binary
:param cc: Path to CC binary
:return: A path to binary if it exists and clang is being used, None if ... | 9f17748ba111a7ece33b8a0a7315c8832d15b014 | 1,493 |
import glob
def mean_z_available():
"""docstring for mean_z_available"""
if glob.glob("annual_mean_z.nc"):
return True
return False | d53f8dc6fe540e8f74fd00760d1c810e510e53b8 | 1,495 |
import requests
import io
import tarfile
def sources_from_arxiv(eprint):
"""
Download sources on arXiv for a given preprint.
:param eprint: The arXiv id (e.g. ``1401.2910`` or ``1401.2910v1``).
:returns: A ``TarFile`` object of the sources of the arXiv preprint.
"""
r = requests.get("http://a... | b26c46009b23c5a107d6303b567ab97492f91ad9 | 1,496 |
from typing import List
def game_over(remaining_words: List[str]) -> bool:
"""Return True iff remaining_words is empty.
>>> game_over(['dan', 'paul'])
False
>>> game_over([])
True
"""
return remaining_words == [] | 8d29ef06bd5d60082646cef00f77bbabfbac32eb | 1,497 |
import csv
def read_manifest(instream):
"""Read manifest file into a dictionary
Parameters
----------
instream : readable file like object
"""
reader = csv.reader(instream, delimiter="\t")
header = None
metadata = {}
for row in reader:
if header is None:
header... | afa6c2bb0a9d81267b1d930026a229be924a1994 | 1,498 |
def query_urlhaus(session, provided_ioc, ioc_type):
""" """
uri_dir = ioc_type
if ioc_type in ["md5_hash", "sha256_hash"]:
uri_dir = "payload"
api = "https://urlhaus-api.abuse.ch/v1/{}/"
resp = session.post(api.format(uri_dir), timeout=180, data={ioc_type: provided_ioc})
ioc_dicts ... | 171bff1e9b1bfdf8ac6b91a4bbbd7226f80c8c4c | 1,499 |
import webbrowser
def open_in_browser(path):
"""
Open directory in web browser.
"""
return webbrowser.open(path) | 41328b2b478f0bd69695da1868c412188e494d08 | 1,503 |
def encode_letter(letter):
"""
This will encode a tetromino letter as a small integer
"""
value = None
if letter == 'i':
value = 0
elif letter == 'j':
value = 1
elif letter == 'l':
value = 2
elif letter == 'o':
value = 3
elif letter == 's':
... | 6c72c4c9e44c93d045296ab1f49c7783f2b4fc59 | 1,504 |
def electron_mass_MeVc2():
"""The rest mass of the electron in MeV/c**2
https://en.wikipedia.org/wiki/Electron
"""
return 0.5109989461 | 4496ddcc35a0aa6528cc19e47233f5a81626fefe | 1,505 |
def clean_features(vgsales):
"""
This function cleans up some of the dataset's features. The dataset is
quite messy as many values are missing from both categorical and numerical
features. Many of these features are difficult to impute in a reasonable
manner.
<class 'pandas.core.frame.DataFrame... | ffcae20af436d4012381c4933c841c3689fbbca0 | 1,506 |
def UpdateDatabase(asset, images, status):
"""Update the database entries of the given asset with the given data."""
return {'asset': asset} | 1d7d42355410be7481e706e47d7810755974dadc | 1,509 |
import hashlib
import json
def get_config_tag(config):
"""Get configuration tag.
Whenever configuration changes making the intermediate representation
incompatible the tag value will change as well.
"""
# Configuration attributes that affect representation value
config_attributes = dict(fram... | 2cab6e9473822d0176e878114ceb3fda94d1e0f7 | 1,510 |
def list_lines(lines):
"""Returns the list of trimmed lines.
@param lines Multi-line string
"""
return list(filter(None, (x.strip() for x in lines.splitlines()))) | 293610d17e1fe8a27ab6bb5c35a349059e0179f3 | 1,511 |
def replace_newlines(s, replacement=' / ', newlines=(u"\n", u"\r")):
"""
Used by the status message display on the buddy list to replace newline
characters.
"""
# turn all carraige returns to newlines
for newline in newlines[1:]:
s = s.replace(newline, newlines[0])
# while there are... | d7b42ad67a3732c1ecac5bbfd7b9920b0215aa13 | 1,512 |
import requests
import re
def api_wowlight_version_check(version: str) -> bool:
"""
Checks incoming wow-lite wallet version, returns False when the version is too old and needs to be upgraded.
:param version:
:return: bool
"""
url = "https://raw.githubusercontent.com/wownero/wow-lite-wallet/ma... | 470f8580df357c206b595c1145e04e33fd897058 | 1,515 |
import requests
from bs4 import BeautifulSoup
def soup_from_name(username):
""" Grabs bs4 object from html page """
# html_source = urlopen('https://www.instagram.com/'+ str(username) + '/')
url = 'https://www.instagram.com/'+ str(username) + '/'
headers = {"User-Agent" : "Mozilla/5.0 (Macintosh; Inte... | 442c6e9fa036fef59b82246462bf0e992384fd15 | 1,516 |
def construct_SN_default_rows(timestamps, ants, nif, gain=1.0):
""" Construct list of ants dicts for each
timestamp with REAL, IMAG, WEIGHT = gains
"""
default_nif = [gain] * nif
rows = []
for ts in timestamps:
rows += [{'TIME': [ts],
'TIME INTERVAL': [0.1],
... | b81e45d2d5299042b3332a2386a0fd4d2d6d59d7 | 1,517 |
def kron_diag(*lts):
"""Compute diagonal of a KroneckerProductLazyTensor from the diagonals of the constituiting tensors"""
lead_diag = lts[0].diag()
if len(lts) == 1: # base case:
return lead_diag
trail_diag = kron_diag(*lts[1:])
diag = lead_diag.unsqueeze(-2) * trail_diag.unsqueeze(-1)
... | d57bb679dede93ababb2d164cfc85132acef60db | 1,518 |
import os
def _parse_env(name, default=None, dtype=None):
"""Parse input variable from `os.environ`.
Parameters
----------
name : str
Name of the variable to parse from env.
default : any, optional
Set default value of variable.
If None (default), parameter is considered r... | ab947506899ffefafc37197877bcb51ea9bc78da | 1,522 |
def add_init_or_construct(template, variable_slot, new_data, scope, add_location=-1):
"""Add init or construct statement."""
if isinstance(new_data, list):
template[variable_slot][scope].extend(new_data)
return template
if add_location < 0:
template[variable_slot][scope].append(new_d... | 125bc4e34dff837372dbbdc70c69a08a1e83e176 | 1,523 |
import os
def get_subdirs(dir):
"""Get the sub-directories of a given directory."""
return [os.path.join(dir,entry) for entry in os.listdir(dir) \
if os.path.isdir(os.path.join(dir,entry))] | 64b204b1c2878e454910b3d27a326d16a585477a | 1,524 |
def no_conjugate_member(magic_flag):
"""should not raise E1101 on something.conjugate"""
if magic_flag:
something = 1.0
else:
something = 1.0j
if isinstance(something, float):
return something
return something.conjugate() | 5e32d31aa907ac9de2bd153bbe61354207262409 | 1,526 |
def isUniqueSeq(objlist):
"""Check that list contains items only once"""
return len(set(objlist)) == len(objlist) | 4522c43967615dd54e261a229b05c742676c7f99 | 1,528 |
def tag_to_dict(node):
"""Assume tag has one layer of children, each of which is text, e.g.
<medalline>
<rank>1</rank>
<organization>USA</organization>
<gold>13</gold>
<silver>10</silver>
<bronze>9</bronze>
<total>32</total>
</medalline>
"""
d =... | e2131e070dce8620630e994cc25578a9a8438c64 | 1,531 |
def _vj_stat(v = None, j = None, freq_type = 'vj_occur_freq', ts = None):
"""
Return estimate of a single v-gene, j-gene, or vj-gene-pairings frequency
specified < v > and <j> argumens , given a tcrsamper instance < ts >
Parameters
----------
v : str
j : str
e.g.,
freq_type :... | 99228d17714c5ba403071ad0251f8642bc3148e6 | 1,532 |
from typing import Dict
from typing import Any
import yaml
def yaml_dump(dict_to_dump: Dict[str, Any]) -> str:
"""Dump the dictionary as a YAML document."""
return yaml.safe_dump(dict_to_dump, default_flow_style=False) | 4635514ba8ff901656b8a4b5869a6ae101528fa8 | 1,533 |
def dict_check_defaults(dd, **defaults):
"""Check that a dictionary has some default values
Parameters
----------
dd: dict
Dictionary to check
**defs: dict
Dictionary of default values
Example
-------
.. ipython:: python
@suppress
from xoa.misc import d... | 8edc3fdb351f7ec2d4ec3b1e788e6aa5cc0f8787 | 1,534 |
def make_album(singer, name, number = ''):
"""Return singers' names and album"""
album = {'singer': singer, 'name': name}
if number:
album['number'] = number
return album | 1f1bfaaeb501be0aa6fefd358177922246488b31 | 1,535 |
import hashlib
def cache_key(path):
"""Return cache key for `path`."""
return 'folder-{}'.format(hashlib.md5(path.encode('utf-8')).hexdigest()) | 6b9afe1267e0cc0c7168bf3b0d5c7536e2b3c768 | 1,537 |
import torch
def quaternion2rotationPT( q ):
""" Convert unit quaternion to rotation matrix
Args:
q(torch.tensor): unit quaternion (N,4)
Returns:
torch.tensor: rotation matrix (N,3,3)
"""
r11 = (q[:,0]**2+q[:,1]**2-q[:,2]**2-q[:,3]**2).unsqueeze(0).T
r12 = (2.0*(q[:,1]*q[:... | feeed764ee179b31674790f9d2afc7b606a02aef | 1,538 |
def get_total_trainsets(df_anual_data, segments):
"""
# Fill the training_sets dict
:param df_anual_data:
:return:
"""
rows_per_day = int(((60 / 15) * 24))
training_sets = {'ID_SEGMENT': [], 'MES': [], 'COD_LABORALIDAD': [], 'TRAINING_SET': []}
for seg_id in segments: # 1) Particionar ... | 968c3af1fdba5eb759eb93618ed48e3ca3ce5223 | 1,539 |
def find_most_similar(top_k, probs, cache_dict, num=10):
"""返回最相似的num张照片的文件名,如果找到相似的,
则返回一个包括匹配元组的列表,否则返回一个空列表
top_k : 包含最佳分类的索引的列表
probs : 包含最佳分类索引对应的概率
cache_dict: 缓存中的索引和概率
num : 返回最近匹配的数目
"""
similar = []
for filename in cache_dict:
score = 0
count =... | 471083e1ed2b0fadb98cafad64d314ba779aa9e6 | 1,540 |
from operator import mul
from operator import inv
def berlekamp_massey(s):
"""Given a sequence of LFSR outputs, find the coefficients of the LFSR."""
C, B, L, m, b = [1], [1], 0, 1, 1
for n in range(len(s)):
d = s[n]
for i in range(1, L + 1):
d ^= mul(C[i], s[n - i])
if... | 351f52dce7e4a95b986cc169f380347f317f851a | 1,541 |
def normalize_parameter(kv):
"""
Translate a parameter into standard form.
"""
(k, v) = kv
if k[0] == 'requiressl' and v in ('1', True):
k[0] = 'sslmode'
v = 'require'
elif k[0] == 'dbname':
k[0] = 'database'
elif k[0] == 'sslmode':
v = v.lower()
return (tuple(k),v) | 933ea71f452a16c1d4ae2630d6b58a92da1cbec0 | 1,542 |
def __iadd__(self, other):
"""Pythonic use of concat
Example:
xs += ys
Returns self.concat(self, other)"""
return self.concat(self, other) | 713980aed9713c2882a19ae9837315a431611bbc | 1,543 |
def calculate_reliability(data):
""" Calculates the reliability rating of the smartcab during testing. """
success_ratio = data['success'].sum() * 1.0 / len(data)
if success_ratio == 1: # Always meets deadline
return ("A+", "green")
else:
if success_ratio >= 0.90:
return ("A", "green")
elif success_ratio... | d1c9ad7bba220beeae06c568cfd269aaaebfb994 | 1,545 |
def explode(screen):
"""Convert a string representing a screen
display into a list of lists."""
return [list(row) for row in screen.split('\n')] | a43a9d8c830c4a784bb9c3505c62aaf2077bb732 | 1,548 |
import csv
import glob
import os
def merge_csv_files(directory, out):
"""\
Merges the CSV files in the provided `directory` into one CSV file.
:param str directory: Path where to find the CSV files
:param str out: Resulting file name.
"""
f = open(out, 'w', encoding='utf-8')
writer = csv.... | 4d5066b27b9977161b92061a39a6207040982b41 | 1,549 |
def fpath_to_pgn(fpath):
"""Slices the pgn string from file path.
"""
return fpath.split('/')[-1].split('.jpeg')[0] | 1cc6cad60c5356b6c731947a59998117bf15035a | 1,552 |
def data_zip(data):
"""
输入数据,返回一个拼接了子项的列表,如([1,2,3], [4,5,6]) -> [[1,4], [2,5], [3,6]]
{"a":[1,2],"b":[3,4]} -> [{"a":1,"b":3}, {"a":2,"b":4}]
:param data: 数组 data
元组 (x, y,...)
字典 {"a":data1, "b":data2,...}
:return: 列表或数组
"""
if isinstance(data, tuple):
... | 31dcaa3905a7d062cfe994543df31f293fdc962a | 1,553 |
from pathlib import Path
from typing import List
import re
def tags_in_file(path: Path) -> List[str]:
"""Return all tags in a file."""
matches = re.findall(r'@([a-zA-Z1-9\-]+)', path.read_text())
return matches | 1071c22ac79f51697b2ed18896aa1d17568ecb2c | 1,554 |
def check_ip_in_lists(ip, db_connection, penalties):
"""
Does an optimized ip lookup with the db_connection. Applies only the maximum penalty.
Args:
ip (str): ip string
db_connection (DBconnector obj)
penalties (dict): Contains tor_penalty, vpn_penalty, blacklist_penalty keys with i... | 2d6e3615d4b0d9b0fb05e7a0d03708856ffcbfef | 1,555 |
def aiohttp_unused_port(loop, aiohttp_unused_port, socket_enabled):
"""Return aiohttp_unused_port and allow opening sockets."""
return aiohttp_unused_port | 9c5d0c1125a7758be2e07a8f8aca6676429a841a | 1,556 |
import os
def os_specific_command_line(command_line):
"""
Gets the operating system specific command string.
:param command_line: command line to execute.
:type command_line: str
"""
current_os = os.environ["TEMPLATE_OS"]
command = "/bin/bash -c '{}'" if current_os.lower() == "linux" els... | 898b97a57841af3c671bf530c6a31460bd1882a7 | 1,557 |
def keypoint_angle(kp1, kp2):
"""求两个keypoint的夹角 """
k = [
(kp1.angle - 180) if kp1.angle >= 180 else kp1.angle,
(kp2.angle - 180) if kp2.angle >= 180 else kp2.angle
]
if k[0] == k[1]:
return 0
else:
return abs(k[0] - k[1]) | 3feee667bcf767656da6334727b8d502be41d909 | 1,559 |
def is_validated(user):
"""Is this user record validated?"""
# An account is "validated" if it has the `validated` field set to True, or
# no `validated` field at all (for accounts created before the "account
# validation option" was enabled).
return user.get("validated", True) | c1ddfc52a62e71a68798dc07e7576a4ae42aa17f | 1,562 |
import pickle
def load_config(path):
"""Loads the config dict from a file at path; returns dict."""
with open(path, "rb") as f:
config = pickle.load(f)
return config | eb12aed2ebdeebacf3041f3e4880c714f99c052c | 1,563 |
def lower_strings(string_list):
"""
Helper function to return lowercase version of a list of strings.
"""
return [str(x).lower() for x in string_list] | 58dcaccbc0f4ce8f22d80922a3ac5da26d7f42b1 | 1,564 |
import os
def normalize_group_path(group, suffix=None):
"""
:param group:
:param suffix:
:return:
"""
group = os.path.join('/', group)
if suffix is not None:
if not group.endswith(suffix):
group = os.path.join(group, suffix.rstrip('/'))
return group | 31b0ef7eb808dce8ea51a0f4edbaec61e5c5cc2c | 1,565 |
import os
import subprocess
def mock_data(rootdir, data_dir):
"""Build mock functional data from available atlases"""
mock_dir = os.path.join(data_dir, 'mock')
if not os.path.exists(mock_dir):
subprocess.run("python setup_mock_data.py".split(), cwd=rootdir)
return mock_dir | 2eed6ba8da9849e099841f61af56f1a982151c66 | 1,566 |
def eiffel_artifact_created_event():
"""Eiffel artifact created event."""
return {
"meta": {
"id": "7c2b6c13-8dea-4c99-a337-0490269c374d",
"time": 1575981274307,
"type": "EiffelArtifactCreatedEvent",
"version": "3.0.0",
},
"links": [],
... | 0ef2e5adadb58b92c94bac42c9880728573b159e | 1,567 |
def _select_index_code(code):
"""
1 - sh
0 - sz
"""
code = str(code)
if code[0] == '3':
return 0
return 1 | 697d8e5ca1744c897b7eebbb7b9b0a3b45faec3d | 1,568 |
import hashlib
import hmac
def _HMAC(K, C, Mode=hashlib.sha1):
"""
Generate an HMAC value.
The default mode is to generate an HMAC-SHA-1 value w/ the SHA-1 algorithm.
:param K: shared secret between client and server.
Each HOTP generator has a different and unique secret K.
:type K: ... | db9bf26c52427acc259f3cb1590c7c13b0d0dd9e | 1,569 |
def extends_dict(target, source):
""" Will copy every key and value of source in target if key is not present in target """
for key, value in source.items():
if key not in target:
target[key] = value
elif type(target[key]) is dict:
extends_dict(target[key], value)
... | 5a68dde5e3bb7dbb81ad61c3698614f56dd5efd7 | 1,570 |
def nth_even(n):
"""Function I wrote that returns the nth even number."""
return (n * 2) - 2 | 26e1465a039352917647ae650d653ed9842db7f6 | 1,571 |
import typing
def remove_fields_with_value_none(fields: typing.Dict) -> typing.Dict:
"""
Remove keys whose value is none
:param fields: the fields to clean
:return: a copy of fields, without the none values
"""
fields = dict((key, value) for key, value in fields.items() if
va... | 22d7ac2a77248809c691bdb98f5f6ebaaf6d4f2b | 1,572 |
import hashlib
def calculate_file_hash(f, alg, buf_size):
"""BUF_SIZE - 64 kb
need for large file"""
h = hashlib.new(alg)
for chunk in iter(lambda: f.read(buf_size), b""):
h.update(chunk)
return h.hexdigest() | 6361ef8f18f5ae66e1d51503426c77f7505e10be | 1,574 |
import typing
import hashlib
def sha512(data: typing.Optional[bytes] = None):
"""Returns a sha512 hash object; optionally initialized with a string."""
if data is None:
return hashlib.sha512()
return hashlib.sha512(data) | 067fffc4c006d9c46e5037b07b86149ac15bb573 | 1,575 |
def compute_state(observations, configuration):
"""
:param observations:
:param configuration:
:return StateTensor:
"""
StateTensorType = configuration.STATE_TYPE
return StateTensorType([observations]) | 44a08caa02137438359c4cd764fff1700b6252b2 | 1,577 |
def nt(node, tag):
""" returns text of the tag or None if the
tag does not exist """
if node.find(tag) is not None and node.find(tag).text is not None:
return node.find(tag).text
else:
return None | 7ca5f83cf18f918f594374fa2aa875415238eef6 | 1,578 |
def _explored_parameters_in_group(traj, group_node):
"""Checks if one the parameters in `group_node` is explored.
:param traj: Trajectory container
:param group_node: Group node
:return: `True` or `False`
"""
explored = False
for param in traj.f_get_explored_parameters():
if pa... | 71cbafbad0dcc3fa9294c0bede5f6a09941d452b | 1,581 |
from pathlib import Path
def _construct_out_filename(fname, group_name):
"""
Construct a specifically formatted output filename.
The vrt will be placed adjacent to the HDF5 file, as
such write access is required.
"""
basedir = fname.absolute().parent
basename = fname.with_suffix('.vrt').na... | 117bb8470ab65f0b9fb11bb3151ae653e5e28d23 | 1,582 |
def _format_breed_name(name):
"""
Format breed name for displaying
INPUT
name: raw breed name, str
OUTPUT
name : cleaned breed name, str
"""
return name.split('.')[1].replace('_', ' ') | 0c2680de9bd19e61d717fb84c1ce01e5095ddf35 | 1,584 |
from datetime import datetime
def now():
""" Get current timestamp
Returns:
str: timestamp string
"""
current_time = datetime.now()
str_date = current_time.strftime("%d %B %Y, %I:%M:%S %p")
return str_date | 4c487416fa119cae0c5310678dfd96e0f737b937 | 1,585 |
import ast
def _get_import(name, module: ast.Module):
"""
get from import by name
"""
for stm in ast.walk(module):
if isinstance(stm, ast.ImportFrom):
for iname in stm.names:
if isinstance(iname, ast.alias):
if iname.name == name:
... | bc33a882c65f7fe44d446376db3a71631629ff04 | 1,586 |
def get_dict_from_args(args):
"""Extracts a dict from task argument string."""
d = {}
if args:
for k,v in [p.strip().split('=') for p in args.split(',')]:
d[k] = v
return d | 8fb05329f6119393f94215808c6ab9b3116ec759 | 1,587 |
def change_app_header(uri, headers, body):
""" Add Accept header for preview features of Github apps API """
headers["Accept"] = "application/vnd.github.machine-man-preview+json"
return uri, headers, body | 3610d1d482e057ba73a1901aed8430ff35d98f3b | 1,588 |
def fib_fail(n: int) -> int:
"""doesn't work because it's missing the base case"""
return fib_fail(n - 1) + fib_fail(n - 2) | 6e8138b7ce330c9ab191367e3911fe8146240c25 | 1,589 |
import itertools
def largets_prime_factor(num):
"""
Returns the largest prime factor of num.
"""
prime_factors = []
for n in itertools.count(2):
if n > num:
break
if num%n == 0:
prime_factors.append(n)
while (num%n == 0):
num = num/n
return max(prime_factors) | 12100b6cdc2e0553295c1803e699544aa930bbfb | 1,590 |
def format_decimal(amount):
""" jinja2 filter function for decimal number treatment """
amt_whole = int(amount)
amt_whole_len = len(str(amt_whole))
if amount < 1:
amt_str = '{:0.15f}'.format(amount).rstrip("0").rstrip(".")
elif amt_whole_len < 4:
amt_str = '{:0.3f}'.format(amount).r... | 55ee4b6134abd409ade396233fa07061d0a30764 | 1,591 |
def remove_special_char(df, col):
"""Removes special characters such as % and $ from numeric variables and converts them into float"""
df[col] = df[col].replace(regex = True, to_replace = r'[^0-9.\-]', value=r'')
df[col] = df[col].astype("float")
return df[col] | c6c4c86eb480d2f045e40b3eb831d0b8d5381d33 | 1,592 |
def swap(lst, idx1, idx2):
"""
>>> swap([0, 1, 2], 0, 1)
[1, 0, 2]
>>> swap([0, 1, 2], 0, 0)
[0, 1, 2]
"""
# print("Swapping [{}, {}] from {}".format(idx1, idx2, lst))
lst[idx1], lst[idx2] = lst[idx2], lst[idx1]
# print("resulting to {}".format(lst))
return lst | 81dee804db05eedaa1a9b5611e836a4c1da89b4b | 1,593 |
def round_grade(grade: int) -> int:
"""
Round the grade according to policy.
Parameters
----------
grade: int
Raw grade.
Returns
-------
rounded_grade: int
Rounded grade.
"""
if grade < 38:
rounded_grade = grade
else:
closest_multiple_5 = (gr... | 8f1be9575d98b4ed24ff1e5904a5345d7ebc3e48 | 1,595 |
def _urpc_test_func_2(buf):
"""!
@brief u-RPC variable length data test function.
@param buf A byte string buffer
@return The same byte string repeated three times
"""
return buf*3 | f13f7dcf45eaa0706b69eb09c63d29ba2bbd3d60 | 1,596 |
def versionString(version):
"""Create version string."""
ver = [str(v) for v in version]
numbers, rest = ver[:2 if ver[2] == '0' else 3], ver[3:]
return '.'.join(numbers) + '-'.join(rest) | 2feec3f8ac5a1f2b848d0805dfa0c3ff53a44ead | 1,597 |
def pymongo_formatter(credentials):
"""Returns a DSN for a pymongo-MongoDB connection.
Note that the username and password will still be needed separately in the constructor.
Args:
credentials (dict):
The credentials dictionary from the relationships.
Returns:
(string) A f... | 69216575258f297c368ec3015c1c14569bb82cd2 | 1,601 |
def get_scanner(fs_id):
""" get scanner 3T or 1.5T"""
sc = fs_id.split("_")[2]
if sc in ("15T", "1.5T", "15t", "1.5t"):
scanner = "15T"
elif sc in ("3T", "3t"):
scanner = "3T"
else:
print("scanner for subject " + fs_id + " cannot be identified as either 1.5T or 3T...")
... | f905bd16f3103b0c6c02193d30fb945646afb54c | 1,602 |
def compute_alphabet(sequences):
"""
Returns the alphabet used in a set of sequences.
"""
alphabet = set()
for s in sequences:
alphabet = alphabet.union(set(s))
return alphabet | cf8f7dc1e31a28fe0910d806d18189aae7d7a85b | 1,603 |
def Diff(a, b):
"""Returns the number of different elements between 2 interables.
Args:
a(iterable): first iterable.
b(iterable): second iterable.
Returns:
int: the number of different elements.
"""
return sum(map(lambda x, y: bool(x-y), a, b)) | 0885bd224f956f138e80a4b681ebc581c733cc51 | 1,604 |
import random
def _get_random_hangul(count=(0xd7a4 - 0xac00)):
"""Generate a sequence of random, unique, valid Hangul characters.
Returns all possible modern Hangul characters by default.
"""
valid_hangul = [chr(_) for _ in range(0xac00, 0xd7a4)]
return random.sample(valid_hangul, count) | 3a41edd36cd2aac05e51a121743bcfb61455bd9b | 1,605 |
import toml
def load_page_details(data, filename=None):
"""
# Raises
ValueError of (filename, error)
"""
try:
options = toml.loads(data)
except toml.TomlDecodeError as exc:
raise ValueError(filename, exc)
if not isinstance(options, dict):
raise ValueError(filename, 'page details could not b... | 117bb7d84625475745a30522fda7dccf1bc5a487 | 1,607 |
def display_datetime(datetime_str, time_zone=None, verbose=True):
"""Returns a formatted datetime with TZ (if provided) or 'Error (Missing)"""
"""
>>> print(datetime.datetime.utcnow().strftime("%Y/%m/%d %a %I:%M %p"))
2019/05/19 Sun 01:10 AM
"""
if datetime_str: # and type(datetime_str) =... | 45caa488688e790ae19f8f3f2cda2cb0f250b1fd | 1,608 |
import torch
def mask_channels(mask_type, in_channels, out_channels, data_channels=3):
"""
Creates an autoregressive channel mask.
Input:
mask_type: str
Either 'A' or 'B'. 'A' for first layer of network, 'B' for all others.
in_channels: int
Number of input channels... | 772fa71f63d2f31c80966db0b0eb43a70ac5e9a9 | 1,609 |
import textwrap
def dedent(text):
"""
Remove all common indentation from every line but the 0th.
This will avoid getting <code> blocks when rendering text via markdown.
Ignoring the 0th line will also allow the 0th line not to be aligned.
Args:
text: A string of text to dedent.
Returns:
String d... | b450a873c4c2b667d10c66985d19f8057aa205f9 | 1,610 |
def S_difference_values(_data_lista, _data_listb):
"""
Returns new data samples where values are transformed by transformer values.
"""
d_data = []
dsa = len(_data_lista)
dsb = len(_data_listb)
if dsa != dsb:
return []
for i in range(dsa):
d_data.append(_data_lista[i] ... | 40ec82cb7ef53d5e227b3287a9c1d08e78112e09 | 1,611 |
import platform
def get_platform_system():
"""return platform.system
platform module has many regexp, so importing it is slow...
import only if required
"""
return platform.system() | 2531f1883d5acd0c192c0061d7cbf29637197706 | 1,613 |
def sumaDigits(s):
"""assumes s is a string and returns the sum of the
decimal digits in s. For example if s is 'a2b3c' it returns 5"""
suma = 0
for c in s:
try:
suma+=int(c)
except ValueError:
continue
return suma | 47b09476925d45741d97eca5362e736f83a8185d | 1,614 |
def join_nonempty(l):
"""
Join all of the nonempty string with a plus sign.
>>> join_nonempty(('x1 + x2 + x1:x2', 'x3 + x4'))
'x1 + x2 + x1:x2 + x3 + x4'
>>> join_nonempty(('abc', '', '123', ''))
'abc + 123'
"""
return ' + '.join(s for s in l if s != '') | 041948f95caaef14cb96e761f08b4a84fba37d6e | 1,615 |
def sieveEr(N):
"""
input: positive integer 'N' > 2
returns a list of prime numbers from 2 up to N.
This function implements the algorithm called
sieve of erathostenes.
"""
# precondition
assert isinstance(N,int) and (N > 2), "'N' must been... | 8d48d2a491341d5302307597ad64ac4a37b1abb8 | 1,617 |
def validate_fields(item, fields=None):
"""
Check that all requested fields were returned
:param item: comment or submission
:param fields: list[str]
:return: list[str]
"""
actual_fields = item.d_.keys()
if fields is None:
requested_fields = actual_fields
else:
requ... | 88bd6d20ba1cc04f8478128f7f32192ef680762b | 1,618 |
from typing import Iterable
def remove_nones(sequence: Iterable) -> list:
"""Removes elements where bool(x) evaluates to False.
Examples
--------
Normal usage::
remove_nones(['m', '', 'l', 0, 42, False, True])
# ['m', 'l', 42, True]
"""
# Note this is redundant with it.chain
... | 975c0104b3cc05bb82fa211c1b85b49c7d3cb174 | 1,619 |
from typing import List
import pathlib
def retrieve(passed: List[str]) -> List[str]:
"""
Retrieves all items that are able to be
converted, recursively, from the passed list.
Parameters
----------
passed: List[str]
The items to search.
Returns
-------
List[str]:
A... | 6789255e302caf9dc6e481df532acec20dfc6b3c | 1,620 |
def removeBots(gdf, bot_list):
"""
A Function for removing Twitter bots.
Parameters
----------
gdf: <gpd.GeoDataFrame>
A GeoDataFrame from which Twitter bots should be removed.
bot_list: <list>
Input either 'home_unique_days' or 'home_unique_weeks'
... | e938f46bcf5c87dfa81db96f127c88d948f061db | 1,621 |
def bq_to_rows(rows):
"""Reformat BigQuery's output to regular pnguin LOD data
Reformat BigQuery's output format so we can put it into a DataFrame
Args:
rows (dict): A nested list of key-value tuples that need to be converted into a list of dicts
Returns:
list: A list of dictionaries ... | 9ff842d1c41d7ebe5c822d4c07b2f26b5524b0fe | 1,622 |
def css_defaults(name, css_dict):
"""Находит первое значение по-умолчанию
background -> #FFF
color -> #FFF
content -> ""
"""
cur = css_dict.get(name) or css_dict.get(name[1:-1])
if cur is None:
return None
default = cur.get('default')
if default is not None:
return de... | 8418af5e27dfc85a3ec70dea2e7416595ee86a1f | 1,623 |
def average_saccades_time(saccades_times):
"""
:param saccades_times: a list of tuples with (start_time_inclusive, end_time_exclusive)
:return: returns the average time of saccades
"""
return sum([saccade_time[1] - saccade_time[0] for saccade_time in saccades_times]) / len(saccades... | a22a5d89ddd4317fa10ed6f5d920f17560028514 | 1,625 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.