content
stringlengths
39
14.9k
sha1
stringlengths
40
40
id
int64
0
710k
def parseDigits(digits: str, base: int) -> int: """ Wrapper around the "int" constructor that generates a slightly more detailed ValueError message if the given string contains characters that are not valid as digits in the given base. """ try: return int(digits, base) except ValueEr...
3f1c6aac10f5c08d4e3ee48347a2c511546843c0
105,695
def createList(r1, r2): """Create a list from a range.""" return list(range(r1, r2 + 1))
4bf90beaa5cc02d408e9e0939c0adf3082da95b0
105,697
def get_setter_func(field_name, value): """ Returns the setter function patched to the target model. :param field_name: the name of the field storing the choice :param value: the value to set :return: function """ def func(self, commit=False): setattr(self, field_name, value) ...
e7116ad3927a4333ec8ebc59fc006e2e732e6e4a
105,698
def return_student_assignment(df, student, assignment, assign_id, stu_id): """Return entries of selected student and assignment in dataframe.""" if isinstance(student, list) & isinstance(assignment, list): return df[ (df[stu_id].isin(student)) & df[assign_id].isin(assignment) ...
77b28b09cd5ffba992fb06a9ee7578577b16c28f
105,699
from typing import List def list_intersection(lst1: List, lst2: List) -> List: """Intersect the values of two lists Parameters ---------- lst1 : List First list lst2 : List Second list Returns ------- Intersected list """ return [value for k, value in enumerat...
d6c850e2c786224e2c95fc9d50c84bdf6a4e73f1
105,703
import re def buy_sell_ratio_color_red_green(val: str) -> str: """Add color tags to the Buys/Sells ratio cell Parameters ---------- val : str Buys/Sells ratio cell Returns ------- str Buys/Sells ratio cell with color tags """ buy_sell_match = re.match(r"(\d+)% Bu...
d203aea8afefb131409e8b4b2040bf7eceecf87d
105,706
def constantize(term): """Formats a term (string) to look like a Constant.""" # Replace spaces by underscores and enclose in quotes for a Constant term return f"'{term.replace(' ', '_')}'"
203f16a6f6bba2737242e3f266d7b2ab4fc6c387
105,723
def volume_level(self): """Volume level of the media player (0..1).""" return self._volume
578c014566ea94b127e4733f300a5fe403be0e4b
105,724
def eval_E(E, t): """ Tries to evaluate the possibly function E, otherwise just returns the value E. """ if type(E)==float or type(E)==int: return E else: try: return E(t) except: print("Something went awfully bad in eval_E(E,t)") return None return
2ccfa6d153016908fc5ac884821c02a0e7281064
105,728
def get_cursor_ratio(image_size: tuple, screen_size: tuple): """ Used to calculate the ratio of the x and y axis of the image to the screen size. :param image_size: (x, y,) of image size. :param screen_size: (x, y,) of screen size. :return: (x, y,) as the ratio of the image size to the screen size. ...
7e0f0e66ba572657cc058aa7e83feeac2212f818
105,731
def indent(text, indent=4): """Indents text with spaces.""" return u'\n'.join([u' ' * indent + x for x in text.splitlines()])
81684634882cdc061c3b453eaa8aff69e91accec
105,734
from datetime import datetime def timestamp_to_datetime(timestamp): """Convert utc timestamp to local datetime.""" return datetime.fromtimestamp(timestamp / 1000)
627bb3bf12c18c87203b96836be3c8998ddbdc0c
105,736
from datetime import datetime def get_strfdate(year, month=None, day=None): """Returns an string format of a date depending on args given. """ if day: date = "{}-{}-{}".format(year, month, day) date = datetime.strptime(date,"%Y-%m-%d") return date.strftime("%d %b, %Y") if month...
8b7e8ea63c3cecd0dd567d00c923b07be1754025
105,743
def get_node_index(nodes): """Get node index""" return nodes.index.to_list()
bc167397f73e9f9845fa4cf79769bae1ab1cf88b
105,744
def _encoded_str_len(l): """ Compute how long a byte string of length *l* becomes if encoded to hex. """ return (l << 2) / 3 + 2
c4656413acae81d21246aecd6a6ad624483839f4
105,745
def puzzle_hash_for_address(address): """ Turn a human-readable address into a binary puzzle hash Eventually this will use BECH32. """ return bytes.fromhex(address)
4b068d6ed9bc075382a6c3a1da1701211d1c4466
105,748
def extract_numbers(value, type=str): """Extracts numbers only from a string.""" def extract(vs): for v in vs: if v in "01234567890.": yield v return type("".join(extract(value)))
cbe4303dcdc5546eb3d65d822a4ddc5a66376ade
105,749
def mfouri(self, oper="", coeff="", mode="", isym="", theta="", curve="", **kwargs): """Calculates the coefficients for, or evaluates, a Fourier series. APDL Command: *MFOURI Parameters ---------- oper Type of Fourier operation: Calculate Fourier coefficients COEFF from...
1ad1244e7b64a1caf4fe2f35aa85a45bc7e9146c
105,750
def _parse_scram_response(response): """Split a scram response into key, value pairs.""" return dict(item.split(b"=", 1) for item in response.split(b","))
0e55c2e82f1967d1f3bf7c27529bcca422114d77
105,753
def computeLPSArray(pattern): """ Utility function to calculate the LPS (Longest Proper Prefix that is also a Suffix) array. Args: pattern (str): pattern Raises: Exception: pattern not of type string Returns: array: the LPS array """ if isinstance(pattern, str) == ...
7ee298557aeba19996f22441c3eab722d86f960f
105,755
def create_corpus(documents, dictionary): """Creates BOW (bag-of-words) corpus for a set of documents and its word dictionary. Parameters: documents (list of str): set of documents dictionary (gensim.corpora.Dictionary): gensim dicionary of words from dataset Returns: list of int list: ...
eb2cdc86e75c24938754628c088470b2cff7f89e
105,756
import secrets def random_split(s, d, n): """Split each secret given in s into n random Shamir shares. The (maximum) degree for the Shamir polynomials is d, 0 <= d < n. Return matrix of shares, one row per party. """ p = s[0].modulus m = len(s) shares = [[None] * m for _ in range(n)] ...
64479ee985d7973e6f7f88f7186c7d5b6f521b98
105,760
def from_flags(flags, ednsflags): """Return the rcode value encoded by flags and ednsflags. *flags*, an ``int``, the DNS flags field. *ednsflags*, an ``int``, the EDNS flags field. Raises ``ValueError`` if rcode is < 0 or > 4095 Returns an ``int``. """ value = (flags & 0x000f) | ((ednsf...
3eabff49babd72278f3d7de52c3e7477bc85774c
105,766
def unquote(s): """ Strips matching single and double quotes from the start and end of the given string. """ if len(s) > 1 and ((s[0] == '"' and s[-1] == '"') or (s[0] == "'" and s[-1] == "'")): return s[1:-1] else: return s
03e86b68a01b5a05e9fb3430d1efa398f1ba7d03
105,768
def clipped_map(value, from_low, from_high, to_low, to_high): """Clip a value to fit a domain and then map it to a range. :param value: value to be clipped and mapped :param from_low, from_high: domain of the value. If the value is outside this domain, it will first be clipped. :param to_low, ...
f1851e620db7c32287e6e6a5b44eca323c978244
105,770
from io import StringIO import tokenize def has_comment(src): """Indicate whether an input line has (i.e. ends in, or is) a comment. This uses tokenize, so it can distinguish comments from # inside strings. Parameters ---------- src : string A single line input string. Ret...
124345d5fef3f518009dd6bd3f67c58b2780d554
105,771
from typing import List def explain_stability(*args): """ Based on ~ CSC2032: Tutorial 1.4.1/2.1.1 ~ Question 4 The user must type the definition below -- of course as a user you may change the definition typed out. By changing the string below. """ a = "If an input list contains two eq...
e7711f269157e477426fa480aee793accc1e319c
105,772
def hamming_distance(str1, str2): """ For binary strings a and b the Hamming distance is equal to the number of ones (population count) in a XOR b. """ diffs = [a^b for a, b in zip(str1, str2)] count = 0 for diff in diffs: while diff != 0: diff = diff & (diff -1) co...
38ebb74d091603f74be62e1a2dbdd8f53fdceb81
105,778
def is_child(parent, child, locations): """ Determines if child is child of parent Args: parent: parent_id child: child_id locations: all locations in dict Returns: is_child(Boolean): True if child is child of parent """ parent = int(parent) child = int(child...
803da3c89530861abc8e355d7dc1cee4f986f10a
105,779
def get_prediction_breakdown(dashboard): """Retrieves the prediction breakdown Parameters: ---------- dashboard : plsexplain.dashboard.Dashboard Returns ------- Callable The API handler for the prediction breakdown """ def get_prediction_explanation_internal(index): ...
c8daf69d8c4e5992112663d51dde96902d2cbaee
105,784
def solve_substring_left_to_right(text): """ Solve a flat/small equation that has no nested parentheses Read from left to right, regardless of the operation :param str text: A flat equation to solve :return: The result of the given equation :rtype: int """ text = text.replace("(", "") ...
7ac57effd54bebdaa1a5479a2d33881a0b640b73
105,785
import socket def _addressfamily_host_lookup(hostname, options): """ Try looking up ``hostname`` in an IPv4 or IPv6 specific manner. This is an odd duck due to needing use in two divergent use cases. It looks up ``AddressFamily`` in ``options`` and if it is ``inet`` or ``inet6``, this function us...
445f126fd197f7fdd9e51cb53533f7729516648f
105,793
def _getOrientation(orig_channel, orient): """ Return a character representing the orientation of a channel. Args: orig_channel (string): String representing the seed channel (e.g. 'HNZ'). The final character is assumed to be the (uppercase) orientation. orient (str ...
ce03f454e076c0b61e2950d0a3c19a810a4dd421
105,797
import re def strings(text): """Return a list of extracted alphanumeric strings. Example: strings('53_7A,a735') --> ['53', '7A', 'a735'] """ return re.findall(r'[A-Za-z\d]+', text, re.ASCII)
c9bfa3246d108fdf2a102783288d73e8987ed0e4
105,798
def x_and_y_separation(df): """This function splices the given dataframe into two dataframes - x an y Parameters ---------- df : pandas.DataFrame A given dataframe; Returns ------- x : pandas.DataFrame The x variables dataframe; y : pandas.DataFrame The y variab...
2200eeb938ef7e0544c7a125f91321e4798b8d00
105,806
def _trim(p, bound): """ Trim a probabilty to be in (bound, 1-bound) Parameters ---------- p: numpy.array of numbers (generally between 0 and 1) bound: small positive number <.5 to trim probabilities to Returns ------- Trimmed p """ p[p<bound]=bound p[p>1-bound]=1-boun...
b53ce1dcf0751214d1b3a5adede3186a862f88a5
105,812
def sample_perturb(counts_frame, crime_type, pct_change): """ Utility function to increase the counts of specific crime types after sampling by a given percentage. Inputs : counts_frame, the counts of crime dataframe produced by sampler crime_type, string of crime type that we want to incre...
aa52e4abceac70409865d12e4c1889bc543190da
105,813
def split_string_at_suffix(s, numbers_into_suffix=False): """ Split a string into two parts: a prefix and a suffix. Splitting is done from the end, so the split is done around the position of the last digit in the string (that means the prefix may include any character, mixing digits and chars). The...
dfd6a3d1981574b9319f2fbcb2d8d57e4d051a84
105,814
def get_day_type(day_date): """ Determine whether the given date is a weekday or weekend day. :param day_date: Date to check :return: String indicating the day type """ if day_date.weekday() < 5: day_type = 'WEEKDAY' else: day_type = 'WEEKEND' return day_type
2adee8690e9e82e6ffd1cfb465df70047df56168
105,820
def get_param_stats_num(param_file, observed_df): """ Get number of parameters and statistics from simulation. :param param_file: param file that was used to run the simulations. :param observed_df: dataframe of parameter and summary stats from one simulation. :return: param_num: number of paramete...
c3ed19b5983a8a785804a5594216f04f63448125
105,821
def get_size(fileobject): """get the size of a file in bytes Args: fileobject ([type]): [description] Returns: int: the size in bytes """ # region def getSize(fileobject): fileobject.seek(0,2) # move the cursor to the end of the file size = fileobject.tell() return size
21db8240a146aea2991027931e9eb635b581e48f
105,825
def simpletlv_unpack(data): """Unpacks a simpletlv coded string into a list of 3-tuples (tag, length, newvalue).""" result = [] rest = data while rest != '': tag = ord(rest[0]) if tag == 0 or tag == 0xff: raise ValueError length = ord(rest[1]) if length =...
88564ce6bfb93ad9ff9cf685a3d14d2dedaa029d
105,827
def _CreateSuiteDescriptionDict(suites): """Gets a dict of test suite names to descriptions.""" # Because of the way that descriptions are specified, all of the test suites # for different bots should have te same description. We only need to get # description from one entity for each test suite name. results...
c4851b121e2586f9c7582e98a2d9499513af43e4
105,828
def product(value1, value2, value3): """ Returns the product of the three input values. """ prod = value1 * value2 prod = prod * value3 return prod
efe7da7ddbca7ca281026ea3aafa2258731af9ae
105,834
def bit_set(x, n): """Returns if nth bit of x is set""" return bool(x & (1 << n))
654fca38dba3e0571164452488754758c5e251a8
105,835
def ne(a, b): """Evaluate whether a does not equal b.""" return a != b
c6b4189051cbc0f7204706a0e8b4114569903552
105,836
def next_is(tokens, expected): """ Consumes the next token if it's `expected` otherwise does not touch the tokens. Returns whether it consumed a token """ if tokens.peek(None) == expected: next(tokens) return True return False
29c6e8bd7e7ee489d553ae2174741f67c3a1024c
105,837
def split_matrix(a): """ Given a matrix, return the TOP_LEFT, TOP_RIGHT, BOT_LEFT and BOT_RIGHT quadrant """ if len(a) % 2 != 0 or len(a[0]) % 2 != 0: raise Exception('Odd matrices are not supported!') matrix_length = len(a) mid = matrix_length // 2 top_left = [[a[i][j] for j in ran...
41a39ed04387dbb4dd6edb77878effaf3e198463
105,840
import struct def get_os_architecture() -> int: """Get current os architecture (32 or 64 bit).""" return struct.calcsize('P') * 8
5c00da37be2e532023536e11b6390103fb3d6664
105,841
def fix_timestamp(timestamp): """ Fix timestamp values, due to a len issue when posting them to Zipkin. :param timestamp: The unix timestamp format. """ default_timestamp_len = 16 if len(str(timestamp)) < default_timestamp_len: miss_len = default_timestamp_len - len(str(timestamp)) ...
01c644e57cd5c84fd1d54884b97f3b7a027c842d
105,842
def Fence(Token,Fence1='\"',Fence2='\"'): """ This function takes token and returns it with Fence1 leading and Fence2 trailing it. By default the function fences with quotations, but it doesn't have to. For example: A = Fence("hi there") B = Fence("hi there","'","'") C = Fence("hi ther...
d9b10ac9a2eac0b423591fa8ca728bdc95b2c14c
105,847
def get_bucket_key_from_path(bucketed_path_with_prefix, prefix): """ Get bucket and key from path, assuming it begins with given prefix. Args: bucketed_path_with_prefix (str): Prefixed path including bucket and key. prefix (str): Prefix to look for in bucketed_path_w...
f3ded454042f796a6840faa59049322ff774a163
105,848
def ensure_empty(gen): """Return True if the generator is empty. If it is not empty, the first element is discarded. """ try: next(gen) return False except StopIteration: return True
ee28cefef8a9d3445692a89be0d36ba457caa35e
105,849
def querydict_to_dict(querydict): """ Converts a QueryDict instance (i.e.request params) into a plain dictionary """ pure_dict = {} for item_key in querydict.keys(): item_val_list = querydict.getlist(item_key) if item_val_list: if len(item_val_list) == 0: ...
74111d1540a1903c453db15e3a89f1340468c309
105,850
def shorten_to_len(text, max_len): """ Take a text of arbitrary length and split on new lines. Keep adding whole lines until max_len is reached or surpassed. Returns the new shorter text. """ shorter_text = '' text_parts = text.split("\n") while text_parts and len(shorter_text) < max_l...
0df300df761181563e6e829eb6c19095119a51dc
105,851
def gather_loss(loss_dict: dict, loss_weight: dict): """Gather overall loss and compute mean of individual losses. Args: loss_dict (dict): individual loss terms loss_weight (dict): weights for each loss, only the loss with valid weight will be meaned. """ loss = 0.0 sca...
0269eb7389ed837cee8e1115f9566b5ef4f05834
105,852
def _human_readable_time(seconds: float) -> str: """ Convert seconds to a human-readable time. """ minutes, seconds = divmod(seconds, 60) hours, minutes = divmod(minutes, 60) days, hours = divmod(hours, 24) months, days = divmod(days, 30) years, months = divmod(months, 12) if years >...
52c25c06835442c25473cca4f31615da8f600fed
105,855
def _classification_column_names(otu_defs): """ column names for a csv file being used for a classification problem between two cohorts. First column is 'cohort' (predicted variable). Remaining columns are otu names (input features) """ column_names = list() column_names.append('cohort')...
7cb81251b8c19016c4c61738bd642f950610dfb7
105,858
def shortest_edge_paths(graph, edge_index, position=0.5): """Find the shortest path from the edge given by `edge_index`. If we have no lengths, then each edge has length 1. This could be achieved by using the "derived graph", but our use will also require knowing the _vertex_ degree of the path. W...
959e5715a09f2e15e0bf5fb62131a8ac51502618
105,860
def manhattan_dist(pos1, pos2): """ Manhattan distance between two points. Parameters ---------- pos1 : tuple of (int, int) the first position pos2 : tuple of (int, int) the second position Returns ------- manhattan_dist : int Manhattan distance between two poin...
15f0c60d60fdcf4bffbfed0610c35fff6a021dde
105,861
def remove_large_spaces(text): """Iteratively replace any large spaces or tabs with a single space, until none remain.""" for pattern in ['\t', ' ']: while pattern in text: text = text.replace(pattern, ' ') while text.startswith(' '): text = text[1:] while text.endswith(...
b437dff8a8380bd3b48b959cbd7ff0f56f8fbd3f
105,864
def _product(*args): """Returns a Cartesian product of provided `*args`. The result is the same as the list of lists produced by nested loops going through every passed collection: result = [] for x in arg1: for y in arg2: ... return result.a...
7766cd06dde5d18cb1d7a58e6148467e43673f39
105,873
def diff_sets(desired, current): """ Diff two state dictionaries by key :param desired: the desired state :param current: the current state :type desired: dict :type current: dict :return: returns a tuple that contains lists of added, removed and \ changed elements from the desired ...
4c68f6d5e9f8555dcda8e3acdc9cdefd3b501c9d
105,875
import click import json import collections def _get_ldap_dict(ldap_json): """ return an OrderedDict for the given json file Parameters ---------- ldap_json : string filepath to json file with config options to be loaded Returns ------- ldap_dict : collections.OrderedDict ...
1b3472dbf203a875ebc22c3cade50de5a44ac1d2
105,877
def sec0to10(val): """ Converts the system security values into values between 0 and 10 """ retval = val * 10 if retval < 0: retval = 0 elif retval > 10: retval = 10 else: retval = int(round(retval)) return retval
2c4e2d8527ec5fe672a3f16874d55be875d686b1
105,879
def remove_peptide_sequence_alterations(base_sequence, insert_sites, delete_sites): """ Remove all the sequence insertions and deletions in order to reconstruct the original peptide sequence. Parameters ---------- base_sequence : str The peptide sequence string which contains a combinat...
1c61ae3dfd3bbbeead17696a052c73c77cd81d27
105,881
def archimedes(mass_in_air, mass_in_liquid, density_material_theoretical, density_liquid): """ uses results from Archimedes measurements, including absolute uncertainty values, to provide part densities and percentage uncertainty. Each variable mu...
c0b55dca1f743a5d082371081c51da5524395166
105,882
def season_months(season): """ Return list of months (1-12) for the selected season. Valid input seasons are: ssn=['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec', 'djf', 'mam', 'jja', 'son', 'mayjun', 'julaug', 'marapr', 'jjas', 'ond', 'ann'] ""...
5c25922a6fd777599138b6b84db736fb8ace48a7
105,884
def rgb2gray(im): """Transforming image from RGB to grayscale. Parameters ---------- im : np.array matrix of image. Returns ------- np.array image in gray. """ r, g, b = im[:,:,0], im[:,:,1], im[:,:,2] gray = 0.2989 * r + 0.5870 * g + 0.1140 * b return gray
adebb3be7bf0a4992e391f6e5697c7edc2149e95
105,892
def get_line(batch): """Build a list of relevant data to be printed. Args: batch (dict): an object from project batches response Returns: str: tab delimited list of relevant data to be printed """ return "\t".join( [ str(batch.id), batch.last_status....
fd8ad9db9bd7861da4df27b3a455e737b2113b89
105,896
def response_json(status, count, data): """Generates JSON for http responses :param status: True if data is valid and there are no errors, False otherwise :type valid: boolean :param code: http response code :type code: int :param count: Total number of fields in data :type count: int ...
8fcf6f4eeb39e3c07543edbf3e4ae983e9880cce
105,905
def get_box_coord(ctr, size, truncate=True): """Get box coordinates given parameters.""" return ctr - size / 2.0, ctr + size / 2.0
8280e672c6e5ed1a1e03a1b9e3ecba1d71ea8dc1
105,908
def _make_block_conf(block): """Returns a list of .config strings for a block (list) of items.""" # Collect the substrings in a list and later use join() instead of += to # build the final .config contents. With older Python versions, this yields # linear instead of quadratic complexity. strings = ...
4b33453a4e5a68dec175b1d890099e5de572f42f
105,909
def get_line(picardfile, phrase): """Read file. Report line number that starts with phrase and the first blank line after that line. Return tuple of integers """ with open(picardfile, 'r') as f: start = 1000 end = 1000 for i, line in enumerate(f): if line.startswith(p...
9de8e0140964a25deb3d5501fd7f03d7b364b74f
105,911
def toefl_words(testfile, wrddict): """ Makes sure every word in the toefl test is in the dictionary. testfile: Toefl test filename. wrddict: word to index mapping. """ toefls = [] with open(testfile) as toefl: for line in toefl: toefls.extend(line.replace("(", "").replac...
0378a22141576c9f31809a8e31e30db72557acf6
105,914
def prepare_lists(listen_by_party_and_bundesland): """ This function quickly prepares the dictionary by including in each dataframe a column Sitz_Bundestag. Input: listen_by_party_and_bundesland (dict): contains for each Bundesland a dictionary containing parties with their lists Outpu...
c9a153d272b324b912b3c050193aa7f9048f7631
105,916
import io import torch def _deserialize(serialized: bytes): """ Deserializes from bytes using PyTorch's serialization tools. Args: serialized (bytes): The data as bytes. Returns: Any: The original data """ buff = io.BytesIO() buff.write(serialized) buff.seek(0) ...
f3c2a76f8d074ffb944eae3e9346f466ece611ee
105,917
def ReadScript(script_uri): """Method to read a sql script based on its local path. Arguments: script_uri: Local URI of file containing SQL query. Returns: Query String contents of the URI location. Raises: IOError: If the script cannot be read. """ with open(script_uri) as fp: return fp....
84505ed9ae4951a9b8d67309a87b38998f38be43
105,921
def is_set(parameter: str): """ Checks if a given parameter exists and is not empty. :param parameter: param to check for :return: if param is not None and not empty """ return parameter and parameter != ""
932b4128484885d3e40a7a33f0d1d99c76d5067b
105,925
def w(l, es): """Compute w""" return (1 + l) * es
e682cef81bae5bd1b24ee4c0c0fcdf90fd862391
105,929
import re def camelize(string, uppercase_first_letter=True): """ Convert strings to CamelCase. Examples:: >>> camelize("device_type") "DeviceType" >>> camelize("device_type", False) "deviceType" :func:`camelize` can be thought of as a inverse of :func:`underscore`, ...
15169d9aa24c0ed1c395bcb4d9de56b4422dddb3
105,931
import random def get_examples(d, vtk_class, lang, all_values=False, number=5, ): """ For the VTK Class and language return the total number of examples and a list of examples. :param d: The dictionary. :param vtk_class: The VTK Class e.g. vtkActor. :param lang: The language, e.g. Cxx. :...
c028338330bbc904a7121d99324a96ea11107a22
105,933
def count_non_zero(vector): """Count the number of non-zero values in the vector @arg vector list() of integers @return the number of non-zero values """ cnt = 0 for val in vector: if val != 0: cnt += 1 return cnt
69682520072632f9110108d9e8178c3b5c690ba2
105,936
import re def validate(password): """ Validates password using regexp. Input: password (string): Password to validate Output: (boolean): bool if password is valid or not """ regexp = re.compile('^(?=.{1,20}$)(?=[a-zA-Z\u00C0-\u00D6\u00D8-\u00f6\u00f8-\u00ff])[a-zA-Z0-9.-\u00C0-\u00D6\u...
dff1fff3ce7ee3643b8004752109bac30c2c23bc
105,940
def to_bytes(strng): """Convert a python str or unicode to bytes.""" return strng.encode('utf-8', 'replace')
70298981ce67753eb879049747399f1203ed97f2
105,941
import re def _replace_patterns( content: str, plugin_name: str, old_specifier: str, new_specifier: str ) -> str: """ Replace specific patterns. It identifies three patterns: 1) strings of the form: <plugin-name><old_specifier_set> 2) YAML strings of the form: plugin-name: vers...
78c27506e786c0f247eb7de3c9d8fe3f72df1c44
105,942
def make_xml(top='Hello', bottom='World'): """ Test xml that prints a shipping label with top and bottom text seperated by a line. """ resp = """<?xml version="1.0" encoding="utf-8"?> <DieCutLabel Version="8.0" Units="twips"> <PaperOrientation>Landscape</PaperOrientation> ...
81cd6a97415574933010875bf633504c14a0da98
105,947
def sql_placeholder_string(n: int) -> str: """ Return an SQL value placeholder string for n values. Example: sql_placeholder_string(5) returns '(?,?,?,?,?)' """ return '(' + ','.join('?'*n) + ')'
04d8ca2255f4c3d47d93571b212e38abf8a366dc
105,953
import logging def get_logger(*args, **kwargs): """Fetch an instance of logging.Logger. This is just a stub that can later be expanded if we want to perform any processing on the Logger instance before passing it on. Using this as a middle-man also ensures that our logging configuration will alw...
587f7cb8c88761600270a78c56afb892c7c011cb
105,954
def get_index_for_position(season1, season2, pos = 'QB'): """ Function that returns the index of common players for a specific position :param season1: The first year of season data :param season2: The send year of season data :param pos: The position to get the index for :return: The index with...
c358d6e5231c6dbcbdce1272e19ef7f7deb1f532
105,955
def get_type_filter(desired_type): """Returns a value filter that only keeps values of the given type.""" return lambda arg_value: arg_value.type is desired_type
77a7e813b40e4524e708030630513146948a5d9e
105,956
def normalize(array): """Normalize the values of a Numpy array in the range [0,1]. Parameters ---------- array : array like The array to normalize Returns ------- ndarray The normalized array """ min_value = array.min() max_value = array.max() size = max_val...
a0a1cb2b681ed8274483da6516a4d92231182687
105,957
import re def valid_md5_str(md5_str): """ 校验md5 字符 :param md5_str: :return: bool """ str_list = md5_str.split('.') n_len = len(str_list) if n_len != 2: return False n_len_md5 = len(str_list[0]) if n_len_md5 != 32: return False find_str = re.findall('[^a-z0-9]+'...
01e6de753dd4fc76f76b7e434c020d506e1d7c6f
105,959
def what_type(data): """ Description: Identify the data type :param data: raw data (e.g. list, dict, str..) :return: Data type in a string format """ return str(type(data)).split('\'')[1]
c38274da376d8e4ef28090e9a1951797eeb4dac0
105,961
def get_neighbours(x_coord, y_coord): """ Returns 8-point neighbourhood of given point. """ return [(x_coord - 1, y_coord - 1), (x_coord, y_coord - 1), (x_coord + 1, y_coord - 1), \ (x_coord - 1, y_coord), (x_coord + 1, y_coord), \ (x_coord - 1, y_coord + 1), (x_coord, y_coord + 1), (x_...
2c1843d5c317aaec8f159b2cfc67aa04d2925441
105,963
def get_attr(attr, element): """ Like get, but for attributes. Complexity: O(1) params: attr: the attribute to get element: the element to search returns: the attribute """ return getattr(element, attr)
8ec94cf776fc6aa2d37cfd47c46b0a3a28e00610
105,968
def SIRmodel(v, t, N, beta, gamma): """Determines three differential equations of the SIR model depending on initial conditions and chosen parameters. dSdt determines the rate of change of those that are not infected but are susceptible to being infected. dIdt determines the rate of change of the total...
813136dee289bba8a253c3c2542927d8cf44990a
105,974
def append_PKCS7_padding(val): """ Function to pad the given data to a multiple of 16-bytes by PKCS7 padding. """ numpads = 16 - (len(val) % 16) return val + numpads * bytes(chr(numpads), 'utf-8')
297af4f3e7ea6522a265573517b763f3684513ec
105,977
def remove_axes_from_shape(shape, axis): """ Given a shape tuple as the first input, construct a new one by removing that particular axis from the shape and all preceeding axes. Negative axis numbers are permittted, where the axis is relative to the last axis. """ if len(shape) == 0: re...
0b1cb00f7b9a9d89700094a875b7c158efd50422
105,978
def capitalise_first_letter(old_string): """ Really simple method to capitalise the first character of a string. Args: old_string: The string to be capitalised Returns: new_string: The capitalised string """ if len(old_string) > 0: return old_string[0].upper() + old_str...
c0de488ad15cdc48059c532b7d1935c0112534d7
105,980