content
stringlengths
39
14.9k
sha1
stringlengths
40
40
id
int64
0
710k
def gcd(a,b): """ Return the greatest common divisor E.g. gcd(8,12)=4 """ if (a % b == 0): return b else: return gcd(b, a % b)
9353b6f86f7c77a2f293af5f9d03bc7ba4740a29
98,624
def find_middle(arr): """ Gets the middle of an array :param arr: array :return: middle of array, middle index """ middle = float(len(arr))/2 if middle % 2 != 0: return arr[int(middle - .5)], int(middle - .5) return arr[int(middle)], int(middle)
cff2c4bba9af3684674dfb35c94c1abd24e00663
98,627
def clamp(lower: int, value: int, upper: int) -> int: """ Clamp a value between (inclusive) lower and upper """ return min(max(value, lower), upper)
f83bbf5807fa42b7351d90b481cb76a5bfa28361
98,630
import torch from typing import get_args def create_optim(enc, parameters, **kwargs): """Initialise optimisers. Args: enc (string): type of optimiser - either 'SGD' or 'Adam'. parameters (iterable): parameters to be optimised. Returns: An instance of torch.optim. Raises: Val...
abbc6e41fbbee030316d6c4515ec4a47a4d2824a
98,632
def is_valid_vlan(vlan): """Determine whether vlan is valid.""" try: if 0 < int(vlan) < 4095: return True else: return False except (ValueError, TypeError): return False
9f7864e4dcc1c1c5922a8dc6da463becf2e4943a
98,635
from typing import Any from typing import Iterable from typing import Sequence from typing import Mapping def seq(x: Any) -> Iterable: """Transforms x into an iterable sequence. Maps are transformed into iterations of (k,v) pairs """ if isinstance(x, Sequence): return x elif isinstance(x,...
03e9d13603096d68e51f711610dc1e9d4e71282a
98,639
def e_matrix(distance_matrix): """Compute E matrix from a distance matrix. Squares and divides by -2 the input elementwise. Eq. 9.20 in Legendre & Legendre 1998.""" return distance_matrix * distance_matrix / -2
007f42d868aaacbec926e5bb8e7aeb86e51fe339
98,640
def mac_byte_mask(mask_bytes=0): """Return a MAC address mask with n bytes masked out.""" assert mask_bytes <= 6 return ':'.join(['ff'] * mask_bytes + (['00'] * (6 - mask_bytes)))
3e3acd78402fc4307141e3ef38aaa73e6e546d20
98,641
def tcl_delta_filename(curef, fvver, tvver, filename, original=True): """ Generate compatible filenames for deltas, if needed. :param curef: PRD of the phone variant to check. :type curef: str :param fvver: Initial software version. :type fvver: str :param tvver: Target software version. ...
afd0f12e4413a2557474f75869ca17b59f7660db
98,645
def cleanForIRI(string): """Cleans a string to be suitable for use as an IRI (punctation we dont want is removed)""" iri = "" for c in string: if c.isalnum() or c in ["-", ".", "_", "~"]: iri+=c return iri
ab7e677c4636e023d57286bcdd5301225130c7ec
98,646
def line_edit_val(le_wg, default_val): """Get QLineEdit field value. Parameters ---------- le_wg : QtGui.QLineEdit QtGui.QLineEdit widget default_val : float Default value of the widget Returns ------- le_val : float the value in the widget """ le_val = ...
3b41bea6255a34d0774497a51d99bb84f9a99104
98,653
from typing import List from typing import Iterator import itertools def flatten(x: List[List]) -> Iterator: """ Flatten a list of list. Args: x: List of list of elements Returns: Iterator of flattened array. """ return itertools.chain.from_iterable(x)
4f1b87bfacf7b63b4256475fa30b21e948fc7c9c
98,660
def _retrieve_bucket_name(bucket_url_or_name: str) -> str: """Returns bucket name retrieved from URL. Args: bucket_url_or_name: The name or url of the storage bucket. """ return bucket_url_or_name.split('/')[-1]
74f57752c4bdc175cdd42aea2bfa2f67984da0a3
98,661
def like_cdid(xycell): """ Given an xycell return True if the .value attribute of the cell _appears_ to be a CDID code, a CDID code is an upper cased alpha numeric code of length four. """ if isinstance(xycell.value, str) and xycell.value.isalnum() == True and xycell.value.isupper() == True and len...
af1225dc21c9e730336970fae479fbab05f2d19a
98,662
import unicodedata def normalise(s): # type: (str) -> str """normalises a unicode string""" return unicodedata.normalize("NFKD", s)
3f6ea953e8365472c949ec671c73975ca17a6a16
98,664
def get_parent_resource(project): """Returns the parent resource.""" return f'projects/{project}'
933d13526d48e0a98bcac57933e5c6507cba8209
98,670
def posofend(str1, str2): """returns the position immediately _after_ the end of the occurence of str2 in str1. If str2 is not in str1, return -1. """ pos = str1.find(str2) if pos>-1: ret= pos+len(str2) else: ret = -1 return ret
adab104d88d5a5fc23a949c0dec1982f58b8162a
98,671
def max_norm() -> float: """Gradient clipping max norm.""" return 1.0
a6096a54aec359de99812328c1aae44d9ea687d1
98,676
def _HasDefaultRepr(obj): """Returns True if obj has default __repr__ and __str__ methods.""" try: d = obj.__class__.__dict__ return '__str__' not in d and '__repr__' not in d except AttributeError: return False
34f8515f4c5d25da45fa849aa1fc90beb831dfb7
98,680
import json import codecs def parse_json(filename): """Parse data from filename and return a list of boats.""" country = filename.split("/")[2][0:3] try: rms = json.load(codecs.open(filename, "r", "utf-8-sig"), strict=False) except json.decoder.JSONDecodeError as e: print(f"Error par...
db05745a9ff37377fe419afae50ec3cf9cc643e9
98,682
def contagem(pai,sub_pergaminho): """ Função que retorna a quantidade de pais no sub_pergaminho :param sub_pergaminho: sub_pergaminho a ser lido :return: Int com o numero de pais """ cont = 0 for i in range(len(sub_pergaminho)): if pai in sub_pergaminho[i]: cont += 1 ...
ee3bfc90256713ec5ee3ec9878531d63d14b3450
98,683
def _get_ordered_params(link): """Get a list of parameters sorted by parameter names.""" name_param_pairs = list(link.namedparams()) ordered_name_param_pairs = sorted(name_param_pairs, key=lambda x: x[0]) return [x[1] for x in ordered_name_param_pairs]
ffb42541b005c048f7bcb507bb4733712e2db5ac
98,684
def pop(interp, stackname): """ POP stackname outputs the most recently PUSHed member of the stack that is the value of the variable whose name is ``stackname`` and removes that member from the stack. """ var = interp.get_variable(stackname) return var.pop()
43e96b0d84090c488b5594c560d9f8222cfdc212
98,685
def conv_outdim(i_dim, k, padding=0, stride=1, dilation=1): """Return the dimension after applying a convolution along one axis""" return int(1 + (i_dim + 2 * padding - dilation * (k - 1) - 1) / stride)
56436dde53f4463494011a0fb1f6b3bfc93bbb0a
98,686
def get_problem_name(base_name, was_reversed=False, was_copy=False): """Construct a problem name from base and reversed/copy options. Inverse of `parse_problem_name`. Args: base_name: base problem name. Should not end in "_rev" or "_copy" was_reversed: if the problem is to be reversed was_copy: if t...
03deb05c4565842f234921c06bee1a647f7ce8c0
98,688
def remove_namespace_from_string(name): """ Removes namespace from given string. Does not matter if the given name is a short or long one :param name: str :return: str """ sub_name = name.split('.') if not sub_name: return '' return sub_name[-1]
fd2f0307ea6c419ffefba1e4cbea829e8400901b
98,689
import math def sieve(pos): """Given pos this function returns the determinated prime""" # limit was a totally abritary number that I assigned limit = 5000000 numbers = [True for _ in range(1, limit)] numbers[0] = numbers[1] = False for index_i in range(2, int(math.sqrt(limit))): if...
1a9aaf30508fb23a5404c563eecd4cd52955cb58
98,693
def snspectralist(fname, logffname=None): """ List all the spectra files associated with a phosim instance catalog """ x = [] with open(fname, 'r') as f: for line in f: if 'spectra_file' in line: x.append(line.split()[5]) return x
905b1985e3cc7bd25177b06e6adffd54c0c41cc8
98,695
def transpose_to_new_key(measures, key): """ Translates all notes from their current key to the new key Args: measures (List[List[AnalyzedNotes]]): Song notes grouped by measure key (music21.key.Key): The key signature context. Returns: transposed_measures (List[List[AnalyzedNo...
afc388410650f518da3c25e6ad70a69e3b345693
98,699
import re def cpu_share_to_cores(share): """ Convert CPU shares to core fractions """ number = float(re.findall(r"[0-9\.]+|$", str(share))[0]) unit = re.findall(r"[a-zA-Z]+|$", str(share))[0] if unit == "": return float(number) elif unit.lower() == "m": return float(number)/1000.0
31660b5338326d6c1d5e22e24d01680d759850ab
98,703
def get_suit_of_card(position_of_card, deck): """Returns the suit of the card that has the specific position in the deck""" suit_int = deck[position_of_card][0] if suit_int == 0: return "Spades" elif suit_int == 1: return "Hearts"
0ebef9b82530684d6056ec2d0f11a9ab4babdbe8
98,709
import json def load_dict(file_name): """Loads a dictionary saved in a JSON file.""" with open(file_name) as json_file: key_value = json.load(json_file) return key_value
f68ff426958bbbc38ac2b9ed31dab70191910306
98,713
def dist(v1, v2): """ Root-mean-squared-error between vector 1 and vector 2 """ return (sum([(v1[i]-v2[i])**2 for i in range(len(v1))])/len(v1))**(1/2)
d47a1c14403ca928e7ddcd2c27bad0153231717a
98,716
def parse_llil(context, llil_list): """ Helps the GUI go from lists of instruction data to a cleanly formatted string """ newText = "" for llil in llil_list: if llil is not None: tokens = llil.deref_tokens if hasattr(llil, 'deref_tokens') else llil.tokens newText += "{}: ".fo...
4540cec30a90912f54efd8d9134baaff79192f46
98,719
def _get_inter_grid(hw_isol, r_coarse, ngrid, ncell_grad=2): """ Find the half-width and r_fine for an intermediate grid that guarantees that particles within the central hw_isol box will *not* be ghosts of the particles outside the box (i.e. they are completely excluded from that calculation) ...
bf7b790948e071bb04ba4b1ab352f1608a8e85d9
98,720
def heaviside(x): """Heaviside step function""" theta = None if x < 0: theta = 0. elif x == 0: theta = 0.5 else: theta = 1. return theta
60ea270378598376634d0d666e02ad822a0253a8
98,721
def _get_hostname(url): """ Find the hostname in a url. Assume url can take these forms. The () means optional.: 1: (http(s)://)hostname 2: (http(s)://)hostname:port 3: (http(s)://)hostname:port/path """ if url.find('http://') == 0: url = url.replace('http://...
2b28742df9e6a45fb450424dae7a812d5f901b01
98,727
import math def get_vehicle_max_steering_angle(vehicle_info): """ Get the maximum steering angle of a carla vehicle :param vehicle_info: the vehicle info :type vehicle_info: carla_ros_bridge.CarlaEgoVehicleInfo :return: maximum steering angle [radians] :rtype: float64 """ # 70 degrees...
fa72d9c71e1cfa6710d5ce6f4870ce506b1732e7
98,731
def find_terminals(grammar): """ For a given grammar, return a set of the terminal symbols. :param grammar: The grammar (set of productions rules). :return: set of terminal symbols. """ terminals = set() for key, val in grammar.items(): for word_list in val: for word in word_list: if word not in gramma...
98704fa4adf164e974bef95d11021a2bb2481670
98,748
def cygwin_to_windows_path(path): """Turn /cygdrive/c/foo into c:/foo, or return path if it is not a cygwin path. """ if not path.startswith('/cygdrive/'): return path path = path[len('/cygdrive/'):] path = path[:1] + ':' + path[1:] return path
96aa3279544a835b41cc91ffca85b186310fe78d
98,754
def trailing_zero_bits(i): """Returns the number of trailing zero bits.""" n = 0 while not i & 0x1: i >>= 1 n += 1 return n
86882d80f493ea28e3cb01fcdcc57997ced9257d
98,757
import signal def translate_exit_code(exit_code): """ @brief Check exit code and convert it to a human readable string @param exit_code The exit code from a program @return tuple containing a human readeable representation of the exit code and a boolean value indicating succcess of the e...
cffa455fc96fa3fa3b0f1bea66255e4617328917
98,759
from typing import Iterable def get_components_of_message(data: str) -> Iterable[str]: """Returns the three components (origin, destination, message) of a data packet.""" data_list = data.split(',') origin, destination, message = data_list return origin, destination, message
cc01d0107ef456d8c7d8a9dd0e7c5068e189d665
98,762
def flatten_list(arg) -> list: """Function used for flattening lists recursively""" ls = [] for i in arg: if isinstance(i, list): ls.extend(i) else: ls.append(i) return ls
27ab4f454ff07bc8a0a85e109fb3691b5858ebca
98,772
def to_int(value: str) -> int: """Convert value to an integer number""" return int(value)
5bd6c8681c84458db9fe36ee409efdfc62d46bc7
98,773
def tag_if(self, condition, name): """ Tag the current state of the stack if a condition matches; do noting otherwise. :param condition: The condition to determine if to execute the tagging operation. :param name: The name to use for the tagging. """ if condition: return self.tag(name) ...
7675213f3861832e6dd26d7967075afa1e14823a
98,775
def services_by_user(account, days_back, user_arn, user_name): """ Returns query for eventsource (service) / actions performed by user. """ query_string = f"""SELECT DISTINCT eventsource, eventname FROM behold WHERE account = '{account}' AND (useridentity.arn = '{user_arn}') AND from_iso...
94865c95560581cdacc544dde99e745ce5c006f6
98,776
from typing import Dict from typing import Any def is_existing_emulator_provided(launcher_args: Dict[str, Any]) -> bool: """Returns true if all necessary args were provided.""" return bool(launcher_args.get('adb_port') and launcher_args.get('emulator_console_port') and launcher_args.ge...
f85bc86581d000f3119dfbf005887eb427667629
98,781
def simpleplanet(armageddon): """ This returns a simple planet with g=0, Cl=0, alpha=0, and with an exponential atmosphere. This planet will be used to compare the solver against the analytical solution as well as solve_ivp (Scipy's solver). """ return armageddon.Planet(atmos_func='exponential', Cd...
09420c6c6174f01437b78ca071381cb40dee2348
98,783
def chunker(seq, size): """ :param seq: any sequence structure :param size: the size of the chunk to return when looping through the generator :return: a generator which produces smaller chunks of the seq based on the size parameter """ return (seq[pos:pos + size] for pos in range(0, len(seq), size))
150234020e1fe25fa55ef4c7c014d87b71ebcc63
98,785
def pg_array_escape(tok): """ Escape a string that's meant to be in a Postgres array. We double-quote the string and escape backslashes and double-quotes. """ return '"%s"' % str(tok).replace('\\', '\\\\').replace('"', '\\\\"')
f557b5d7ef9c2a077f03afa22908177acf4bf8ba
98,788
def get_sec(time_str): """Get Seconds from time.""" h, m, s = time_str.split(':') return int(h) * 3600 + int(m) * 60 + float(s)
39e77438e05b30f16265e9cadedc5d8b786eca70
98,793
import math def direction(a, b) -> float: """Returns the angle of a pointing to b.""" dx = b[0] - a[0] dy = a[1] - b[1] return math.degrees(math.atan2(dy, dx))
d0eb3f692f67e18c087ada820582ca1d2bb78b29
98,797
def _get_arg(key, from_kwargs, default): """Remove value from kwargs and return it, else return default value""" if key in from_kwargs: arg = from_kwargs[key] del from_kwargs[key] return arg return default
8bf388b507158fddc3e9d1e605b20e374b3f00b5
98,799
def index_of_in(a, b): """ a = [1, 2, 3, 4] b = [2, 4, 5, 6] index_of_in(a, b) == [1, 3, -1, -1] """ al = list(a) res = [al.index(bitem) if bitem in al else -1 for bitem in b] return res
07738e1d7d6fa552915fd9b3194c98b78ba81b27
98,801
def convert_minutes_to_mins_secs(minutes_in): """Converts minutes to MM:SS format.""" minutes = int(minutes_in) seconds = int((minutes_in - minutes) * 60) out_str = "{:0>2d}:{:0>2d}".format(minutes, seconds) return out_str
1ad443cfb415e70ba88bd5151d65e0395af322e0
98,808
def searchMovieByTitle(movies, title): """ We search for the title with a simple string match in our list movie titles. Keeping it simple, as this is jsut a demo! """ for k in movies: if title.lower() in movies[k]['title'].lower(): return movies[k] return None
dab57f24898df97a2db9171856f900e866020a51
98,814
def encode(s_plaintext: str, bit_length: int) -> list[int]: """Encodes bytes to integers mod p. Example if n = 24, k = n / 8 = 3 z[0] = (summation from i = 0 to i = k)m[i]*(2^(8*i)) where m[i] is the ith message byte Args: s_plaintext: String text to be encoded bit_length: bit l...
8a9b6cee5669742afa641ae8503ff2aa6788ae0f
98,815
def with_metaclass(mcls): """ 2.7 and 3.5+ compatable metaclass decorator python2 uses a __metaclass__ class atribute whlie python3 has a class level keyword argument. """ # http://stackoverflow.com/questions/22409430/portable-meta-class-between-python2-and-python3 def decorator(cls): b...
70756c881e802e78b6e215216ea45dc1e7aed31a
98,818
def _profile_tag_from_conditions(conditions): """ Given a list of conditions, return the profile tag of the device rule if there is one """ for c in conditions: if c['kind'] == 'device': return c['profile_tag'] return None
ca9a640ecfe52714ba901eeaf952e7c18a5a4210
98,819
def read_lines_from_tar_file(tar_file): """ Read the tar file returning the lines """ txt = tar_file.read() txt = txt.decode('utf-8') return txt.splitlines()
82c702a4c2fcdb9115774c32730a49f1b3280c8c
98,828
def revrange(a,b): """ Returns the tuple (b-1, b-2, ..., a) Note that this tuple is the reverse of tuple(range(a,b)) Parameter a: the "start" of the range Precondition: a is an int <= b Parameter b: the "end" of the range Precondition: b is an int >= a """ assert type(a) == int an...
28c0de37d354401f45db33f83d0397b6cde8ed80
98,829
def list_between(begin, end, r): """Returns the list of players from begin to end (inclusive).""" if begin <= end: return list(range(begin, end+1)) return list(range(begin, r.nPlayers)) + list(range(end+1))
425b34d554e128f0329b8532a5cc39318d9c13d1
98,837
import pickle def load_exp(fname): """ Load an experiment from the specified file. """ with open(fname, 'rb') as f: exp = pickle.load(f) return exp
29e453e49a30f330d7231ef11538ace9ccba467e
98,843
def list_bucket_with_prefix(s3_client, bucket, prefix): """ Paginated listing of contents within an S3 bucket prefix. """ token = None more_keys = True keys = [] while more_keys: kwargs = { 'Bucket': bucket, 'Prefix': prefix, } if token is not None: ...
17db9d62daa6119951c1023373eb98211f02c244
98,845
def naive_pass_if_low(player, lowest_to_keep): """Strategy logic: simply keeps if >= lowest Arguments: player -- self-reference to the player using the strategy lowest_to_keep {int} -- lowest """ if player.current_card.rank.value >= lowest_to_keep: return False else: ...
b8d83ff2a1c9ef8d3b140061d791a27a7291386b
98,851
def calc_tree_depth(n_features, max_depth=5): """Calculate tree depth Args: n_features (int): Number of features max_depth (int, optional): Max depth tree. Defaults to 15. Returns: [int]: Final depth tree """ # Designed using balls-in-bins probability. See the paper for detai...
c818e7606d0b6661c33d2d32487e35c316279420
98,852
def k_half_mode(alpha, beta, gamma): """finds the wavenumber where the transfer function is surpressed by 1/2""" fraction = 0.5 return 1./alpha * (fraction**(-1./gamma) - 1. )**(1./beta)
b080ba88a213c88b17862b47b6f47e600f6185ca
98,853
import logging def _setup_logger() -> logging.Logger: """Setup logging.""" log_format = '[%(asctime)s][%(levelname)s] %(message)s' stream_handler = logging.StreamHandler() stream_handler.setFormatter(logging.Formatter(log_format)) stream_handler.setLevel(logging.INFO) custom_logger = logging.g...
276c5c301cfe0a3a58f8ba3a0ef38221a624bd9f
98,854
import re def is_ok_words(text: str) -> bool: """Check if the redaction is one of several words that are OK :param text: A string to check :returns: True if it's an OK word, else False """ text = " ".join(text.strip().split()) text = re.sub( r"confidential|name +redacted|privileged?|r...
89d8e0e29db8d3a39e330b7aa40aa2ddd7d1cbe4
98,859
from typing import Sequence from typing import Mapping def _build_query_to_hit_index_mapping( hit_query_sequence: str, hit_sequence: str, indices_hit: Sequence[int], indices_query: Sequence[int], original_query_sequence: str) -> Mapping[int, int]: """Gets mapping from indices in original query s...
014c9b7d52b6318b97855e8c42149051d0b93fcc
98,860
import torch def indices_to_dense_vector(indices, size, indices_value=1., default_value=0): """ Creates dense vector with indices set to specific value and rest to zeros. This function exists because it is unclear if it is safe to use tf.sparse_to_dense(indices, [size], 1, validate_indices=False) with ...
2199a732e3196bcbc6c4609292c41c39c790fcb9
98,862
import glob def LabelPaths(label, src_suffix): """Compute single proto file source/destination paths from a Bazel proto label. Args: label: Bazel source proto label string. src_suffix: suffix string to append to source path. Returns: source, destination path tuple. The source indicates where in the...
d4494317bdcb96404bf33354846f5ad875139fc4
98,864
def OneLett_to_ThrLett(resi, cap = 'standard', suppress_alert = True): """ Usage: OneLett_to_ThrLett(resi, cap = 'standard', suppress_alert = True) This function receives resi, a one-letter amino acid code, and returns the three letter amino acid code. If cap(italization) is standa...
43fdbbf3f9a47846ee8ff07d162b975645b9e9bf
98,865
def depth_sw_interface_Glover1959(x, Q, K, rho_f, rho_s): """ Calculate depth of the fresh-salt water interface in a coastal aquifer, following Glover (1959). """ gamma = (rho_s - rho_f) / rho_f y2 = 2 * Q / (gamma * K) * x + Q**2 / (gamma**2 * K**2) depth = y2**0.5 return depth
56814e40e4b8523427e5b07872379741ad68cb9b
98,867
def biot(h, d, k): """ Calculate the dimensionless Biot number. .. math:: Bi = \\frac{h\\, d}{k} Parameters ---------- h : float Convective heat transfer coefficient [W/(m²⋅K)] d : float Characteristic length or dimension [m] k : float Thermal conductivity [W/(m...
26e73c263700d7b82021e9437e25049dcdc81b20
98,868
def clean_null_values(dic): """Cleans the entries with value None in a given dictionary.""" return {key: value for key, value in dic.items() if value is not None}
293438bb01dd1344484683521233b7f6064960e7
98,869
import re def clean_sheet_dir_name(name): """ Clean up / sanitize sample sheet directory name. :param name: String :return: String """ return re.sub(r'[\s]+', '_', re.sub(r'[^\w\s-]', '', name).strip())
2ea16776785564781359d2dc998ccf30d2c71a87
98,873
def _bbox_crop(image, bbox): """Crop PIL.Image according to bbox. Args: image(PIL.Image): image to crop bbox(iterable): iterable with 4 elements. Returns: Cropped image. """ width, height = image.size ratio = int(max(bbox[2], bbox[3]) * 0.75) center_x = int((2 * bb...
2bdac5ed84a48663120366fbbb9aae5fae0e4e28
98,876
def sma(prices, n=20): """ Calculate simple moving average of one stock using rolling mean Params: @prices: price data of stock with dates as index @n: number of days in smoothing period (typically 20) Return: @moving_avg: Moving average price of the stock """ moving_avg = prices.rollin...
91bbc2ec257d27fa51c16691cc00ebf5132ae99f
98,884
import math def _NextHighestSquare(n): """Takes an integer and returns the next highest square number. Args: n (int): Any integer. Returns: (int): The nearest square number larger than n. For example, input 1 returns 4, input 4 returns 9, input 10 returns 16. """ return int(math.pow(math.f...
afec8c707e811b07e2d9e5d3fc2a8d22e25bbce4
98,890
def get_schema_from_path(path): """Match table from path.""" return path.split('/')[-2]
77ca333607666d1483a1527972ea119739b1aac5
98,891
def usage(err=''): """ Prints the Usage() statement for the program """ m = '%s\n' %err m += ' Default usage is to get Branch info from SalesForce.\n' m += ' ' m += ' sfTaskBranch -cl do (load TBs from MODs)\n' m += ' or\n' m += ' sfTaskBranch -cs -p all do|3600 (...
f9a057b913f5c6d67a8f7812a800bf31cfadd288
98,894
def get_network_size(netmask): """Get cidr size of network from netmask""" b = '' for octet in netmask.split('.'): b += bin(int(octet))[2:].zfill(8) return str(len(b.rstrip('0')))
be55892656ce78d130770fcb3d1cda3169e27e52
98,896
def color_code(color_number): """Generate an ANSI escape sequence with the given color number or description string.""" return '\033[' + str(color_number) + 'm'
1859919bccc07befd74e6c335064e8a74d3620c4
98,900
from typing import TextIO from typing import Dict from typing import List from typing import Optional def parse_record_log(file: TextIO) -> Dict[str, List[Dict[str, Optional[str]]]]: """ Parse record.log from Doozer into a dict. The dict will be keyed by the type of operation performed. The values wil...
4c84ace475a26a96bb8bc5fe22c333d81e5a82bb
98,902
def topological_order(graph): """Topological sorting by maintaining indegree :param graph: directed graph in listlist format, cannot be listdict :returns: list of vertices in order :complexity: `O(|V|+|E|)` """ V = range(len(graph)) indeg = [0 for _ in V] for node in V: # dét...
b501a2be13da21549281e49898ddd5011ae13647
98,903
def vector_orientation (x, y): """Assigns an orientation to a 2D vector according to the Spanish CTE compass rose.""" if x <= 0.3826 and x >= -0.3826 and y <= 1 and y >= 0.9238: return "North" elif x < 0.8660 and x > 0.3826 and y < 0.9238 and y > 0.5000: return "Northeast" elif x <= 1 and x >= 0.8660 and y <= 0...
d23030e759dcb697cd4ed9d1ad8a50ac51204ac7
98,907
def pick_fields(obj, fields): """ Returns a new object with only the fields in fields. """ return {field: getattr(obj, field) for field in fields}
a03093aece4e7d46b8b5a00ec5b7602012d73623
98,911
def remove_final_whitespace(string): """ Return a copy of *string* with final whitespace removed from each line. """ return '\n'.join(x.rstrip() for x in string.split('\n'))
136692e32aa14ec607c908e7cd455e7885d6d463
98,912
def create_exclude_set(exclude_file): """ Create a list of interactions to be excluded from analysis, e.g. if they are part of the positive set. """ excludes = [] with open(exclude_file, 'r') as fin: for line in fin: fields = line.split('\t') p1, p2 = fields[0].st...
e4bc50e3766d6005ef67c55cb515eb53b381df86
98,920
import time def annotate_heatmap(im, # the AxesImage to be labeled # a 2D numpy array of shape (N, M) containing the standard deviations to be used to annotate # the heatmap std, # a 2D python array containing Boolean values indicati...
dc85f08ecdecb49c4f8b170ce331117f677f5075
98,932
from pathlib import Path def traces_path(app): """Returns the path to the traces.json for a given app name.""" tests_path = Path(__file__).parent.parent sub_path = f"fixtures/aws_trace_analyzer/{app}/traces.json" return (tests_path / sub_path).resolve()
94a259b7973fcf33997a2cdab4ebf80f4d584f46
98,933
def split(str, delimiters, joiner=None): """Split a string into pieces by a set of delimiter characters. The resulting list is delimited by joiner, or the original delimiter if joiner is not specified. Examples: >>> split('192.168.0.45', '.') ['192', '.', '168', '.', '0', '.', '45'] >>> s...
4aaaf0fa85bbb67c465c06cb6c61dc72258ba749
98,936
def control_plane_ingress_ip(k8s_client): """Return the Control Plane Ingress IP from Kubernetes service""" ingress_svc = k8s_client.read_namespaced_service( name="ingress-nginx-control-plane-controller", namespace="metalk8s-ingress", ) return ingress_svc.spec.load_balancer_ip or ingress...
dd1b78f30ec60defb13713c9324882069eda0499
98,939
def find_note_index(scale, search_note): """ Given a scale, find the index of a particular note """ for i, note in enumerate(scale): # Deal with situations where we have a list of enharmonic # equivalents, as well as just a single note as and str. if type(note) == list: if search_note in note: return i ...
e1317fd2e726c4bfd2fc507532a34681741114b3
98,942
def qa_filter( mhm_df, has_genus=False, min_larvae_count=-9999, has_photos=False, is_container=False, ): """ Can filter a cleaned and flagged mosquito habitat mapper DataFrame based on the following criteria: - `Has Genus`: If the entry has an identified genus - `Min Larvae Count` : ...
db70da2dcc96088a84a257eabb5f15509faca3ec
98,943
def format_changes(github_config, owner, repo, prs, markdown=False): """Format the list of prs in either text or markdown""" lines = [] for pr in prs: number = "#{number}".format(number=pr.number) if markdown: link = "{github_url}/{owner}/{repo}/pull/{number}".format( ...
061457b0b893ef0c0af4dd7fe576c43760ac7570
98,945
def FilterBuildStatuses(build_statuses): """We only want to process passing 'normal' builds for stats. Args: build_statuses: List of Cidb result dictionary. 'stages' are not needed. Returns: List of all build statuses that weren't removed. """ # Ignore tryserver, release branches, branch builders, c...
816361edd5db9d6f9bc758629a2d71a3e1431f8d
98,946
def passageLinks(passages, sec0Type, sec0, sec1, tillLevel): """Provide navigation links for passages, in the form of links to sections of level 0, 1 and 2 (books, chapters and verses). If `sec0` is not given, only a list of sec0 links is produced. If `sec0` is given, but `sec1` not, a list of links ...
becc9428aa6fba655679aaa98c9faf0f5599fc31
98,949