content
stringlengths
35
416k
sha1
stringlengths
40
40
id
int64
0
710k
def onBoard(top, left=0): """Simplifies a lot of logic to tell if the coords are within the board""" return 0 <= top <= 9 and 0 <= left <= 9
2b2007ae2e3acdbb9c04c3df1397cffce97c6717
10,247
def name( path ): """Extracts the resource name.""" return path[1+path.rfind('/'):]
7e8448e5b1c62c30e7ae28c80580731aa9f6f9fb
10,250
def report_dfa(q_0, dfa, g): """ Give a complete description of the DFA as a string """ output = "" output += "----------- DFA ----------- " + "Goal: " + g + " ----------- \n" transitions = [(i,dfa[(i,sigma)],sigma) for i,sigma in dfa] transitions.sort() for i,j,sigma in transitions: output += (f"delta({i},{s...
99d86557b9e1aede93f46e1ef78ecb1fe6cdbf30
10,251
def score(n): """根据成绩,计算成绩的级别,级别有:A、B、C、D 成绩>=90 ——A 成绩>=80 ——B 成绩>=70 ——C 成绩>=60 ——D 参数: - n-:成绩 返回值:返回‘A’或‘B’或者'C'或者'D' """ if n >= 90: return 'A' if n >= 80: return 'B' if n >= 70: return 'C' if n >= 60: return 'D'
fb854dbdb77e31b75a70eddf6d001814100c44d3
10,252
import os def normalize_path(p): """Normalize filesystem path (case and origin). If two paths are identical, they should be equal when normalized.""" return os.path.normcase(os.path.abspath(p))
747948440eeebd99fca79ec413a616eaaba4dbdd
10,253
def algo_options(): """ Return the list of default options for supported algorithms. """ return {"grid": "", "hubbard": "", "medial": "-merge -burst -expand", "octree": "", "spawn": ""}
f52c12efe477bd50a49e7053cca97fc9e4072433
10,254
def shutting_down(globals=globals): """ Whether the interpreter is currently shutting down. For use in finalizers, __del__ methods, and similar; it is advised to early bind this function rather than look it up when calling it, since at shutdown module globals may be cleared. """ # At shutdow...
01f601b989611b06a438a3be3e15937eff389038
10,255
def _err(msg=None): """To return a string to signal "error" in output table""" if msg is None: msg = 'error' return '!' + msg
029fae3786df61160867696fb71cc94b2edf0506
10,256
def add_xls_tag(file_name): """ Check the file_name to ensure it has ".xlsx" extension, if not add it """ if file_name[:-5] != ".xlsx": return file_name + ".xlsx" else: return file_name
e053d9f7dad8e638122e93d05e49c5a06de3e664
10,258
import os import json def Open(filename): """ You can open/read a Zype File with Open() function. Usage: Open(filename) Filename is the Zype File's Name. """ if os.path.isfile(filename): with open(filename) as Zype: content = Zype.read() content = conten...
20a48af9c7e7a0f74e72fa02c7241915b5c5b78c
10,260
import sys import os def check_enableusersite(): """Check if user site directory is safe for inclusion The function tests for the command line flag (including environment var), process uid/gid equal to effective uid/gid. None: Disabled for security reasons False: Disabled by user (command line o...
466ce7da62b6578db0f99ca31c7271ef3bc2d832
10,262
def pedestal_ids_file(base_test_dir): """Mock pedestal ids file for testing.""" pedestal_ids_dir = base_test_dir / "auxiliary/PedestalFinder/20200117" pedestal_ids_dir.mkdir(parents=True, exist_ok=True) file = pedestal_ids_dir / "pedestal_ids_Run01808.0000.h5" file.touch() return file
edda4c192e577774e0cc4a38aaa7d838127e7dcd
10,263
def get_fa_icon_class(app_config): """Return Font Awesome icon class to use for app.""" if hasattr(app_config, "fa_icon_class"): return app_config.fa_icon_class else: return 'fa-circle'
3766abb1f80b7ccea9e09a5edf011f1586e9b49e
10,264
from typing import Any def get_valid_ref(ref: Any) -> str: """Checks flow reference input for validity :param ref: Flow reference to be checked :return: Valid flow reference, either 't' or 's' """ if ref is None: ref = 't' else: if not isinstance(ref, str): raise ...
16c66dc9e0568bcd33e1cc9956ed31b5ae47595e
10,267
def return_dict(): """ "interfaces": { "Tunnel0": { "state": "UP" }, "Tunnel1": { "state": "DOWN" } } } """ return {"interfaces": {"Tunnel0": {"state": "UP"}, "Tunnel1": {"state": "DOWN"}}}
2c3e71341c425166d11aba9175e3a98027c3d53e
10,268
import torch def replace_magnitude(x, mag): """ Extract the phase from x and apply it on mag x [B,2,F,T] : A tensor, where [:,0,:,:] is real and [:,1,:,:] is imaginary mag [B,1,F,T] : A tensor containing the absolute magnitude. """ phase = torch.atan2(x[:, 1:], x[:, :1]) # imag, real ret...
b535e4271c6fc4fe508af358fbe3eee59a95cc6b
10,269
def cut_rod2(p, n, r={}): """Cut rod. Same functionality as the original but implemented as a top-down with memoization. """ q = r.get(n, None) if q: return q else: if n == 0: return 0 else: q = 0 for i in range(n): ...
2fa1433dffb9099709e466025645c4981f289692
10,270
def _set_karma(bot, trigger, change, reset=False): """Helper function for increasing/decreasing/resetting user karma.""" channel = trigger.sender user = trigger.group(2).split()[0] if reset: bot.db.set_nick_value(user, 'karma', 0) return karma = bot.db.get_nick_value(user, ...
72531c032625c365e057057edb84672b86a4faac
10,271
def monthly_file_name(var, model, rcp): """Function for creating file connections for different variables scenarios and models. Preasently, ensemble member r1i1p1 is assumed, as well as 200601-210012 dime span for the monthly data.""" # e.g. hfls_Amon_CNRM-CM5_rcp85_r1i1p1_200601-210012.nc f = var + "_" + "Amon_...
7aeea6d3724c470e076645ddb96877e9fa15843f
10,276
def calc_distance(l): """Calculates distance between list items in two lists""" # l needs to start from zero, get lowest number and substract it from all numbers min_l = min([x[1] for x in l if x[1] != ''], default=0) l = [[x[0], (x[1] - min_l)] for x in l if x[1] != ''] distance = 0 for id...
57d52eb4bb4b772024d68cb397f2e315825a25df
10,277
def lam(x, lam0, alpha=4.0): """Return classic alpha model lambda value(s) for input value(s).""" return lam0 * ( 1.0 - x**alpha )
37a10d890acc2b983c09300b865e58fe9dc2f7fe
10,278
def subset(part, whole): """Test whether `part` is a subset of `whole`. Both must be iterable. Note consumable iterables will be consumed by the test! This is a convenience function. Examples:: assert subset([1, 2, 3], [1, 2, 3, 4, 5]) assert subset({"cat"}, {"cat", "lynx"}) ...
4200ea95e0c9ff03d0b7589812d0313c5d13cfac
10,279
from pathlib import Path def stem(fname, include_suffix=False): """/blah/my_file.json.gz --> my_file""" path = Path(fname) stem = path.stem # If a filename has multiple suffixes, take them all off. stem = stem[: stem.index(".")] if "." in stem else stem if include_suffix: stem = stem...
9e4c557dff8583f9129215f91f8e123f062ccf52
10,280
import sqlite3 def username_lookup(userName): """ Lookup user from availability.db by unique username """ # connect to db conn = sqlite3.connect("availability.db") # create cursor c = conn.cursor() # check if lookup initiated for specific user or for all users if userName: # quer...
36c0927a79791eca8d69f574799490c716f2fe05
10,281
def get_backend(config): """ :param app: celery instance :type app: celery.Celery """ klass = config.backend_class kwargs = config.backend_kwargs url = config.backend_url return klass(url, **kwargs)
57d6c82f99888ae992503492a8edfa802315a3cc
10,282
def atol(s, base=None): # real signature unknown; restored from __doc__ """ atol(s [,base]) -> long Return the long integer represented by the string s in the given base, which defaults to 10. The string s must consist of one or more digits, possibly preceded by a sign. If base is 0, it i...
f39aa403cbad98c448a35305c97c595bc3a77c02
10,283
def tokens_to_sovatoms(tokens: float) -> int: """Convert tokens to sovatoms.""" return int(tokens * 100000000)
23f4bc3a1afc4520b5e2416332702d0a594c5039
10,284
def _frame_only(frame, skeleton_data): """ Save only one frame from skeleton data """ result = [] for raw_descriptor in skeleton_data: if raw_descriptor[0] == frame: result.append(raw_descriptor) return result
1581ddc52eedc81dbe2cc71ed66524b6af5f4b3d
10,285
def sort_node_id(a, b): """ @param a, b: node pair to be sorted by id @type treenode, treenode """ if a.id > b.id: return 1 else: return -1
2db33f63f009d4d50c922b4daf45dbac56a60312
10,286
def __Boundary_outside__(self): """Is the boundary is on the outside of the mesh.""" return self.leftCell() is not None and self.rightCell() is None
cce3ffadc5e2598beae8b320b4d2f5122d6de904
10,287
def flow_cell_mode(info_reads): """Return flow cell sequencing mode.""" res = '' if info_reads: read_lens = [ a['num_cycles'] for a in info_reads if not a['is_indexed_read']] if len(read_lens) == 1: res = '1x{}'.format(read_lens[0]) elif len(set(read_lens)) ==...
0563d0c163c2bd42b05d07fb30940669a8ef3513
10,289
def sortKey(e): """ This sorts the chores based on their start time. e[0] is the start time for all the chores in my array of chores. """ return int(e[0])
00d37751d23fe6210b406485cbd76906075b2578
10,290
def merge_into_dict(original, secondary): """Merge two dictionaries into the first and return it. This is simply a conveinence wrapper around the dictionary update method. In addition to the update it returns the original dict to allow for chaining. Args: original: The dict which will be updated. seco...
899d40396885f0775f2cbaa865702ed0e5706dba
10,291
def normalize_obs(obs_dict, obs_normalization_stats): """ Normalize observations using the provided "mean" and "std" entries for each observation key. The observation dictionary will be modified in-place. Args: obs_dict (dict): dictionary mapping observation key to np.array or ...
c866b6d18df13b9e6903b7d96024d48cde99d2ff
10,292
def get_closest_language(differences): """[summary] Args: differences ([list]): [contains tuples with language and difference score] Returns: [tuple]: [containing 3 closest possible languages to given input] """ # print(differences) differences_sorted = sorted(differences, key=...
55e231e249c8bae5116be0b2feac96d184a6cbee
10,293
def remap_labels(labels, mappings): """ :param labels: :param mappings: :return: """ for source, target in mappings.items(): labels[labels == int(source)] = target return labels
df418b76c7831ac315e095cd9bf75b7596b04a91
10,296
def get_bprop_l2_loss(self): """Grad definition for `L2Loss` operation.""" def bprop(x, out, dout): dx = x * dout return (dx,) return bprop
6f52c07d9133939f5a7dc6d12a2416169f32147e
10,297
def change_dimension_shape_resolution(changed_dimension_shape_conflict): """Create a resolution for a changed shape prior""" return changed_dimension_shape_conflict.ChangeDimensionResolution( changed_dimension_shape_conflict )
c6f93f080ed14876a4724924dc848fb835364c33
10,298
def extract_tracklist_begin_num(content): """Return list of track names extracted from messy web content. The name of a track is defined as a line which begins with a number (excluding whitespace). """ tracklist = [] for line in content.splitlines(): # Empty line if not line: ...
7d860fb0ea444ae0d9bd536a4644fa6b1c11a826
10,299
def net_solar_radiation(rs, albedo=0.23): """ Calculate the fraction of the solar radiation that is not reflected from the surface (Allen et al. 1998). Parameters ---------- rs : float Solar radiation (MJ m-2 day-1). albedo : float, optional Albedo (-), default is 0.23 (valu...
41a8930966db4a658d1c3ec31e754987bc9ed387
10,300
def text_color(message='{}', color_code='\033[0;37m'): """Set text to a color, default color is White""" no_color = '\033[0m' return f'{color_code}{message}{no_color}'
bede08b771b33ce26bbb0ee4fd42f3712d224cc1
10,301
def get_max_elements_in_row(row: list) -> int: """ Loops through the dataset and gets the max elements in a list if one is found in the list or 1 if all strings. """ max_array_count = 0 # get the max height of the cells. for item in row: if isinstance(item, list) and len(item) > max...
0f8573bbabe95c03e3eda5949ff9c1c209b0f5fa
10,302
def get_adventure(): # noqa: E501 """Get all adventures # noqa: E501 :rtype: List[Adventure] """ return "do some magic!"
8ca2cb6b8e0aa004ca7fa54ec35f907c3351cab8
10,303
def cst_efield_2freq_cut_healpix(cst_efield_2freq_cut_healpix_main): """Make function level cut down HEALPix 2-freq efield beam.""" return cst_efield_2freq_cut_healpix_main.copy()
b7b2388efbe4f6ca1e22c08e46ec70d391c68ce8
10,304
def shift_chord(chord, shift): """Shift chord""" if chord < 12: new_chord = (chord + shift) % 12 elif chord < 24: new_chord = (chord - 12 + shift) % 12 + 12 else: new_chord = chord return new_chord
bc72df71282d8ae7d15e591bb2a46e5d00f1cd30
10,305
def register_new_user(access, username, password): """ Register a new user & handle duplicate detection """ if access.user_data(username) is not None: raise ValueError("User '%s' already exists!" % username) if username in access.pending_users(): raise ValueError("User '%s' has already regis...
25b98c4def9da81d71176aed196f61b2e71d64c5
10,306
def get_not_constant_species(model): """ get species of the model that are not constant @param model: libsbml.model @type model: libsbml.model @return: list of species @rtype: list[libsbml.species] """ def not_const(s): return not( s.getConstant() or s.getBoundaryCondition() ) return...
abb376899405fa1623ec5ca646d0399e067fd5cc
10,307
from math import floor from typing import Tuple from typing import Union def conv_output_shape( h_w: Tuple[int, int], kernel_size: Union[int, Tuple[int, int]] = 1, stride: int = 1, padding: int = 0, dilation: int = 1, ) -> Tuple[int, int]: """ Calculates the output shape (height and width)...
ea757a413a3b38ea024b85dd6987beda8a3b9aeb
10,310
def sum_all(grid_values): """ Calculates the sum of all grid values. Results in scores from :param grid_values: values of grid :return: metrics score """ score = sum(grid_values) return score
a7741961c240cb8edbff050566b7f9341a203af7
10,311
def _path(from_object, to_object): """ Calculates the 'path' of objects starting from 'from_object' to 'to_object', along with the index of the first common ancestor in the tree. Returns (index, list) tuple. """ if from_object._root != to_object._root: raise ValueError('No connecti...
0ccfe54d36832b8dce3c55168f02abb3c79261ef
10,312
def is_type_name(type_name): """Does not handle keywords. """ return type_name[0].isupper()
fd8f4e7cdc0bac7f00bc41ecaa87533103907db5
10,314
def process(data, action): """Выполняет верхнюю операцию в стаке и возвращаем результат в стэк""" if not action.function: return True # Если для операции не хватает аргументов или значение не подходит - выдаём ошибку try: # Берём нужное кол-во аргументов для операции if action.a...
84bce6a3d942e1db308b3fe4848da9044cc856d4
10,315
def get_key_in_nested_dict(nested_dict, target_key): """ Traverses the passed dict to find and return the value of target_key in the dict. :param nested_dict: dictionary to search in :param target_key: key you are looking for :return: values of key """ for key in nested_dict: if key ...
f0e677cc02ccbab7a4e3c09ba8bf1694c52b1818
10,316
import argparse import sys def _parse_args() -> argparse.Namespace: """ Creates an arg parser for AsciiQrCode and parses the supplied args. :return: The parsed args. """ parser = argparse.ArgumentParser(description='Processes ASCII QR Codes.') parser.add_argument('-v', '--verbose', action='sto...
bea8fb2e58b55e3e749036e171aa7bc5796d330b
10,318
def unique(data): """ in python 3: TypeError: '<' not supported between instances of 'int' and 'str' need to keep the same Type of member in List """ data.sort() l = len(data) - 1 i = 0 while i < l: if (data[i] == data[i + 1]): del data[i] i -= 1 ...
5102a0d868741f9dca745e11972987ce74e78b8a
10,320
def PtknsToStr(path_tokens): """ There are three ways to store paths: As a single string: '/Protein/Phe/Ca' <- the format entered by the user As a list of tokens ['Protein', 'Phe', 'Ca'] <- split into tokens As a list of nodes in a tree (pointers to nodes in a tree hierarchy) This functio...
8dd64e6213f8a49f5b20619261a4b3d8daa8d95d
10,321
def traverse_grid(start_cell, direction, num_steps): """ Helper function that iterates over the cells in a grid in a linear direction and returns a list of their indices. """ indices = list() for step in range(num_steps): row = start_cell[0] + step * direction[0] col = start_...
0ce6f91759c36a63b103ebff2cddd8dd50ca837b
10,322
def __format_size(file_size): """ Format file size information depending on the amount of bytes. """ file_size = int(file_size) list_units = ["B", "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"] list_index = 0 while file_size > 1000: file_size = float(file_size) / 1000 l...
d893e09281fce75cb5d0ea011cca623767ae6cbb
10,323
def parse_wiggle_header(header): """ :param header: :return: """ _, chrom, start, step = header.strip().split() foo, chrom = chrom.split('=') assert foo == 'chrom', 'Unexpected wiggle header: {}'.format(header) bar, start = start.split('=') assert bar == 'start', 'Unexpected wiggle h...
87525a16b849fca7f78b786c220c7861de085b82
10,324
def _path_in_ignore_dirs(source_path: str, ignore_dirs: list) -> bool: """Checks if the source path is to be ignored using a case sensitive match Arguments: source_path: the path to check ignore_dirs: the list of directories to ignore Return: Returns True if the path is to be ignored...
5d392392e735bdbc1e60cca9414fca8a1eb3ec0c
10,325
import argparse def init_parser(): """Initialize and return the command line parser.""" autoddoc_description =\ ("AutoDDoc 0.1\n" "Documentation generator script for D using DDoc.\n" "Copyright Ferdinand Majerech 2011.\n\n" "AutoDDoc scans subdirectories of the current direc...
49090858be2baed2f0efcf375c195267d5eacc38
10,328
import requests def open_recipe_file(file, recipes_path=None, github_repo='bioconda/bioconda-recipes'): """ Open a file at a particular location and return contents as string """ if recipes_path: return open(f'{recipes_path}/{file}').read() else: # if no clone of the repo is available loc...
ce5fc3c054bc937203966459e9981a5befdae40b
10,329
def confidence_interval(data, column_name, confidence_level): """ get a 95% confidence interval from a bootstrap dataframe column Parameters ---------- data : pandas dataframe the bootstrap dataframe generated by :py:func:`.bootstrapLE` column_name : string the statistic that y...
69668a88030c0a2d6d90dbc1b834cbab76d0ec17
10,330
def dist_to_freq(dist: float, bw: float, ts: float) -> float: """ """ return int(2 * dist * bw / (299792458 * ts))
5e232569e25e663ca6b13a7acdd0c5f1b2afd5aa
10,331
def pig_latin(wrd): """Returns the Pig Latin version of a word. For words that begin with a consonant, take the consonant/consonant cluster and move it to the end of the word, adding the suffix 'ay' to the end of the word. For words that begin with a vowel, leave the word as is and add the suffix ...
2eba5f4aaff1391e60f4097e526539d5b486c9bd
10,334
def parse_units(units_str): """ Extract and parse the units Extract the bounds over which the expression is assumed to apply. Parameters ---------- units_str Returns ------- Examples -------- >>> parse_units('Widgets/Month [-10,10,1]') ('Widgets/Month', (-10,10,1)) ...
18f35a06aedfc9d026cfa70a1217b0b5b0420ca5
10,335
def seg_pixel_accuracy_nd(label_imask, pred_imask, vague_idx=-1, use_vague=False, macro_average=True, empty_result=0.0): """ The segmentation pixel accuracy (for MXNet nd-arrays). ...
7da093ef624dee07fd335021ae2317d53583e612
10,336
import importlib import inspect def getCoursesFromModels(): """This method imports and inspects Models.py file and adds name of its classes to the list. User class is skipped so it is not added into list of courses. Returns: list: List of string names of classes in Models.py file. """ co...
fd3685ca68e98afd9384ad0711e43ac68e02c94d
10,337
def extract_seed(path, key): """ Scrape the 5-character seed from the path and return it as an integer. :param path: path to the tsv file containing results :param key: substring preceding the seed, "batch-train" for splits, seed-" for shuffles """ try: i = path.find(key) + len(key) ...
c5073ad43e8a966aba5382894490aa6cbc871271
10,338
def get_neighbor_dict_from_table(db, table_name): """ returns a dict with bgp neighbor ip as key and neighbor name as value :param table_name: config db table name :param db: config_db """ neighbor_dict = {} neighbor_data = db.get_table(table_name) try: for entry in neighbor_data...
17d8230956c36db8c79bd98f0eec63320b6e77d0
10,339
import pickle def get_cells_to_calculate_variance(file_path, percentage_of_extreme_cells=15): """ Get a list of cells to use to calculate the methylation and variance In this case we have a list of all cells that might be possible and the avg methylation and variance of them and we want to take the pe...
c151b03cb873f179eb946dd12f6a286aeea8e7a3
10,340
def calc_buckets( start: float, upper_bound: float, /, *, increment_ratio: float = 1.20 ) -> tuple[float, ...]: """Calculate histogram buckets on a logarithmic scale.""" # See https://amplitude.com/blog/2014/08/06/optimal-streaming-histograms # for more details. result: list[float] =...
541fdb81b150a81d24b515acaf53365afb4b62b4
10,341
def from_hexpoints(s): """Parses a string from its codepoints as hex. Given a string containing one or more code points (as hex values), parse it to a a string. For example, the input "006E 006F" produces output "no". """ return "".join([chr(int(cp, 16)) for cp in s.split()])
55b5088d000cf90059ca93d7e3895aee043d554e
10,342
def basicFitness(individual, env): """ The trivial case, where fitness is just the result of passing through the environment. """ return individual.result
7d108bac92ce390699b66e1ead5b08080856c5be
10,344
import os def solution_name() -> str: """ Get the Solution Name from environment variable :return: the solution name """ return os.environ["SOLUTION_NAME"]
a43b79ac9ad39b22ab65de02ec6845f3058e259e
10,345
def find_missing_integer(arr): """ Find the first missing integer in unsorted array of integers """ # segregate integers, with negative (including zero) on right and positives # on left left = 0 right = len(arr) - 1 while left < right: if arr[left] > 0: left += 1 ...
d31b5a42ed9bd43d7d036098e8491b4b839c5873
10,346
import re import argparse def valid_labels_regex(arg_value, pat=re.compile(r"^all|random|([a-z|0-9|,|\.]+)|([a-z|0-9|\.]+-[a-z]+-[1-9]-[0-9]-[1-9]-[c|h],?)+$")): """Get the params regex.""" if not pat.match(arg_value): raise argparse.ArgumentTypeError return arg_value
7f278654cf7c1630ce6751aaacfa85d0b08e65cb
10,347
def get_html_fields(fields): """ Converts a fields table with mandatory keywords type, text, id and partially optional keywords value, allowed_values, checked and help into html input lines. The tal in the templates has become too complicated therefore the python code handles most of the condition...
9269d26a86892791d5ef4847546600d629c8f7c6
10,350
def get_metadata_from_attributes(Object, skip_attributes = None, custom_classes = None): """ Get metadata dict from attributes of an object. Parameters ---------- Object : object from which the attributes are. skip_attributes : list, optional If given, these attributes are...
0c6eacae223ea94e128ff5b507fcaa5a71034c38
10,351
import zipfile import json def _GetExtensionInfoFromCRX(crx_path): """Parse an extension archive and return information. Note: The extension name returned by this function may not be valid (e.g. in the case of a localized extension name). It's use is just meant to be informational. Args: crx_path...
8a5f2ef2547c67d65195334df89d589fbff54dcf
10,352
def update_state(td_state, job_results): """ Updates the torsiondrive state with the compute jobs. The state is updated inplace Parameters ---------- td_state : dict The current torsiondrive state job_results : dict A dictionary of completed jobs and job ID's Returns --...
476d19fb9946045dc555f815d680d0475f253003
10,353
from typing import Tuple def yaml_remove_split(docstr: str) -> Tuple[str, str]: """Extract parameter summary within :yaml: tags in docstring, and clean up the :yaml: tag for the full docstring. Return cleaned up docstring, and summary version.""" key = ":yaml:" summary = "" i_start = docstr.fi...
e0e3e34871c56c5cc176fcd371e5402846771078
10,354
def trace_size_converter(value, params, key): """ Converts trace size from seconds to samples """ params = params[key] if value is None: return None if not value: return value if not params['frequency']: raise AttributeError('No frequency specified for trace-size argu...
87ec3707b36ee76bed365c4a91d4af829161b4b5
10,355
def decode_chrome_leveldb_bytes(value): """ decode the encoded localstorage values from the leveldb file """ if value[0] == 0: return value[1:].decode('utf-16le') elif value[0] == 1: return value[1:].decode('utf-8') else: msg = "Unable to process Chrome LevelDB bytes in u...
e200c3da3a2f75c215fa13fc12eb12f1034b3e14
10,357
import requests import logging def get_url_descriptor(url): """ Returns an url descriptor or None on failure """ try: resp = requests.get(url) except requests.exceptions.ConnectionError: logging.error("Error connecting to {}".format(url)) return None if resp.ok: ...
8e09711e08200980c1778fd47673dcaaba67c47b
10,358
def year_isnt_int(YEARS): """A funciton to test if years are integers""" return any(type(x) != int for x in YEARS)
d23d093f4655846d07228019b4110e2ef3180c69
10,359
import os def get_pictures(pictures_dir): """Return a list of picture files found in pictures_dir""" pictures = [] for directory, subdirs, files in os.walk(pictures_dir): for fname in files: if fname.lower().endswith(('.jpg', '.png')): pictures.append(os.path.join(dire...
5bb257fdf3bb910d8c0b45bbc8368a23d17ca7bf
10,360
import json def isJsonDict(s): """ Take a string and determine if valid JSON. """ try: data = json.loads(s) return type(data) == dict except ValueError: return False
222841fc39f78a45f0c682a83282e714a26dc0ed
10,361
from datetime import datetime def blog(): """ The blog section will show the user an infinite cascade of blog posts that will load based on the user scroll. """ return dict( title="Blog", year=datetime.now().year )
51a6447ef8081cf8053afbbacfcd145efefca5e4
10,363
import json def read_dependencies(file_path): """Reads a json file and creates an iterable of unique dependencies. Args: file_path: The path to the runtime dependencies file. Returns: An iterable with unique dependencies. """ deps = None with open(file_path) as deps_file: deps = json.load(de...
52756a443b3a7b0ee6ed1a932b3d1b7984fe4189
10,364
def get_tags_by_month_for_users(data , usernames): """ initialize list of months and sets for each list of data in data slice out twitter information if username in username list for each tag in hashtags in tweet add hashtag to set in data list :param data - l...
ca2fbfb2137b47fe23c7d113f002e528cb55b3ae
10,365
def get_face_rectangles(azure_response): """ Returns the rectangles corresponding to the faces detected by Azure :param azure_response: Response from Azure Face request as dictionary. :return: The rectangles of any detected face with the format: (width, height, left, top) """ result = [] for...
d07e40f1b4c648c52ea660179f8d8c1f4957f0db
10,367
def retr_spacegroup_number(xtalstr,ini0): """ Retrieve the space group number. When choosing real space grids some space groups imply restrictions on the number of points along the different lattice vectors. To impose the correct restrictions we need to know the space group number of the curren...
f86827aa089b79c054fe8c4d78c5a6da48f0463e
10,368
import requests import numpy as np from requests.exceptions import ReadTimeout def post_nadlan_sviva_rest(body, only_neighborhoods=True, subject=None, add_coords=True): """take body from request and post to nadlan.gov.il deals REST API, Sviva=other parameters, demographics, etc, ...
c659b5ac32b6b5317d614460def207fe9fc20820
10,370
import numpy def positions_join(positions_sequence): """Return concatenated positions arrays.""" return numpy.concatenate(positions_sequence)
f2743b00ac6b3c19e2c8efe0209e8a3f938389b7
10,371
def callback_on_failure(): """Simple callback on failure""" return False
98fcb160561ff4c6c25f49e95610394b56580a04
10,372
def snd(pair): """Return the second element of pair """ return pair[1]
a7893d60324ebdd358a0a0bb86bd2842d2617629
10,374
from numpy import log def log_mean(T_hi, T_lo, exact=False): """ compute the logarithmic mean """ if exact: return (T_hi-T_lo)/log(T_hi/T_lo) else: d = T_hi - T_lo return T_hi - d/2*(1 + d/6/T_hi*(1 + d/2/T_hi))
dcae1d753c416a117dc2f8502454d18f9413fc36
10,376
def reduceSet(setList): """Step through a list of sets and combine sets that overlap. This will create a unique list of sets, where each set contains the headers of reads that optical duplicates.""" setList2 = [setList[0]] for item1 in setList[1:]: inSetList2 = False for item2 ...
4e7e763ae78d5cf97fa122f991b01529e12c86a5
10,377
def weird_compare(interval, start, end): """ This is a function that is used later on in data_upscale, to add a corrective integer (either 1 or 0), when that function checks whether the image it is working on has reached the border. This function is not expected to be used anywhere outside data_upscale....
f4b67c2b740a318ad659d1001bd14d402dad9e21
10,378