content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def count_increasing(ratings, n): """ Only considering the increasing case """ arr = [1] * n cnt = 1 for i in range(1, n): cnt = cnt + 1 if ratings[i - 1] < ratings[i] else 1 arr[i] = cnt return arr
9fe274527fbba505467a195bf555c77d2f3e6aed
2,412
def decorate(rvecs): """Output range vectors into some desired string format""" return ', '.join(['{%s}' % ','.join([str(x) for x in rvec]) for rvec in rvecs])
31a3d4414b0b88ffd92a5ddd8eb09aaf90ef3742
2,413
def get_color(card): """Returns the card's color Args: card (webelement): a visible card Returns: str: card's color """ color = card.find_element_by_xpath(".//div/*[name()='svg']/*[name()='use'][2]").get_attribute("stroke") # both light and dark theme if (color == "#ff0101...
452266b81d70973149fed4ab2e6cbc9c93591180
2,414
def add_chr_prefix(band): """ Return the band string with chr prefixed """ return ''.join(['chr', band])
08a99220023f10d79bdacdb062a27efcb51086ce
2,415
def disable_text_recog_aug_test(cfg, set_types=None): """Remove aug_test from test pipeline of text recognition. Args: cfg (mmcv.Config): Input config. set_types (list[str]): Type of dataset source. Should be None or sublist of ['test', 'val'] Returns: cfg (mmcv.Config):...
bda3a5420d32d55062b23a6af27cee3e203b878c
2,416
def delta_in_ms(delta): """ Convert a timedelta object to milliseconds. """ return delta.seconds*1000.0+delta.microseconds/1000.0
4ed048155daf4a4891488e28c674e905e1bbe947
2,418
def selection_sort(data): """Sort a list of unique numbers in ascending order using selection sort. O(n^2). The process includes repeatedly iterating through a list, finding the smallest element, and sorting that element. Args: data: data to sort (list of int) Returns: sorted l...
8b745be41c857669aedecb25b3006bbdc1ef04eb
2,419
def player_count(conn, team_id): """Returns the number of players associated with a particular team""" c = conn.cursor() c.execute("SELECT id FROM players WHERE team_id=?", (team_id,)) return len(c.fetchall())
cfced6da6c8927db2ccf331dca7d23bba0ce67e5
2,420
import math def format_timedelta(value, time_format="{days} days, {hours2}:{minutes2}:{seconds2}"): """Format a datetie.timedelta. See """ if hasattr(value, 'seconds'): seconds = value.seconds + value.days * 24 * 3600 else: seconds = int(value) seconds_total = seconds minutes ...
19dc2b175beb1d030f14ae7fe96cb16d66f6c219
2,421
def max_delta(model, new_model): """Return the largest difference between any two corresponding values in the models""" return max( [(abs(model[i] - new_model[i])).max() for i in range(len(model))] )
faf4a9fb2b24f7e7b4f357eef195e435950ea218
2,422
def child_is_flat(children, level=1): """ Check if all children in section is in same level. children - list of section children. level - integer, current level of depth. Returns True if all children in the same level, False otherwise. """ return all( len(child) <= level + 1 or child...
e14f9210a90b40b419d21fffa1542212429d80be
2,423
import os def is_processable(path: str, should_match_extension: str): """ Process scandir entries, copying the file if necessary """ if not os.path.isfile(path): return False filename = os.path.basename(path) _, extension = os.path.splitext(filename) if extension.lower() != should...
5d99b821d3653ff452acac1e5fe48cab559c509e
2,424
import time def timestamp(): """Get the unix timestamp now and retuen it. Attention: It's a floating point number.""" timestamp = time.time() return timestamp
8e56a61659da657da9d5dda364d4d9e8f3d58ed2
2,425
import itertools def cycle(iterable): """Make an iterator returning elements from the iterable and saving a copy of each. When the iterable is exhausted, return elements from the saved copy. Repeats indefinitely. This function uses single dispatch. .. seealso:: :func:`itertools.cycle` """ re...
13f479fca709dffa77eeca3d32ff7265c81588bf
2,427
def find_process_in_list( proclist, pid ): """ Searches for the given 'pid' in 'proclist' (which should be the output from get_process_list(). If not found, None is returned. Otherwise a list [ user, pid, ppid ] """ for L in proclist: if pid == L[1]: return L r...
19eab54b4d04b40a54a39a44e50ae28fbff9457c
2,428
import os import random def select_images(img_dir, sample_size=150, random_seed=42): """Selects a random sample of image paths.""" img_paths = [] for file in os.listdir(img_dir): if file.lower().endswith('.jpeg'): img_paths.append(os.path.join(img_dir, file)) if sample_size is not...
999bf71eb6b8072bd91cbb98d9fe1b50d5e9b8ac
2,429
def get_dp_logs(logs): """Get only the list of data point logs, filter out the rest.""" filtered = [] compute_bias_for_types = [ "mouseout", "add_to_list_via_card_click", "add_to_list_via_scatterplot_click", "select_from_list", "remove_from_list", ] for log in...
e0a7c579fa9218edbf942afdbdb8e6cf940d1a0c
2,430
def subtraction(x, y): """ Subtraction x and y >>> subtraction(-20, 80) -100 """ assert isinstance(x, (int, float)), "The x value must be an int or float" assert isinstance(y, (int, float)), "The y value must be an int or float" return x - y
203233897d31cb5bc79fca0f8c911b03d7deb5ba
2,431
def apo(coalg): """ Extending an anamorphism with the ability to halt. In this version, a boolean is paired with the value that indicates halting. """ def run(a): stop, fa = coalg(a) return fa if stop else fa.map(run) return run
a1e64d9ed49a8641095c8a8c20ae08c1cc6e9c19
2,432
def heap_sort(li): """ [list of int] => [list of int] Heap sort: divides its input into a sorted and an unsorted region, and it iteratively shrinks the unsorted region by extracting the largest element from it and inserting it into the sorted region. It does not waste time with a linear-time scan of...
a72be31e5256c880c157636aa7a15df013ce651d
2,434
def filter_rows(df, condition, reason): """ :param reason: :param df: :param condition: boolean, true for row to keep :return: filter country_city_codes df """ n_dropped = (condition == False).sum() print( f"\nexcluding {n_dropped} locations ({n_dropped / df.shape[0]:.1%}) due to...
7e5e6925bfb7d90bc90b42fda202d80e8ef5e3f6
2,435
import random def attack(health, power, percent_to_hit): """Calculates health from percent to hit and power of hit Parameters: health - integer defining health of attackee power - integer defining damage of attacker percent to hit - float defining percent chance to hit of attacker ...
83a74908f76f389c798b28c5d3f9035d2d8aff6a
2,436
import json def load_data(path): """Load JSON data.""" with open(path) as inf: return json.load(inf)
531fc2b27a6ab9588b1f047e25758f359dc21b6d
2,437
def time_pet(power,energy): """Usage: time_pet(power,energy)""" return energy/power
11e9c82b8c1be84995f9517e04ed5e1270801e27
2,442
def create_graph(edge_num: int, edge_list: list) -> dict: """ Create a graph expressed with adjacency list :dict_key : int (a vertex) :dict_value : set (consisted of vertices adjacent to key vertex) """ a_graph = {i: set() for i in range(edge_num)} for a, b in edge_list: a_graph...
6ec1a71cf82a3a669090df42ac7d53e1286fda2d
2,443
import random def seed_story(text_dict): """Generate random seed for story.""" story_seed = random.choice(list(text_dict.keys())) return story_seed
0c0f41186f6eaab84a1d197e9335b4c28fd83785
2,444
from pathlib import Path import sys def detect_conda_env(): """Inspect whether `sys.executable` is within a conda environment and if it is, return the environment name and Path of its prefix. Otherwise return None, None""" prefix = Path(sys.prefix) if not (prefix / 'conda-meta').is_dir(): # No...
2cb88ebfbb8a2919300e1d0072540e448dcf35ad
2,445
def same_datatypes(lst): """ Überprüft für eine Liste, ob sie nur Daten vom selben Typ enthält. Dabei spielen Keys, Länge der Objekte etc. eine Rolle :param lst: Liste, die überprüft werden soll :type lst: list :return: Boolean, je nach Ausgang der Überprüfung """ datatype = type(lst[0]).__...
9c49376ec34ed0970171597f77de4c4c224350b4
2,446
def round_int(n, d): """Round a number (float/int) to the closest multiple of a divisor (int).""" return round(n / float(d)) * d
372c0f8845994aaa03f99ebb2f65243e6490b341
2,447
def check_hostgroup(zapi, region_name, cluster_id): """check hostgroup from region name if exists :region_name: region name of hostgroup :returns: true or false """ return zapi.hostgroup.exists(name="Region [%s %s]" % (region_name, cluster_id))
b237b544ac59331ce94dd1ac471187a60d527a1b
2,448
def encode_mecab(tagger, string): """ string을 mecab을 이용해서 형태소 분석 :param tagger: 형태소 분석기 객체 :param string: input text :return tokens: 형태소 분석 결과 :return indexs: 띄어쓰기 위치 """ string = string.strip() if len(string) == 0: return [], [] words = string.split() nodes = tagger....
847278728ebe7790d8aef2a125a420d5779adc6b
2,449
import subprocess def run_cmd(cmd, cwd=None): """ Runs the given command and return the output decoded as UTF-8. """ return subprocess.check_output(cmd, cwd=cwd, encoding="utf-8", errors="ignore")
5d2f5b85878291efaa16dcb4bb8a8c72b3d22230
2,452
def refresh_wrapper(trynum, maxtries, *args, **kwargs): """A @retry argmod_func to refresh a Wrapper, which must be the first arg. When using @retry to decorate a method which modifies a Wrapper, a common cause of retry is etag mismatch. In this case, the retry should refresh the wrapper before attemp...
089b859964e89d54def0058abc9cc7536f5d8877
2,453
def pad_rect(rect, move): """Returns padded rectangles given specified padding""" if rect['dx'] > 2: rect['x'] += move[0] rect['dx'] -= 1*move[0] if rect['dy'] > 2: rect['y'] += move[1] rect['dy'] -= 1*move[1] return rect
48bdbdc9d4736e372afc983ab5966fc80a221d4d
2,454
import math def number_format(interp, num_args, number, decimals=0, dec_point='.', thousands_sep=','): """Format a number with grouped thousands.""" if num_args == 3: return interp.space.w_False ino = int(number) dec = abs(number - ino) rest = "" if decimals == 0 and ...
9d5ab0b9ed5dd6054ce4f356e6811c1b155e2062
2,455
def selectTopFive(sortedList): """ 从sortedList中选出前五,返回对应的名字与commit数量列成的列表 :param sortedList:按值从大到小进行排序的authorDict :return:size -- [commit数量] labels -- [名字] """ size = [] labels = [] for i in range(5): labels.append(sortedList[i][0]) size.append(sortedList[i][1...
747ad379ed73aeb6ccb48487b48dc6150350204e
2,456
def get_license(file): """Returns the license from the input file. """ # Collect the license lic = '' for line in file: if line.startswith('#include') or line.startswith('#ifndef'): break else: lic += line return lic
126fff2dd0464ef1987f3ab672f6b36b8fa962f7
2,457
async def user_has_pl(api, room_id, mxid, pl=100): """ Determine if a user is admin in a given room. """ pls = await api.get_power_levels(room_id) users = pls["users"] user_pl = users.get(mxid, 0) return user_pl == pl
5678af17469202e0b0a0232e066e7ed5c8212ee6
2,458
def sanitize_for_json(tag): """eugh the tags text is in comment strings""" return tag.text.replace('<!--', '').replace('-->', '')
211c07864af825ad29dfc806844927db977e6ce0
2,459
def custom_field_check(issue_in, attrib, name=None): """ This method allows the user to get in the comments customfiled that are not common to all the project, in case the customfiled does not existe the method returns an empty string. """ if hasattr(issue_in.fields, attrib): value = str(eval('iss...
d9c051fa922f34242d3b5e94e8534b4dc8038f19
2,460
def arrangements(ns): """ prime factors of 19208 lead to the "tribonacci" dict; only needed up to trib(4) """ trib = {0: 1, 1: 1, 2: 2, 3: 4, 4: 7} count = 1 one_seq = 0 for n in ns: if n == 1: one_seq += 1 if n == 3: count *= trib[one_seq] one_seq = 0 return count # # one-liner... # return r...
01f3defb25624d7a801be87c7336ddf72479e489
2,462
from bs4 import BeautifulSoup def render_checkbox_list(soup_body: object) -> object: """As the chosen markdown processor does not support task lists (lists with checkboxes), this function post-processes a bs4 object created from outputted HTML, replacing instances of '[ ]' (or '[]') at the beginning of a list...
640f00d726a1268eb71134e29dbde53ef0ec44f5
2,463
import numpy as np def manualcropping(I, pointsfile): """This function crops a copy of image I according to points stored in a text file (pointsfile) and corresponding to aponeuroses (see Args section). Args: I (array): 3-canal image pointsfile (text file): contains points' coordina...
eb3f49b5b46d1966946fc3d00bcae113f51c60d1
2,464
def num_from_bins(bins, cls, reg): """ :param bins: list The bins :param cls: int Classification result :param reg: Regression result :return: computed value """ bin_width = bins[0][1] - bins[0][0] bin_center = float(bins[cls][0] + bins[cls][1]) / 2 return bin...
468e56075cf214f88d87298b259f7253d013a3f3
2,466
def rotate90(matrix: list) -> tuple: """return the matrix rotated by 90""" return tuple(''.join(column)[::-1] for column in zip(*matrix))
770a8a69513c4f88c185778ad9203976d5ee6147
2,467
def get_event_details(event): """Extract event image and timestamp - image with no tag will be tagged as latest. :param dict event: start container event dictionary. :return tuple: (container image, last use timestamp). """ image = str(event['from'] if ":" in event['from'] else event['from'] + ":la...
c9b4ded7f343f0d9486c298b9a6f2d96dde58b8c
2,468
import json def copyJSONable(obj): """ Creates a copy of obj and ensures it is JSONable. :return: copy of obj. :raises: TypeError: if the obj is not JSONable. """ return json.loads(json.dumps(obj))
1cc3c63893c7716a4c3a8333e725bb518b925923
2,469
def min_max_two(first, second): """Pomocna funkce, vrati dvojici: (mensi ze zadanych prvku, vetsi ze zadanych prvku). K tomu potrebuje pouze jedno porovnani.""" return (first, second) if first < second else (second, first)
7ddda1ad69056c22d9ba890e19e62464f56c08e1
2,470
import re import requests from bs4 import BeautifulSoup def searchCVE(service, version): """Return a list of strings""" re.search url = "https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword="+service+"+"+version res = requests.get(url) soup = BeautifulSoup(res.content, "lxml") listCVE = [] for elt in soup.find_a...
f9daf52e0c508496273c8a07b279051ebf662198
2,472
import argparse def init_parser(): """ initialize argument parser for S1 processing utilities """ parser = argparse.ArgumentParser() parser.add_argument('-t', '--transform', action='store_true', help='transform the final DEM to UTM coordinates') parser.add_argument('-l', '--logfiles', action='...
427eeff31ee83105afba1a9e22e8c789059efb23
2,473
def deco_inside_ctx_method_self(target): """decorator: wrap a class method inside a `with self: ...` context""" def tgt(self, *args, **kwargs): with self: return target(self, *args, **kwargs) return tgt
6a29ad468840229c026e6abf87556018a3e16718
2,475
def validate_blacklist(password): """ It does not contain the strings ab, cd, pq, or xy """ for blacklisted in ['ab', 'cd', 'pq', 'xy']: if blacklisted in password: return False return True
93ad092d5622e0567171f487522c2db824089eb9
2,477
import time def f(x): """Squares something""" time.sleep(10) return x * x
6c1ab07ebaaeca6258601ec33f181e75086a355a
2,478
def get_added_after( fetch_full_feed, initial_interval, last_fetch_time=None, filter_args=None ): """ Creates the added_after param, or extracts it from the filter_args :param fetch_full_feed: when set to true, will limit added_after :param initial_interval: initial_interval if no :param last_fe...
281cb7d7429071bf8dca0d04eedee9130a29b28d
2,479
def _a_in_b(first, second): """Check if interval a is inside interval b.""" return first.start >= second.start and first.stop <= second.stop
e4ca21e1861b691510252eb3be53eed16c8bc8cf
2,482
def get_password(config, name): """Read password""" passfile = config.passstore / name with open(passfile, 'r') as fd: return fd.read()
caae733030077eedc4428555eb0b106cfe586e50
2,483
def attribute_string(s): """return a python code string for a string variable""" if s is None: return "\"\"" # escape any ' characters #s = s.replace("'", "\\'") return "\"%s\"" % s
9ed9d4f26e797119a339d2a3827772b945e29839
2,484
import os def read_dfcpp_test_results(d4cpp_output_dir): """ Returns test results """ test_results = {} for dir_name in os.listdir(d4cpp_output_dir): path_to_dir = os.path.join(d4cpp_output_dir, dir_name) if not os.path.isdir(path_to_dir): continue case = dir_na...
d99f749dbf20179bc317a026d0e0112aea17ae12
2,485
async def ping_server(): """ Ping Server =========== Returns the message "The Optuna-server is alive!" if the server is running. Parameters ---------- None Returns ------- msg : str A message witnessing that the server is running. """ msg = 'The Optuna-server is alive!' return msg
2098f2167a14f08105824490824d62dd34b4c49e
2,487
def test_from_rsid(rsids, start_rsid): """Continue collecting publications for rsids in list, beginning with start_rsid Args: rsids (list): list of rsids to collect publications on start_rsid (str): rsid identifier to resume collecting publications on Returns: runtime_rsids (list):...
bf2be86f28645addc08737e64f08695cd6b3a6d3
2,489
import os def _abs_user_path(fpath): """don't overload the ap type""" return os.path.abspath(os.path.expanduser(fpath))
c5ee29b13783afcd5c6ad99d9e751f7ed5db58be
2,490
def get_base_url(host_name, customer_id): """ :arg host_name: the host name of the IDNow gateway server :arg customer_id: your customer id :returns the base url of the IDNow API and the selected customer """ return 'https://{0}/api/v1/{1}'.format(host_name, customer_id)
5a24a87f597cf01c61ab6a01202b2e01e3b00bf8
2,491
import requests def is_url_ok(url: str) -> bool: """Check if the given URL is down.""" try: r = requests.get(url) return r.status_code == 200 except Exception: return False
97e0ba4b609282ef0dc166f0f0407e4aacdf30b2
2,492
import math def sort_by_value(front, values): """ This function sorts the front list according to the values :param front: List of indexes of elements in the value :param values: List of values. Can be longer than the front list :return: """ copied_values = values.copy() # Copy so we can modify it sor...
2d259ebbc0117f9aa043d78394b6423e596f176e
2,493
import re def cigar_segment_bounds(cigar, start): """ Determine the start and end positions on a chromosome of a non-no-matching part of an RNA-seq read based on a read's cigar string. cigar string meaning: http://bioinformatics.cvr.ac.uk/blog/tag/cigar-string/ Example: '50M25N50M' with ...
c870dfb9b11e2fd1df9fb347528252f114b8d70f
2,496
import functools import asyncio def no_block(func): """Turns a blocking function into a non-blocking coroutine function.""" @functools.wraps(func) async def no_blocking_handler(*args, **kwargs): partial = functools.partial(func, *args, **kwargs) return await asyncio.get_event_loop().run_i...
5681fe7275a89c522384b28f9473fded8bba846b
2,497
def get_ua_list(): """ 获取ua列表 """ with open('zhihu_spider/misc/ua_list.txt', 'r') as f: return [x.replace('\n', '') for x in f.readlines()]
6ebcf5d85650ad6644ccdf48aafed0160bd52ec0
2,499
from typing import List def load_numbers_sorted(txt: str) -> List[int]: """ファイルから番号を読み込みソートしてリストを返す Args: txt (str): ファイルのパス Returns: List[int]: 番号のリスト """ numbers = [] with open(txt) as f: numbers = sorted(map(lambda e: int(e), f)) return numbers
6f10badd417a2ceefefa9f28a5c40583ea077d43
2,501
def translate_pt(p, offset): """Translates point p=(x,y) by offset=(x,y)""" return (p[0] + offset[0], p[1] + offset[1])
9fdc578d461219e9e5d1b557b9fde3d7a0946815
2,502
def truncate(sequence): """ Do nothing. Just a placeholder. """ string = str(sequence) return string.split()[0]
2e8eeffb08d6d3d5d6ad5e6a83e596ec61a2eea2
2,503
import os def get_files(dir="."): """ Gets all the files recursivly from a given base directory. Args: dir (str): The base directory path. Returns: list: A list that contains all files. """ folder_queue = [dir] files = set() while(folder_queue): next_fold...
4c29efa262c2b1be04952beb9acb6a2d8b622a3a
2,505
import os import zipfile import json def load_project_resource(file_path: str): """ Tries to load a resource: 1. directly 2. from the egg zip file 3. from the egg directory This is necessary, because the files are bundled with the project. :return: the file as json """ ...
b9d46e1363fc1ca8b397b1512642b7795a8ea9c9
2,506
import torch def hsic(k_x: torch.Tensor, k_y: torch.Tensor, centered: bool = False, unbiased: bool = True) -> torch.Tensor: """Compute Hilbert-Schmidt Independence Criteron (HSIC) :param k_x: n by n values of kernel applied to all pairs of x data :param k_y: n by n values of kernel on y data :param c...
7c91aa5991b90f396abbf835111a456208cbc50a
2,509
def int_converter(value): """check for *int* value.""" int(value) return str(value)
ba1b780c7886fccf1203225de249ef129561fd36
2,510
from typing import Callable def map_filter(filter_function: Callable) -> Callable: """ returns a version of a function that automatically maps itself across all elements of a collection """ def mapped_filter(arrays, *args, **kwargs): return [filter_function(array, *args, **kwargs) for arr...
a5f9f97d1a0d4acdaa39b9fb72a73b95a81553bb
2,511
import binascii def generate_ngrams_and_hashit(tokens, n=3): """The function generates and hashes ngrams which gets from the tokens sequence. @param tokens - list of tokens @param n - count of elements in sequences """ return [binascii.crc32(bytearray(tokens[i:i + n])) for i in r...
eb627add56f51a533c773e0dfea029bfcdb808ee
2,513
from datetime import datetime def get_clip_name_from_unix_time(source_guid, current_clip_start_time): """ """ # convert unix time to readable_datetime = datetime.fromtimestamp(int(current_clip_start_time)).strftime('%Y_%m_%d_%H_%M_%S') clipname = source_guid + "_" + readable_datetime return...
0a212a76a69507ae3020c1e05ec354a927ad3dae
2,514
def normalize_sides(sides): """ Description: Squares the sides of the rectangles and averages the points so that they fit together Input: - sides - Six vertex sets representing the sides of a drawing Returns: - norm_sides - Squared and fit sides list """ sides_list = [] # Average side vertices and make...
855fcc45d14db2eede9fd7ec2fa6bf2f6854950d
2,516
def ratingRange(app): """ Get the rating range of an app. """ rating = 'Unknown' r = app['rating'] if r >= 0 and r <= 1: rating = '0-1' elif r > 1 and r <= 2: rating = '1-2' elif r > 2 and r <= 3: rating = '2-3' elif r > 3 and r <= 4: rating = '3-4' elif r > 4 and r <= 5: rating = '4-5' return rating
69056c367a87e331cd3b606423540250b20f6485
2,517
import io def generate_table_definition(schema_and_table, column_info, primary_key=None, foreign_keys=None, diststyle=None, distkey=None, sortkey=None): """Return a CREATE TABLE statement as a string.""" if not column_info: raise Exception('N...
383cdc8ed13fbaa45adadec26f31ad0f5ac52fbc
2,519
def gradient_descent_update(x, gradx, learning_rate): """ Performs a gradient descent update. """ # Return the new value for x return x - learning_rate * gradx
db5ec512883352f473990eca124c8ad302ec3564
2,520
def next_line(grd_file): """ next_line Function returns the next line in the file that is not a blank line, unless the line is '', which is a typical EOF marker. """ done = False while not done: line = grd_file.readline() if line == '': return line, False elif line.strip(): return line, True
337f188930a03142bae59cdb378b09f1ac5e2ecb
2,522
from pathlib import Path import hashlib def file_md5_is_valid(fasta_file: Path, checksum: str) -> bool: """ Checks if the FASTA file matches the MD5 checksum argument. Returns True if it matches and False otherwise. :param fasta_file: Path object for the FASTA file. :param checksum: MD5 checksum...
ec400afbe29d940d0638a581da7f2ee001b9e985
2,523
def combine_to_int(values): """Combine several byte values to an integer""" multibyte_value = 0 for byte_id, byte in enumerate(values): multibyte_value += 2**(4 * byte_id) * byte return multibyte_value
58ff7cbee356cdcbe5b26e973de16c5b1cc40afc
2,524
def error_response(error, message): """ returns error response """ data = { "status": "error", "error": error, "message": message } return data
f3e52ea42cb48378f08ecb65f58d2291960e6488
2,525
def getFBA(fba): """AC factory. reads a fileobject and creates a dictionary for easy insertation into a postgresdatabase. Uses Ohlbergs routines to read the files (ACfile) """ word = fba.getSpectrumHead() while word is not None: stw = fba.stw mech = fba.Type(word) datadic...
e5c5f52fe831938400eec5ae15c043ecbf8cf7d1
2,526
import requests from bs4 import BeautifulSoup def get_soup(page_url): """ Returns BeautifulSoup object of the url provided """ try: req = requests.get(page_url) except Exception: print('Failed to establish a connection with the website') return if req.status_code == 404: ...
d837e3b6aa6184285857428b2c796172379f3a1f
2,527
def foreign_key_constraint_sql(table): """Return the SQL to add foreign key constraints to a given table""" sql = '' fk_names = list(table.foreign_keys.keys()) for fk_name in sorted(fk_names): foreign_key = table.foreign_keys[fk_name] sql += "FOREIGN KEY({fn}) REFERENCES {tn}({kc}), ".fo...
0883050d2b9d302ab9099ef27abd400e4d4fe69e
2,528
from pathlib import Path def get_world_paths() -> list: """ Returns a list of paths to the worlds on the server. """ server_dir = Path(__file__).resolve().parents[1] world_paths = [] for p in server_dir.iterdir(): if p.is_dir and (p / "level.dat").is_file(): world_paths.app...
bf1c23c6a1c928dc66470db2e11b49ad2fc9e5d9
2,529
import hmac import hashlib def is_valid_webhook_request(webhook_token: str, request_body: str, webhook_signature_header: str) -> bool: """This method verifies that requests to your Webhook URL are genuine and from Buycoins. Args: webhook_token: your webhook token request_body: the body of the...
1ce1ef0a9e1386ebbea7773d8cd9d40df2544792
2,530
def is_even(x): """ True if obj is even. """ return (x % 2) == 0
f19563063515eb4d39b8b607cf68f6f188af409e
2,531
def _preprocess_stored_query(query_text, config): """Inject some default code into each stored query.""" ws_id_text = " LET ws_ids = @ws_ids " if 'ws_ids' in query_text else "" return '\n'.join([ config.get('query_prefix', ''), ws_id_text, query_text ])
bc63391724773cd4a60f3dc9686d243d6d733b40
2,532
import numpy def get_object_ratio(obj): """Calculate the ratio of the object's size in comparison to the whole image :param obj: the binarized object image :type obj: numpy.ndarray :returns: float -- the ratio """ return numpy.count_nonzero(obj) / float(obj.size)
fd18e460be32037c73fe75c8fa5eef5ba6c1c217
2,533
def get_region(ds, region): """ Return a region from a provided DataArray or Dataset Parameters ---------- region_mask: xarray DataArray or list Boolean mask of the region to keep """ return ds.where(region, drop=True)
102b672f8040b722ec346435775cba1056485ae2
2,534
def print_scale(skill, points): """Return TeX lines for a skill scale.""" lines = ['\\cvskill{'] lines[0] += skill lines[0] += '}{' lines[0] += str(points) lines[0] += '}\n' return lines
c88de0c6db9e7b92dbcee025f42f56817a4aa033
2,536
import operator def device_sort (device_set): """Sort a set of devices by self_id. Can't be used with PendingDevices!""" return sorted(device_set, key = operator.attrgetter ('self_id'))
92a22a87b5b923771cd86588180a8c6eb15b9fdf
2,537
def _ontology_value(curie): """Get the id component of the curie, 0000001 from CL:0000001 for example.""" return curie.split(":")[1]
7ef1f0874e698c498ccef16294c0469f67cd5233
2,538
import re def parse_IS(reply: bytes, device: str): """Parses the reply to the shutter IS command.""" match = re.search(b"\x00\x07IS=([0-1])([0-1])[0-1]{6}\r$", reply) if match is None: return False if match.groups() == (b"1", b"0"): if device in ["shutter", "hartmann_right"]: ...
827b5ebf5c98bcc65b823276d5ab5b8086a2c069
2,539
import os def generate_s3_strings(path): """Generates s3 bucket name, s3 key and s3 path with an endpoint from a path with path (string): s3://BUCKETNAME/KEY x --> path.find(start) returns index 0 + len(start) returns 5 --> 0 + 5 = 5 Y --> path[len(start):] = BUCKENAME/KEY --> .find(end) l...
601b20514c93e2159f9d5747063ce70d265d6e6e
2,540
def only_t1t2(src, names): """ This function... :param src: :param names: :return: """ if src.endswith("TissueClassify"): # print "Keeping T1/T2!" try: names.remove("t1_average_BRAINSABC.nii.gz") except ValueError: pass try: ...
60116fbc602bbe03f7c18776b623ef3680b9dfc1
2,541