common_id
stringlengths 1
5
| image
stringlengths 15
19
| code
stringlengths 26
239
|
|---|---|---|
3290
|
Train/png/3290.png
|
def mk_dir(self):
if not os.path.exists(self.abs):
os.makedirs(self.abs)
|
3693
|
Train/png/3693.png
|
def checkout(self, ref, branch=None):
return git_checkout(self.repo_dir, ref, branch=branch)
|
7578
|
Train/png/7578.png
|
def fire_event(self, event, *args, **kwargs):
self.event_queue.append((event, args))
self.process_events()
|
6616
|
Train/png/6616.png
|
def BNReLU(x, name=None):
x = BatchNorm('bn', x)
x = tf.nn.relu(x, name=name)
return x
|
6301
|
Train/png/6301.png
|
def path_qs(self):
if not self.query_string:
return self.path
return "{}?{}".format(self.path, self.query_string)
|
9812
|
Train/png/9812.png
|
def histogram(self, stat, value, tags=None):
self._log('histogram', stat, value, tags)
|
9256
|
Train/png/9256.png
|
def ExecuteRaw(self, position, command):
self.EnsureGdbPosition(position[0], None, None)
return gdb.execute(command, to_string=True)
|
3624
|
Train/png/3624.png
|
def dispose():
if _driver:
log.msg_debug("[{driver}] dispose".format(driver=_driver.get_name()))
_driver.dispose()
|
9253
|
Train/png/9253.png
|
def add_datatype(self, name: str, datatype: DT):
self._datatypes[name] = datatype
|
6772
|
Train/png/6772.png
|
def deactivate(self):
if not self._optional:
self._optional = True
self._activated = False
|
3241
|
Train/png/3241.png
|
def indent(txt, spacing=4):
return prefix(str(txt), ''.join([' ' for _ in range(spacing)]))
|
1389
|
Train/png/1389.png
|
def from_sbv(cls, file):
parser = SBVParser().read(file)
return cls(file=file, captions=parser.captions)
|
7119
|
Train/png/7119.png
|
def get_device_id(self, use_cached=True):
device_json = self.get_device_json(use_cached)
return device_json["id"].get("devId")
|
1317
|
Train/png/1317.png
|
def load_unixtime(buf, pos):
secs, pos = load_le32(buf, pos)
dt = datetime.fromtimestamp(secs, UTC)
return dt, pos
|
9970
|
Train/png/9970.png
|
def close(self):
self.read_queue.put(QueueClosed)
self.write_queue.put(QueueClosed)
|
8176
|
Train/png/8176.png
|
def is_natural(x):
try:
is_integer = int(x) == x
except (TypeError, ValueError):
return False
return is_integer and x >= 0
|
1631
|
Train/png/1631.png
|
def bytes_to_ustr(self, b):
"convert bytes array to unicode string"
return b.decode(charset_map.get(self.charset, self.charset))
|
7211
|
Train/png/7211.png
|
def connect(self):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(("127.0.0.1", self._port))
return sock
|
5421
|
Train/png/5421.png
|
def _tag_ec2(self, conn, role):
tags = {'Role': role}
conn.create_tags([self.instance_id], tags)
|
5555
|
Train/png/5555.png
|
def cli(self, *args, **kwargs):
kwargs['api'] = self.api
return cli(*args, **kwargs)
|
9040
|
Train/png/9040.png
|
def todict(self):
return OrderedDict((name, self[i]) for i, name in enumerate(self._fields))
|
1766
|
Train/png/1766.png
|
def clean_tmpdir(path):
if os.path.exists(path) and \
os.path.isdir(path):
rmtree(path)
|
7054
|
Train/png/7054.png
|
def fromDict(cls, _dict):
obj = cls()
obj.__dict__.update(_dict)
return obj
|
6523
|
Train/png/6523.png
|
def weight_variable(shape):
initial = tf.truncated_normal(shape, stddev=0.1)
return tf.Variable(initial)
|
9891
|
Train/png/9891.png
|
def onPublish(self, topic, payload, qos, dup, retain, msgId):
log.debug("msg={payload}", payload=payload)
|
2859
|
Train/png/2859.png
|
def abort(self, count=2, timeout=60):
for counter in xrange(0, count):
self.putc(CAN, timeout)
|
7942
|
Train/png/7942.png
|
def complete_hit(self, text, line, begidx, endidx):
return [i for i in PsiturkNetworkShell.hit_commands if
i.startswith(text)]
|
8437
|
Train/png/8437.png
|
def split_classes(X, y):
lstsclass = np.unique(y)
return [X[y == i, :].astype(np.float32) for i in lstsclass]
|
5729
|
Train/png/5729.png
|
def remove(self, id):
v = VRF.get(int(id))
v.remove()
redirect(url(controller='vrf', action='list'))
|
3472
|
Train/png/3472.png
|
def state_fluents(self) -> Dict[str, PVariable]:
return {str(pvar): pvar for pvar in self.pvariables if pvar.is_state_fluent()}
|
6162
|
Train/png/6162.png
|
def spin1z_from_mass1_mass2_chi_eff_chi_a(mass1, mass2, chi_eff, chi_a):
return (mass1 + mass2) / (2.0 * mass1) * (chi_eff - chi_a)
|
7975
|
Train/png/7975.png
|
def im_create(self, username, **kwargs):
return self.__call_api_post('im.create', username=username, kwargs=kwargs)
|
8348
|
Train/png/8348.png
|
def plugins(all, plugins_dir):
"List currently available plugins"
app = Datasette([], plugins_dir=plugins_dir)
click.echo(json.dumps(app.plugins(all), indent=4))
|
4435
|
Train/png/4435.png
|
def sunionstore(self, dest, keys, *args):
result = self.sunion(keys, *args)
self.redis[self._encode(dest)] = result
return len(result)
|
2040
|
Train/png/2040.png
|
def base_url(self):
if self.doc.package_url:
return self.doc.package_url
return self.doc._ref
|
9034
|
Train/png/9034.png
|
def _Keyword(self, t):
self._write(t.name)
self._write("=")
self._dispatch(t.expr)
|
9100
|
Train/png/9100.png
|
def clear(self):
self.__values.clear()
self.__access_keys = []
self.__modified_times.clear()
|
1847
|
Train/png/1847.png
|
def _Pairs(data):
keys = sorted(data)
return [{'@key': k, '@value': data[k]} for k in keys]
|
449
|
Train/png/449.png
|
def prepare_blobs(self):
self.raw_header = self.extract_header()
if self.cache_enabled:
self._cache_offsets()
|
2374
|
Train/png/2374.png
|
def consume(self, state):
self.state.append(self.func(state))
return self.state
|
1288
|
Train/png/1288.png
|
def full(self, external=False):
return self.fs.url(self.filename, external=external) if self.filename else None
|
9875
|
Train/png/9875.png
|
def shell():
"Open a shell"
from gui.tools.debug import Shell
shell = Shell()
shell.show()
return shell
|
4414
|
Train/png/4414.png
|
def write_config(repo_directory, config):
return write_config_file(os.path.join(repo_directory, config_file), config)
|
6452
|
Train/png/6452.png
|
def concat(self, arrs: Collection[Tensor]) -> Tensor:
"Concatenate the `arrs` along the batch dimension."
return [torch.cat([l[si] for l in arrs], dim=1) for si in range_of(arrs[0])]
|
1505
|
Train/png/1505.png
|
def is_univariate_ca(self):
return self.ndim == 2 and set(self.dim_types) == {DT.CA_SUBVAR, DT.CA_CAT}
|
9945
|
Train/png/9945.png
|
def set(self, **kw):
self.args = kw
log.debug(self.args)
|
4454
|
Train/png/4454.png
|
def of_operator(context, x, y):
return x.eval(context), y.eval(context)
|
27
|
Train/png/27.png
|
def _consfcn(self, x):
h, g = self._gh(x)
dh, dg = self._dgh(x)
return h, g, dh, dg
|
589
|
Train/png/589.png
|
def project(v, n):
return v - matmul(v, n) * n / (norm(n) ** 2.0)
|
2980
|
Train/png/2980.png
|
def from_string(cls, s, space):
import hashlib
hs = hashlib.sha1(s).hexdigest()
return cls.from_hex(hs, space)
|
6692
|
Train/png/6692.png
|
def on_uninstall(self):
self._on_close = True
self.enabled = False
self._editor = None
|
6786
|
Train/png/6786.png
|
def execute(self):
r = self._s.execute()
r._faceted_search = self
return r
|
2855
|
Train/png/2855.png
|
def translate(self):
ident = self.ident
expr = ex_rvalue(VARIABLE_PREFIX + ident)
return [expr], set([ident]), set()
|
7948
|
Train/png/7948.png
|
def total_charge(self):
charge = (sum(self.data_points) / self.hz) * 1000 / 3600
return round(charge, self.sr)
|
8355
|
Train/png/8355.png
|
def remove_variation(self, move: chess.Move) -> None:
self.variations.remove(self.variation(move))
|
3576
|
Train/png/3576.png
|
def append(self, element):
super(ObservableList, self).append(element)
self._notify_add_at(len(self) - 1)
|
5334
|
Train/png/5334.png
|
def analytic_kl_builder(posterior, prior, sample):
del sample
return tf.reduce_sum(tfp.distributions.kl_divergence(posterior, prior))
|
3412
|
Train/png/3412.png
|
def img(self, id):
return self._serve_file(os.path.join(media_path, 'img', id))
|
4195
|
Train/png/4195.png
|
def retrieve_pool_stats(self, pool, **_params):
return self.get(self.pool_path_stats % (pool), params=_params)
|
4752
|
Train/png/4752.png
|
def filter(self): # noqa A001
return [tag for tag in self.get_contents(self.tag) if not self.is_navigable_string(tag) and self.match(tag)]
|
4966
|
Train/png/4966.png
|
def search(self, string, *args, **kwargs):
return self._pattern.search(string, *args, **kwargs)
|
2011
|
Train/png/2011.png
|
def attr(obj, attr):
if not obj or not hasattr(obj, attr):
return ''
return getattr(obj, attr, '')
|
5084
|
Train/png/5084.png
|
def _on_client_latency_changed(self, data):
self._clients.get(data.get('id')).update_latency(data)
|
4768
|
Train/png/4768.png
|
def connect(self, host, port):
super(GeventTransport, self).connect((host, port), klass=socket.socket)
|
208
|
Train/png/208.png
|
def feed_parser(self, data):
assert isinstance(data, bytes)
self.parser.feed(data)
|
5137
|
Train/png/5137.png
|
def update(self, *args):
"Appends any passed in byte arrays to the digest object."
for string in args:
self._hobj.update(string)
self._fobj = None
|
218
|
Train/png/218.png
|
def save_task(self):
task = self.request.activation.task
task.status = STATUS.ASSIGNED
task.save()
|
2768
|
Train/png/2768.png
|
def umi_cycles(self) -> int:
return sum((int(re.sub(r'\D', '', op)) for op in self.umi_tokens))
|
1192
|
Train/png/1192.png
|
def update_token_tempfile(token):
with open(tmp, 'w') as f:
f.write(json.dumps(token, indent=4))
|
6471
|
Train/png/6471.png
|
def keep_only_digits(s):
r
fs = ''
for c in s:
if c.isdigit():
fs += c
return int(fs)
|
338
|
Train/png/338.png
|
def second(self):
self.magnification = 1
self._update(self.baseNumber, self.magnification)
return self
|
3216
|
Train/png/3216.png
|
def flushIndexes(self):
"drops all indexes created by Raba"
for n in self.getIndexes(rabaOnly=True):
self.dropIndexByName(n[1])
|
7733
|
Train/png/7733.png
|
def handleError(self, error_code, message):
self._fail = True
self.reason = error_code
self._error = message
|
238
|
Train/png/238.png
|
def with_prefix(self, root_path):
return Conflict(self.conflict_type, root_path + self.path, self.body)
|
5314
|
Train/png/5314.png
|
def close(self):
if not self.closed and self.ins is not None:
os.close(self.ins)
self.closed = True
self.ins = None
|
5801
|
Train/png/5801.png
|
def col2hue(r, g, b):
return round2(180 / pi * atan2(sqrt(3) * (g - b), 2 * r - g - b) + 360) % 360
|
7327
|
Train/png/7327.png
|
def fingerprint(value):
h = hashlib.sha256()
_digest(value, h)
return h.digest().encode('hex')
|
1983
|
Train/png/1983.png
|
def delete(self):
self.room.check_owner()
self.conn.make_call("deleteFiles", [self.fid])
|
7994
|
Train/png/7994.png
|
def result(self, value):
if self._process_result:
self._result = self._process_result(value)
self._raw_result = value
|
5626
|
Train/png/5626.png
|
def vec_angle(a, b):
cosang = np.dot(a, b)
sinang = fast_norm(np.cross(a, b))
return np.arctan2(sinang, cosang)
|
10
|
Train/png/10.png
|
def move(self):
a = random.randint(0, len(self.state) - 1)
b = random.randint(0, len(self.state) - 1)
self.state[[a, b]] = self.state[[b, a]]
|
1546
|
Train/png/1546.png
|
def to_json(obj):
i = StringIO.StringIO()
w = Writer(i, encoding='UTF-8')
w.write_value(obj)
return i.getvalue()
|
5511
|
Train/png/5511.png
|
def Set(self, value, fields=None):
self._metric_values[_FieldsToKey(fields)] = self._value_type(value)
|
5859
|
Train/png/5859.png
|
def setnx(self, key, value):
fut = self.execute(b'SETNX', key, value)
return wait_convert(fut, bool)
|
1141
|
Train/png/1141.png
|
def _entity_list_as_bel(entities: Iterable[BaseEntity]) -> str:
return ', '.join(
e.as_bel()
for e in entities
)
|
8113
|
Train/png/8113.png
|
def stop(self):
with self.lock:
self.halting = True
self.go.clear()
|
7880
|
Train/png/7880.png
|
def ignore(self, filename):
_, ext = os.path.splitext(filename)
return ext in ['.pyc', '.pyo', '.o', '.swp']
|
9938
|
Train/png/9938.png
|
def _nodes_changed(self, object, name, undefined, event):
self._delete_nodes(event.removed)
self._add_nodes(event.added)
|
8792
|
Train/png/8792.png
|
def interpolate_series(start, end, steps, how='linear'):
return INTERP_DICT[how](start, end, steps)
|
595
|
Train/png/595.png
|
def increase_last(self, k):
idx = self._last_idx
if idx is not None:
self.results[idx] += k
|
8810
|
Train/png/8810.png
|
def apply(self, node):
new_node = self.run(node)
return self.update, new_node
|
1339
|
Train/png/1339.png
|
def text_extract(path, password=None):
pdf = Info(path, password).pdf
return [pdf.getPage(i).extractText() for i in range(pdf.getNumPages())]
|
7875
|
Train/png/7875.png
|
def load_state(self, fname=None):
with open(fname, 'rb') as fh:
self.state = pickle.load(fh)
|
7405
|
Train/png/7405.png
|
def connectionMade(self):
cmd = self.sm.connect()
self.transport.write(cmd)
|
6888
|
Train/png/6888.png
|
def poly2o_residual(params, data, mask):
bg = poly2o_model(params, shape=data.shape)
res = (data - bg)[mask]
return res.flatten()
|
9613
|
Train/png/9613.png
|
def to_one_hot(x, k):
unit = np.eye(k, dtype=int)
return unit[x]
|
7424
|
Train/png/7424.png
|
def query_source(self, source):
return self._get_repo_filter(Layer.objects).filter(url=source)
|
2196
|
Train/png/2196.png
|
def dictionize(fields: Sequence, records: Sequence) -> Generator:
return (dict(zip(fields, rec)) for rec in records)
|
8087
|
Train/png/8087.png
|
def init_report(self, reporter=None):
self.options.report = (reporter or self.options.reporter)(self.options)
return self.options.report
|
6999
|
Train/png/6999.png
|
def search(self, start_ts, end_ts):
query = '_ts: [%s TO %s]' % (start_ts, end_ts)
return self._stream_search(query)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.