content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def compress_dataframe_time_interval(processed_df, interval): """ Resamples dataframe according to time interval. If data is originally in 1 minute intervals the number of rows can be reduced by making the interval 15 minutes. To maintain data quality, an average is taken when compressing the dataframe....
ffbb35719e33f445ba4b5c91acf8a069cd4902a6
700,277
def iseast(bb1, bb2, north_vector=[0,1,0]): """ Returns True if bb1 is east of bb2 For obj1 to be east of obj2 if we assume a north_vector of [0,1,0] - The min X of bb1 is greater than the max X of bb2 """ #Currently a North Vector of 0,1,0 (North is in the positive Y direction) #i...
9764d373d14530fca2d26d8c7855cc0620e14496
700,278
import itertools def concat_list(in_list: list) -> list: """Concatenate a list of list into a single list.""" return list(itertools.chain(*in_list))
5a58e8e1899fce99f8dabe681206507ae8ad4b8c
700,279
def is_sale(line): """Determine whether a given line describes a sale of cattle.""" return len(line) == 5
e4ff4ae2ea7ea14a2975eaf87852eed2fad0abff
700,280
def _is_recipe_fitted(recipe): """Check if a recipe is ready to be used. Fitting a recipe consists in wrapping every values of `fov`, `r`, `c` and `z` in a list (an empty one if necessary). Values for `ext` and `opt` are also initialized. Parameters ---------- recipe : dict Map the...
77e438dd00ac5606c52c88518c6932a09dff75df
700,281
def view_event(user, event): """ Check whether a user may view a specified event. :param User user: :param Event event: :return: bool """ if event is None: return None return user.has_perm("booking.view_hidden_events") or event.visible is True
0aca52c9a60449ab0711a2291c5f12f42c8b3f96
700,282
def parse_filename(fname, return_ext=True, verbose=False): """ Parses `fname` (in BIDS-inspired format) and returns dictionary Parameters ---------- fname : str os os.PathLike Filename to parse return_ext : bool, optional Whether to return extension of `fname` in addition to key...
1512b50fa6d07a0bcbb69831418a935f28abe2d8
700,283
def get_ls(omega_list): """Return the array of the Solar longitude of each OMEGA/MEx observation in omega_list. Parameters ========== omega_list : array of OMEGAdata The input array of OMEGA observations. Returns ======= ls : ndarray The array of the omega_list Ls. ...
c8be1927a55ff9aac0134d52691b3b2bdd049724
700,284
def run_intcode(memory, noun, verb): """Assign noun and verb then run intcode program on memory.""" memory[1] = noun memory[2] = verb pointer = 0 while True: opcode = memory[pointer] if opcode == 99: return memory[0] param_one = memory[pointer + 1] param_...
b4f0c6762a9a27021ce1cabd03b950fb8fabcd48
700,285
def fix_term_scope(term): """ 对term的scope进行硬处理 :param term: :return: """ scope = 'realtime' left = term.left if left and left.type == 'func' and left.subtype == 'getvariable' and 'profile' in left.variable[1]: scope = 'profile' # hard code if left and left.subtype == ...
bf67f5839a402281c2ef943983e857e10d5da627
700,286
import pkg_resources def version(): """ Returns the current version of the CySCS Python wrapper. """ return pkg_resources.get_distribution("cyscs").version
b530c798702dfb62a041a6a9c1fb8ff1dc1e6365
700,288
import random def miller_rabin_primality_testing(n): """Calculates whether n is composite (which is always correct) or prime (which theoretically is incorrect with error probability 4**-k), by applying Miller-Rabin primality testing. For reference and implementation example, see: https://en.wikip...
6f7263f261bf20b851aa40e0c616a68e9936f16d
700,289
import functools from datetime import datetime def busy_try(delay_secs: int, ExceptionType=Exception): """ A decorator that repeatedly attempts the function until the timeout specified has been reached. This is different from timeout-related functions, where the decorated function is called only *onc...
0d005935ffa8b7f594da692edfa39ec4342ed4e1
700,290
def MakeDeclarationString(params): """Given a list of (name, type, vectorSize) parameters, make a C-style parameter declaration string. Ex return: 'GLuint index, GLfloat x, GLfloat y, GLfloat z'. """ n = len(params) if n == 0: return 'void' else: result = '' i = 1 for (name, type, vecSize) in params: ...
1b009bce0d6c25b25e4830b3a021dda877519ea3
700,291
from typing import Tuple from typing import Union def min_avg(arr: list, k: int) -> Tuple[list, Union[float, int]]: """ Time Complexity: O(n) space complexity: O(1) """ avg: Union[int, float] = sum(arr[:k]) / k start: int = 0 end: int = k - 1 cur_avg = avg for index in range(k, le...
1a2cdafd54eda4ed1078fe72f369fb8750634b84
700,292
import numpy as np def rand_jitter(arr, sensib = 0.01, lowerLimit=None, upperLimit=None): """ Creation of jittering in a one-D data array arr sensibility can be adjust with parameter sensib. In case of an array only made of a same value, you can use the lowerlimit and upperlimit parameters """...
1e7e6f67a660508effedb1b68cb4034acaa5e0c2
700,293
def make_text_list(postings_dict, first_n_postings=100): """ Extract the texts from postings_dict into a list of strings Parameters: postings_dict: first_n_postings: Returns: text_list: list of job posting texts """ text_list = [] for i in rang...
0d2a4e0f2d904b246942508e03cfd97cf5d43ea0
700,294
import json def get_file(projectCode, branch, filepath): """ :projectCode: идентификатор проекта :branch: необходимая ветка :folderPath: GET параметр путь к папке, получить через request.args.get('filePath') **Response:** ``` { "name": "myfile.md", "full_path": "/folder/my...
1765c422e2f9ced254775f1da354f424071b7763
700,295
def calculate_iou(confusion_matrix): """ https://github.com/ternaus/robot-surgery-segmentation/blob/master/validation.py """ confusion_matrix = confusion_matrix.astype(float) ious = [] for index in range(confusion_matrix.shape[0]): true_positives = confusion_matrix[index, index] ...
7f8eb6f957b031c808bb4ef0f921de26a2c855eb
700,296
def cards_db(db): """Empty the CardsDB object after each function""" db.delete_all() return db
1f62dc919e860b9d4db31f611a8109356c1c6c1b
700,297
def invert0(x): """ Invert 0 -> 1 if OK = 0, FALSE > 1 """ return 0 if x > 0 else 1
1c7a71885cdc84f12b3e2214aa74f99ff2aab326
700,298
import torch def bounded_iou_loss(loc1, size1, loc2, size_): """ loc1/2:[(l,t),...] size1/2:[(w,h),...] 2 |= target :return 0 if same, >0 if diff SINGLE_IMAGE """ loc_delta = torch.abs(loc1 - loc2) iou_loc = torch.div(size_ - loc_delta, size_ + loc_delta) iou_size = torch.min(t...
67964833f5a190065b843f1c89c1eccd16824245
700,299
def one_or_more(amount, single_str, multiple_str): """ Return a string which uses either the single or the multiple form. @param amount the amount to be displayed @param single_str the string for a single element @param multiple_str the string for multiple elements @return the string represent...
8c3495614cd8c718e243383bcc72cc7daa8fa286
700,300
import torch def accuracy(output, target, topk=(1,), exact=False): """ Computes the top-k accuracy for the specified values of k Args: output (ch.tensor) : model output (N, classes) or (N, attributes) for sigmoid/multitask binary classification target (ch.t...
cc2194bb72460ff39e3648e173d52875f64abeab
700,301
import itertools def enumerate_hyperparameter_combinations(parameter_to_options): """ Returns a list of dictionaries of all hyperparameter options :param parameter_to_options: a dictionary that maps parameter name to a list of possible values :return: a list of dictionaries that map parameter names ...
8665ef66b7cb1467599ff0a56f47ac60042e0e9a
700,302
def get_new_pvars(opvs, epvs): """Returns a list of new projection variables from a list of old PVar's opvs, based on a list of existing PVar's epvs. Args: opvs: Old projection variables. evps: Existing projection variables. Returns: A list of projection variables. """ ...
b344e4fb60daa0452c944065b3164d90e7698a21
700,303
def count_gaps(sequence): """In order to calculate the correct percent divergence between two strings where there are gaps present, the gaps need to be counted in order to be deducted from the total number of differences. This function takes a sequence string and returns the number of instanc...
a0124ef8ee77d5b1c39da96131a9a0dff7301bcc
700,304
def suffix(pattern, k): """we define SUFFIX(Pattern) as the last (k-1)-mers in a k-mer Pattern""" return pattern[-(k - 1):]
d6cec61ba024f551071a6ba9d6409963ff2ffe7d
700,305
def runSingleThreaded(runFunction, arguments): """ Small overhead-function to iteratively run a function with a pre-determined input arguments :param runFunction: The (``partial``) function to run, accepting ``arguments`` :param arguments: The arguments to passed to ``runFunction``, one r...
9cdc34f5e44751667ec5a3bddcf2958b3302f4d1
700,306
def comp(*args) -> bool: """Compare string lengths.""" return len(set([len(arg) for arg in args])) == 1
c3bf069c723b37030531ffbbb84a0a91488a7345
700,308
import sysconfig def get_build_cflags(): """Synthesize a CFLAGS env var from the current python env for building of C modules.""" return '{} {} -I{}'.format( sysconfig.get_config_var('BASECFLAGS'), sysconfig.get_config_var('OPT'), sysconfig.get_path('include') )
4449c19a6f1758c4db415f76a50fd7749afd8b57
700,309
def clip(num, num_min=None, num_max=None): """Clip to max and/or min values. To not use limit, give argument None Args: num (float): input number num_min (float): minimum value, if less than this return this num Use None to designate no minimum value. num_max (float): maxim...
fe46f5a200ab24d517c57c5e1d93d4bf86192e13
700,310
def Singleton(name, bases, dict): """Use this metaclass on Converter subclasses to create a instance.""" return type(name, bases, dict)()
d7a196f0a645dac8150d9fba46b426882358a9a6
700,311
def calculate_fraction_of_sn_discovered( log, surveyCadenceSettings, snSurveyDiscoveryTimes, redshifts, peakAppMagList, snCampaignLengthList, extraSurveyConstraints, zmin, zmax): """ *Given a list of the snSurveyDiscoveryTimes calculate the...
70409bba2f7dd2601ed073ad140d75c8ec863942
700,312
def create_model_info(config, loss_func, accuracy): """Create a dictionary of relevant model info. Parameters ---------- param : dict Any parameter relevant for logging. accuracy_log : dict A dictionary containing accuracies. Returns ------- type Description of ...
25cd8f49a0c7c7fd9b52f3d33c8a8ac24167fbff
700,313
def grid_coordinates(roi, x_divisions, y_divisions, position): """ Function that returns the grid coordinates of a given position. To do so it computes, for a given area and taking into account the number of x and y divisions which is the total amount of cells. After that it maps the given position to the cell it ...
1db6e8ed8b1c0abde965e3a5536867ae32ac2228
700,314
def splitmessage(message): """Returns a tuple containing the command and arguments from a message. Returns None if there is no firstword found """ assert isinstance(message, str) words = message.split() if words: return (words[0], words[1:])
d8db56ef55097f9f8858de95ee3d7799c0dc127e
700,315
def dec_to_str(total): """Converts decimals to strings for more natural speech.""" if total == 0.125: return "an eighth" elif total == 0.25: return "a quarter" elif total == 0.5: return "a half" elif total == 0.75: return "three quarters" else: if total % ...
05e170eb21f5f0b188a32a634b5c617536c64a11
700,317
def maybe_cast_list(value, types): """ Try to coerce list values into more specific list subclasses in types. """ if not isinstance(value, list): return value if type(types) not in (list, tuple): types = (types,) for list_type in types: if issubclass(list_type, list): ...
c3078c42087103ee8b0a8b3257d345e7d73c0fd7
700,318
def read_wi_table(wi_file, wi_column): """ Reads in the relative adaptiveness file """ tmp_wi_dict = {} line_number = 0 with open(wi_file, 'r') as infile: for line in infile: line_number += 1 if line_number == 1: continue # skip header ...
89a1b38e375678b8d221b7386dd742fe6745223c
700,319
from os import makedirs from os.path import exists def check_path(path): """Check if path ends with a slash ('/'). Else, it adds a slash. The function also creates the directory if it does not existing. Parameters ---------- path : str A path Returns ------- path : str ...
f583d720d04d84f62fef4ca022a1b7d71c5d4493
700,320
import numpy def w_conj_kernel_fn(kernel_fn): """Wrap a kernel function for which we know that kernel_fn(w) = conj(kernel_fn(-w)) Such that we only evaluate the function for positive w. This is benificial when the underlying kernel function does caching, as it improves the cache hit rate. ...
c5ba5bb741e9e696a94535c4373e84268a7ab95d
700,321
def loadWorld(worldName, store): """ Load an imaginary world from a file. The specified file should be a Python file defining a global callable named C{world}, taking an axiom L{Store} object and returning an L{ImaginaryWorld}. This world (and its attendant L{Store}) should contain only a sing...
801c98b5be82e9d5c9ca19db9adbe3078f500674
700,322
import torch def full(*args, **kwargs): """ In ``treetensor``, you can use ``ones`` to create a tree of tensors with the same value. Example:: >>> import torch >>> import treetensor.torch as ttorch >>> ttorch.full((2, 3), 2.3) # the same as torch.full((2, 3), 2.3) tensor...
8c6df708b76a799c27a45979e9a43b3d3678ac8d
700,323
import math def tan(x): """Get tan(x)""" return math.tan(x)
112b52faee2f08262515086fe59b2ff978001200
700,324
def piece_placed(x, y, player, board): """This function determines the piece played. It takes the coordinates of the piece, the player number, and the board. The pieces are zeros or ones and the function returns the piece on the board based on the number.""" if player == 0: board[x][y] = 1 e...
ffcd46e11c3e5b0704ed66d6010dfc227106c752
700,325
def get_max_unsecured_debt_ratio(income): """Return the maximum unsecured-debt-to-income ratio, based on income.""" if not isinstance(income, (int, float)): raise TypeError("Expected a real number.") # Below this income, you should not have any unsecured debt. min_income = 40000 if income <...
ffff63807842197e2f60ebfd29b54ecf895f6279
700,326
def pubkey_to_merkletree(key, hashfunction, salt, prefix=""): """Convert a full signing-key pubkey into a merkletree dictionary""" drval = dict() part1 = key[0] part2 = key[1] if len(key) > 2: breakpoint = int(len(key)/2) part1, dpart1 = pubkey_to_merkletree(key[:breakpoint], hashfun...
50e5283a7189aa0202e93201d70f7343719f1f13
700,328
from typing import Any import json def is_jsonable(x: Any): """ Check if an object is json serializable. Source: https://stackoverflow.com/a/53112659 """ try: json.dumps(x) return True except (TypeError, OverflowError): return False
3735de8bd1940d84c185142c0a4387366d7cd9c2
700,329
def add_number_of_different_roles(dev_type: str) -> int: """ INPUT dev_type - dev_type answer (separeted by ';') OUTPUT numeric value - number of different dev types """ try: return len(dev_type.split(';')) except: return 0
78872b9101b128cc107a0194fc85b353f1d2f836
700,330
def GetBigQueryTableID(tag): """Returns the ID of the BigQuery table associated with tag. This ID is appended at the end of the table name. """ # BigQuery table names can contain only alpha numeric characters and # underscores. return ''.join(c for c in tag if c.isalnum() or c == '_')
0fe659fd3c7ca3df5f061289dad5635841146901
700,331
def _linear_transform(src, dst): """ Parameters of a linear transform from range specifications """ (s0, s1), (d0,d1) = src, dst w = (d1 - d0) / (s1 - s0) b = d0 - w*s0 return w, b
7f55a2617721fdefcc724bcb8ce9f880d7bcd846
700,332
def feature_within_s(annolayer, list_of_s): """Extracts all <annolayer> from all sentence-elements in list_of_s; returns a flat list of <annolayer>-elements; """ list_of_lists_of_feature = [s.findall('.//' + annolayer) for s in list_of_s] list_of_feature = [element for sublist in list_of_lists_of_fe...
df6ed3603381a4b8d2ea12fc483fa37ea3068372
700,333
def showname(keyvalue): """filter koji za neku od prosledjenih kljuceva vraca vrednost""" key_dict ={'P':'Accepted','C': 'Created','Z': 'Closed','O': 'On Wait'} return key_dict[keyvalue]
59453d5e0dd31696b99d01c8b927297adddec10c
700,334
def processPostMessage(post_message, status_type): """ Check if the message is >500 characters If it is, shorten it to 500 characters Ouput: a tuple of strings: read_more (empty if not shortened), post text """ if len(post_message) > 500: post_message = post_message[:500] last_sp...
2d21ec04ef863b57f95bb4b8256f2195559e6f8e
700,335
def data_for_keys(data_dict, data_keys): """ Return a dict with data for requested keys, or empty strings if missing. """ return {x: data_dict[x] if x in data_dict else '' for x in data_keys}
b844ae2dba804e179e7e8dd08166f392a90e7f7a
700,336
def distinct_values_bt(bin_tree): """Find distinct values in a binary tree.""" distinct = {} result = [] def _walk(node=None): if node is None: return if node.left is not None: _walk(node.left) if distinct.get(node.val): distinct[node.val] =...
8d84d57559a0c813e7ac12199680172a9b591be9
700,337
import subprocess def runshell(cmd): """ Run a shell command. if fails, raise an exception. """ p = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if p.returncode != 0: err = "Subprocess: \"{0}\" failed, std err = {1}".format(str(cmd), str(p.stderr)) raise RuntimeError...
d5a617cec03fe70d601f496f9f62b6c30fcdbd1e
700,338
def fix_iobtag(iob, DESC_DECISION): """ This is specific to the BBN Corpus; the reason some of the entity labels are being modified: 1) Errors in the original labeling, or 2) Not enough labels of the given category The parameter DESC_DECISION can be 'keep', 'merge' or 'remove', which determine...
2743e7d36c7d8153a7cf6694a69e9a212219ae8f
700,339
from typing import List def get_answered_questions(question_list: List[List[bytes]]) -> list: """Dont let the type hint confuse you, problem of not using classes. It takes the result of get_question_list(file_list) Returns a list of questions that are answered. """ t = [] for q in quest...
d485b374721f445ab62853eaa67de65bd2a893e2
700,340
def split_data_list(list_data, num_split): """ list_data: list of data items returning: list with num_split elements, each as a list of data items """ num_data_all = len(list_data) num_per_worker = num_data_all // num_split print("num_data_all: %d" % num_data_all...
7282d1ae89f830d5b48fa73ea3d355cd63344f5c
700,341
def patch_set_approved(patch_set): """Return True if the patchset has been approved. :param dict patch_set: De-serialized dict of a gerrit change :return: True if one of the patchset reviews approved it. :rtype: bool """ approvals = patch_set.get('approvals', []) for review in approvals: ...
af7e56be45e537be9308f0031fe3923425afd48c
700,343
import os def get_files_with_ext(path, str_ext, flag_walk=False): """ get files with filename ending with str_ext, in directory: path """ list_all = [] if flag_walk: # 列出目录下,以及各级子目录下,所有目录和文件 for (root, dirs, files) in os.walk(path): for filename in files: ...
1a8ade0b5efead0b6260430145e601d98f6fa057
700,344
def PySet_Pop(space, w_set): """Return a new reference to an arbitrary object in the set, and removes the object from the set. Return NULL on failure. Raise KeyError if the set is empty. Raise a SystemError if set is an not an instance of set or its subtype.""" return space.call_method(space.w_set...
5303f9b7afd4d4cfdb6ee065e860720af5b88b8e
700,345
import random def random_mac_address(local=True): """ Generate random MAC address """ vendor = random.SystemRandom().choice( ( (0x00, 0x05, 0x69), # VMware MACs (0x00, 0x50, 0x56), # VMware MACs (0x00, 0x0C, 0x29), # VMware MACs (0x00, 0x16, 0...
eb89ab223d0e8ae9f011277d92f3cd01d27627e8
700,346
def check_win(game, players): """ -1: ongoing 0: tie > 0: id of winner """ # print(status) # print(status) for player in players: if len(player.destination_cards) == 0: return player.id, 1 if game.card_index >= len(game.cards) or player.trains == 0: ...
0127de10c9b6b9b08dbf07b3747d92a2a9b4115c
700,347
def message_has_label(message, label): """Tests whether a message has a label Args: message: message to consider. label: label to check. Returns: True/False. """ return label['id'] in message.get('labelIds', [])
634808b2533469daa42779a3563f127d06ce1b14
700,348
def indent_func_def(func_def): """Ensures max columns in a function signature follows style guide""" if len(func_def) < 80: return func_def parts = func_def.split(',') idx = func_def.index('(') params = parts[0] for x in parts[1:]: params += ',\n{}{}'.format(idx * ' ', x) ret...
371bde9c8580982894759d6716a9be6d4f8521a5
700,349
import sys def good_default_options(): """ Probably very subjective. But just to have some reasonable defaults, which might be used. This is dependent on the OS. Usage in your config might be like:: import common globals().update(common.good_default_options()) """ if sys.platform == "darwin":...
29a739081f70bdce5fda4070036823854a22f53f
700,350
def transform_case(input_string): """ Lowercase string fields """ return input_string.lower()
4d15f33781c1b58d3a04a52fcc8e5f5042e33bdf
700,352
from typing import Union def format_numbers_consistently(number: Union[int, float]) -> Union[int, float]: """ Formats numeric values in a consistent way. Prevents inconsistencies with how numbers are formatted (e.g. '12.0' as '12') :type number: float or int :param number: numeric value to forma...
ebf7acdca53ac331ac7a5e1e8ba2ee416cc7112b
700,353
import re def extract_date_from_date_time(date_time: str) -> str: """ Given a date in format YYYY-MM-DDTHH:MM:SS, extract the date part (i.e. YYYY-MM-DD) :param date_time : str (DATETIME_FORMAT) :return str a date in DATE_FORMAT """ assert type(date_time) == str, "date_time must ...
4727273615fa38a48eace841c4ff8760ab10d08e
700,354
def cli(ctx, role_name, description, user_ids="", group_ids=""): """Create a new role. Output: Details of the newly created role. For example:: {'description': 'desc', 'url': '/api/roles/ebfb8f50c6abde6d', 'model_class': 'Role', 'type': 'admin', ...
7b9b9f0d72dd2312448eee96dc9743b2b9657271
700,356
import numpy def sentence_to_weight_matrix(sentence): """ Converts the dependency graph of a sentence of tokens into a weight matrix. weight[u, v] = 0 iff u == v weight[u, v] = 1 iff u != v and are_bidirectionaly_directly_connected(u, v) == True weight[u, v] = 0 else """ V = len(sentence)...
e413de859ce825b8fc0c00b4241d74746d26b0b0
700,358
import csv def find_by_column(filename, column, value): """ This method discovers interactions registered in the DLT looking at one specific value""" list = [] with open(filename) as f: reader = csv.DictReader(f) for item in reader: if item[column] == value: lis...
928f53e72c7b5e3e63316748545a530c20559f8b
700,359
from datetime import datetime def dt_to_dec(dt): """Convert a datetime to decimal year.""" year_start = datetime(dt.year, 1, 1) year_end = year_start.replace(year=dt.year+1) return dt.year + ((dt - year_start).total_seconds() / # seconds so far float((year_end - year_start).total_seconds()))
0841f21c245b0f3a2a1404c7c8c5bff9a26aae21
700,360
def enhanceEntries(entriesList, feedId, feedName): """ Add Id of feed to each entry so that we only need the item, which then contains all information that we need Parameters ---------- entriesList : list A List of RSSEntries (FeedParserDicts) feedId : string The URL of th...
db4bf6a82ca4fe41ee0797d361b962126836a7b8
700,361
def tf_out(): """Static equilibrium results from threebar funicular.""" output = {} output["xyz"] = {0: [0.29289321881345254, -0.7071067811865475, 0.0], 1: [1.0, 0.0, 0.0], 2: [2.5, 0.0, 0.0], 3: [3.207106, -0.7071067, 0.0]} output["force"]...
1f60894de3cb14b147baa552e4485aed0544a2b0
700,363
from bs4 import BeautifulSoup def get_text_from_XML_without_saving(path): """ :param path: path to the XML file :return: Text extracted from the path """ tree = open(path, 'r', encoding='utf8') soup = BeautifulSoup(tree) for script in soup(["script", "style"]): script.extract() ...
f6fd435ae75ca6cc7743e8d0b7da6afca24b0719
700,364
import os def find(dir_name :str) -> list: """ List regular files in a stored in given directory or one of its subdirectories. Args: dir_name: A String corresponding to an existing directory. Returns: A list of String, each of them corresponding to a file. """ filenames = list(...
369b9997bdf36949972140a5c7a54fac72c3d25d
700,365
def pysiphash(uint64): """Convert SipHash24 output to Py_hash_t """ assert 0 <= uint64 < (1 << 64) # simple unsigned to signed int64 if uint64 > (1 << 63) - 1: int64 = uint64 - (1 << 64) else: int64 = uint64 # mangle uint64 to uint32 uint32 = (uint64 ^ uint64 >> 32) & 0xf...
a0a4bb7703aef9a95146c519aa1ace751bcf532e
700,366
import random import string def get_unique_key(str_len: int) -> str: """Returns a random string of length str_len. Args: str_len (int): Length of string. Returns: str: Random string """ return "".join([random.choice(string.ascii_lowercase) for _ in range(str_len)])
de8a7743ac5b802e3fe5687e4305ec14e26987a8
700,367
from typing import OrderedDict def sort_by_key(value, reverse=False): """ sorts a dictionary by its keys. :param dict value: dict to be sorted. :param bool reverse: sort by descending order. defaults to False if not provided. :rtype: OrderedDict """ result = so...
df200eaf2810e04281e8f8379ded09f21ed6df74
700,369
def transformation(job_title): """ Transform a job title in a unisex job title Here are examples of main transformations : - Chauffeur / Chauffeuse de machines agricoles --->>> Chauffeur de machines agricoles - Débardeur / Débardeuse --->>> Débardeur - Arboriste grimpeur / grimpeuse --->>> Arbor...
f8580e9a64070ba96cfd540a58327f904c311f9b
700,370
import random def coin_flip(): """Randomly return 'heads' or 'tails'.""" if random.randint(0,1) == 0: return "heads" else: return "tails"
c46afd1e6f6b899448501043400d1a7570aecabe
700,371
import requests def spotlight(text): """To implement the DBpedia Spotlight API: """ headers = { 'Accept': 'application/json', } #e.g. text = "What is a car?" "enitenziagite" #"President Obama" data = { "text":text , 'confidence': '0.35' } response = requests.post('http:...
dcf47994ae343cba9102d26e3cb86954e6f6c213
700,373
def detect_anomalies_cons(residuals, threshold, summary=True): """ Compares residuals to a constant threshold to identify anomalies. Can use set threshold level or threshold determined by set_cons_threshold function. Arguments: residuals: series of model residuals. threshold: constant th...
4c37ca93ab8cbde85b57cb94b44ac1e234809be6
700,374
import redis def connect_redis(dsn): """ Return the redis connection :param dsn: The dsn url :return: Redis """ return redis.StrictRedis.from_url(url=dsn)
0b17418c36cd9a6eb5c0b4ea40a40762c1e41259
700,375
def _tag_depth(path, depth=None): """Add depth tag to path.""" # All paths must start at the root if not path or path[0] != '/': raise ValueError("Path must start with /!") if depth is None: depth = path.count('/') return "{}{}".format(depth, path).encode('utf-8')
6746ce97ac2569e2775cbdc13510263df0860deb
700,376
def calc_sl_price(contract_price, sl_percent): """Returns price that is sl_percent below the contract price""" return round(contract_price * (1 - sl_percent), 2)
487690208c81dcc708b526630929f1ba424b0c0f
700,377
import hashlib def verifyhash_password_hashlib(password: str, hash: str) -> bool: """check if password is correct using hashlib Args: password (str): user password hash (str): user password encrypted Returns: bool: True if correct password else False """ return hashlib.md...
a3ca663abc33777df4f33d0483ba598cef8c5c3b
700,379
def riscale_coordination(coordinates, x, y, z): """ Robert: I do not understand why you would want this quantity. """ coordinatesCM = [] for i in range(len(coordinates)): coordinatesCM.append( [str(coordinates[i][0]), coordinates[i][1]-x, coordinates[i][2]-y,...
cee155c66b857f9bee6a2e6975f3797de40dfdcc
700,380
def get_bonds(input_group): """Utility function to get indices (in pairs) of the bonds.""" out_list = [] for i in range(len(input_group.bond_order_list)): out_list.append((input_group.bond_atom_list[i * 2], input_group.bond_atom_list[i * 2 + 1],)) return out_list
4f39d9d588a1d3e919fcd5e369cd72c6dbac3442
700,381
def read_data(file, delimiter="\n"): """Read the data from a file and return a list""" with open(file, 'rt', encoding="utf-8") as f: data = f.read() return data.split(delimiter)
e0854a2f7ac2190f3b296725b36da0bb4ad14ce3
700,383
def get_sources(dataframe): """ extract sources :param pandas.core.frame.DataFrame dataframe: :rtype: set :return: set of archive.org links """ sources = set() for index, row in dataframe.iterrows(): sources.update(row['incident_sources'].keys()) return sources
468c0cf6428833c9b05c06415917a516471189a5
700,385
from datetime import datetime def set_mediafile_attrs(mediafile, ufile, data, user): """ Copy metadata from uploaded file into Model """ mediafile.name = ufile.name mediafile.original_filename = ufile.name mediafile.filesize = ufile.size mediafile.original_path = data['pathinfo0'] # Da...
e7c373dadb3cd0087184fc725fb749e1a13e0b57
700,386
import ipaddress def is_valid_ipv6_address(ip): """Return True if valid ipv6 address """ try: ipaddress.IPv6Address(ip) return True except ipaddress.AddressValueError: return False
33f4785e768f5117c6fe43c320e2290791fc86a5
700,387
import argparse def parse_args(): """Parses arguments.""" parser = argparse.ArgumentParser( description='Train semantic boundary with given latent codes and ' 'attribute scores.') parser.add_argument('-o', '--output_dir', type=str, required=True, help='Directory to ...
c5315ef2e68214403c4168074108401318b4e22e
700,388
def get_list_view_name(model): """ Return list view name for model. """ return '{}-list'.format( model._meta.object_name.lower() )
765f4b2456d319a6cc5657dbe1e04d3eab471b42
700,389
import copy def render_plugins(plugins, context, placeholder, processors=None): """ Renders a collection of plugins with the given context, using the appropriate processors for a given placeholder name, and returns a list containing a "rendered content" string for each plugin. This is the mai...
2217033cea70a0c88dd6ab378cfc60f71ccfaa4f
700,390