content
stringlengths
39
9.28k
sha1
stringlengths
40
40
id
int64
8
710k
import random def generate_nationalities_and_passports(num_users, num_existing_users, countries): """Generates a list of nationalities and/or passports to be inserted into the database. Keyword arguments: num_users -- number of users being created by the ...
dcbe58fbbaae802b579e790fb76f589442d484c3
411,667
def transpose_list(input): """ INPUT: - ``input`` -- a list of lists, each list of the same length OUTPUT: - ``output`` -- a list of lists such that output[i][j] = input[j][i] EXAMPLES:: sage: from sage.schemes.hyperelliptic_curves.monsky_washnitzer import transpose_li...
47d1cf21e221ec5e5960cc90015ae3b80bcb93f2
162,933
def get_subjectaltname(certificate): """Return subjectAltName associated with certificate. """ return certificate.get_extension(6)._subjectAltNameString()
683dd5e3dd31a622ff70ba036701968d551bbf0c
68,807
def sideplr(p, p1, p2): """ Calculates the side of point p to the vector p1p2. Input p: the point p1, p2: the start and end points of the line Output -1: p is on the left side of p1p2 0: p is on the line of p1p2 1: p is on the right side of p1p2 """ return int((p....
2f6450133ffd8158f70e97cf31402fd95adb993f
241,092
def to_square_feet(square_metres): """Convert metres^2 to ft^2""" return square_metres * 10.7639
50510aad230efcb47662936237a232662fef5596
1,738
def ent_dims_from_state_dict(state_dict: dict) -> tuple[int, int]: """ From a state dict, return the appropriate values of `ent_hidden_size` and `ent_intermediate_size` which can be used for instantiating the model. """ # We assume that all transformer blocks have same dim. low_dim_key = "encode...
7ed009d9683df7ec98b3c99ab289b3bce438692d
601,701
def identify_galaxy_entries(misp_data, galaxy_type, initial): """ Generate a dictionary of the entries in the specified galaxy within the data misp_data - The events and attributes loaded from the MISP server galaxy_type - The type of the galaxy to look at initial - The initial dictionary of entrie...
c862bbb63c2c8f4de185d6074a2df4e593d6895d
334,409
def underscore(s: str) -> str: """Appends an underscore (_) to s.""" return f'{s}_'
8094e8b72993d3fabee5ea88196f91b1cbcaa9ae
491,782
def example_function_keyword(a, b, c=1): """ Example with keyword and default value """ return a * b * c
5b51ffaf95f8677b888fc6f48af085813ae57020
485,165
def _read_text_file_lines(file_name): """ Read text file lines. Open a text file and read it, return a list of lines. Parameters ---------- file_name: string Path to the file to be read. Returns ------- list of strings A list of lines. """ with open(file_n...
e5c12777b35289196ef13aced84709004a4968a3
585,955
def _get_rest_endpoint_base_url(rest_service_base_url: str) -> str: """ Return the base URL of the endpoints of BAM's REST service. :param rest_service_base_url: Base URL of BAM's REST service. :type rest_service_base_url: str :return: The base URL of the endpoints of BAM's REST service. :rtype...
d947d242a63203f0007433be383ed74cb4289ff4
696,703
def replace_with(repl_str): """ Helper method for common parse actions that simply return a literal value. Especially useful when used with :class:`transform_string<ParserElement.transform_string>` (). Example:: num = Word(nums).set_parse_action(lambda toks: int(toks[0])) na = one...
1fa00581b5bd2d77886187ada1c0bd1d46f089a9
534,397
import random def split_train_val_test(data, split=[0.6, 0.1, 0.3], shuffle=False): """Split sequence of data into train, validation and test. Parameters ---------- data : [N,] list Input data. split : [3,] list, default=[0.6, 0.2, 0.2] Train, validation, test fractions. suffl...
d7f3eb3ac403afd01a168a608eed24a1cb2b2ff8
294,244
import asyncio async def gather_dict(dct): """Utility function to do asyncio.gather for dictionaries Do asyncio.gather on the dictionary's values, and return the dictionary with the futures' results replacing the futures. >>> promise = Future() >>> promise.set_result("value") >>> await gathe...
c2799dcdee218e3d47af180f8121624d11cc42a2
312,658
def getPMUtiming(lines): """ Function to get the timing for the PMU recording. Parameters ---------- lines : list of str list with PMU file lines To improve speed, don't pass the first line, which contains the raw data. Returns ------- MPCUTime : list of two int ...
d4f07fe08ea38cf8f5f6dd6b806a42d2a9a0121b
369,862
from typing import List def parseRanges(rangeStr: str, inlcudeLast: bool = True, unique: bool = True) -> List[int]: """ Parses range strings in the form of 1,2,4:8,9 to a list 1,2,4,5,6,7,8,9 Args: rangeStr (): a range sting separated by commas and : inlcudeLast (): If true ranges 1:3 => 1...
36d4cb444c5789c6b6f9d7e503aebda9b531c8cc
464,066
def is_int32(t): """ Return True if value is an instance of an int32 type. """ return t.typecode == "i"
075c87757c0942042a267f3a2acf280209894400
584,112
import textwrap def indent_text(text, indent, trailing_nl): """Reindent text by `indent` characters.""" text = textwrap.indent(text, indent) # remove trailing newline if so desired if not trailing_nl and text.endswith('\n'): text = text[:-1] return text
66b6de41e37720000242a8455bbee5476e69eb31
528,250
def _num_two_factors(x): """return number of times x is divideable for 2""" if x <= 0: return 0 num_twos = 0 while x % 2 == 0: num_twos += 1 x //= 2 return num_twos
d122f5a084c38e9b6a8de251f2a0658957f23b63
675,025
import csv def read_csv_to_dictionary(csvfile, delimiter=';'): """Reads a csv file and returns a dictionary with the respective keys specified in the first row of the csv file. """ data = [] with open(csvfile, mode='r') as infile: reader = csv.reader(infile, delimiter=delimiter) fo...
947e4bc04f89f96cef4b4f2b50da8797d2abe1f3
141,782
def _checksum_valid(line): """ Calculate the checksum of the GPS output and check if it is equal to the provided checksum in output; therefore - there was no transmission errors. The checksum is XOR of all bytes between $ and * characters (excluding themselves). :param line: line of output...
3affdede2ea61ca0beb13748da4cd425bd825aa2
534,272
def flatten(seq): """Recursively flattens a sequence.""" lst = [] for el in seq: if isinstance(el, (list, tuple)): lst.extend(flatten(el)) else: lst.append(el) return lst
449f6f9d428c58c9a46def0ceedf4f792051bc86
403,021
from typing import Counter def bag_of_character_ngrams(msg, n): """ Extract a bag of character ngrams from a message (including whitespace), with fixed n :param msg: input string :param n: size of ngram :return: bag of features, as a Counter """ if n == 0: raise ValueError('n must ...
af0e414582b76a32ffa9b7268aee6cf1c85c8d99
210,612
def fix_sanitizer_crash_type(crash_type): """Ensure that Sanitizer crashes use generic formats.""" # General normalization. crash_type = crash_type.lower().replace('_', '-').capitalize() # Use more generic types for certain Sanitizer ones. crash_type = crash_type.replace('Int-divide-by-zero', 'Divide-by-zero...
a2971f209e380f7b50d4234876e7421249737d44
83,133
def find_zeros(list_of_lists, height, width): """ Finds the indices of zeros in a height by width list of lists """ zeros_lst = [] for row in range(height): for col in range(width): if list_of_lists[row][col] == 0: zeros_lst.append([row, col]) return zeros_lst
d72528c4dae587ec36f985a76288059b6832251b
304,796
def deg_to_arcmin(x): """ Convert *x* from [deg] to [arcmin]. """ return x * 60
2444eeef478c2bcc50518483791915861d9ac7cb
249,108
def pp_peername(peername): """Prettily format a peername tuple (host, port)""" return f"{peername[0]}:{peername[1]}"
7b165931939932ae571e0bfb1e0df4642309a069
285,625
def get_n_last_liked(sp, n): """Get n most recently liked songs by user.""" items = sp.current_user_saved_tracks(n)['items'] return items
e3d60e6c3a4bf4b7c46f66d8731c633d8f455885
500,723
def transform_seed_objects(objects): """Map seed objects to state format.""" return {obj['instance_id']: { 'initial_player_number': obj['player_number'], 'initial_object_id': obj['object_id'], 'initial_class_id': obj['class_id'], 'created': 0, 'created_x': obj['x'], ...
685c0c5b22fdff108311338354bb42fb53fd07f6
7,894
def get_mu(area): """ 获取平均入渗率,由于关系很简单,不再录入数据库,这里直接按规则判断。 :param area: int 所在分区 :return: float 平均入渗率 """ if area == 1: return 2.0 if area == 2: return 3.0 if area == 3: return 4.0 if area == 4: return 3.0 if area == 5: return 5.0 if area...
55a2f281ad4d6049aceafa084948b8619adb4053
251,772
from typing import List from typing import Dict from typing import Optional def aggregate_statuses(statuses: List[Dict], dc_voltage=False) -> Optional[Dict]: """Aggregates inverter statuses for use for PVOutput.org uploads. Does some rounding and integer conversion. Args: statuses: List of inver...
8432ec1f14c3e96360934df456e655eb08553f37
40,401
def fits_file_name(rerun, run, camcol, field, band): """ SDSS FITS files are named, e.g., 'frame-g-001000-1-0027.fits.bz2'. We will uncompress this and save it as 'frame-g-001000-1-0027.fits'. This function returns 'frame-g-001000-1-0027.fits' in this case (without the '.bz2' extension). """ ...
5d2b0f4c08ef1a8b25838d0fdc959dbbe0c153bf
452,595
def fit_and_predict(model, X_train, X_test, y): """ Fitting of the model and predicting :param model: Keras model :param X_train: Training samples :param X_test: Test samples :param y: Labels :return: Predicted values """ y_train = y.reshape((-1,1)) model.fit(X_train, y_train, ep...
6e9c1f155ee39b2061a2d3aae1b72d76dcbc0dae
346,479
from typing import List from typing import Any from functools import reduce def prod(list_: List[Any]) -> Any: """ Multiply all elements in a list :param list_: list of elements to be multiplied :return: the product of the elements in the input list """ return reduce((lambda x, y: x * y), lis...
601876d9a90a586c4782f1ff21775e704326f877
283,800
def merge(a, b): """ Given two clocks, return a new clock with all values greater or equal to those of the merged clocks. """ return tuple(map(max, zip(a, b)))
3cdf31c9f32e846fcf8b65bfc2d6a7359d68b317
602,391
def determine_duration_in_seconds(duration_string): """ takes a timestamp of the form '10:10:10' (hours, minutes, seconds) and returns an integer number of seconds. """ hours, minutes, seconds = duration_string.split(":") return (int(hours)*60*60) + (int(minutes)*60) + int(seconds)
cc5c55bee1fb04be7f4c3bad9978f230a25c31e5
237,932
import random import hashlib def md5(*args): """Generates MD5 based on the provided string or a random int""" value = "" if len(args) > 0: value = args[0] if value == "": value = str(random.getrandbits(128)) return hashlib.md5(value.encode('utf-8')).hexdigest()
0d0becac0fad0aca2dcc79923f580ee7e6f06d16
616,407
def bb_intersection_over_union(box_a, box_b): """ Find out how much 2 boxes intersect :param box_a: :param box_b: :return: IOU overlap """ # determine the (x, y)-coordinates of the intersection rectangle x_a = max(box_a[0], box_b[0]) y_a = max(box_a[1], box_b[1]) x_b = min(box_...
bd420cb1b991c350e1554e77666dfaff9c0472ef
595,109
from pathlib import Path def find_feats(directory, utt_id, typ="out_duration", ext="-feats.npy"): """Find features for a given utterance. Args: directory (str): directory to search utt_id (str): utterance id typ (str, optional): type of the feature. Default: "out_duration" ext...
ca12f9ac333c8a794361374b54ad089bebef0cee
287,811
import struct def _GoToIffChunk(file_object, iff_chunk_id): """Jump to a named chunk in a (R)IFF file. Args: file_object: file object. iff_chunk_id: 4 chars ID of the chunk. Returns: length of the chunk in bytes. -1 if the chunk has not been found. If the chunk is found, file_object is posit...
be8864b79777cea1b27f14342e042b89813d7ec5
512,799
def twoNumberSumBetter(array, targetSum): """ This function takes an array of numbers and check if there exists any two numbers sum up to a target number. This implementation has O(nlogn) time complexity and O(1) space complexity. args --------- array: an array of numbers targetSum: a target number out...
e31a73c8c17973766867335368fb2820f345072c
321,183
def sort_top_editors_per_country(editors, editcount_index, top_n): """ Takes a list of lists of editors with editcounts and a top editor cutoff int, returns a sorted top list. """ editors.sort(key=lambda x: int(x[2]), reverse=True) if len(editors) > top_n: editors = editors[:top_n] return editors
97505fccc411758247c2d39b167d87d19cc33454
246,371
def read_key_value_pairs(filepath): """Reads key value pairs from a file. Format: [key]:value :param filepath: file to read from :type filepath: str :return: The key value pairs stored in a dictionary and the leftover string before the first pair. :return: tuple(dict[str,str],str) """ ...
1a733ea773977d950ae8963514867a40ae921732
523,995
def flatten_dict(d, tld="") -> dict: """Flatten the given dict recursively while prepending the upper level key to all the lower level keys separated by a dot (.)""" new_dict = {} for k, v in d.items(): if isinstance(v, dict): lower = flatten_dict(v, tld=f"{tld}{k}.") new_dic...
ed44559d4a3083c51f85a55a07b820d058272412
32,213
import inspect import typing def get_params(signature: inspect.Signature) -> typing.List[str]: """ Given a function signature, return a list of parameter strings to use in documentation. Eg. test(a, b=None, **kwargs) -> ['a', 'b=None', '**kwargs'] """ params = [] render_pos_only_separator ...
c4c6583c8e2ed53f67255209e6a1ec99d3da8d96
369,121
import torch def get_binary_kernel2d(window_size): """ Creates a binary kernel to extract the patches. If the window size is HxW will create a (H*W)xHxW kernel. """ window_range = window_size[0] * window_size[1] kernel = torch.zeros(window_range, window_range) for i in range(wind...
b06c4b5875c6b6b2f9b785ac03ee04778209a7e8
411,987
def multAll(lst): """Multiplies a list of variables together""" if len(lst) == 0: return 0 out = lst[0] for i in range(1,len(lst)): out *= lst[i] return out
6d985d8c69b25f35b14b2bc94cc4e45be8f826e0
635,467
def rollout(rnn, inputs, init_h): """ rnn partial rollout for k steps given init_h Arguments: rnn: RNN network inputs: (B,T,D) init_h: (B,D) Returns: hs: list of hidden states, [(B,H)]*T qs: list of outputs, [(B,O)]*T or [dict (B,O)]*T """ hs, qs = [init_h]...
0af0e2152400faa4a1225771a053a77f020c34fb
565,633
def qD_func(g, a): """ Parameter --------- g : float ratio between exchange and dipolar interaction (supposed g << 1) a : float lattice constant of the cubic unit cell Return ------ qD : float dipolar wavevector of the system """ return g**0.5 / a
524549964aa8130584a80017ce4462bdb5bd0a77
474,202
import functools def empty_energy_result(energy_result): """ Return False if the energy_result list contains only negative numbers, True otherwise """ return functools.reduce(lambda acc, x: acc or (x >= 0), energy_result, False)
980cd49f687ee975eac773139855eec2a4fd59d2
635,104
import math def calculate_dist(coord, a, b, c): """Calculate the distance d from a point (x0, y0) to the line ax + by + c = 0, defined as the shortest distance between a fixed point and any point on the line. It is the length of the line segment that is perpendicular to the line and passes through the...
6610b2901bd2ccd006f9e70ba26f1cf9b300b5e7
392,894
def make_gateway_name( gateway_type, volume_name, host ): """ Generate a name for a gateway """ return "%s-%s-%s" % (volume_name, gateway_type, host)
1918efea9a190432d551919d3772d21612d94b4f
279,194
import csv def _decode_csv(input_str): """ Decodes CSVs into a list of strings. """ reader = csv.reader([input_str], quotechar='"', delimiter=',', escapechar="\\", doublequote=False, quoting=csv.QUOTE_ALL, skipinitialspace=True); result = [] for row in reader: result += row return ...
6ab4e99ea17e502d498c5a79b23bbc37094e4743
582,965
def get_file_location(data_dir, filename): """ Concat data_dir and filename """ return data_dir + filename
4142b6558a019d6600c9993aacfd8118a43cc6ba
552,494
def get_positions_dict(board_size): """Returns a dictionary with the positions of each tile in the puzzle.""" number_of_tiles = board_size ** 2 current_tile = 1 positions = {} for y in range(board_size): for x in range(board_size): positions[current_tile] = (x, y) cur...
ff27a91cb1620a49b40382da4debebad171b1029
141,682
def filter_data(data, options): """Filters the data by the given options.""" if not options: return data return [item for item in data if all(key in item and options[key] == item[key] for key in options.keys())]
1d765e58efe615595537f7190f6afd8b4df30115
486,500
import requests def get_html(url): """ Gets the HTML for a page. """ print("Attempting to grab html...\n") r = requests.get(url) return r.text
1d74b5a67fcfc05190fb0ae24b6de344f6d52e38
138,957
def config_file_toml(tmpdir): """Mock config.toml""" config_toml = """[gcp] [gcp.prod] project_id = "mock-project-dl" bucket = "mock-project-dl" location = "EU" [gcp.test] project_id = "mock-project-test" bucket = "mock-project-test" location = "EU" [gcp.dev] ...
28e648ed3fdb327439bed15717e6965df2353ac3
530,914
import re def is_georgian(txt: str) -> bool: """Detects if a text is in Georgian by its UTF8 char range.""" return re.search(r"[\u10D0-\u10F1]+", txt) is not None
0f232b05994db258210dd431427ff98837f049c2
480,223
from pathlib import Path def find_config_file(src: Path) -> Path: """Look for sniptly.toml config file Args: src (Path): File or folder where to look for sniptly snippets. Raises: FileNotFoundError Returns: Path: Path to tohe config file. """ parents = src.resolve()....
82d0bdafce311087eed2b15c260e11d737df2d54
66,637
def is_good_read(a_read, min_q, min_pct): """Check whether a read has >= min_pct bases of Q >= min_q""" l_qual = a_read.letter_annotations["phred_quality"] good_bases = list(filter(lambda q: q >= min_q, l_qual)) good_pct = round(100 * len(good_bases) / len(l_qual)) result = good_pct >= min_pct r...
056e441d20503f1a78d936c0e0a9695e62a428b9
437,180
def find_home_listing_urls(soup): """ Finds all the relative individual house data links on a landing page. :param soup: a bs4 Soup object :return: list of strings. Each string is a relative URL representing one house listing. """ listing_url_list = [] for url in soup.find_all("a", class_=...
9b4072e2f9167bc1c59eae7618a07826d001ef42
68,987
def mpii_to_openpose(mpii): """ Converts keypoints in MPII order to OpenPose order. Parameters ---------- mpii : numpy.ndarray Keypoints in MPII order. Returns ------- kpss : numpy.ndarray Keypoints in OpenPose order. """ order = [9,8,13,14,15,12,11,10,6,3,4,5,2...
6aaa165f006f5d3350043c375d7e82e278f3d98c
196,220
import collections def multi_dict(pairs): """ Given a set of key value pairs, create a dictionary. If a key occurs multiple times, stack the values into an array. Can be called like the regular dict(pairs) constructor Parameters ------------ pairs: (n, 2) array of key, value pairs R...
ad3ad2f1e6dd591b77a0238e5199c24a36ccc49c
298,659
def KToF(temp): """ Converts temperature from Kelvin to Fahrenheit :param temp: temperature :return: Return the temperature in Fahrenheit """ C = temp - 273 F = (C * 9/5) + 32 F = round(F, 0) return F
4551d1d7a6b170bc3fae5dc4e92f7f6bc3557079
124,326
def convert_contract(contract): """ Map a contract from the DB format to what we want to send back """ return { "_id": contract["_id"], "title": contract["temp_type"], "body": contract["template"], }
d04e4fbf9ffe2db7e432da27858333b062c39272
321,478
def expand_value(value, params): """Expand str / list value with parameters by using str.format() """ if not value: return value if isinstance(value, list): value = list(map( lambda s: s.format(**params), value )) else: value = value.format(**p...
f8fe0633beb4073d16aae2a56fca70e8701778e5
599,138
def get_player_scoring_dict(method='nfl.com'): """Returns a dictionary of scoring rules for each individual player stat. All stats in this dictionary are part of the nflgame API except for defense_two_pt_return. Modified from https://github.com/BurntSushi/nflgame/wiki/Cookbook #calculate-t...
3bfed4ebce6bea65fb4977eed9adcca382e5adcd
194,722
from typing import List from typing import Tuple from typing import Union from pathlib import Path def files_size(files: List[Tuple[Union[str, Path], int]]) -> int: """ Sums the sizes from a supplied list of file sizes """ return sum([x[1] for x in files])
9077c53f8efbcbe553d5d5610f2ac313f2cb1e55
391,272
def _clip(value, lower, upper): """ Helper function to clip a given value based on a lower/upper bound. """ return lower if value < lower else upper if value > upper else value
a84395414ca4fd6739ecebc6c2e0c1ee4716f506
637,639
def choose_color_by_layertype(layertype): """Define colors for nodes based on the layer type """ color = '#6495ED' # Default if layertype == 'Conv': color = '#FF5050' elif layertype == 'Embedding': color = '#FF9900' elif layertype == 'FullConnect': color = '#CC33FF' elif layertype == 'M...
7cf32790a0c4b51c3d24cd77ae2d1d0a52661517
88,182
import math def coords_to_kavrayskiy(coords): """Convert geographical coordinates to Kavrayskiy VII coordinates. A Kavrayskiy VII map is defined with the following dimensions: - Height: pi units - Width: sqrt(3) * pi units """ # convert degrees to radians lat, lng = map(lambda deg: deg * ...
963269e5f4bae78a536d8917c88d5c493b3d5b7f
46,515
import torch def cuda_network(network): """Converts network to CUDA if available""" if torch.cuda.is_available(): print('CUDA available: converting network to CUDA') network.cuda() return network
78729d2e924e216ee976653cebf59b60ce30dff4
484,082
def EI(sections, normal=None): # {{{ """Calculate the bending stiffnes of a cross-section. The cross-section is composed out of rectangular nonoverlapping sections that can have different Young's moduli. Each section is represented by a 4-tuple (width, height, offset, E). The offset is the distan...
24b5ca79f0a3f041586e2f9d7fe8d7953cd96780
699,859
def gen_ticks(bound: int): """Generate increasing ticks from a reversed axis. Parameters ---------- bound : `int` The highest value, tick for this is 0 Returns ------- `List[int]` Array of tick positions """ res = [bound] while bound >= 0: bound -= 7 ...
1e43327c637fe52462437975b61406a895c69d1f
283,134
def pattern_sort(lst, pattern, key=None, reverse=False): """sorts lst based on pattern (e.g. ```pattern_sort(['a','ba','c'], [2, 0, 1], lambda x: len(x))``` would return ```['ba','a','c']```) lst: the list to sort \\ pattern: the pattern to sort with (list of numbers, i.e. ```[2, 1, 0]``` would swa...
142dfaa760ca68b49696270b6026b4c489b13938
490,455
from bs4 import BeautifulSoup def extract_post_text(html): """Returns the contents of each post contained within the html.""" soup = BeautifulSoup(html, 'html.parser') posts = soup.find_all('div', 'showforumtopic-message-contents-text') return [post.text for post in posts]
7a053e9bf578429b495957aed237f69f8a3595eb
192,019
def elem2dict(node): """ Convert an lxml.etree node tree into a dict. """ d = {} for e in node.iterchildren(): key = e.tag.split('}')[1] if '}' in e.tag else e.tag value = e.text if e.text else elem2dict(e) d[key] = value return d
3b754af9c9a518a9e88d94c3868fc4d2f2eed151
204,468
def list_size_reducer(reduction_factor,your_list): """ Optional function to reduce the size of the lists output by the inspiral functions (not the merger lists, as those are much shorter), in order to reduce filesize to conserve storage space. NOTES: The typical reduction factor we have used in ...
377aa817fd172fad24ea1caf55f81a14e2fe3785
113,686
def uVal(thick): """Compute the wals U-value starting from the thickness of the insulation layer Parameters ---------- thick : float insulation thickness in m """ R_th = .17 layers = [ { 'Thickness':.025, 'Conductivity':.33 },{ 'Thickness':thick, 'Conductivi...
2bdb74ad673feddc10f7e83613df577b198d0a38
521,710
import re from datetime import datetime def _get_iso_date(date_string: str) -> str: """ convert date from the form 1/22/2021 13:28:27 to iso format """ regex = r'\d{1,2}/\d{1,2}/\d{4} \d{1,2}:\d{1,2}:\d{1,2}' found_list = re.findall(regex, date_string) if found_list: date_value = datetime.strp...
fa9d6c733014ad4d738d63f2399085f08949c108
683,851
import struct def upstream_forward(sock, data): """ Forward a DNS request to a upstream server using TLS. Params: sock - socket object connected to upstream server data - wireformat DNS request packet to forward Returns: A wireformat DNS response packet Notes: Using DNS over TLS format as described he...
7447786ae51833ff486b2924f5a85639eb760fbf
606,791
def app_config(app_config): """Application config fixture.""" app_config[ "RECORDS_REFRESOLVER_CLS" ] = "invenio_records.resolver.InvenioRefResolver" app_config[ "RECORDS_REFRESOLVER_STORE" ] = "invenio_jsonschemas.proxies.current_refresolver_store" # Variable not used. We set i...
5ed3278a648382a2f164e3b29a0605b43dfe228d
478,622
def unpack_point_msg(msg, stamped=False): """ Get coordinates from a Point(Stamped) message. """ if stamped: p = msg.point else: p = msg return p.x, p.y, p.z
9c73105be73cbcdc55cef0f268851567dcbcd822
651,445
def remove_toffoli_from_line(local_qasm_line, qubit_1, qubit_2, target_qubit): """ Remove a specific Toffoli gate from a line of qasm. Args: local_qasm_line: The line of qasm qubit_1: The first control qubit of the Toffoli gate qubit_2: The second control qubit target_qubit:...
3bd95d5514af966dddb1f203b43749b51def1646
111,423
def dict2list_param(param): """Convert dictionary to list and add name by key.""" if isinstance(param, dict): out = [] for key in param: item = param[key] item["name"] = key out.append(item) return out return param
86fb42be91598987c06c8f6f229b9948b3ffc59a
580,360
def _get_named_code(error) -> int: """Gets the error code as an integer (e.g. 404) from the error string.""" return int(str(error)[:3])
28aec57eccf2793c1efc084f0d86bb22eed973d9
118,803
def clamp_value(value, max_value=1.0, min_value=0.0): """Clamp a value between max and min Args: value (float): value to clamp Kwargs: max (float): max value min (float): min value Returns: .float """ return max(min(value, max_value), min_value)
8dbc949361a0c7aff5501bf2a9e3f3faa1821c98
96,246
def is_auto_primary_key(primary_key: bool, autoincrement: bool) -> bool: """ Checks if field is an autoincrement pk -> if yes it's optional. :param primary_key: flag if field is a pk field :type primary_key: bool :param autoincrement: flag if field should be autoincrement :type autoincrement: b...
3c3c06b9b7e3453cb5078e9c4e5d2355724d1dad
685,844
def transform_symbol_entrez_map(json_data, id_field='hugoGeneSymbol', values_field='entrezGeneId'): """Transform a list of homogeneous dicts into a dict of lists. Using the values of the `id_field` entries as the keys, mapping to lists of corr...
cf2c531d2d36ea0d74b5a443d26d686a0dce55a1
419,535
def parallel_anims(anims): """Combines animations in anims to a single animation, where the animations run simultaneously""" def func(ctx, time): for anim in anims: anim(ctx, time) return func
1393e60836a6a839fd195fd0b5f3464ae3f4b437
587,191
def check_empty(values_cookies, values_no_cookies, negative_values, method=lambda x,y: x in y, convert=lambda x: x): """Returns True if one mode only returns negative values and the other does not return negative values. value_cookies: Series, results of run with cookies value_no_cookies: Series, resul...
c220684279526cfaf0b95e500398076d450fd23c
220,617
def is_digit_or_single_char(token): """ Acronyms or dates are formed either by tokens that have a sigle letter (acronyms ie. I-B-M) or numerical strings that can have more than 1 digit. (ie 2020-10-10). """ return token.isdigit() or len(token) < 2
5152a2628341e28f7e74eca94bbd7e60497ca45d
410,991
def get_last_byte(name): """Return the last byte in a file""" with open(name, 'r') as infp: infp.seek(-1, 2) return infp.read(1)
2a19bd4bb9816fc2fb36aa2b518bfc6f4aa4fba7
318,932
import importlib def get_module(name): """ Convenience method for importing a module (i.e. sub-command) from a string :param name: module name to import :return: the module object """ return importlib.import_module("api_builder.subcommands." + name)
63f362054452034a0712db72a6c1a201553664d2
306,050
def dedupe_tweets(tweet_list): """ Return de-duped list of tweets by throwing out retweets. Assumes list of tweets is in reverse chronological order. """ tweets = [] id_set = set() tweet_list.sort(key=lambda x: x['created_at']) for tweet in tweet_list: if tweet.id_str in id...
425d718a43121adeb557866eef305fa6525a7512
225,760
def MatchScorer(match, mismatch): """Factory function that returns a score function set to match and mismatch. match and mismatch should both be numbers. Typically, match should be positive and mismatch should be negative. Resulting function has signature f(x,y) -> number. """ def scorer(x, y...
fe3829efc64cb4d9785e52b8af6949c147481902
1,636
def rotate180_augment(is_training=True, **kwargs): """Applies rotation by 180 degree.""" del kwargs if is_training: return [('rotate180', {})] return []
4973181fed90fbe4639de7f2eae8b2fe3b5f2448
620,048
def bk_category_initialized(bk_category): """Returns bk_category object (the same as from bk_category fixture), but with grid elements initialized.""" bk_category.initialize_grid_elements() return bk_category
27344a88a1b1a5beb329167725fd803981304a5d
322,104
def export(varname): """Returns "export varname={formated value}\\n" """ var = str(globals()[varname]) frmted_var = var.strip("'\"").replace("\"", "\\\"").replace(r"\n", r"\\n") return f"export {varname}=\"{frmted_var}\"\n"
0c0e0d09cfbc8784fc4ce7e265b5be4e534dc4ff
45,254