common_id
stringlengths 1
5
| image
stringlengths 15
19
| code
stringlengths 26
239
|
|---|---|---|
9231
|
Train/png/9231.png
|
def write_file(path, data):
with open(path, 'w') as f:
log.debug('setting %s contents:\n%s', path, data)
f.write(data)
return f
|
3415
|
Train/png/3415.png
|
def check(ty, val):
"Checks that `val` adheres to type `ty`"
if isinstance(ty, basestring):
ty = Parser().parse(ty)
return ty.enforce(val)
|
8460
|
Train/png/8460.png
|
def trim_and_pad_all_features(features, length):
return {k: _trim_and_pad(v, length) for k, v in features.items()}
|
1621
|
Train/png/1621.png
|
def incr(self, att, val=1):
if att not in self.counters:
raise ValueError("%s is not a counter.")
self.db.hincrby(self.key(), att, val)
|
5989
|
Train/png/5989.png
|
def get_category_or_404(path):
path_bits = [p for p in path.split('/') if p]
return get_object_or_404(Category, slug=path_bits[-1])
|
7022
|
Train/png/7022.png
|
def _type_string(label, case=None):
return label, abstractSearch.in_string, lambda s: abstractRender.default(s, case=case), ""
|
2942
|
Train/png/2942.png
|
def subtitle(self, txt):
num = len(txt)
ticks = "-" * num
print(txt)
print(ticks)
|
5871
|
Train/png/5871.png
|
def hsetnx(self, key, field, value):
return self.execute(b'HSETNX', key, field, value)
|
3137
|
Train/png/3137.png
|
def create(self, **fields):
entry = self.instance(**fields)
entry.save()
return entry
|
9480
|
Train/png/9480.png
|
def load_dict(self, dct):
for k, v in dct.items():
setattr(self, k, v)
|
2659
|
Train/png/2659.png
|
def intersection(self, other):
taxa1 = self.labels
taxa2 = other.labels
return taxa1 & taxa2
|
9368
|
Train/png/9368.png
|
def Y(self, value):
if isinstance(value, (int, float,
long, types.NoneType)):
self._y = value
|
6368
|
Train/png/6368.png
|
def _consolidate_inplace(self):
def f():
self._data = self._data.consolidate()
self._protect_consolidate(f)
|
2102
|
Train/png/2102.png
|
def _format_dates(self, start, end):
start = self._split_date(start)
end = self._split_date(end)
return start, end
|
7236
|
Train/png/7236.png
|
def move_right(self):
self.at(ardrone.at.pcmd, True, self.speed, 0, 0, 0)
|
9939
|
Train/png/9939.png
|
def _edges_replaced(self, object, name, old, new):
self._delete_edges(old)
self._add_edges(new)
|
8091
|
Train/png/8091.png
|
def is_primary(self):
return isinstance(self._key, Primary) and not isinstance(self._key, Sub)
|
527
|
Train/png/527.png
|
def on_any_event(self, event):
for delegate in self.delegates:
if hasattr(delegate, "on_any_event"):
delegate.on_any_event(event)
|
5262
|
Train/png/5262.png
|
def resume(self, instance_id):
nt_ks = self.compute_conn
response = nt_ks.servers.resume(instance_id)
return True
|
8954
|
Train/png/8954.png
|
def from_interval(self, startnote, shorthand, up=True):
return self.from_interval_shorthand(startnote, shorthand, up)
|
9633
|
Train/png/9633.png
|
def selection_can_redo(self, name="default"):
return (self.selection_history_indices[name] + 1) < len(self.selection_histories[name])
|
9974
|
Train/png/9974.png
|
def __fetch_crate_data(self, crate_id):
raw_crate = self.client.crate(crate_id)
crate = json.loads(raw_crate)
return crate['crate']
|
6532
|
Train/png/6532.png
|
def find_root(self):
node = self
while node.parent is not None:
node = node.parent
return node
|
576
|
Train/png/576.png
|
def fib(number: int) -> int:
if number < 2:
return number
return fib(number - 1) + fib(number - 2)
|
1955
|
Train/png/1955.png
|
def resolve(self, *pargs, **kwargs):
self._cached = (pargs, kwargs)
self._try_then()
|
9485
|
Train/png/9485.png
|
def effect_ratio(self, mechanism, purview):
return self._ratio(Direction.EFFECT, mechanism, purview)
|
7983
|
Train/png/7983.png
|
def iteritems(self, raw=False):
for key in self:
yield key, self.__getitem__(key, raw=raw)
|
3681
|
Train/png/3681.png
|
def set_children(self, value, defined):
self.children = value
self.children_defined = defined
return self
|
2010
|
Train/png/2010.png
|
def get_by_model(self, model):
content_type = ContentType.objects.get_for_model(model)
return self.filter(content_type=content_type)
|
6617
|
Train/png/6617.png
|
def total_timer(msg):
start = timer()
yield
t = timer() - start
_TOTAL_TIMER_DATA[msg].feed(t)
|
3004
|
Train/png/3004.png
|
def dotted(self):
v = str(self.geoid.tract).zfill(6)
return v[0:4] + '.' + v[4:]
|
1912
|
Train/png/1912.png
|
def compute_amount(self):
self.amount = self.base_amount * self.aliquot / 100
return self.amount
|
1438
|
Train/png/1438.png
|
def watch_activations(self, flag):
lib.EnvSetDefruleWatchActivations(self._env, int(flag), self._rule)
|
800
|
Train/png/800.png
|
def fetch_cache_key(request):
m = hashlib.md5()
m.update(request.body)
return m.hexdigest()
|
837
|
Train/png/837.png
|
def close(self):
if self._is_connected:
self.comm.close()
self._is_connected = False
|
8844
|
Train/png/8844.png
|
def getnodes(self, name):
"Return the direct subnodes with name 'name'"
for node in self.nodes:
if striptag(node.tag) == name:
yield node
|
5055
|
Train/png/5055.png
|
def workspace_cli(ctx, directory, mets_basename, backup):
ctx.obj = WorkspaceCtx(os.path.abspath(directory),
mets_basename, automatic_backup=backup)
|
3228
|
Train/png/3228.png
|
def paginate(self, request, offset=0, limit=None):
return self.collection.offset(offset).limit(limit), self.collection.count()
|
1176
|
Train/png/1176.png
|
def wrap(string, length, indent):
newline = "\n" + " " * indent
return newline.join((string[i: i + length] for i in range(0, len(string), length)))
|
4223
|
Train/png/4223.png
|
def update(self, typ, id, **kwargs):
return self._load(self._request(typ, id=id, method='PUT', data=kwargs))
|
10090
|
Train/png/10090.png
|
def accept_EP_PKG(self, inst):
for child in many(inst).PE_PE[8000]():
self.accept(child)
|
9539
|
Train/png/9539.png
|
def empirical(X):
print("Empirical")
cov = np.dot(X.T, X) / n_samples
return cov, np.linalg.inv(cov)
|
6912
|
Train/png/6912.png
|
def fetch_feature_type(self):
query = self.query().add_query_parameter(req='featureType')
return self.get_query(query).content
|
1722
|
Train/png/1722.png
|
def write_document(self, document: BioCDocument):
tree = self.encoder.encode(document)
self.__writer.send(tree)
|
3400
|
Train/png/3400.png
|
def blend(c1, c2):
return [c1[i] * (0xFF - c2[3]) + c2[i] * c2[3] >> 8 for i in range(3)]
|
3556
|
Train/png/3556.png
|
def write_short(self, number):
buf = pack(self.byte_order + "h", number)
self.write(buf)
|
1489
|
Train/png/1489.png
|
def remove(h, i):
n = h.size() - 1
if n != i:
h.swap(i, n)
down(h, i, n)
up(h, i)
return h.pop()
|
2178
|
Train/png/2178.png
|
def get_term(self, term, value=False):
return self.doc.find_first(term, value=value, section=self.name)
|
7120
|
Train/png/7120.png
|
def get_ip(self, use_cached=True):
device_json = self.get_device_json(use_cached)
return device_json.get("dpLastKnownIp")
|
661
|
Train/png/661.png
|
def do_exit(self, arg):
if self.arm.is_connected():
self.arm.disconnect()
print('Bye!')
return True
|
1097
|
Train/png/1097.png
|
def kill_threads(self):
self._terminate.set()
while self.are_threads_alive():
time.sleep(0.001)
self._threads = ()
return self
|
4850
|
Train/png/4850.png
|
def copy(self):
return self.__class__(self, key=self._key, load=self._load)
|
3721
|
Train/png/3721.png
|
def _static(self, target, value):
return 'static ' + self.__p(ast.Assign(targets=[target], value=value))
|
3108
|
Train/png/3108.png
|
def feed_interval_delete(feed_id, parameters):
'Invalidate cached adaptive interval value.'
cache.delete(getkey(T_INTERVAL,
key=feed_interval_key(feed_id, parameters)))
|
6010
|
Train/png/6010.png
|
def crop(self, *args, **kwargs):
return self._generate_scene_func(self._scenes, 'crop', True, *args, **kwargs)
|
2431
|
Train/png/2431.png
|
def subtract_days(self, days: int) -> datetime:
self.value = self.value - relativedelta(days=days)
return self.value
|
2381
|
Train/png/2381.png
|
def save_hdf(self, filename, path=''):
self.dataframe.to_hdf(filename, '{}/df'.format(path))
|
9225
|
Train/png/9225.png
|
def set(self, value):
self.deadline = self.timer() + self.duration
self.value = value
|
6432
|
Train/png/6432.png
|
def dihedral(x, dih):
x = np.rot90(x, dih % 4)
return x if dih < 4 else np.fliplr(x)
|
1396
|
Train/png/1396.png
|
def get_playcount(self):
doc = self._request(self.ws_prefix + ".getInfo", True)
return _number(_extract(doc, "playcount"))
|
4750
|
Train/png/4750.png
|
def get_tag(self, el):
name = self.get_tag_name(el)
return util.lower(name) if name is not None and not self.is_xml else name
|
9976
|
Train/png/9976.png
|
def crate(self, crate_id):
path = urijoin(CRATES_API_URL, CATEGORY_CRATES, crate_id)
raw_crate = self.fetch(path)
return raw_crate
|
6209
|
Train/png/6209.png
|
def resolve(self):
'Resolve pathname shell variables and ~userdir'
return os.path.expandvars(os.path.expanduser(self.fqpn))
|
8620
|
Train/png/8620.png
|
def create_done_path(done_path, uid=-1, gid=-1):
with open(done_path, 'wb'):
pass
os.chown(done_path, uid, gid)
|
6061
|
Train/png/6061.png
|
def write_str(self, s):
self.write(s)
self.room -= len(s)
|
6509
|
Train/png/6509.png
|
def toc_print(self):
res = self.toc()
for n, k, v in res:
logging.info('Batch: {:7d} {:30s} {:s}'.format(n, k, v))
|
3938
|
Train/png/3938.png
|
def branches_containing(commit):
lines = run('branch --contains %s' % commit).splitlines()
return [l.lstrip('* ') for l in lines]
|
2290
|
Train/png/2290.png
|
def get_by_label(self, label):
return next((x for x in self if x.label == label), None)
|
9115
|
Train/png/9115.png
|
def quit(self):
self.script.LOG.warn("Abort due to user choice!")
sys.exit(self.QUIT_RC)
|
123
|
Train/png/123.png
|
def lazy_result(f):
@wraps(f)
def decorated(ctx, param, value):
return LocalProxy(lambda: f(ctx, param, value))
return decorated
|
7774
|
Train/png/7774.png
|
def unit_tangent(self, t=None):
assert self.end != self.start
dseg = self.end - self.start
return dseg/abs(dseg)
|
8797
|
Train/png/8797.png
|
def set_seed(seed: int):
random.seed(seed)
np.random.seed(seed)
torch.random.manual_seed(seed)
|
9265
|
Train/png/9265.png
|
def set(self, key, value):
return self.__setitem__(key, value, force=True)
|
7996
|
Train/png/7996.png
|
def get_selected_keys(self, selection):
return [k for k, b in self._lookup.items() if b & selection]
|
7645
|
Train/png/7645.png
|
def match_in(grammar, text):
for result in grammar.parseWithTabs().scanString(text):
return True
return False
|
4615
|
Train/png/4615.png
|
def mod_issquare(a, p):
if not a:
return True
p1 = p // 2
p2 = pow(a, p1, p)
return p2 == 1
|
1792
|
Train/png/1792.png
|
def delete(self, **kwargs):
url = self.base_url + '/%s' % kwargs['notification_id']
resp = self.client.delete(url=url)
return resp
|
8679
|
Train/png/8679.png
|
def send(self):
web.ctx.status = _convert_http_status(self.status_code)
return _api_convert_output(self.return_value)
|
5662
|
Train/png/5662.png
|
def pddet(A):
L = jitchol(A)
logdetA = 2*sum(np.log(np.diag(L)))
return logdetA
|
6183
|
Train/png/6183.png
|
def close(self):
gevent.killall(self._tasks, block=True)
self._tasks = []
self._ssh.close()
|
7246
|
Train/png/7246.png
|
def date_to_timestamp(date):
date_tuple = date.timetuple()
timestamp = calendar.timegm(date_tuple) * 1000
return timestamp
|
9154
|
Train/png/9154.png
|
def versions_request(self):
ret = self.handle_api_exceptions('GET', '', api_ver='')
return [str_dict(x) for x in ret.json()]
|
3862
|
Train/png/3862.png
|
def tty_stream(self):
return hasattr(self.options.stream, "isatty") \
and self.options.stream.isatty()
|
1602
|
Train/png/1602.png
|
def is_float(value):
return isinstance(value, float) or isinstance(value, int) or isinstance(value, np.float64), float(value)
|
4408
|
Train/png/4408.png
|
def build(self, **kwargs):
self.lexer = ply.lex.lex(object=self, **kwargs)
|
4076
|
Train/png/4076.png
|
def do_down(self, arg):
print("running down migration")
self.manager.run_one(arg, Direction.DOWN)
|
4442
|
Train/png/4442.png
|
def check_signature(signature, *args, **kwargs):
return hmac.compare_digest(signature, create_signature(*args, **kwargs))
|
1206
|
Train/png/1206.png
|
def walletpassphrase(self, passphrase, timeout=99999999, mint_only=True):
return self.req("walletpassphrase", [passphrase, timeout, mint_only])
|
6978
|
Train/png/6978.png
|
def set(self, mutagen_file, value):
self.store(mutagen_file, self.serialize(value))
|
6363
|
Train/png/6363.png
|
def set_metadata(self, metadata):
if metadata is not None:
metadata = np.array(metadata, copy=False).ravel()
self.metadata = metadata
|
5595
|
Train/png/5595.png
|
def strictly_decreasing(values):
return all(x > y for x, y in zip(values, values[1:]))
|
1974
|
Train/png/1974.png
|
def __expire_files(self):
self.__files = OrderedDict(
item for item in self.__files.items() if not item[1].expired
)
|
8396
|
Train/png/8396.png
|
def _get_line(self) -> str:
line = self.in_lines[self.index]
self.index += 1
return line
|
7158
|
Train/png/7158.png
|
def _normalize(mat: np.ndarray):
return ((mat - mat.min()) * (255 / mat.max())).astype(np.uint8)
|
6739
|
Train/png/6739.png
|
def set_scheme(self, scheme_name):
self.stack.setCurrentIndex(self.order.index(scheme_name))
self.last_used_scheme = scheme_name
|
9396
|
Train/png/9396.png
|
def color(self):
color = idc.GetColor(self.ea, idc.CIC_FUNC)
if color == 0xFFFFFFFF:
return None
return color
|
1017
|
Train/png/1017.png
|
def write_to_file(chats, chatfile):
with open(chatfile, 'w') as handler:
handler.write('\n'.join((str(id_) for id_ in chats)))
|
9415
|
Train/png/9415.png
|
def postman(filename, pretty, urlvars, swagger):
data = api.as_postman(urlvars=urlvars, swagger=swagger)
json_to_file(data, filename, pretty)
|
5992
|
Train/png/5992.png
|
def year_crumb(date):
year = date.strftime('%Y')
return Crumb(year, reverse('zinnia:entry_archive_year',
args=[year]))
|
3300
|
Train/png/3300.png
|
def value_at_coord(dset, coords):
return nl.numberize(nl.run(['3dmaskave', '-q', '-dbox'] + list(coords) + [dset], stderr=None).output)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.