blob_id stringlengths 40 40 | directory_id stringlengths 40 40 | path stringlengths 3 288 | content_id stringlengths 40 40 | detected_licenses listlengths 0 112 | license_type stringclasses 2 values | repo_name stringlengths 5 115 | snapshot_id stringlengths 40 40 | revision_id stringlengths 40 40 | branch_name stringclasses 684 values | visit_date timestamp[us]date 2015-08-06 10:31:46 2023-09-06 10:44:38 | revision_date timestamp[us]date 1970-01-01 02:38:32 2037-05-03 13:00:00 | committer_date timestamp[us]date 1970-01-01 02:38:32 2023-09-06 01:08:06 | github_id int64 4.92k 681M ⌀ | star_events_count int64 0 209k | fork_events_count int64 0 110k | gha_license_id stringclasses 22 values | gha_event_created_at timestamp[us]date 2012-06-04 01:52:49 2023-09-14 21:59:50 ⌀ | gha_created_at timestamp[us]date 2008-05-22 07:58:19 2023-08-21 12:35:19 ⌀ | gha_language stringclasses 147 values | src_encoding stringclasses 25 values | language stringclasses 1 value | is_vendor bool 2 classes | is_generated bool 2 classes | length_bytes int64 128 12.7k | extension stringclasses 142 values | content stringlengths 128 8.19k | authors listlengths 1 1 | author_id stringlengths 1 132 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
6f686e08a7cefc2451681d1601521582f55624d6 | 25bf4f39762b4fa0e249c7fc85681368f3d49573 | /test/test_Util/test_param_util.py | 1192a531afea3ec6ae4b61d9bc1d83481660a6f2 | [
"MIT"
] | permissive | linan7788626/lenstronomy | ca740c25c717f2b674903039d582f283f29fb07e | dc9b4651a5b530e659048fd1a65c9955720b40cd | refs/heads/master | 2021-05-04T20:43:20.442654 | 2018-01-31T07:20:52 | 2018-01-31T07:20:52 | null | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 3,180 | py | import numpy as np
import pytest
import numpy.testing as npt
import lenstronomy.Util.param_util as param_util
def test_cart2polar():
#singel 2d coordinate transformation
center = np.array([0,0])
x = 1
y = 1
r, phi = param_util.cart2polar(x,y,center)
assert r == np.sqrt(2) #radial part
assert phi == np.arctan(1)
#array of 2d coordinates
center = np.array([0,0])
x = np.array([1,2])
y = np.array([1,1])
r, phi = param_util.cart2polar(x,y,center)
assert r[0] == np.sqrt(2) #radial part
assert phi[0] == np.arctan(1)
def test_polar2cart():
#singel 2d coordinate transformation
center = np.array([0,0])
r = 1
phi = np.pi
x, y = param_util.polar2cart(r, phi, center)
assert x == -1
assert abs(y) < 10e-14
def test_phi_q2_elliptisity():
phi, q = 0, 1
e1,e2 = param_util.phi_q2_elliptisity(phi,q)
assert e1 == 0
assert e2 == 0
phi, q = 1, 1
e1,e2 = param_util.phi_q2_elliptisity(phi,q)
assert e1 == 0
assert e2 == 0
phi, q = 2.,0.95
e1, e2 = param_util.phi_q2_elliptisity(phi,q)
assert e1 == -0.016760092842656733
assert e2 == -0.019405192187382792
def test_phi_q2_elliptisity_bounds():
bounds = 'lower'
phi, q = 0, 1
e1, e2 = param_util.phi_q2_elliptisity_bounds(phi, q, bounds)
assert e1 == 0
assert e2 == 0
phi, q = 1, 1
e1, e2 = param_util.phi_q2_elliptisity_bounds(phi,q, bounds)
assert e1 == 0
assert e2 == 0
phi, q = 2., 0.95
e1, e2 = param_util.phi_q2_elliptisity_bounds(phi, q, bounds)
assert e1 == -0.019405192187382792
assert e2 == -0.019405192187382792
bounds = 'upper'
phi, q = 2., 0.95
e1, e2 = param_util.phi_q2_elliptisity_bounds(phi, q, bounds)
assert e1 == 0.019405192187382792
assert e2 == 0.019405192187382792
def test_elliptisity2phi_q():
e1, e2 = 0.3,0
phi,q = param_util.elliptisity2phi_q(e1,e2)
assert phi == 0
assert q == 0.53846153846153844
def test_elliptisity2phi_q_symmetry():
phi,q = 1.5, 0.8
e1,e2 = param_util.phi_q2_elliptisity(phi,q)
phi_new,q_new = param_util.elliptisity2phi_q(e1,e2)
assert phi == phi_new
assert q == q_new
phi,q = -1.5, 0.8
e1,e2 = param_util.phi_q2_elliptisity(phi,q)
phi_new,q_new = param_util.elliptisity2phi_q(e1,e2)
assert phi == phi_new
assert q == q_new
e1, e2 = 0.1, -0.1
phi, q = param_util.elliptisity2phi_q(e1, e2)
e1_new, e2_new = param_util.phi_q2_elliptisity(phi,q)
npt.assert_almost_equal(e1, e1_new, decimal=10)
npt.assert_almost_equal(e2, e2_new, decimal=10)
e1, e2 = 2.8, -0.8
phi, q = param_util.elliptisity2phi_q(e1, e2)
e1_new, e2_new = param_util.phi_q2_elliptisity(phi,q)
npt.assert_almost_equal(e1, e1_new, decimal=10)
npt.assert_almost_equal(e2, e2_new, decimal=10)
def test_phi_gamma_ellipticity():
phi = -1.
gamma = 0.1
e1, e2 = param_util.phi_gamma_ellipticity(phi, gamma)
print(e1, e2, 'e1, e2')
phi_out, gamma_out = param_util.ellipticity2phi_gamma(e1, e2)
assert phi == phi_out
assert gamma == gamma_out
if __name__ == '__main__':
pytest.main() | [
"simon.birrer@pyhs.ethz.ch"
] | simon.birrer@pyhs.ethz.ch |
81808de5af7f87fb82b724de12996ceca4290f0e | 9968b58abae0639df4233a038a89fe9c872e141b | /examples/02plot/misc/candidates.py | 6fc2a6d2ebb944641a482eaaeb3b91d143d4bc9f | [] | no_license | podhmo/utatane | 5dffa1df6fd4c63a7ddd4075c73c67a18a864c52 | c38a2615fe89efb163651ef3f764144a0cb902cf | refs/heads/master | 2021-01-01T16:46:31.487204 | 2017-08-07T01:47:07 | 2017-08-07T01:47:07 | 97,915,447 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 970 | py | import matplotlib
matplotlib.use("Agg") # NOQA
from matplotlib import pyplot as plt
from utatane import subplot
from collections import defaultdict
def defined_with(mro, name):
owner = None
for cls in mro:
if not hasattr(cls, name):
return owner
owner = cls
with subplot(plt, ncols=1, nrows=1) as nth:
with nth(1) as ax:
print("hierarchy(mro)")
print("")
mro = [ax, *ax.__class__.mro()]
for cls in mro:
print("-", cls)
d = defaultdict(list)
for attr in sorted(dir(ax)):
d[defined_with(mro, attr)].append(attr)
for cls in mro:
attrs = d[cls]
print("")
print(cls)
print("")
for attr in attrs:
if callable(getattr(cls, attr)):
if not any(attr.startswith(x) for x in ("_", "get_", "set_", "add_", "update_")):
print("-", attr)
| [
"ababjam61+github@gmail.com"
] | ababjam61+github@gmail.com |
2c3781633d95f44eb76888ed600cf855f5ba9f03 | 55c250525bd7198ac905b1f2f86d16a44f73e03a | /Python/Games/Making Games with Python & Pygame/drawing.py | 5c043ef052eeaf031e33696603e08f84f5db5f16 | [] | no_license | NateWeiler/Resources | 213d18ba86f7cc9d845741b8571b9e2c2c6be916 | bd4a8a82a3e83a381c97d19e5df42cbababfc66c | refs/heads/master | 2023-09-03T17:50:31.937137 | 2023-08-28T23:50:57 | 2023-08-28T23:50:57 | 267,368,545 | 2 | 1 | null | 2022-09-08T15:20:18 | 2020-05-27T16:18:17 | null | UTF-8 | Python | false | false | 129 | py | version https://git-lfs.github.com/spec/v1
oid sha256:c80352eee128cec2e7813b952de0835d4a061ca8607f2b1e31c472e8244844a3
size 1219
| [
"nateweiler84@gmail.com"
] | nateweiler84@gmail.com |
38b6c08a4a112060d351a0e66345401a44d57378 | 94e2d1fba52b0d8f93c99bdb6a5f58c7de15b842 | /userhandler/migrations/0003_userpersonal_verified.py | da523e58862f39f03c8837457a013b0705f1a6e0 | [] | no_license | hks74123/covidhelpmain | 023b0cfe7c3cb140b2d68a3fbab6e695e6d9c6af | ee96d0b157cd048d2ea27865bf98551186dead98 | refs/heads/main | 2023-04-26T16:16:39.029555 | 2021-05-24T19:25:12 | 2021-05-24T19:25:12 | null | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 399 | py | # Generated by Django 3.2.3 on 2021-05-20 21:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('userhandler', '0002_auto_20210521_0227'),
]
operations = [
migrations.AddField(
model_name='userpersonal',
name='verified',
field=models.BooleanField(default=False),
),
]
| [
"experimentallyf@gmail.com"
] | experimentallyf@gmail.com |
94b858cec97d32e847d9187305d9f1873514aad8 | 9b50b3a7dda2711c5665909f6801249de53e70f6 | /0x0C-python-almost_a_circle/tests/test_base.py | 448df3af8b02c58fed9730cc03782f0cede681df | [] | no_license | nikolasribeiro/holbertonschool-higher_level_programming | 3119e5442887f06da104dc8aa93df371f92b9f2b | 7dcdf081d8a57ea1f5f6f9830555f73bf2ae6993 | refs/heads/main | 2023-04-21T05:22:03.617609 | 2021-05-05T11:38:51 | 2021-05-05T11:38:51 | 319,198,337 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 2,600 | py | #!/usr/bin/python3
""" Module test_base"""
import os
import unittest
from models.base import Base
from models.rectangle import Rectangle
from models.square import Square
class TestBase(unittest.TestCase):
""" class TestBase """
def test_normal(self):
""" function test_normal """
self.base = Base(6)
self.assertEqual(self.base.id, 6)
self.base = Base()
self.assertEqual(self.base._Base__nb_objects, 7)
self.base = Base()
self.assertEqual(self.base.id, 8)
def test_arg_count(self):
""" function test_arg_count """
with self.assertRaises(TypeError):
self.base = Base(2, 2)
def test_json(self):
""" function test_json """
self.base = Base()
dic = {"test": 1, "test2": 2, "test3": 3}
lidi = [dic]
json_dict = self.base.to_json_string(lidi)
self.assertTrue(isinstance(json_dict, str))
dic1 = {"test": 1, "test2": 2, "test3": 3}
lidi = [dic, dic1]
json_dict = self.base.to_json_string(lidi)
self.assertTrue(isinstance(json_dict, str))
json_dict = self.base.to_json_string([])
self.assertEqual(json_dict, "[]")
json_dict = self.base.to_json_string(None)
self.assertEqual(json_dict, "[]")
def test_json_to_file(self):
""" function test_json_to_file """
self.r1 = Rectangle(1, 2)
Rectangle.save_to_file([self.r1])
with open("Rectangle.json", "r") as f:
data = f.read()
self.assertEqual(len(data), 52)
self.r2 = Rectangle(3, 4)
Rectangle.save_to_file([self.r1, self.r2])
with open("Rectangle.json", "r") as f:
data = f.read()
self.assertEqual(len(data), 104)
Rectangle.save_to_file([])
with open("Rectangle.json", "r") as f:
data = f.read()
self.assertEqual(len(data), 2)
def test_from_json(self):
""" function test_from_json """
self.rec = Rectangle(1, 2)
li = [self.rec.to_dictionary()]
json_list_input = Rectangle.to_json_string(li)
from_json = Rectangle.from_json_string(json_list_input)
self.assertTrue(isinstance(from_json, list))
self.assertTrue(isinstance(from_json[0], dict))
self.assertEqual(Rectangle.from_json_string(None), [])
self.assertEqual(Rectangle.from_json_string("[]"), [])
def test_create_cls(self):
""" function test_create_cls """
self.r1 = Rectangle(10, 10, 10)
self.r1_dict = self.r1.to_dictionary()
| [
"nikolasribeiro2@outlook.com"
] | nikolasribeiro2@outlook.com |
130bcaa32fbf9c16da199ad5238345639327879b | f63db957cb63b3a37642d138d3092f8f897d6a53 | /hila_webapp/hila/auth/backends.py | 0798c740954b2d325558900ec384d44bc418ee65 | [] | no_license | fillarikanava/old-fillarikanava | c6fd819f95e675e6eddc674e71528c798b391967 | 8dbb89ea34c2aa98450e403ca2d7f17179edff8d | refs/heads/master | 2021-01-13T02:30:01.501771 | 2013-10-03T16:26:13 | 2013-10-03T16:26:13 | 13,201,013 | 0 | 1 | null | null | null | null | UTF-8 | Python | false | false | 2,916 | py | '''
Created on 1.4.2009
@author: jsa
'''
from django.contrib.auth.models import User
from hila import roundup_utils
from roundup.password import Password
db = roundup_utils.db()
class RoundupUser(User):
def __init__(self, usernode):
super(RoundupUser, self).__init__(
id=usernode.id,
username=usernode.username,
first_name=usernode.screenname,
last_name="",
email=usernode.address,
password=None,
is_staff=False,
is_active=True,
is_superuser=False,
# groups = models.ManyToManyField(Group, verbose_name=_('groups'), blank=True,
# help_text=_("In addition to the permissions manually assigned, this user will also get all permissions granted to each group he/she is in."))
# user_permissions = models.ManyToManyField(Permission, verbose_name=_('user permissions'), blank=True)
)
self.usernode = usernode
def save(self):
print "called backends.py RoundupUser.save()"
pass
class RoundupBackend(object):
"""
Authenticates against RoundUp user database.
"""
def authenticate(self, username=None, password=None):
db = roundup_utils.db()
try:
usernode = db.user.getnode(db.user.lookup(username))
if usernode.password == Password(password):
print "Authentication successful!"
return RoundupUser(usernode)
else:
print "Authentication failure!"
except KeyError:
pass
return None
def get_permissions_for_group(self, group):
return {
'organisation': ['organisation.access', 'public.report.modify_priority'],
}.get(group, {})
# def get_group_permissions(self, user_obj):
# perms = reduce(lambda role, roles: roles + self.get_permissions_for_group(role),
# [],
# [role.strip().lower() for role in
# user_obj.usernode.roles.split(',')])
# if user_obj.usernode.organisation:
# perms += self.get_permissions_for_group('organisation')
# return perms
#
# def get_all_permissions(self, user_obj):
# return self.get_group_permissions(user_obj)
#
def has_perm(self, user_obj, perm):
return perm in self.get_all_permissions(user_obj)
def has_module_perms(self, user_obj, app_label):
"""
Returns True if user_obj has any permissions in the given app_label.
"""
for perm in self.get_all_permissions(user_obj):
if perm[:perm.index('.')] == app_label:
return True
return False
def get_user(self, user_id):
if db.user.hasnode(user_id):
return RoundupUser(db.user.getnode(user_id))
else:
return roundup_utils.get_user_by_name('anonymous')
| [
"rkarhila@iki.fi"
] | rkarhila@iki.fi |
55b64b2105130f31d48bc584c5a9ac1ab6655c83 | a80963fbac8c0edcef5b1b9bad67a4b5913cd569 | /web_data/check_profanity.py | 9cd251c833e6d6947acdfb9a3506e0d327f4f3c6 | [] | no_license | manurp/Python_programs | 946877caf93a2ff0239c68dc4e8e02c72fe6f156 | 1a0c896b05b72afee7a48dd1bc2bef2aa7ffe0af | refs/heads/master | 2020-06-28T01:22:59.140092 | 2018-09-01T17:03:18 | 2018-09-01T17:03:18 | 97,080,367 | 2 | 0 | null | null | null | null | UTF-8 | Python | false | false | 641 | py | import urllib.request, urllib.parse, urllib.error
def check_profanity(text):
connection = urllib.request.urlopen('http://www.wdylike.appspot.com/?q='+text)
output = connection.read()
print(output)
connection.close()
def read_text():
fhand = open('file.txt')
contents = fhand.read().split()
# words = contents.split()
contents = ''.join(contents)
contents = contents.rstrip()
# print(contents,end='')
check_profanity(contents)
# for contents in fhand.readlines():
# words = contents.split()
# for word in words:
# check_profanity(word)
# print(contents)
fhand.close()
read_text()
# check_profanity('shot%in%the%fuck') | [
"manojrpoojary@gmail.com"
] | manojrpoojary@gmail.com |
153479a79245d9a606054d6ec1ac2b88deffe40f | 83ed8b754703a1c9e661c90f0763bfebbc0f2606 | /数据处理/Brokerage/create_db.py | 4f34cf8e25321badf0c3409fc6e0102b3fe613a5 | [] | no_license | zbh123/hobby | 4ce267a20e1af7f2accd2bde8d39af269efa319b | 2215c406fe7700bf150fd536dd56823a2e4733d1 | refs/heads/master | 2021-08-02T10:31:34.683391 | 2021-07-26T07:26:16 | 2021-07-26T07:26:16 | 150,555,879 | 4 | 0 | null | 2021-07-27T07:34:28 | 2018-09-27T08:41:44 | Python | UTF-8 | Python | false | false | 2,936 | py | import MySQLdb
from sshtunnel import SSHTunnelForwarder
import time
with SSHTunnelForwarder(
("10.29.24.47", 222), # ssh IP和port
ssh_password="zts000000", # ssh 密码
ssh_username="tianyj", # ssh账号
remote_bind_address=("10.29.129.94", 3306)) as server: # 数据库所在的IP和端口
server.start()
# 打印本地端口,已检查是否配置正确
print(server.local_bind_port)
conn = MySQLdb.connect(host="127.0.0.1", # 固定写法
port=server.local_bind_port,
user="rpa", # 数据库账号
passwd="zts000", # 数据库密码
db='brokerage',
charset='utf8') # 可以限定,只访问特定的数据库,否则需要在mysql的查询或者操作语句中,指定好表名
print('连接成功')
time.sleep(100)
cur = conn.cursor()
# sql = """CREATE TABLE shenzhen_month (
# month CHAR(150),
# total_amount CHAR(150),
# market_share CHAR(150),
# stock_trading_amount CHAR(150),
# fund_trading_amount CHAR(150),
# bond_trading_amount CHAR(150),
# warrants_trading_amount CHAR(150),
# `current_time` CHAR(150))"""
# sql = """CREATE TABLE sse_month(
# member_name CHAR(150),
# number_seats CHAR(150),
# total CHAR(150),
# stock CHAR(150),
# investment_funds CHAR(150),
# ETF CHAR(150),
# treasury CHAR(150),
# amount_lgd CHAR(150),
# corporate_bonds CHAR(150),
# convertible_bonds CHAR(150),
# repurchase_bonds CHAR(150),
# warrants CHAR(150),
# current_month CHAR(150),
# `current_time` CHAR(150))
#
# """
# sql = """CREATE TABLE shenzhen_total_day(
# types_bond CHAR(150),
# number CHAR(150),
# transaction_amount CHAR(150),
# turnover CHAR(150),
# total_equity CHAR(150),
# total_market_value CHAR(150),
# negotiable_capital CHAR(150),
# circulation_market_value CHAR(150),
# `current_time` CHAR(150))"""
# sql = """ CREATE TABLE sse_stock_day(
# single_day_situation CHAR(150),
# stock CHAR(150),
# mainboard_A CHAR(150),
# mainboard_B CHAR(150),
# ipo CHAR(150),
# repurchase_bonds CHAR(150),
# `current_time` CHAR(150)
# )
# """
# sql = """CREATE TABLE sse_fund_day(
# single_day_situation CHAR(150),
# fund CHAR(150),
# closed_fund CHAR(150),
# ETF CHAR(150),
# LOF CHAR(150),
# trading_fund CHAR(150),
# repurchase_fund CHAR(150),
# `current_time` CHAR(150)
# )
# """
# cur.execute(sql)
print("CREATE TABLE OK")
# 关闭数据库连接
cur.close()
# 关闭连接
conn.close()
| [
"zbh@example.com"
] | zbh@example.com |
0d45a727bc28374f7e8457cccf8c58524bade227 | d42954213667ce37a1eeadc125dc6ba1c67cf5d9 | /todoapp/todolist/migrations/0001_initial.py | d21f6b48027b9a9c184f8e38b6325c85ccb21f36 | [] | no_license | Hossain-Shah/Project | 8363f37e6557bca4fd03882b8aae7f344b8eb789 | 338e5fbdc132ea0952b02f93932031546d992d8a | refs/heads/master | 2023-08-09T12:35:01.774043 | 2023-08-05T13:05:22 | 2023-08-05T13:05:22 | 233,031,408 | 0 | 0 | null | 2020-10-13T18:22:53 | 2020-01-10T11:17:42 | Python | UTF-8 | Python | false | false | 1,342 | py | # Generated by Django 2.2.1 on 2019-10-01 16:28
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Category',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
],
options={
'verbose_name': 'Category',
'verbose_name_plural': 'Categories',
},
),
migrations.CreateModel(
name='TodoList',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=250)),
('content', models.TextField(blank=True)),
('created', models.DateField(default='2019-10-01')),
('due_date', models.DateField(default='2019-10-01')),
('category', models.ForeignKey(default='general', on_delete='models.CASCADE', to='todolist.Category')),
],
options={
'ordering': ['-created'],
},
),
]
| [
"noreply@github.com"
] | Hossain-Shah.noreply@github.com |
ee8c450917f609d531ffc85dbe264150f66aa9ee | d9eef8dd3489682c8db41f2311e3058d1f369780 | /.history/abel-network-files/mcmc_alg_implementation_own_20180626142636.py | 056663041df5c2070817234221eb3afcb7505416 | [] | no_license | McKenzie-Lamb/Gerrymandering | 93fe4a49fe39a0b307ed341e46ba8620ea1225be | b7a7c4129d6b0fcd760ba8952de51eafa701eac3 | refs/heads/master | 2021-01-25T06:06:43.824339 | 2018-10-16T14:27:01 | 2018-10-16T14:27:01 | 93,526,515 | 0 | 0 | null | 2018-07-12T19:07:35 | 2017-06-06T14:17:47 | Python | UTF-8 | Python | false | false | 1,820 | py | # Author: Abel Gonzalez
# Date: 06/26/18
#
# Description:
# This program uses the .shp file to create a network graph where each node
# represents a census tract and the edge represents adjacency between each
# tract, usign graph-tool instead of networkx
import graph_tool.all as gt
from pathlib import Path
# Paths
data_folder = Path("abel-network-files/data/")
images_folder = Path("abel-network-files/images/")
# Loading the previous created Graph and creating the prop maps
graph = gt.load_graph(str(data_folder / "tmp_graph.gt"))
district_no = graph.new_vertex_property("int")
color = graph.new_vertex_property("vector<double>")
ring_color = graph.new_vertex_property("vector<double>")
# Assigning the district to each vertex as a property map
districts_data = {}
districts = gt.minimize_blockmodel_dl(graph, 2,2)
blocks = districts.get_blocks()
for i in graph.vertices():
district_no[graph.vertex(i)] = blocks[i]
color[graph.vertex(i)] = (255, 255, 0, 1) if blocks[i] == 1 else (0, 255, 255, 1)
if district_no[i] in districts_data.keys():
for j in districts_data[blocks[i]].keys():
districts_data[blocks[i]][j] += graph.vp.data[i]
else:
districts_data[blocks[i]] = graph.vp.data[i]
# Assign ring color based on democrats total votes:
for i in districts_data.keys():
if districts_data[i]['CONDEM14'] > districts_data[i]['CONREP14']:
ring_color_ = (0, 0, 255, 1)
else:
ring_color_ = (255, 0, 0, 1)
matched_vertices = gt.find_vertex(graph, district_no, i)
for j in matched_vertices:
ring_color[graph.vertex(j)] = ring_color_
gt.graph_draw(graph, bg_color=(255, 255, 255, 1), vertex_fill_color=color, vertex_color=ring_color, pos=graph.vp.pos,
vertex_text=graph.vertex_index, output='abel-network-files/tmp.png')
| [
"gonzaleza@ripon.edu"
] | gonzaleza@ripon.edu |
8d70e1519b3f927b87482b6e543cdcf6457c7802 | 28d5d19196ac52d4bd60cbe5e06963dd8fd2ed74 | /etat_civil/geonames_place/tests/test_models.py | e7ad712113190310e59ed9582d5b45c388da847e | [
"MIT"
] | permissive | kingsdigitallab/etat-civil-django | a01ebea68ea205a185a36cfa76b6245d5a1df3e6 | 02bb32870dfd75d42f10189db6a527f133cbcdd6 | refs/heads/master | 2020-11-26T23:10:49.810602 | 2020-07-02T14:30:15 | 2020-07-02T14:30:15 | 229,226,182 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 2,640 | py | import geocoder
import pytest
from django.conf import settings
from django.db.utils import IntegrityError
from etat_civil.geonames_place.models import Place
pytestmark = pytest.mark.django_db
@pytest.mark.django_db
class TestPlace:
GEONAMES_ID = 2635167
GEONAMES_ADDRESS = "United Kingdom"
def test_save(self):
place = Place(geonames_id=self.GEONAMES_ID)
place.save()
assert place.address == self.GEONAMES_ADDRESS
with pytest.raises(IntegrityError):
place = Place()
place.save()
place.geonames_id = self.GEONAMES_ID
place.update_from_geonames = False
place.save()
def test_hydrate_from_geonames(self):
place = Place()
place.hydrate_from_geonames()
assert place.address is None
place.geonames_id = self.GEONAMES_ID
place.hydrate_from_geonames()
assert place.address == self.GEONAMES_ADDRESS
def test__hydrate(self):
place = Place(geonames_id=self.GEONAMES_ID)
place._hydrate(None)
assert place.address is None
g = geocoder.geonames(
place.geonames_id, key=settings.GEONAMES_KEY, method="details"
)
place._hydrate(g)
assert place.address == self.GEONAMES_ADDRESS
def test_to_list(self):
place = Place(geonames_id=1, address="Address", lat=1, lon=1)
place_as_list = place.to_list()
assert len(place_as_list) == 4
assert place_as_list[0] == place.geonames_id
assert place_as_list[1] == place.address
assert place_as_list[2] == place.lat
assert place_as_list[3] == place.lon
def test_create_or_update_from_geonames(self):
assert Place.create_or_update_from_geonames(None) == 0
assert Place.create_or_update_from_geonames("un") == 0
assert (
Place.create_or_update_from_geonames(self.GEONAMES_ADDRESS)
== settings.GEONAMES_MAX_RESULTS
)
def test_get_or_create_from_geonames(self):
assert Place.get_or_create_from_geonames(None) is None
assert Place.get_or_create_from_geonames("un") is None
place = Place.get_or_create_from_geonames(self.GEONAMES_ADDRESS)
assert place is not None
assert place.geonames_id == self.GEONAMES_ID
def test_places_to_list(self, tmpdir):
places = Place.places_to_list()
assert len(places) == 0
Place.objects.get_or_create(geonames_id=1, address="Address", lat=1, lon=1)
places = Place.places_to_list()
assert len(places) == 1
assert "Address" in places[0]
| [
"jmvieira@gmail.com"
] | jmvieira@gmail.com |
1dea1bd5576192e35833fe57508301a3a89aeb69 | 08176a94897588554501217f5ceb89bf8f004e63 | /galpy_cuda_demo/orbits/__init__.py | 7ae680602986aab03874a4c225e71cd40280a674 | [
"MIT"
] | permissive | jobovy/galpy_cuda_demo | 8e8f717a552a588fa7df6a2f25ff3eff8c2f083a | 3e79f3a6701721fd5d89914b2f9c144e68a72ec8 | refs/heads/master | 2020-03-30T18:23:01.791959 | 2018-10-03T02:57:58 | 2018-10-03T02:57:58 | 151,497,462 | 2 | 0 | MIT | 2018-10-04T00:15:10 | 2018-10-04T00:15:09 | null | UTF-8 | Python | false | false | 737 | py | from .CUDAOrbits import CUDAOrbits
from .npOrbits import npOrbits
def Orbits(x, y, vx, vy, mode='cuda'):
"""
Create Orbits array orbit, return Orbits instance depending on the mode
:param x: x-locations in AU
:type x: np.ndarray
:param y: y-locations in AU
:type y: np.ndarray
:param vx: x-velocity in AU/yr
:type vx: np.ndarray
:param vy: y-velocity in AU/yr
:type vy: np.ndarray
:param mode: 'cuda' to use CUDA GPU or 'cpu' to use numpy CPU
:type mode: str
"""
if mode.lower() == 'cuda':
return CUDAOrbits(x, y, vx, vy)
elif mode.lower() == 'cpu':
return npOrbits(x, y, vx, vy)
else:
raise ValueError("Mode can only be either 'CUDA' or 'CPU'")
| [
"henryskyleung@gmail.com"
] | henryskyleung@gmail.com |
fb0a1027debe02013a8d8ada8b134957351cf9e8 | 7a4ed01a40e8d79126b26f5e8fca43c8e61e78fd | /Geeky Shows/Advance Pyhton/220.Module[34]/PythonProject/Example-1.py | 9bee856020e437b89c563e04fbe4e699c04ee8c1 | [] | no_license | satyam-seth-learnings/python_learning | 5a7f75bb613dcd7fedc31a1567a434039b9417f8 | 7e76c03e94f5c314dcf1bfae6f26b4a8a6e658da | refs/heads/main | 2023-08-25T14:08:11.423875 | 2021-10-09T13:00:49 | 2021-10-09T13:00:49 | 333,840,032 | 1 | 0 | null | null | null | null | UTF-8 | Python | false | false | 192 | py | # Example-1.py <---- Main Module
import cal
print("Cal Module's Variable:",cal.a)
cal.name()
a=cal.add(10,20)
print(a)
print(cal.sub(20,10))
add=cal.add
print(add(4,7))
s=cal.sub
print(s(4,7)) | [
"satyam1998.1998@gmail.com"
] | satyam1998.1998@gmail.com |
7144f28804ed1051f0f61ebacd38ccfa966ca844 | 68f78e45e7cdeeaf2f9f3e8551c5bc922971a3be | /analysis/longbaseline/ch3cn_fiteach_e8.py | 7d23870c4560c80e7e9ba28d564704251679a105 | [] | no_license | keflavich/W51_ALMA_2013.1.00308.S | cdbb2b2aa569836c15fd424356d4a0778fccd2ec | 5389047e3e8adf7bcb4f91b1f4783bcc825961f6 | refs/heads/master | 2023-02-02T08:47:30.104031 | 2023-01-30T16:21:18 | 2023-01-30T16:21:18 | 44,909,889 | 3 | 12 | null | 2016-11-09T11:58:26 | 2015-10-25T12:51:54 | TeX | UTF-8 | Python | false | false | 5,040 | py | from ch3cn_fits import SpectralCube, pyspeckit, fits, u, np
import os
T=True
F=False
cubefn = '../../FITS/longbaseline/W51e8_CH3CN_cutout.fits'
if not os.path.exists(cubefn):
cube = SpectralCube.read('../../FITS/longbaseline/W51e2cax.CH3CN_K3_nat_all.image.fits')
scube = cube[:,1120:1440,2400:2760]
scube.write(cubefn)
cube = SpectralCube.read(cubefn).minimal_subcube()
contcubeK = cube.to(u.K, u.brightness_temperature(cube.beam,
cube.wcs.wcs.restfrq*u.Hz))
cubeK = cube.to(u.K, u.brightness_temperature(cube.beam,
cube.wcs.wcs.restfrq*u.Hz))
med = cubeK.percentile(25, axis=0)
cubeK.allow_huge_operations=True
cubeK = cubeK - med
# BAD error estimate
err = cubeK.std(axis=0)
err[:] = 5*u.K
peak = (cubeK).max(axis=0)
mask = (peak > 200*u.K)# & (peak > 6*err)
absorption_mask = cubeK.min(axis=0) < -150*u.K
mask = mask & (~absorption_mask)
pcube = pyspeckit.Cube(cube=cubeK[:400,:,:]) # crop out k=0,1
vguesses = 62*u.km/u.s
colguesses = np.ones_like(mask)*1e16
temguesses = np.ones_like(mask)*250.
widths = np.ones_like(mask)*2.0
#guesses = np.array([vguesses.value, widths, temguesses, colguesses])
guesses = [62, 2.0, 250., 1e16]
# For laptop
#mask &= (peak>10*u.K)
start_point = (43,43)#np.unravel_index(np.nanargmax(peak*mask), peak.shape)
position_order = 1./peak.value
position_order[np.isnan(peak)] = np.inf
sp = pcube.get_spectrum(*start_point)
sp.plotter()
sp.specfit(fittype='ch3cn', guesses=guesses)
pcube.fiteach(fittype='ch3cn', guesses=guesses, integral=False,
verbose_level=3, start_from_point=start_point,
use_neighbor_as_guess=True, position_order=position_order,
limitedmax=[T,T,T,T],
limitedmin=[T,T,T,T],
maxpars=[100,5,1500,1e18],
minpars=[0,0.1,50,1e13],
signal_cut=0,
maskmap=mask,
errmap=err.value, multicore=4)
pcube.write_fit('e8_CH3CN_Emission_fits.fits', clobber=True)
min_background = 100
background_guess = med.value
background_guess[background_guess < min_background] = min_background
guesses = np.empty((5,)+cube.shape[1:], dtype='float')
guesses[0,:] = 62
guesses[1,:] = 2
guesses[2,:] = 250.
guesses[3,:] = 1e16
guesses[4,:] = background_guess
# again, try cropping out the k=0,1 lines under the assumption that they do not
# trace the disk
pcube_cont = pyspeckit.Cube(cube=contcubeK[:400,:,:])
start_point = (71,66)#np.unravel_index(np.nanargmax(peak*mask), peak.shape)
sp = pcube_cont.get_spectrum(71,66)
sp.specfit(fittype='ch3cn_absorption', guesses=guesses[:,66,71],
limitedmax=[T,T,T,T,T], limitedmin=[T,T,T,T,T],
maxpars=[100,5,1500,1e18,10000],
minpars=[0,0.1,50,1e13,100],)
pcube_cont.fiteach(fittype='ch3cn_absorption', guesses=guesses, integral=False,
verbose_level=3, start_from_point=start_point,
use_neighbor_as_guess=True, position_order=position_order,
limitedmax=[T,T,T,T,T],
limitedmin=[T,T,T,T,T],
maxpars=[70,5,1500,1e18,10000],
minpars=[40,0.1,50,1e13,min_background],
signal_cut=0,
maskmap=absorption_mask,
errmap=err.value, multicore=4)
pcube_cont.write_fit('e8_CH3CN_Absorption_fits.fits', clobber=True)
from astropy import coordinates
e8 = coordinates.SkyCoord("19h23m43.90s", "14d30m28.3s", frame='fk5')
pcube_cont.show_fit_param(0,vmin=58,vmax=63)
pcube_cont.mapplot.FITSFigure.recenter(e8.ra.deg, e8.dec.deg, 0.3/3600.)
pcube.show_fit_param(0, vmin=60, vmax=70)
pcube.mapplot.FITSFigure.recenter(e8.ra.deg, e8.dec.deg, 0.3/3600.)
# from kinematic_analysis_pv_LB import diskycoords, outflowpath
# import pvextractor
# import pylab as pl
#
# pl.figure(5).clf()
# for width in (None, 0.05*u.arcsec, 0.1*u.arcsec, 0.15*u.arcsec):
# diskypath = pvextractor.Path(diskycoords, width)
# extracted_disky = pvextractor.extract_pv_slice(pcube_cont.parcube[0:1,:,:], diskypath, wcs=pcube_cont.wcs)
#
# pl.plot(extracted_disky.data.squeeze(), label=str(width))
#
# pl.xlabel("Offset (pixels)")
# pl.ylabel("Velocity (km/s)")
# pl.ylim(55,60)
# pl.xlim(855,890)
#
# pl.legend(loc='best')
#
# pl.figure(6).clf()
# diskypath = pvextractor.Path(diskycoords, width=None)
# extracted_disky = pvextractor.extract_pv_slice(pcube_cont.parcube[0:1,:,:], diskypath, wcs=pcube_cont.wcs)
# extracted_disky_width = pvextractor.extract_pv_slice(np.abs(pcube_cont.parcube[1:2,:,:]), diskypath, wcs=pcube_cont.wcs)
#
# pl.fill_between(np.arange(len(extracted_disky.data.squeeze())),
# extracted_disky.data.squeeze()-extracted_disky_width.data.squeeze(),
# extracted_disky.data.squeeze()+extracted_disky_width.data.squeeze(),
# alpha=0.5)
# pl.plot(extracted_disky.data.squeeze())
#
#
# pl.xlabel("Offset (pixels)")
# pl.ylabel("Velocity (km/s)")
# pl.ylim(52,62)
# pl.xlim(855,890)
#
| [
"keflavich@gmail.com"
] | keflavich@gmail.com |
aac340369aca6edb334b4fe4d8ece4fa11967c4b | 163bbb4e0920dedd5941e3edfb2d8706ba75627d | /Code/CodeRecords/2151/60788/281320.py | 6778e5f7a57d954b16e2da82cdf7a01966bd5874 | [] | no_license | AdamZhouSE/pythonHomework | a25c120b03a158d60aaa9fdc5fb203b1bb377a19 | ffc5606817a666aa6241cfab27364326f5c066ff | refs/heads/master | 2022-11-24T08:05:22.122011 | 2020-07-28T16:21:24 | 2020-07-28T16:21:24 | 259,576,640 | 2 | 1 | null | null | null | null | UTF-8 | Python | false | false | 2,828 | py | import copy
class Disjoint_set:
def __init__(self,n):
self.li=[[x+1] for x in range(n)]
def union(self,x,y):
index1=0
index2=0
for i in range(len(self.li)):
if x in self.li[i]:
index1=i
if y in self.li[i]:
index2=i
self.li[index1]+=self.li[index2]
self.li.pop(index2)
def query(self,x):
for i in range(len(self.li)):
if x in self.li[i]:
return i
return 0
class Edge:
def __init__(self,a,b,value):
self.dot1=a
self.dot2=b
self.value=value
def ten_to_three(number):
num=number
s=[]
while num!=0:
s.append(num%3)
num=int(num/3)
s.reverse()
return ''.join([str(x) for x in s])
def three_to_ten(a):
m=0
list_a=list(a)
for k in list_a:
m*=3
m+=int(k)
return m
def add(a,b):
list_a=list(a)
list_b=list(b)
s=[]
if len(list_a)>len(list_b):
for i in range(len(list_a)-len(list_b)):
s.append(list_a.pop(0))
elif len(list_b)>len(list_a):
for i in range(len(list_b)-len(list_a)):
s.append(list_b.pop(0))
for i in range(len(list_a)):
s.append(str((int(list_a[i])+int(list_b[i]))%3))
return ''.join(s)
def do_sum(x):
m='0'
for k in x:
m=add(m,str(k.value))
return three_to_ten(m)
def f(disjoint,edge_li,total_edge):
if len(edge_li)<total_edge :
return []
elif len(edge_li)==0:
return [[]]
else:
first_edge=edge_li.pop(0)
if disjoint.query(first_edge.dot1)!=disjoint.query(first_edge.dot2):
set1=f(disjoint,edge_li,total_edge)
disjoint.union(first_edge.dot1,first_edge.dot2)
set2 =f(disjoint,edge_li,total_edge-1)
for every_edges in set2:
every_edges.append(first_edge)
return set1+set2
else:
return f(disjoint,edge_li,total_edge)
def seek_all_tree(edge_li,total_edge_num):
if len(edge_li)==0 or len(edge_li)<total_edge_num:
return []
disjoint_set=Disjoint_set(total_edge_num+1)
first_edge=edge_li.pop(0)
trees1=seek_all_tree(copy.deepcopy(edge_li),total_edge_num)
disjoint_set.union(first_edge.dot1,first_edge.dot2)
trees2=f(disjoint_set,edge_li,total_edge_num-1)
for tree in trees2:
tree.append(first_edge)
return trees1+trees2
line1=input().strip()
dot_num=int(line1.split()[0])
edge_num=int(line1.split()[1])
edge_list=[]
for i in range(edge_num):
line=input().strip()
edge=Edge(int(line.split()[0]),int(line.split()[1]),int(line.split()[2]))
edge_list.append(edge)
trees=seek_all_tree(edge_list,dot_num-1)
trees_value=[do_sum(x) for x in trees]
print(sum(trees_value)%1000000007)
| [
"1069583789@qq.com"
] | 1069583789@qq.com |
d2cd0667277f7d6b98e2d0ac48d781ee254dc794 | 2869eb01810389ab7b64355ec189800e7b1d49b9 | /MetaCTF 2021/Crypto/hideandseek/solve.py | 6cfdd54cf61a129c4c65c01876d7a134ef749e84 | [] | no_license | Giantpizzahead/ctf-archive | 096b1673296510bddef9f284700ebdb0e76d71a7 | 5063cd2889cd300aade440429faf9c4ca68511ef | refs/heads/master | 2021-12-28T14:23:33.598960 | 2021-12-20T17:23:55 | 2021-12-20T17:23:55 | 252,905,854 | 1 | 0 | null | 2021-12-20T17:14:05 | 2020-04-04T04:11:24 | C | UTF-8 | Python | false | false | 4,606 | py | import gmpy2
import math
import itertools
with open('raw2.txt', 'r') as fin:
raw = fin.readlines()
# Predict random bits
with open('randbits.txt', 'r') as fin:
rand_bits = eval(fin.read())
curr_bit = 0
def predictrandbits(n):
global curr_bit
x = 0
good = True
for i in reversed(range(n // 32)):
x *= (2 ** 32)
if rand_bits[curr_bit+i] == -1: good = False
x += rand_bits[curr_bit+i]
curr_bit += n // 32
return x if good else -1
last_00 = False
def parse_raw(i):
global last_00
# print(i, end=' ')
if raw[i][0] == 'C':
# Client
packet = bytes.fromhex(raw[i][2:])
if packet[0] == 0:
# Requesting new public key from the server
# print('Public key request')
last_00 = True
return ('request')
else:
# Encrypted message
# print('Sent encrypted message') # {}'.format(packet[2:]))
return ('sent', int.from_bytes(packet[1:], byteorder="big"))
else:
# Server
packet = bytes.fromhex(raw[i])
if packet[0] == 0:
# Getting a new key
e = int.from_bytes(packet[1:4], byteorder="big")
if last_00:
# Public key
n = int.from_bytes(packet[4:260], byteorder="big")
print('public')
# print('New public key e={} n={}'.format(e, n))
last_00 = False
# return ('public', e, n)
# Attempt to predict the public key
p = gmpy2.next_prime(predictrandbits(1024))
q = gmpy2.next_prime(predictrandbits(1024))
# print(e, p, q)
return ('public', e, p, q)
else:
# Private key
p = int.from_bytes(packet[4:132], byteorder="big")
q = int.from_bytes(packet[132:260], byteorder="big")
pp = gmpy2.next_prime(predictrandbits(1024))
pq = gmpy2.next_prime(predictrandbits(1024))
if pq != -1 and pq != -1 and (p != pp or q != pq):
print('rand error ', p, pp, q, pq)
# print('private {} {}'.format(p, q))
# print('New private key e={} p={} q={}'.format(e, p, q))
return ('private', e, p, q)
else:
# Receiving encrypted message
# print('Received encrypted message')
return ('received', int.from_bytes(packet[1:], byteorder="big"))
def encrypt(p, e, n):
guess = int.from_bytes(p.encode("utf-8"), byteorder="big")
enc = pow(guess, e, n)
return enc
keys = []
special = None
seen_private = set()
seen_public = set()
prime_pairs = []
for i in range(len(raw)):
res = parse_raw(i)
'''
if i == 72:
priv = gmpy2.invert(res[1], (res[2]-1) * (res[3]-1))
special = (int(priv), res[2] * res[3])
'''
if res[0] == 'private':
# Track private keys
priv = gmpy2.invert(res[1], (res[2]-1) * (res[3]-1))
key = (int(priv), res[2] * res[3])
keys += [key]
if key in seen_private:
print('SEEN', key)
seen_private.add(key)
prime_pairs += [(res[2], res[3])]
elif res[0] == 'received':
# Decrypt the message
'''
if i == 140:
msg = pow(res[1], special[0], special[1])
msg = pow(res[1], keys[0][0], keys[0][1])
else:
'''
msg = pow(res[1], keys[0][0], keys[0][1])
keys = keys[1:]
print('S:', msg.to_bytes(256, byteorder="big").lstrip(b'\x00'))
elif res[0] == 'public':
# Track public keys
key = (res[1], res[2], res[3])
keys += [key]
# if key in seen_public:
# print('SEEN', key)
seen_public.add(key)
elif res[0] == 'sent':
# Try to decrypt the message
e, p, q = keys[0]
keys = keys[1:]
if p != -1 and q != -1:
d = gmpy2.invert(e, (p-1) * (q-1))
msg = int(pow(res[1], d, p*q))
if msg < 0: msg = 0
print('C:', msg.to_bytes(256, byteorder="big").lstrip(b'\x00'))
else:
print('C: Cannot decrypt')
'''
e, n = keys[0]
keys = keys[1:]
guesses = [
'Do you want to play a game?',
'Wanna play a game?',
'Want to play a game?',
'Let\'s play a game.',
'Let\'s play a game!',
'Ok.',
'Ok!',
'Sure.',
'No.',
'No',
'Yes',
'Yes.',
'No problem!',
'No problem',
'No problem.',
'Nice.',
'Nice!',
'Nice',
'Not bad.',
'Not bad!',
'Not bid',
'Good job.',
'Good job!',
'Good job',
'Nice work.',
'Nice work!',
'Nice work',
'Fine',
'Fine.',
'Fine!',
]
for guess in itertools.permutations('abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ.?!', r=2): #guesses:
guess = ''.join(guess)
enc = encrypt(guess, e, n)
if enc == res[1]:
print('CORRECT', res[1], enc)
'''
'''
for a in prime_pairs:
for b in seen_public:
if a[0] * a[1] == b[1]:
print('REUSED', a[0], a[1], b[1])
if math.gcd(a[0], b[1]) != 1 or math.gcd(a[1], b[1]) != 1:
print('GCD prime', a[0], a[1], b[1])
for a in seen_public:
for b in seen_public:
if a[1] != b[1] and math.gcd(a[1], b[1]) != 1:
print('GCD public', a[1], b[1])
'''
| [
"43867185+Giantpizzahead@users.noreply.github.com"
] | 43867185+Giantpizzahead@users.noreply.github.com |
25c0219880c40b5103c897230579f8ae55bbd1d3 | 2e682fa5f6a48d7b22b91e5d518fc28ff0fbb913 | /promoSystemProject/asgi.py | 8b2455dc7b1d3337f6fc58b37ddfa879e494bf9f | [] | no_license | Mohamed-awad/PromoSystem | 90c17d67fdac05c1652cd269b2d4b5f8015bdbb3 | 173abd9bade0524daff8c91c73d24c68d02cf4a5 | refs/heads/master | 2023-07-24T03:28:54.411511 | 2021-08-29T14:11:42 | 2021-08-29T14:11:42 | 299,772,631 | 0 | 1 | null | null | null | null | UTF-8 | Python | false | false | 413 | py | """
ASGI config for promoSystemProject project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'promoSystemProject.settings')
application = get_asgi_application()
| [
"awadmohamed233@gmail.com"
] | awadmohamed233@gmail.com |
b80e0355fffad9d7410648f19d6a06c0bb3f39ff | 6f31a15cb73175084f2c4485d3dea0b8975b2ec9 | /egs/yomdle_zh/v1/local/prepare_lexicon.py | 3ebb52e38f4d3ce7f9cafbcc40bfb03b91006d74 | [
"Apache-2.0",
"LicenseRef-scancode-public-domain"
] | permissive | Idlak/idlak | c7cd5e6c0b02918cda85dbb2fb5c7333a789c304 | 4be6f7d951ba0d707a84a2cf8cbfc36689b85a3c | refs/heads/master | 2021-11-23T13:28:43.709163 | 2021-11-01T15:51:46 | 2021-11-01T15:51:46 | 127,285,931 | 65 | 26 | NOASSERTION | 2021-11-01T15:51:47 | 2018-03-29T12:06:52 | Shell | UTF-8 | Python | false | false | 1,634 | py | #!/usr/bin/env python3
# Copyright 2018 Ashish Arora
# Chun-Chieh Chang
import argparse
import os
parser = argparse.ArgumentParser(description="""Creates the list of characters and words in lexicon""")
parser.add_argument('dir', type=str, help='output path')
parser.add_argument('--data-dir', type=str, default='data', help='Path to text file')
args = parser.parse_args()
### main ###
lex = {}
text_path = os.path.join(args.data_dir, 'train', 'text')
text_fh = open(text_path, 'r', encoding='utf-8')
# Used specially for Chinese.
# Uses the ChangJie keyboard input method to create subword units for Chinese.
cj5_table = {}
with open('download/cj5-cc.txt', 'r', encoding='utf-8') as f:
for line in f:
line_vect = line.strip().split()
if not line_vect[0].startswith('yyy') and not line_vect[0].startswith('z'):
cj5_table[line_vect[1]] = "cj5_" + " cj5_".join(list(line_vect[0]))
with open(text_path, 'r', encoding='utf-8') as f:
for line in f:
line_vect = line.strip().split()
for i in range(1, len(line_vect)):
characters = list(line_vect[i])
# Put SIL instead of "|". Because every "|" in the beginning of the words is for initial-space of that word
characters = " ".join([ 'SIL' if char == '|' else cj5_table[char] if char in cj5_table else char for char in characters])
characters = characters.replace('#','<HASH>')
lex[line_vect[i]] = characters
with open(os.path.join(args.dir, 'lexicon.txt'), 'w', encoding='utf-8') as fp:
for key in sorted(lex):
fp.write(key + " " + lex[key] + "\n")
| [
"dpovey@gmail.com"
] | dpovey@gmail.com |
090d7331f80b90bb5fcd60512140923e61e2f4ad | f9ed6d4ef53874453ff429bd67bfdc91369c5d82 | /misc/h5_stats.py | 06c8b662dca2d90920c7a3fa2f1ed56d03e87aa7 | [] | no_license | axeltidemann/propeller | 35a79464f6f0ee249c2d5e91d5e31d2fe6c08b33 | b9485f523812bf37c40404d052e05a43f6dc0799 | refs/heads/master | 2020-04-04T07:37:07.430215 | 2019-06-05T04:45:48 | 2019-06-05T04:45:48 | 39,445,622 | 5 | 1 | null | 2019-05-29T04:55:46 | 2015-07-21T13:02:33 | Python | UTF-8 | Python | false | false | 1,345 | py | # Copyright 2016 Telenor ASA, Author: Axel Tidemann
'''
Collects stats of categories.
'''
import argparse
import glob
import os
import shutil
import pandas as pd
import matplotlib
matplotlib.use('agg')
import matplotlib.pyplot as plt
import seaborn as sns
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
'data_folder',
help='Folder with Inception states for training')
parser.add_argument(
'--filename',
help='Filename to save',
default='counts.png')
parser.add_argument(
'--limit',
help='Minimum amount of data necessary',
default=1000)
parser.add_argument(
'--target',
help='Where to put the file',
default='/mnt/kaidee/curated/')
args = parser.parse_args()
files = sorted(glob.glob('{}/*.h5'.format(args.data_folder)))
counts = []
categories = []
for h5_file in files:
length = len(pd.read_hdf(h5_file, 'data'))
counts.append(length)
category = os.path.basename(h5_file).replace('.h5','')
categories.append(category)
print '{}: {}'.format(category, length)
if length > args.limit:
shutil.copy(h5_file, args.target)
print '--> copied to {}'.format(args.target)
sns.barplot(range(len(categories)), counts)
plt.xticks(range(len(categories)), categories)
plt.savefig(args.filename, dpi=300)
| [
"axel.tidemann@gmail.com"
] | axel.tidemann@gmail.com |
4c37c257452df18c4aa08f338e5f08b9751c4952 | 80a3d98eae1d755d6914b5cbde63fd10f5cc2046 | /autox/autox_video/mmaction2/configs/skeleton/2s-agcn/2sagcn_80e_ntu60_xsub_bone_3d.py | 4a8ffbfc977e37ecd0bf127efd5462d57e5d6ed2 | [
"Apache-2.0"
] | permissive | 4paradigm/AutoX | efda57b51b586209e1d58e1dab7d0797083aadc5 | 7eab9f4744329a225ff01bb5ec360c4662e1e52e | refs/heads/master | 2023-05-24T00:53:37.109036 | 2023-02-14T14:21:50 | 2023-02-14T14:21:50 | 388,068,949 | 752 | 162 | Apache-2.0 | 2022-07-12T08:28:09 | 2021-07-21T09:45:41 | Jupyter Notebook | UTF-8 | Python | false | false | 2,471 | py | model = dict(
type='SkeletonGCN',
backbone=dict(
type='AGCN',
in_channels=3,
graph_cfg=dict(layout='ntu-rgb+d', strategy='agcn')),
cls_head=dict(
type='STGCNHead',
num_classes=60,
in_channels=256,
loss_cls=dict(type='CrossEntropyLoss')),
train_cfg=None,
test_cfg=None)
dataset_type = 'PoseDataset'
ann_file_train = 'data/ntu/nturgb+d_skeletons_60_3d/xsub/train.pkl'
ann_file_val = 'data/ntu/nturgb+d_skeletons_60_3d/xsub/val.pkl'
train_pipeline = [
dict(type='PaddingWithLoop', clip_len=300),
dict(type='PoseDecode'),
dict(type='JointToBone'),
dict(type='FormatGCNInput', input_format='NCTVM'),
dict(type='Collect', keys=['keypoint', 'label'], meta_keys=[]),
dict(type='ToTensor', keys=['keypoint'])
]
val_pipeline = [
dict(type='PaddingWithLoop', clip_len=300),
dict(type='PoseDecode'),
dict(type='JointToBone'),
dict(type='FormatGCNInput', input_format='NCTVM'),
dict(type='Collect', keys=['keypoint', 'label'], meta_keys=[]),
dict(type='ToTensor', keys=['keypoint'])
]
test_pipeline = [
dict(type='PaddingWithLoop', clip_len=300),
dict(type='PoseDecode'),
dict(type='JointToBone'),
dict(type='FormatGCNInput', input_format='NCTVM'),
dict(type='Collect', keys=['keypoint', 'label'], meta_keys=[]),
dict(type='ToTensor', keys=['keypoint'])
]
data = dict(
videos_per_gpu=12,
workers_per_gpu=2,
test_dataloader=dict(videos_per_gpu=1),
train=dict(
type=dataset_type,
ann_file=ann_file_train,
data_prefix='',
pipeline=train_pipeline),
val=dict(
type=dataset_type,
ann_file=ann_file_val,
data_prefix='',
pipeline=val_pipeline),
test=dict(
type=dataset_type,
ann_file=ann_file_val,
data_prefix='',
pipeline=test_pipeline))
# optimizer
optimizer = dict(
type='SGD', lr=0.1, momentum=0.9, weight_decay=0.0001, nesterov=True)
optimizer_config = dict(grad_clip=None)
# learning policy
lr_config = dict(policy='step', step=[30, 40])
total_epochs = 80
checkpoint_config = dict(interval=3)
evaluation = dict(interval=3, metrics=['top_k_accuracy'])
log_config = dict(interval=100, hooks=[dict(type='TextLoggerHook')])
# runtime settings
dist_params = dict(backend='nccl')
log_level = 'INFO'
work_dir = './work_dirs/2sagcn_80e_ntu60_xsub_bone_3d/'
load_from = None
resume_from = None
workflow = [('train', 1)]
| [
"caixiaochen@4ParadigmdeMacBook-Pro.local"
] | caixiaochen@4ParadigmdeMacBook-Pro.local |
c9940272738fd5a2a46479dd072d9a4990c8b199 | bec623f2fab5bafc95eb5bd95e7527e06f6eeafe | /django-gc-shared/payments/systems/forsazh.py | 05a67bfb1ea63578e3361e141481e6e5c7b25d26 | [] | no_license | riyanhax/a-demo | d714735a8b59eceeb9cd59f788a008bfb4861790 | 302324dccc135f55d92fb705c58314c55fed22aa | refs/heads/master | 2022-01-21T07:24:56.468973 | 2017-10-12T13:48:55 | 2017-10-12T13:48:55 | null | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 3,908 | py | # -*- coding: utf-8 -*-
import re
from decimal import Decimal
from django import forms
from django.utils.functional import lazy
from django.utils.translation import ugettext_lazy as _, string_concat
from currencies.currencies import RUR
from geobase.models import Country
from payments.systems import base
from payments.systems.base import (
FormWithCity, FormWithCountry, FormWithName, PhonePursePaymentForm
)
from shared.widgets import DateWidget
name = u"Форсаж"
slug = __name__.rsplit(".", 1)[-1]
mt4_payment_slug = "Forsazh"
logo = "moneygram.png"
languages = ('ru',)
currencies = ['USD', 'EUR', 'RUB']
display_amount = lazy(RUR.display_amount, unicode)
transfer_details = {
"withdraw": {
"time": _("up to 3 days"),
"min_amount": display_amount(5000),
"fee": u"3%",
}
}
templates = {
"deposit": "payments/forms/deposit/moneygram.html",
"withdraw": "payments/forms/withdraw/wu_fastpost_moneygram.html",
}
class DepositForm(base.DepositForm):
pass
class DetailsForm(base.DetailsForm, FormWithName, FormWithCountry, FormWithCity, PhonePursePaymentForm):
nationality = forms.ModelChoiceField(label=u"Гражданство", queryset=Country.objects.all())
address = forms.CharField(label=u"Адрес", max_length=100, help_text=u"Адрес постоянной регистрации")
document_type = forms.CharField(label=u"Тип документа", max_length=100, help_text=u"Тип документа, "
u"удостоверяющего личность")
document_number = forms.CharField(label=u"Номер документа", max_length=100, help_text=u"Номер документа")
document_issuer = forms.CharField(label=u"Кем выдан", max_length=100)
document_issued_date = forms.DateField(label=u"Дата выдачи", widget=DateWidget())
document_expiry = forms.DateField(label=u"Срок действия", widget=DateWidget(), required=False,
help_text=u"Срок действия документа, удостоверяющего личность")
birthday = forms.DateField(label=u"Дата рождения", widget=DateWidget())
birthplace = forms.CharField(label=u"Место рождения", max_length=100)
def __init__(self, *args, **kwargs):
super(DetailsForm, self).__init__(*args, **kwargs)
self.fields["purse"].label = u"Номер телефона"
self.fields["country"].help_text = _("The country in which you receive transfer")
self.fields["city"].help_text = _("The city in which you receive transfer")
profile = self.request.user.profile
self.fields["purse"].initial = profile.phone_mobile
self.fields["nationality"].initial = profile.country
self.fields["birthday"].initial = profile.birthday
def clean_purse(self):
if not re.match(r'^[A-Z -]*$', self.cleaned_data['purse']):
raise forms.ValidationError(_('Only uppercase latin letters and space are allowed'))
return self.cleaned_data['purse'].upper()
class WithdrawForm(base.WithdrawForm):
commission_rate = Decimal("0.03")
info = string_concat(
_("Withdrawal of funds from the account - %(time)s"),
"\n",
_("Rouble transfer commission - %(fee)s"),
"\n",
_("Minimal sum of withdrawal - %(min_amount)s")
)
def __init__(self, *args, **kwargs):
super(WithdrawForm, self).__init__(*args, **kwargs)
# self.fields["country"].help_text = _("The country in which you receive transfer")
# self.fields["city"].help_text = _("The city in which you receive transfer")
self.fields["currency"].help_text = _("Choose currency")
def _get_min_amount(self, account):
return 5000, RUR | [
"ibalyko@ubuntu-server-16-04"
] | ibalyko@ubuntu-server-16-04 |
0e90c8be1d35f2c8c360430c4472a00833372326 | a8062308fb3bf6c8952257504a50c3e97d801294 | /problems/N1162_As_Far_From_Land_As_Possible.py | 10b5552d6fd60c2f0ab9b8a7512332ed2e7b0d49 | [] | no_license | wan-catherine/Leetcode | 650d697a873ad23c0b64d08ad525bf9fcdb62b1b | 238995bd23c8a6c40c6035890e94baa2473d4bbc | refs/heads/master | 2023-09-01T00:56:27.677230 | 2023-08-31T00:49:31 | 2023-08-31T00:49:31 | 143,770,000 | 5 | 0 | null | null | null | null | UTF-8 | Python | false | false | 1,097 | py | """
consider from '1' not '0'
"""
class Solution(object):
def maxDistance(self, grid):
"""
:type grid: List[List[int]]
:rtype: int
"""
n = len(grid)
stack = []
res = -1
for i in range(n):
for j in range(n):
if grid[i][j] == 1:
stack.append((i, j))
grid[i][j] = 2
step = 0
directions = [(1,0),(0,1),(-1,0),(0,-1)]
while stack:
new_stack = []
for i, j in stack:
for r, c in directions:
row, col = r+i, c+j
if row < 0 or row >= n or col < 0 or col >= n:
continue
if grid[row][col] == 0:
res = max(res, step + 1)
grid[row][col] = 2
new_stack.append((row, col))
continue
if grid[row][col] == 2:
continue
stack = new_stack
step += 1
return res
| [
"rarry2012@gmail.com"
] | rarry2012@gmail.com |
fe2afc4e27559474c454289a0f2d9f23f9d89c63 | 45614a944ffbdb75a0bef955582a722da5ce7492 | /python/udp_server.py | 02620d0743a3376499c7cbd8f12ad360b23ad43e | [] | no_license | wccgoog/pass | 1c8ab5393547634a27c7543556a75dec771a9e3d | 0ec01536ae10b3d99707002c0e726072acb50231 | refs/heads/2 | 2023-01-15T13:27:26.312648 | 2019-10-23T09:30:45 | 2019-10-23T09:30:45 | 122,595,075 | 0 | 2 | null | 2023-01-07T10:42:38 | 2018-02-23T08:38:36 | JavaScript | UTF-8 | Python | false | false | 320 | py | # -*- coding: utf-8 -*-
"""
Created on Sun Feb 11 14:53:08 2018
@author: wccgo
"""
import socket
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind(('127.0.0.1',9999))
print('Bind UDP on 9999')
while True:
data,addr=s.recvfrom(1024)
print('Received from %s:%s.'%addr)
s.sendto(b'Hello,%s!'%data,addr) | [
"wcc3@sina.com"
] | wcc3@sina.com |
237fca580df650487e817d5233cd1dbf6fa66ee2 | 3de6f7f6d8497e728101c368ec778e67f769bd6c | /notes/algo-ds-practice/problems/array/kth_smallest.py | b8e24a89f9d21d12c470f70ead0f6c1325cee1e6 | [
"MIT"
] | permissive | arnabs542/interview-notes | 1fceae0cafa74ef23d0ce434e2bc8e85c4c76fdd | 65af75e2b5725894fa5e13bb5cd9ecf152a0d652 | refs/heads/master | 2023-01-03T06:38:59.410704 | 2020-10-25T06:49:43 | 2020-10-25T06:49:43 | null | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 752 | py | '''
**Solution 1:**
1. Max-heapify the first k elements.
2. For every index i > k, heap.pushpop(n[i]).
3. At the end, we will have a max-heap containing the k smallest elements.
O(k + (n-k)logk)
**Solution 2:**
1. Min-heapify the whole array in O(n).
2. Call heap.pop() k times.
O(n + klogk)
**Solution 3:**
1. Call the quicksort partition() on array (either on the first or the last element).
2. If the pivot position == k, then return it straightaway.
3. Else, recur for left or right array accordingly.
O(n*n) worst case but O(n) average.
**Solution 4:**
1. Same as solution 3 but use randomized pivot selection.
Expected O(n).
**Solution 5:**
1. Same as solution 4 but use median-of-median to get the median as the pivot.
Guaranteed O(n)
'''
| [
"ajaggi@linkedin.com"
] | ajaggi@linkedin.com |
8948a012db16666753807e0753d132e0481dea7e | 6b3b965597c8f203c0232af19b4f4cd5962699c4 | /src/motan/android_vulnerabilities/invalid_server_certificate/invalid_server_certificate.py | 704cd996c4365579e163f3ddd5795ebce2251d7b | [
"MIT"
] | permissive | cqr-cryeye-forks/motan | 8167060cfabfc6a218fc76eceb439ee8e82257ba | 7687cf23842ac0ddbd0e11efa7788670d4d220c0 | refs/heads/master | 2023-08-15T21:07:00.369536 | 2021-10-22T12:46:42 | 2021-10-22T12:46:42 | null | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 6,408 | py | #!/usr/bin/env python3
import logging
import os
from typing import Optional, List
from androguard.core.analysis.analysis import MethodAnalysis
from androguard.core.bytecodes.dvm import EncodedMethod
import motan.categories as categories
from motan import vulnerability as vuln
from motan.analysis import AndroidAnalysis
from motan.taint_analysis import TaintAnalysis
from motan.util import is_class_implementing_interfaces
class CustomTaintAnalysis(TaintAnalysis):
def vulnerable_path_found_callback(
self,
full_path: List[MethodAnalysis],
caller: MethodAnalysis = None,
target: MethodAnalysis = None,
last_invocation_params: list = None,
):
# This method is not used for the current vulnerability check, we only need this
# class to use one of its methods to get the paths to a target method.
pass
class InvalidServerCertificate(categories.ICodeVulnerability):
def __init__(self):
self.logger = logging.getLogger(self.__class__.__name__)
super().__init__()
def check_vulnerability(
self, analysis_info: AndroidAnalysis
) -> Optional[vuln.VulnerabilityDetails]:
self.logger.debug(f"Checking '{self.__class__.__name__}' vulnerability")
try:
vulnerability_found = False
# Load the vulnerability details.
details = vuln.get_vulnerability_details(
os.path.dirname(os.path.realpath(__file__)), analysis_info.language
)
details.id = self.__class__.__name__
dx = analysis_info.get_dex_analysis()
# Look for the implementation(s) of the X509TrustManager interface
# (https://developer.android.com/reference/javax/net/ssl/X509TrustManager)
# and check if checkServerTrusted method is empty.
interface_implementations = []
classes = dx.get_internal_classes()
for clazz in classes:
if is_class_implementing_interfaces(
clazz.get_vm_class(), ["Ljavax/net/ssl/X509TrustManager;"]
):
for method in clazz.get_vm_class().get_methods():
if (method.get_name() == "checkServerTrusted") and (
method.get_descriptor()
== "([Ljava/security/cert/X509Certificate; "
"Ljava/lang/String;)V"
):
# The method has only one (return) instruction, so there is
# no validation on the server certificates.
if len(list(method.get_instructions())) <= 1:
interface_implementations.append(
method.get_class_name()
)
# No X509TrustManager interface implementation was not found, there is no
# reason to continue checking this vulnerability.
if not interface_implementations:
return None
# The list of methods that contain the vulnerability. The key is the full
# method signature where the vulnerable code was found, while the value is
# a tuple with the signature of the vulnerable API/other info about the
# vulnerability and the full path leading to the vulnerability.
vulnerable_methods = {}
# Find the method(s) where the custom X509TrustManager is used.
for clazz in interface_implementations:
class_analysis = dx.get_class_analysis(clazz)
if not class_analysis:
continue
for caller in class_analysis.get_xref_from():
for m in caller.get_methods():
m = m.get_method()
# Ignore excluded methods (if any).
if analysis_info.ignore_libs:
if any(
m.get_class_name().startswith(prefix)
for prefix in analysis_info.ignored_classes_prefixes
):
continue
if isinstance(m, EncodedMethod):
for i in m.get_instructions():
if i.get_op_value() == 0x22: # 0x22 = "new-instance"
if i.get_string() in interface_implementations:
# A new instance of the custom X509TrustManager
# was found.
taint_analysis = CustomTaintAnalysis(
dx.get_method(m), analysis_info
)
path_to_caller = (
taint_analysis.get_paths_to_target_method()[
0
]
)
vulnerable_methods[
f"{m.get_class_name()}->"
f"{m.get_name()}{m.get_descriptor()}"
] = (
clazz,
" --> ".join(
f"{p.class_name}->"
f"{p.name}{p.descriptor}"
for p in path_to_caller
),
)
for key, value in vulnerable_methods.items():
vulnerability_found = True
details.code.append(vuln.VulnerableCode(value[0], key, value[1]))
if vulnerability_found:
return details
else:
return None
except Exception as e:
self.logger.error(
f"Error during '{self.__class__.__name__}' vulnerability check: {e}"
)
raise
finally:
analysis_info.checked_vulnerabilities.append(self.__class__.__name__)
| [
"gabriel@claudiugeorgiu.com"
] | gabriel@claudiugeorgiu.com |
e9de33ecda71093ff5047338a10ffb1936155a4b | 781e2692049e87a4256320c76e82a19be257a05d | /all_data/exercism_data/python/meetup/24bbef018bfa4ae6a84c2b8e3373973d.py | ece76266e33e9054f25f37179abb3518522019ef | [] | no_license | itsolutionscorp/AutoStyle-Clustering | 54bde86fe6dbad35b568b38cfcb14c5ffaab51b0 | be0e2f635a7558f56c61bc0b36c6146b01d1e6e6 | refs/heads/master | 2020-12-11T07:27:19.291038 | 2016-03-16T03:18:00 | 2016-03-16T03:18:42 | 59,454,921 | 4 | 0 | null | 2016-05-23T05:40:56 | 2016-05-23T05:40:56 | null | UTF-8 | Python | false | false | 2,880 | py | from datetime import date, timedelta
class MeetupDayException(Exception):
pass
def _normalize_ordinality(ordinality):
''' Maps inputs like "third" and "1st" to values we can deal with '''
mappings = {
'1st': '1',
'first': '1',
'2nd': '2',
'second': '2',
'3rd': '3',
'third': '3',
'4th': '4',
'fourth': '4',
'5th': '5',
'fifth': '5'}
return (
mappings[ordinality.lower()] if ordinality.lower() in mappings else ordinality)
def _map_weekday_to_number(weekday):
''' Maps an English-language weekday to a corresponding number '''
return {
'monday': 0,
'tuesday': 1,
'wednesday': 2,
'thursday': 3,
'friday': 4,
'saturday': 5,
'sunday': 6
}[weekday.lower()]
def meetup_day(year, month, weekday, ordinality):
'''
Returns a date corresponding to the inputs given, where ordinality
is something like '1st', '2nd', 'third', 'last', 'teenth', etc.
'''
ordinality = _normalize_ordinality(ordinality)
numerical_weekday = _map_weekday_to_number(weekday)
if ordinality.isdigit():
first_of_month = date(year=year, month=month, day=1)
if first_of_month.weekday() == numerical_weekday:
first_weekday_of_month = first_of_month
elif first_of_month.weekday() < numerical_weekday:
first_weekday_of_month = (
first_of_month + timedelta(days=(numerical_weekday - first_of_month.weekday())))
else:
prev_monday = first_of_month - timedelta(days=first_of_month.weekday())
first_weekday_of_month = (
(prev_monday + timedelta(days=7)) + timedelta(days=numerical_weekday))
meetup_day = first_weekday_of_month + timedelta(days=((int(ordinality) - 1) * 7))
if meetup_day.month != month:
# we have gone past the end of the month
raise MeetupDayException("The month you provided does not contain the specified day.")
else:
return meetup_day
elif ordinality == 'teenth':
first_teenth = date(year=year, month=month, day=13)
if first_teenth.weekday() == numerical_weekday:
return first_teenth
else:
return (first_teenth - timedelta(days=first_teenth.weekday())) + timedelta(days=numerical_weekday)
elif ordinality == 'last':
last_day_of_month = date(year=year, month=(month + 1), day=1) - timedelta(days=1)
if last_day_of_month.weekday() == numerical_weekday:
return last_day_of_month
else:
return (
(last_day_of_month - timedelta(days=last_day_of_month.weekday())) +
timedelta(days=numerical_weekday))
else:
raise MeetupDayException("Unexpected ordinality: %s" % ordinality)
| [
"rrc@berkeley.edu"
] | rrc@berkeley.edu |
47d6c70ccdd47afa280e1e3ca4fd576780a18f33 | 627628700ac9eb3b855fdbf5724d44728dce0b63 | /python/spaceinvaders.py | 685ef9f6a82ca98705cece133c2617631dc1439f | [] | no_license | mn113/codewars-solutions | ffa6f9967f43dd58e00282b04aeb73c65d89747f | f41c93aa16d820d2a4a267b7aa7881323ab8bf46 | refs/heads/master | 2021-01-13T09:52:02.007767 | 2020-06-05T16:58:45 | 2020-06-05T16:58:45 | 69,618,778 | 10 | 2 | null | null | null | null | UTF-8 | Python | false | false | 3,344 | py | def blast_sequence(aliens, player):
return Game(aliens, player).run()
class Game(object):
def __init__(self, aliens, player):
# Wrap each cell in array:
self.aliens = [[[a] if abs(a) > 0 else [] for a in r] for r in aliens]
self.player_x = player[1]
self.player_y = player[0]
self.died = False
self.width = len(self.aliens[0])
def extend_grid(self, num_rows):
while num_rows > 0:
self.aliens.append([[] for x in range(self.width)])
num_rows -= 1
def print_grid(self):
for row in self.aliens:
print(row)
def run(self):
self.hit_blasts = []
t = 0
while self.count_all_aliens() > 0:
t += 1
# Extend grid if aliens in bottom row:
if self.count_row(-1) > 0:
self.extend_grid(1)
# Move each alien and see if one gets us:
self.move_all_aliens()
if self.died:
return None
# Blast them - hit or miss?
if self.blast(t):
self.hit_blasts.append(t-1)
#print(self.count_all_aliens(), "aliens remain")
# Killed all aliens:
return self.hit_blasts
def count_row(self, y):
return sum([len(a) for a in self.aliens[y]])
def count_all_aliens(self):
return sum([self.count_row(y) for y in range(len(self.aliens))])
def move_all_aliens(self):
empty_grid = [[[] for x in range(self.width)] for y in range(len(self.aliens))]
for y in range(len(self.aliens)):
for x in range(self.width):
for a in range(len(self.aliens[y][x])):
val = self.aliens[y][x][a]
dest = self.move_alien(x,y,val)
if (dest):
empty_grid[dest[1]][dest[0]].append(dest[2])
else:
return
self.aliens = empty_grid
def move_alien(self, x, y, val):
dir = val // abs(val)
moved = 0
# Move along same row:
while moved < abs(val) and x + dir >= 0 and x + dir < self.width:
x += dir
moved += 1
# Enter next row (create it if necessary):
if moved < abs(val):
y += 1
if y == self.player_y:
print(val, "got you!")
self.died = True # game over soon
return False
moved += 1
dir *= -1 # reverse dir
val *= -1
# Move along next row:
while moved < abs(val) and x + dir >= 0 and x + dir < self.width:
x += dir
moved += 1
return [x,y,val]
def blast(self, t):
x = self.player_x
y = len(self.aliens)
while y > 0:
y -= 1
victims = self.aliens[y][x]
if len(victims) > 0:
# Blast kills who? sort by 1: max(abs(v)), 2: max(v)
victims.sort() # lo to hi
if abs(victims[0]) > abs(victims[-1]):
victims.reverse()
v = victims.pop()
#print(v, "got blasted at", x, y, "by blast", t-1)
return True
# Missed everyone:
#print("blast missed")
return False
| [
"recyclebing+github@gmail.com"
] | recyclebing+github@gmail.com |
40d967e4f64b55a845f8e91ffb91090ccc5aa01e | 7bededcada9271d92f34da6dae7088f3faf61c02 | /pypureclient/flashblade/FB_2_7/models/api_token.py | 57ed30dc74b9aad64924eb1885eeaed495b5a357 | [
"BSD-2-Clause"
] | permissive | PureStorage-OpenConnect/py-pure-client | a5348c6a153f8c809d6e3cf734d95d6946c5f659 | 7e3c3ec1d639fb004627e94d3d63a6fdc141ae1e | refs/heads/master | 2023-09-04T10:59:03.009972 | 2023-08-25T07:40:41 | 2023-08-25T07:40:41 | 160,391,444 | 18 | 29 | BSD-2-Clause | 2023-09-08T09:08:30 | 2018-12-04T17:02:51 | Python | UTF-8 | Python | false | false | 3,845 | py | # coding: utf-8
"""
FlashBlade REST API
A lightweight client for FlashBlade REST API 2.7, developed by Pure Storage, Inc. (http://www.purestorage.com/).
OpenAPI spec version: 2.7
Generated by: https://github.com/swagger-api/swagger-codegen.git
"""
import pprint
import re
import six
import typing
from ....properties import Property
if typing.TYPE_CHECKING:
from pypureclient.flashblade.FB_2_7 import models
class ApiToken(object):
"""
Attributes:
swagger_types (dict): The key is attribute name
and the value is attribute type.
attribute_map (dict): The key is attribute name
and the value is json key in definition.
"""
swagger_types = {
'created_at': 'int',
'expires_at': 'int',
'token': 'str'
}
attribute_map = {
'created_at': 'created_at',
'expires_at': 'expires_at',
'token': 'token'
}
required_args = {
}
def __init__(
self,
created_at=None, # type: int
expires_at=None, # type: int
token=None, # type: str
):
"""
Keyword args:
created_at (int): Creation time in milliseconds since the UNIX epoch.
expires_at (int): Expiration time in milliseconds since the UNIX epoch.
token (str): An Admin API token. A newly-created token is visible as the result of the POST operation which created it. An existing token is visible when `expose_api_token` is `true` and it is being requested by the user to whom it belongs. In all other cases, the token will be masked.
"""
if created_at is not None:
self.created_at = created_at
if expires_at is not None:
self.expires_at = expires_at
if token is not None:
self.token = token
def __setattr__(self, key, value):
if key not in self.attribute_map:
raise KeyError("Invalid key `{}` for `ApiToken`".format(key))
self.__dict__[key] = value
def __getattribute__(self, item):
value = object.__getattribute__(self, item)
if isinstance(value, Property):
return None
else:
return value
def to_dict(self):
"""Returns the model properties as a dict"""
result = {}
for attr, _ in six.iteritems(self.swagger_types):
if hasattr(self, attr):
value = getattr(self, attr)
if isinstance(value, list):
result[attr] = list(map(
lambda x: x.to_dict() if hasattr(x, "to_dict") else x,
value
))
elif hasattr(value, "to_dict"):
result[attr] = value.to_dict()
elif isinstance(value, dict):
result[attr] = dict(map(
lambda item: (item[0], item[1].to_dict())
if hasattr(item[1], "to_dict") else item,
value.items()
))
else:
result[attr] = value
if issubclass(ApiToken, dict):
for key, value in self.items():
result[key] = value
return result
def to_str(self):
"""Returns the string representation of the model"""
return pprint.pformat(self.to_dict())
def __repr__(self):
"""For `print` and `pprint`"""
return self.to_str()
def __eq__(self, other):
"""Returns true if both objects are equal"""
if not isinstance(other, ApiToken):
return False
return self.__dict__ == other.__dict__
def __ne__(self, other):
"""Returns true if both objects are not equal"""
return not self == other
| [
"tlewis@purestorage.com"
] | tlewis@purestorage.com |
a6afb02780f5418e60601aa83c740eb85a13e07e | bd7d091565ba63c930351203ed912ff82461d540 | /tree_515_largestValuesPerLevel.py | 23dfe044a516310d559d478557227a2d3c61658f | [] | no_license | screnary/Algorithm_python | 6ea3ab571763b5c0a519bdb7eed64dd5b74e8a8f | 8290ad1c763d9f7c7f7bed63426b4769b34fd2fc | refs/heads/master | 2022-12-07T02:59:42.786259 | 2020-08-25T04:27:45 | 2020-08-25T04:27:45 | 258,499,984 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 919 | py | # class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def largestValues(self, root: TreeNode) -> List[int]:
if root is None:
return []
# init max_list
max_list = []
max_list.append(root.val)
# broad first search
queue = []
queue.append((root, 0))
while len(queue) > 0:
item = queue.pop(0)
node, level = item[0], item[1]
if level == len(max_list):
max_list.append(node.val)
else:
if max_list[level] < node.val:
max_list[level] = node.val
if node.left is not None:
queue.append((node.left, level+1))
if node.right is not None:
queue.append((node.right, level+1))
return max_list
| [
"screnary@qq.com"
] | screnary@qq.com |
72b11e9bf6e3be6f40f8d80e557bd486a016a2e9 | 9743d5fd24822f79c156ad112229e25adb9ed6f6 | /xai/brain/wordbase/otherforms/_prickles.py | 7b0da8887b113dba5f2d0ab69d5f213b2af264f5 | [
"MIT"
] | permissive | cash2one/xai | de7adad1758f50dd6786bf0111e71a903f039b64 | e76f12c9f4dcf3ac1c7c08b0cc8844c0b0a104b6 | refs/heads/master | 2021-01-19T12:33:54.964379 | 2017-01-28T02:00:50 | 2017-01-28T02:00:50 | null | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 226 | py |
#calss header
class _PRICKLES():
def __init__(self,):
self.name = "PRICKLES"
self.definitions = prickle
self.parents = []
self.childen = []
self.properties = []
self.jsondata = {}
self.basic = ['prickle']
| [
"xingwang1991@gmail.com"
] | xingwang1991@gmail.com |
f08d4ae3acf8695083cbbc555f751dc5040bd771 | 3ccf552a92dc78da06bcd7242ab62b3adf0c9019 | /algorithm_demo/exp_demo.py | 877817780251e1142207b47ea85518ccef039bc7 | [] | no_license | linkcheng/python_demo | a3437bd56083f04d440ae3b4d44f6bffe806dee2 | 332b75948745d66d1a74253033444a2c63fb8e51 | refs/heads/master | 2022-07-08T10:45:53.587317 | 2020-08-07T10:23:49 | 2020-08-07T10:23:49 | 52,152,418 | 2 | 1 | null | 2021-03-25T21:43:04 | 2016-02-20T12:33:20 | Python | UTF-8 | Python | false | false | 3,985 | py | #!/usr/bin/env python3
# -*- coding: UTF-8 -*
"""
给你一个字符串 s 和一个字符规律 p,请你来实现一个支持 '.' 和 '*' 的正则表达式匹配。
'.' 匹配任意单个字符
'*' 匹配零个或多个前面的那一个元素
所谓匹配,是要涵盖 整个 字符串 s的,而不是部分字符串。
说明:
s 可能为空,且只包含从 a-z 的小写字母。
p 可能为空,且只包含从 a-z 的小写字母,以及字符 . 和 *。
"""
class Solution:
def is_match(self, s: str, p: str) -> bool:
# 特殊值处理
if not p:
return not s
if len(p) == 1 and not s:
return False
m, n = len(s)+1, len(p)+1
dp = [[False]*n for _ in range(m)]
# base case
dp[0][0] = True
dp[0][1] = False
# for i in range(1, m):
# dp[i][0] = False
for i in range(2, n):
if p[i-1] == '*':
dp[0][i] = dp[0][i-2]
# other
# dp[i][j] 表示的状态是 s 的前 i 项和 p 的前 j 项是否匹配。
for i in range(1, m):
for j in range(1, n):
if p[j-1] in {s[i-1], '.'}:
dp[i][j] = dp[i-1][j-1]
elif p[j-1] == '*':
# 如果 p 最后一位是 *
if p[j-2] in {s[i-1], '.'}:
# 如果 * 星号前一个值 == s 当前值或者 . 重复 0 次或者重复 1 次
dp[i][j] = dp[i][j-2] or dp[i-1][j]
else:
# 如果 * 星号前一个值 != s 当前值或者 . 只能重复 0 次
dp[i][j] = dp[i][j-2]
else:
dp[i][j] = False
return dp[m-1][n-1]
def is_match_rec(self, s: str, p: str) -> bool:
if not p:
return not s
if len(p) == 1 and not s:
return False
return self._is_match(s, p, len(s), len(p), 0, 0)
def _is_match(self, s: str, p: str, s_len: int, p_len: int, s_i: int, p_i: int) -> bool:
if p_i >= p_len:
return s_i == s_len
if s_i >= s_len:
return s_i == p_len
# 如果当前长度最后一位是 *,则有两种情况
# 1. 重复前值 0 次
# 2. 重复前值 1 次
match = s_i < s_len and p[p_i] in {s[s_i], '.'}
if (p_i+1) < p_len and p[p_i+1] == '*':
return (
self._is_match(s, p, s_len, p_len, s_i, p_i+2)
or
(match and self._is_match(s, p, s_len, p_len, s_i+1, p_i))
)
else:
return match and self._is_match(s, p, s_len, p_len, s_i+1, p_i+1)
class Solution1:
def isMatch(self, s: str, p: str) -> bool:
if not s:
return p in {'', '*', '?'}
if not p:
return False
return self._isMatch(s, p, len(s), len(p), 0, 0)
def _isMatch(self, s, p, s_len, p_len, i, j) -> bool:
if i == s_len:
return j == p_len
# if j == p_len:
# return i == s_len
if p[j] in {s[i], '?'}:
return self._isMatch(s, p, s_len, p_len, i+1, j+1)
elif p[j] == '*':
return (
# 重复 0 次
self._isMatch(s, p, s_len, p_len, i, j+1)
or
# 重复 1 次
self._isMatch(s, p, s_len, p_len, i+1, j)
)
else:
return False
if __name__ == '__main__':
# so = Solution()
# res = so.is_match_rec("aa", "a*")
# res = so.is_match_rec("mississippi", "mis*is*p*.")
# print(res)
# res = so.is_match("mississippi", "mis*is*p*.")
# print(res)
# res = so.is_match_rec("aab", "c*a*b")
# print(res)
# res = so.is_match("aab", "c*a*b")
# print(res)
so1 = Solution1()
res = so1.isMatch("adceb", "*a*b")
print(res)
| [
"zheng.long@shoufuyou.com"
] | zheng.long@shoufuyou.com |
bcff14a0fc7e9a6fa5d3750e08b2ce7db4660179 | 23b333449524887594530f73c0079ce60cb8eefb | /python_module/examples/340_Longest_Substring_with_At_Most_K_Distinct_Characters.py | 9bf96f58a4f7a28334865e8030552dbcdf9c9b3e | [] | no_license | benbendaisy/CommunicationCodes | 9deb371095f5d67e260030d3d8abf211c90e7642 | 444cc502ef26810b46115797f2e26ab305a4ebdf | refs/heads/master | 2023-08-09T21:46:58.691987 | 2023-07-20T05:11:39 | 2023-07-20T05:11:39 | 27,856,438 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 1,188 | py | from collections import defaultdict
class Solution:
"""
Given a string s and an integer k, return the length of the longest
substring of s that contains at most k distinct characters.
Example 1:
Input: s = "eceba", k = 2
Output: 3
Explanation: The substring is "ece" with length 3.
Example 2:
Input: s = "aa", k = 1
Output: 2
Explanation: The substring is "aa" with length 2.
Constraints:
1 <= s.length <= 5 * 104
0 <= k <= 50
"""
def lengthOfLongestSubstringKDistinct(self, s: str, k: int) -> int:
if not s or k < 1:
return 0
hashMap = defaultdict(lambda: 0)
maxLength = 0
l = 0
for i in range(len(s)):
hashMap[s[i]] = i
if len(hashMap) == k + 1:
minIndex = min(hashMap.values())
del hashMap[s[minIndex]]
l = minIndex + 1
maxLength = max(maxLength, i - l + 1)
return maxLength
if __name__ == "__main__":
s = "ab"
solution = Solution()
ret = solution.lengthOfLongestSubstringKDistinct(s, 1)
print(ret) | [
"benbendaisy@users.noreply.github.com"
] | benbendaisy@users.noreply.github.com |
479d98009251330b275180ead5af42146eaac085 | 8a3102e1d3ed5346a0468aafdc0413858ddc25e3 | /check.py | ac20fee4e32b946d265060c6b115a3848bdadec5 | [] | no_license | a13140120a/E_sun_bank_competition | f9bbb6a9c2ef9581cdeae46bd12102f165038685 | 5286e2d8bdb5e285bc0109233eeb2aa3368eb362 | refs/heads/master | 2023-08-11T14:23:10.438964 | 2021-09-24T05:51:00 | 2021-09-24T05:51:00 | 409,580,809 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 759 | py | import pickle
import matplotlib.pyplot as plt
import os
def load_pickle_file(pile_path):
with open(pile_path,'rb') as file:
pickle_file = pickle.load(file)
return pickle_file
batch_acc = load_pickle_file('./analyze/batch/acc.pickle')
batch_lr = load_pickle_file('./analyze/batch/lr.pickle')
epoch_acc = load_pickle_file('./analyze/epoch/acc.pickle')
epoch_loss = load_pickle_file('./analyze/epoch/loss.pickle')
epoch_lr = load_pickle_file('./analyze/epoch/lr.pickle')
epoch_val_acc = load_pickle_file('./analyze/epoch/val_acc.pickle')
epoch_val_loss = load_pickle_file('./analyze/epoch/val_loss.pickle')
plt.plot(batch_acc, batch_lr, marker='.')
plt.legend(loc='best')
plt.grid()
plt.xlabel('batch_acc')
plt.ylabel('batch_lr')
plt.show()
| [
"you@example.com"
] | you@example.com |
031a0a3da8d9322431d08fee84417af102ea9749 | 9e7e9669ae912e5c3b17deff4267ebf29f32f633 | /seq/__init__.py | 8ab4e9ddd5f93f9551fbac07c408647d01f29f54 | [] | no_license | tjacek/DeepActionLearning | 2304d050986dc8dbd917a7d065b3e68fc03bf9c0 | 153ca8849c78ec265543602728ce0a104da60dcc | refs/heads/master | 2021-01-10T18:29:33.535524 | 2019-08-02T19:53:47 | 2019-08-02T19:53:47 | 40,564,155 | 5 | 0 | null | null | null | null | UTF-8 | Python | false | false | 2,905 | py | import numpy as np
import utils
class ActionGroup(object):
def __init__(self, actions):
self.actions = actions
def __len__(self):
return len(self.actions)
def __getitem__(self, key):
return self.actions[key]
def raw(self):
if(type(self.actions)==dict):
return self.actions.values()
return self.actions
def select(self,selector=None,as_group=False):
if(not selector):
selector=lambda action_i:(action_i.person % 2)==1
train,test=utils.split(self.actions,selector)
if(as_group):
return ActionGroup(train),ActionGroup(test)
return train,test
def normalization(self):
feats=self.as_array()
mean_feats=np.mean(feats,axis=0)
std_feats=np.std(feats,axis=0)
for action_i in self.actions:
img_seq_i=action_i.as_array()
img_seq_i-=mean_feats
img_seq_i/=std_feats
action_i.img_seq=list(img_seq_i)
def as_array(self):
feats=[]
for action_i in self.actions:
feats+=action_i.img_seq
return np.array(feats)
class Action(object):
def __init__(self,img_seq,name,cat,person):
self.img_seq=img_seq
self.name=name
self.cat=cat
self.person=person
def __str__(self):
return self.name
def __len__(self):
return len(self.img_seq)
def __call__(self,fun,whole_seq=True,feats=False):
#print(self.name)
img_seq=self.as_features() if(feats) else self.img_seq
if(whole_seq):
new_seq=fun(img_seq)
else:
new_seq=[ fun(img_i) for img_i in img_seq]
if(feats):
new_seq=np.array(new_seq).T
return Action(new_seq,self.name,self.cat,self.person)
def clone(self,img_seq):
return Action(img_seq,self.name,self.cat,self.person)
def dim(self):
frame=self.img_seq[0]
if(type(frame)==list):
return len(frame)
return frame.shape[0]
def as_array(self):
return np.array(self.img_seq)
def as_features(self):
action_array=self.as_array().T
return [ feature_i for feature_i in action_array]
def as_pairs(self):#,norm=255.0):
#norm_imgs=[ (img_i/norm)
# for img_i in self.img_seq]
return [ (self.cat,img_i) for img_i in norm_imgs]
def by_cat(actions):
cats=[action_i.cat for action_i in actions]
actions_by_cat={ cat_i:[] for cat_i in np.unique(cats)}
for action_i in actions:
actions_by_cat[action_i.cat].append(action_i)
return actions_by_cat
def person_rep(actions):
reps={}
for action_i in actions:
action_id=str(action_i.cat)+str(action_i.person)
if(not action_id in reps):
reps[action_id]=action_i
return reps.values() | [
"tjacek@student.agh.edu.pl"
] | tjacek@student.agh.edu.pl |
ba68f05dcf1908bb7c1f823730e0551e1e00a52f | 8faf4780686c31588ade78ca69b3737b72857fab | /tests/python/test_while.py | 805c752709cd2dd2765e425ef2a2d072e90dbb58 | [
"MIT"
] | permissive | AnimatedRNG/taichi | 0333ce8da61debe51872ff183ba47cd0bbf56469 | f1f403042dadf8b58887431dbf7a9a661c005bb2 | refs/heads/master | 2020-08-08T06:17:23.366495 | 2019-10-08T20:31:20 | 2019-10-08T20:31:20 | 213,751,271 | 0 | 0 | NOASSERTION | 2019-10-08T20:49:48 | 2019-10-08T20:49:48 | null | UTF-8 | Python | false | false | 372 | py | import taichi as ti
def test_while():
for arch in [ti.x86_64, ti.cuda]:
ti.reset()
ti.cfg.arch = arch
x = ti.var(ti.f32)
N = 1
@ti.layout
def place():
ti.root.dense(ti.i, N).place(x)
@ti.kernel
def func():
i = 0
s = 0
while i < 10:
s += i
i += 1
x[0] = s
func()
assert x[0] == 45
| [
"yuanmhu@gmail.com"
] | yuanmhu@gmail.com |
988ec595b96df9a55ca984a2c195065bc0b9b7bc | 3152fd9ec9ccd83b6e0d2ea40aa36a4b145aea2e | /part3/09_面向对象特性/hm_11_多态案例.py | 6383bd69e621871bb5e25b67ee5e824b7d626a37 | [] | no_license | derekduan1028/hm_python | cf1b6037ac1cde8dcac393453a291c39b5a936c2 | ae79f817a55d1b3bfdbdf1b50d5147946c8b7401 | refs/heads/master | 2023-01-21T00:33:00.927709 | 2020-11-27T00:00:35 | 2020-11-27T00:00:35 | 291,869,531 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 823 | py | #!/usr/bin/python
# coding:utf-8
"""
@author:derek
@contract:derek_duan@sina.com
@file: hm_11_多态案例.py
@time: 2020-10-24 22:27
"""
class Dog(object):
def __init__(self, name):
self.name = name
def game(self):
print("%s 蹦蹦跳跳。。。" % self.name)
class XiaoTianDog(Dog):
def game(self):
print("%s 飞到天上去玩耍" % self.name)
class Person(object):
def __init__(self, name):
self.name = name
def game_with_dog(self, dog):
print("%s 和 %s 快乐的玩耍" % (self.name, dog.name))
# 让狗玩耍
dog.game()
# 创建一个狗对象
# wangcai = Dog("旺财")
wangcai = XiaoTianDog("飞天旺财")
# 创建人的对象
xiaoming = Person("小明")
# 小明调用和狗玩的方法
xiaoming.game_with_dog(wangcai)
| [
"derek@Derek-Mbp"
] | derek@Derek-Mbp |
f457721ccf69c25c17cde506ef7326a745186344 | 6199ab5c7d7b135c4d4020a0298c33cddcfea960 | /NanoGardener/python/framework/samples/Run2016_102X_nAODv7.py | 9b673aa310e429efad7128f4e114c7036faf2411 | [] | no_license | friccita/LatinoAnalysis | 45b353b76e3561dc43e4a6c65878813e23369d01 | 954bb150de098f9cc9e96276aca68453c6c42adf | refs/heads/master | 2022-12-27T03:47:46.553078 | 2020-10-14T15:10:32 | 2020-10-14T15:10:32 | 290,237,710 | 0 | 0 | null | 2020-08-25T14:29:39 | 2020-08-25T14:29:38 | null | UTF-8 | Python | false | false | 4,207 | py | Samples = {}
Samples["DoubleEG_Run2016B-02Apr2020_ver1-v1"] = {'nanoAOD': '/DoubleEG/Run2016B-02Apr2020_ver1-v1/NANOAOD'}
Samples["DoubleEG_Run2016B-02Apr2020_ver2-v1"] = {'nanoAOD': '/DoubleEG/Run2016B-02Apr2020_ver2-v1/NANOAOD'}
Samples["DoubleEG_Run2016C-02Apr2020-v1"] = {'nanoAOD': '/DoubleEG/Run2016C-02Apr2020-v1/NANOAOD'}
Samples["DoubleEG_Run2016D-02Apr2020-v1"] = {'nanoAOD': '/DoubleEG/Run2016D-02Apr2020-v1/NANOAOD'}
Samples["DoubleEG_Run2016E-02Apr2020-v1"] = {'nanoAOD': '/DoubleEG/Run2016E-02Apr2020-v1/NANOAOD'}
Samples["DoubleEG_Run2016F-02Apr2020-v1"] = {'nanoAOD': '/DoubleEG/Run2016F-02Apr2020-v1/NANOAOD'}
Samples["DoubleEG_Run2016G-02Apr2020-v1"] = {'nanoAOD': '/DoubleEG/Run2016G-02Apr2020-v1/NANOAOD'}
Samples["DoubleEG_Run2016H-02Apr2020-v1"] = {'nanoAOD': '/DoubleEG/Run2016H-02Apr2020-v1/NANOAOD'}
Samples["DoubleMuon_Run2016B-02Apr2020_ver1-v1"] = {'nanoAOD': '/DoubleMuon/Run2016B-02Apr2020_ver1-v1/NANOAOD'}
Samples["DoubleMuon_Run2016B-02Apr2020_ver2-v1"] = {'nanoAOD': '/DoubleMuon/Run2016B-02Apr2020_ver2-v1/NANOAOD'}
Samples["DoubleMuon_Run2016C-02Apr2020-v1"] = {'nanoAOD': '/DoubleMuon/Run2016C-02Apr2020-v1/NANOAOD'}
Samples["DoubleMuon_Run2016D-02Apr2020-v1"] = {'nanoAOD': '/DoubleMuon/Run2016D-02Apr2020-v1/NANOAOD'}
Samples["DoubleMuon_Run2016E-02Apr2020-v1"] = {'nanoAOD': '/DoubleMuon/Run2016E-02Apr2020-v1/NANOAOD'}
Samples["DoubleMuon_Run2016F-02Apr2020-v1"] = {'nanoAOD': '/DoubleMuon/Run2016F-02Apr2020-v1/NANOAOD'}
Samples["DoubleMuon_Run2016G-02Apr2020-v1"] = {'nanoAOD': '/DoubleMuon/Run2016G-02Apr2020-v1/NANOAOD'}
Samples["DoubleMuon_Run2016H-02Apr2020-v1"] = {'nanoAOD': '/DoubleMuon/Run2016H-02Apr2020-v1/NANOAOD'}
Samples["MuonEG_Run2016B-02Apr2020_ver1-v1"] = {'nanoAOD': '/MuonEG/Run2016B-02Apr2020_ver1-v1/NANOAOD'}
Samples["MuonEG_Run2016B-02Apr2020_ver2-v1"] = {'nanoAOD': '/MuonEG/Run2016B-02Apr2020_ver2-v1/NANOAOD'}
Samples["MuonEG_Run2016C-02Apr2020-v1"] = {'nanoAOD': '/MuonEG/Run2016C-02Apr2020-v1/NANOAOD'}
Samples["MuonEG_Run2016D-02Apr2020-v1"] = {'nanoAOD': '/MuonEG/Run2016D-02Apr2020-v1/NANOAOD'}
Samples["MuonEG_Run2016E-02Apr2020-v1"] = {'nanoAOD': '/MuonEG/Run2016E-02Apr2020-v2/NANOAOD'}
Samples["MuonEG_Run2016F-02Apr2020-v1"] = {'nanoAOD': '/MuonEG/Run2016F-02Apr2020-v1/NANOAOD'}
Samples["MuonEG_Run2016G-02Apr2020-v1"] = {'nanoAOD': '/MuonEG/Run2016G-02Apr2020-v1/NANOAOD'}
Samples["MuonEG_Run2016H-02Apr2020-v1"] = {'nanoAOD': '/MuonEG/Run2016H-02Apr2020-v1/NANOAOD'}
Samples["SingleElectron_Run2016B-02Apr2020_ver1-v1"] = {'nanoAOD': '/SingleElectron/Run2016B-02Apr2020_ver1-v1/NANOAOD'}
Samples["SingleElectron_Run2016B-02Apr2020_ver2-v1"] = {'nanoAOD': '/SingleElectron/Run2016B-02Apr2020_ver2-v1/NANOAOD'}
Samples["SingleElectron_Run2016C-02Apr2020-v1"] = {'nanoAOD': '/SingleElectron/Run2016C-02Apr2020-v1/NANOAOD'}
Samples["SingleElectron_Run2016D-02Apr2020-v1"] = {'nanoAOD': '/SingleElectron/Run2016D-02Apr2020-v1/NANOAOD'}
Samples["SingleElectron_Run2016E-02Apr2020-v1"] = {'nanoAOD': '/SingleElectron/Run2016E-02Apr2020-v1/NANOAOD'}
Samples["SingleElectron_Run2016F-02Apr2020-v1"] = {'nanoAOD': '/SingleElectron/Run2016F-02Apr2020-v1/NANOAOD'}
Samples["SingleElectron_Run2016G-02Apr2020-v1"] = {'nanoAOD': '/SingleElectron/Run2016G-02Apr2020-v1/NANOAOD'}
Samples["SingleElectron_Run2016H-02Apr2020-v1"] = {'nanoAOD': '/SingleElectron/Run2016H-02Apr2020-v1/NANOAOD'}
Samples["SingleMuon_Run2016B-02Apr2020_ver1-v1"] = {'nanoAOD': '/SingleMuon/Run2016B-02Apr2020_ver1-v1/NANOAOD'}
Samples["SingleMuon_Run2016B-02Apr2020_ver2-v1"] = {'nanoAOD': '/SingleMuon/Run2016B-02Apr2020_ver2-v1/NANOAOD'}
Samples["SingleMuon_Run2016C-02Apr2020-v1"] = {'nanoAOD': '/SingleMuon/Run2016C-02Apr2020-v1/NANOAOD'}
Samples["SingleMuon_Run2016D-02Apr2020-v1"] = {'nanoAOD': '/SingleMuon/Run2016D-02Apr2020-v1/NANOAOD'}
Samples["SingleMuon_Run2016E-02Apr2020-v1"] = {'nanoAOD': '/SingleMuon/Run2016E-02Apr2020-v1/NANOAOD'}
Samples["SingleMuon_Run2016F-02Apr2020-v1"] = {'nanoAOD': '/SingleMuon/Run2016F-02Apr2020-v1/NANOAOD'}
Samples["SingleMuon_Run2016G-02Apr2020-v1"] = {'nanoAOD': '/SingleMuon/Run2016G-02Apr2020-v1/NANOAOD'}
Samples["SingleMuon_Run2016H-02Apr2020-v1"] = {'nanoAOD': '/SingleMuon/Run2016H-02Apr2020-v1/NANOAOD'}
| [
"lorenzo.viliani@cern.ch"
] | lorenzo.viliani@cern.ch |
c9d1dacded44e996624f8b185466fb68157b8d0a | 15f321878face2af9317363c5f6de1e5ddd9b749 | /solutions_python/Problem_74/1139.py | c78596798869e06ec2874789c7afc38cee242367 | [] | no_license | dr-dos-ok/Code_Jam_Webscraper | c06fd59870842664cd79c41eb460a09553e1c80a | 26a35bf114a3aa30fc4c677ef069d95f41665cc0 | refs/heads/master | 2020-04-06T08:17:40.938460 | 2018-10-14T10:12:47 | 2018-10-14T10:12:47 | null | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 1,618 | py | data = open('data(2).in', 'r')
testNum = int(data.readline())
for x in range(testNum):
input = data.readline().split()
heldTurns = 0
orange = 1
blue = 1
last = False #false = orange || true = blue
totalSteps = 0
turns = int(input[0])
input = input[1:]
for point in range(turns):
bot = input[point*2]
button = int(input[(point*2)+1])
if point == 0:
stepsTaken = 0
if bot == 'O':
stepsTaken = abs(button-orange)
orange = button
last = False
elif bot == 'B':
stepsTaken = abs(button-blue)
blue = button
last = True
heldTurns = stepsTaken + 1
totalSteps += heldTurns
else:
stepsTaken = 0
curr = False
if bot == 'O':
stepsTaken = abs(button-orange)
orange = button
curr = False
elif bot == 'B':
stepsTaken = abs(button-blue)
blue = button
curr = True
if bool(curr) ^ bool(last):
if stepsTaken != 0:
if heldTurns < stepsTaken:
stepsTaken -= heldTurns
else:
stepsTaken = 0
heldTurns = 0
heldTurns += stepsTaken +1
totalSteps += stepsTaken +1
last = curr
print('Case #' + str(x+1) + ': ' + str(totalSteps))
| [
"miliar1732@gmail.com"
] | miliar1732@gmail.com |
08cc0a8d706f7860b4a1caba53e29db55b105154 | e57a122cba8d00aac9d014a45e815063cb9f0359 | /imagepy/core/engine/report.py | 86fdd6bf79d9af6773d6ab2ed74ea11eb2e35f06 | [
"BSD-2-Clause"
] | permissive | WeisongZhao/imagepy | 9d66664578c77eb2d463de922c8d06af4f8af35a | 43cd5c4dcb9d6fefdcf11b8b9e9c0d56e11fab1e | refs/heads/master | 2020-04-25T23:44:31.304590 | 2020-01-29T06:10:26 | 2020-01-29T06:10:26 | 173,155,520 | 1 | 0 | NOASSERTION | 2019-02-28T17:21:56 | 2019-02-28T17:21:55 | null | UTF-8 | Python | false | false | 2,151 | py | # -*- coding: utf-8 -*-
"""
Created on Thu Dec 29 01:48:23 2016
@author: yxl
"""
import wx
from imagepy import IPy
from imagepy.core.manager import WidgetsManager, TaskManager, ImageManager
from imagepy.core.manager import ReaderManager, ViewerManager, TableManager
from imagepy.ui.propertygrid import GridDialog
from imagepy.core.util import xlreport
from time import time
import openpyxl as pyxl
class Report:
def __init__(self, title, cont):
self.title = title
self.cont = cont
def __call__(self): return self
def runasyn(self, wb, info, key, para = None, callback = None):
TaskManager.add(self)
for i in para:
if i in key and key[i][0] == 'img':
ips = ImageManager.get(para[i])
para[i] = ips if ips is None else ips.img
if i in key and key[i][0] == 'tab':
tps = TableManager.get(para[i])
para[i] = tps if tps is None else tps.data
start = time()
xlreport.fill_value(wb, info, para)
wb.save(para['path'])
IPy.set_info('%s: cost %.3fs'%(self.title, time()-start))
TaskManager.remove(self)
if callback!=None:callback()
def start(self, para=None, callafter=None):
wb = pyxl.load_workbook(self.cont)
xlreport.repair(wb)
info, key = xlreport.parse(wb)
if para is not None:
return self.runasyn(wb, info, para, callafter)
dialog = GridDialog(IPy.curapp, self.title, info, key)
rst = dialog.ShowModal()
para = dialog.GetValue()
dialog.Destroy()
if rst != 5100: return
filt = '|'.join(['%s files (*.%s)|*.%s'%('XLSX', 'xlsx', 'xlsx')])
if not IPy.getpath('Save..', filt, 'save', para): return
win = WidgetsManager.getref('Macros Recorder')
if win!=None: win.write('{}>{}'.format(self.title, para))
self.runasyn(wb, info, key, para, callafter)
def show_rpt(data, title):
wx.CallAfter(Report(title, data).start)
ViewerManager.add('rpt', show_rpt)
def read_rpt(path): return path
ReaderManager.add('rpt', read_rpt, tag='rpt') | [
"imagepy@sina.com"
] | imagepy@sina.com |
725dea3840c0a4ed9891327e89a1d202b33e6b90 | bf939848c38f0e42c163d030f273c64ba545306e | /source/migrations/0005_auto_20160531_2028.py | 4e2f2f5d3e88747507b822caf8ec691750100343 | [] | no_license | security-force-monitor/sfm-cms | 17e25f6990066ae1bf1f14783a3ad5ca176f4384 | 057039ad854a3a6703e373f7d2ec84be6af03565 | refs/heads/master | 2023-02-14T02:22:40.600997 | 2023-01-25T19:48:25 | 2023-01-25T19:48:25 | 57,247,158 | 9 | 4 | null | 2022-11-17T16:26:59 | 2016-04-27T21:00:34 | Python | UTF-8 | Python | false | false | 774 | py | # -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('source', '0004_auto_20160513_2044'),
]
operations = [
migrations.RemoveField(
model_name='publication',
name='country',
),
migrations.AddField(
model_name='publication',
name='country_iso',
field=models.CharField(max_length=2, default=''),
preserve_default=False,
),
migrations.AddField(
model_name='publication',
name='country_name',
field=models.CharField(max_length=2, default=''),
preserve_default=False,
),
]
| [
"eric.vanzanten@gmail.com"
] | eric.vanzanten@gmail.com |
5c767b52310fbce16a1ce44060ce7e3208459470 | ea262de505a1dd5ae1c7b546b85184309c3fdd35 | /src/models/modules/aspp.py | 1ef76d63d0bc32feb48961866576035219c35dac | [
"MIT"
] | permissive | Runki2018/CvPytorch | 306ff578c5f8d3d196d0834e5cad5adba7a89676 | 1e1c468e5971c1c2b037334f7911ae0a5087050f | refs/heads/master | 2023-08-25T09:48:48.764117 | 2021-10-15T05:11:21 | 2021-10-15T05:11:21 | null | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 3,064 | py | # !/usr/bin/env python
# -- coding: utf-8 --
# @Time : 2020/9/15 14:27
# @Author : liumin
# @File : aspp.py
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
class _ASPPModule(nn.Module):
def __init__(self, inplanes, planes, kernel_size, padding=0, dilation=1):
super(_ASPPModule, self).__init__()
self.atrous_conv = nn.Conv2d(inplanes, planes, kernel_size=kernel_size,
stride=1, padding=padding, dilation=dilation, bias=False)
self.bn = nn.BatchNorm2d(planes)
self.relu = nn.ReLU(inplace=True)
self._init_weight()
def forward(self, x):
x = self.atrous_conv(x)
x = self.bn(x)
return self.relu(x)
def _init_weight(self):
for m in self.modules():
if isinstance(m, nn.Conv2d):
torch.nn.init.kaiming_normal_(m.weight)
elif isinstance(m, nn.BatchNorm2d):
m.weight.data.fill_(1)
m.bias.data.zero_()
class ASPP(nn.Module):
def __init__(self, inplanes=2048, dilations = [6, 12, 18], drop_rate=0.1):
super(ASPP, self).__init__()
mid_channels = 256
self.aspp1 = _ASPPModule(inplanes, mid_channels, 1)
self.aspp2 = _ASPPModule(inplanes, mid_channels, 3, padding=dilations[0], dilation=dilations[0])
self.aspp3 = _ASPPModule(inplanes, mid_channels, 3, padding=dilations[1], dilation=dilations[1])
self.aspp4 = _ASPPModule(inplanes, mid_channels, 3, padding=dilations[2], dilation=dilations[2])
self.global_avg_pool = nn.Sequential(nn.AdaptiveAvgPool2d(1),
nn.Conv2d(inplanes, mid_channels, 1, bias=False),
nn.BatchNorm2d(mid_channels),
nn.ReLU(inplace=True))
self.conv_bn_relu = nn.Sequential(nn.Conv2d(mid_channels*5, mid_channels, 1, bias=False) ,
nn.BatchNorm2d(mid_channels),
nn.ReLU(inplace=True),
nn.Dropout(p=drop_rate))
self._init_weight()
def forward(self, x):
x1 = self.aspp1(x)
x2 = self.aspp2(x)
x3 = self.aspp3(x)
x4 = self.aspp4(x)
x5 = self.global_avg_pool(x)
x5 = F.interpolate(x5, size=x4.size()[2:], mode='bilinear', align_corners=True)
x = torch.cat((x1, x2, x3, x4, x5), dim=1)
x = self.conv_bn_relu(x)
return x
def _init_weight(self):
for m in self.modules():
if isinstance(m, nn.Conv2d):
torch.nn.init.kaiming_normal_(m.weight)
if m.bias is not None:
nn.init.constant_(m.bias, 0)
elif isinstance(m, nn.BatchNorm2d) or isinstance(m, nn.Linear):
nn.init.constant_(m.weight, 1)
nn.init.constant_(m.bias, 0)
| [
"569793357@qq.com"
] | 569793357@qq.com |
595d0c4eb7364999f7be3eef043687131a208ba3 | 27317b3adb1ccd99afa86cb931d2d14e23b9b175 | /bcs-app/backend/apps/configuration/models/base.py | 254f7e997e26384e25f1311248aedd20fa4b4394 | [
"BSD-3-Clause",
"LicenseRef-scancode-unicode",
"ICU",
"LicenseRef-scancode-unknown-license-reference",
"Artistic-2.0",
"Zlib",
"LicenseRef-scancode-openssl",
"NAIST-2003",
"ISC",
"NTP",
"BSL-1.0",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"MIT"
] | permissive | freyzheng/bk-bcs-saas | cf5a6c4ab1c20959bda1362bc31de7884451acd7 | 96373cda9d87038aceb0b4858ce89e7873c8e149 | refs/heads/master | 2021-07-05T04:11:08.555930 | 2020-09-22T12:26:37 | 2020-09-22T12:26:37 | 201,279,048 | 0 | 1 | NOASSERTION | 2020-09-16T03:07:16 | 2019-08-08T14:48:27 | Python | UTF-8 | Python | false | false | 1,844 | py | # -*- coding: utf-8 -*-
#
# Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) available.
# Copyright (C) 2017-2019 THL A29 Limited, a Tencent company. All rights reserved.
# Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://opensource.org/licenses/MIT
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
# an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
import logging
from django.db import models
from django.utils import timezone
COPY_TEMPLATE = "-copy"
logger = logging.getLogger(__name__)
# 所有包含 pod 的资源
# TODO mark refactor 移到constants文件中
POD_RES_LIST = ['K8sDeployment', 'K8sDaemonSet', 'K8sJob', 'K8sStatefulSet']
def get_default_version():
"""版本号:默认为时间戳
"""
return timezone.localtime().strftime('%Y%m%d-%H%M%S')
class BaseModel(models.Model):
"""Model with 'created' and 'updated' fields.
"""
creator = models.CharField("创建者", max_length=32)
updator = models.CharField("更新者", max_length=32)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
is_deleted = models.BooleanField(default=False)
deleted_time = models.DateTimeField(null=True, blank=True)
class Meta:
abstract = True
def delete(self, *args, **kwargs):
self.is_deleted = True
self.deleted_time = timezone.now()
self.save(update_fields=['is_deleted', 'deleted_time'])
| [
"gejun.coolfriend@gmail.com"
] | gejun.coolfriend@gmail.com |
f2e6c14e48abbbab4103a628056f283f5f408a1c | 04ce34e125fd9957b51196f5e31c6651ae8cb0ae | /Day-2/itertools/groupby.py | 8fc08a1564dbb0e1962fdd69fc71bfdba9e59d88 | [] | no_license | morshedmasud/100_days_with_python | 403e1d34cb6cebf983295281613045c60737d8f8 | 1c90d6222835f3b105a9ba26f98e3eb7bab40b30 | refs/heads/master | 2020-03-11T19:53:33.082287 | 2018-07-03T18:41:47 | 2018-07-03T18:41:47 | 130,220,708 | 1 | 0 | null | null | null | null | UTF-8 | Python | false | false | 233 | py | # Go to the link to know about the problem
# https://www.hackerrank.com/challenges/compress-the-string/problem
from itertools import groupby
s = input()
for k, g in groupby(s):
print("({}, {})".format(len(list(g)), k), end=" ")
| [
"masudraj6@gmail.com"
] | masudraj6@gmail.com |
65da5795fa137a569d17f96a32989d23ac977d85 | bdb1c323968cd9d5441a187a29ed7e25a2e4f07e | /cp0/metrix/urls.py | 8a45beca0a3e6a133e38cbc258df9fb61e4a7845 | [] | no_license | liangzhaowang/automation_system | beee351dd9f09a51e2b81617ac5bee63023ea9b8 | f77ef433c2366253dc9d9fdb7c54911cb38ed3e8 | refs/heads/master | 2022-02-19T11:07:44.047000 | 2019-09-23T02:16:00 | 2019-09-23T02:16:00 | 209,732,359 | 0 | 1 | null | null | null | null | UTF-8 | Python | false | false | 481 | py | from django.conf.urls import url
import views as metrix_views
urlpatterns = [
# Metrix
url(r'^metrix/$', metrix_views.metrix_index),
url(r'^metrix/data/$', metrix_views.metrix_data),
url(r'^metrix/examp/(.+)/$', metrix_views.examp),
url(r'^metrix/jira_raw_data/(.+)/$', metrix_views.get_jira_raw_data),
url(r'^metrix/examp_templates/(.+).html$', metrix_views.examp_templates),
url(r'^metrix/get_dedualt_config/$',metrix_views.Metrix_Defualt_Config),
] | [
"zhaowangx.liang@intel.com"
] | zhaowangx.liang@intel.com |
406e86df76bdd822048227349e4e85b27e833f25 | bb2e9401499974a3ba6a2c083eba54af301736f9 | /lectures/110opengl/gmtutorials/010triangle/gm013.py | de6246611d9ffda296a5d450738ada5d91dfa700 | [] | no_license | geofmatthews/csci480 | 69188cd6ffc5d5ed3e9d9ea9d3c98deb6988e3f2 | fc21f487b57629ecaa042447d05f83b0837edf16 | refs/heads/master | 2021-01-10T11:18:53.451056 | 2015-11-30T23:10:22 | 2015-11-30T23:10:22 | 43,301,371 | 2 | 6 | null | 2016-04-27T19:28:24 | 2015-09-28T13:06:20 | Python | UTF-8 | Python | false | false | 5,086 | py | # Add a rotation matrix
from ctypes import c_void_p
from OpenGL.GL import *
from OpenGL.GL.shaders import compileShader, compileProgram
import pygame
from pygame.locals import *
import numpy as N
# We will be sending C objects to the graphics card, so we need
# some help making sure python sends the right thing.
# The ctypes module provides a way to create a null pointer:
null = c_void_p(0)
# Sizes in OpenGL are bytes. Since we're going to use 32 bit
# floats, provided by numpy, we'll need to tell OpenGL how big
# they are:
sizeOfFloat = 4
# The vertex shader has one input, the position of the vertex.
# It needs to have one output, also the position of the vertex.
# This is a simple passthrough shader.
strVertexShader = """
#version 330
in vec4 position;
uniform mat4 rotation;
void main()
{
gl_Position = rotation * position;
}
"""
# The fragment shader needs to have one output, the color
# of the fragment. Here we set it to white.
strFragmentShader = """
#version 330
out vec4 outputColor;
void main()
{
outputColor = vec4(1.0f, 1.0f, 1.0f, 1.0f);
}
"""
# Use PyOpenLG's compile shader programs, which simplify this task.
# Assign the compiled program to theShaders.
def initializeShaders():
global theShaders, positionAttrib, rotationAttrib
theShaders = compileProgram(
compileShader(strVertexShader, GL_VERTEX_SHADER),
compileShader(strFragmentShader, GL_FRAGMENT_SHADER)
)
positionAttrib = glGetAttribLocation(theShaders, "position")
rotationAttrib = glGetUniformLocation(theShaders, "rotation")
print "Attribs:", positionAttrib, rotationAttrib
# Vertex Data
#
# Three vertices of a triangle, with an x,y,z & w for each.
vertexPositions = N.array([
0.0, 0.75, 0.0, 1.0,
-0.75, -0.75, 0.0, 1.0,
0.75, -0.75, 0.0, 1.0], dtype=N.float32)
# number of components per point, 4 since we're using homogeneous
# 3d points. This helps figuring out how many triangles we're
# drawing, with len(vertexPositions)/vertexComponents
vertexComponents = 4
def initializeVertexBuffer():
global positionBufferObject
positionBufferObject = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject)
glBufferData(GL_ARRAY_BUFFER, vertexPositions, GL_STATIC_DRAW)
glBindBuffer(GL_ARRAY_BUFFER, 0)
# Ask the graphics card to create a VAO object.
# A VAO object stores one or more vertex buffer objects.
def initializeVAO():
n = 1
vaoArray = N.zeros(n, dtype=N.uint)
vaoArray = glGenVertexArrays(n)
glBindVertexArray( vaoArray )
# Called once at application start-up.
# Must be called after we have an OpenGL context, i.e. after the pygame
# window is created
def init():
initializeShaders()
initializeVertexBuffer()
initializeVAO()
# Called to redraw the contents of the window
def display(time):
# Clear the display
glClearColor(0.0, 0.0, 0.0, 0.0)
glClear(GL_COLOR_BUFFER_BIT)
# Set the shader program
glUseProgram(theShaders)
# compute rotation matrix:
s = N.sin(time)
c = N.cos(time)
rot = N.array(((c,-s,0,0),
(s,c,0,0),
(0,0,1,0),
(0,0,0,1)), dtype=N.float32)
# send rotation matrix to the shader program
glUniformMatrix4fv(rotationAttrib, # attrib location
1, # how many are we sending?
GL_TRUE, # row-major?
rot # the array
)
# Use the buffered data
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject)
# Tell the shader program which attribute to use for this buffer
glEnableVertexAttribArray(positionAttrib)
# Tell the shader program what the data in the buffer look like
glVertexAttribPointer(positionAttrib, # attrib location
vertexComponents, # elements per vertex
GL_FLOAT, # type of element
GL_FALSE, # normalize 0-256 to 0.0-1.0?
0, # stride
c_void_p(0) # offset
)
# Use that data to draw triangles
glDrawArrays(GL_TRIANGLES, 0, len(vertexPositions) / vertexComponents)
# Stop using that buffered data
glDisableVertexAttribArray(0)
# Stop using the shader program
glUseProgram(0)
def main():
global screen
pygame.init()
screen = pygame.display.set_mode((512,512), OPENGL|DOUBLEBUF)
clock = pygame.time.Clock()
init()
time = 0.0
while True:
clock.tick(30)
time += 0.01
for event in pygame.event.get():
if event.type == QUIT:
return
if event.type == KEYUP and event.key == K_ESCAPE:
return
display(time)
pygame.display.flip()
if __name__ == '__main__':
try:
main()
except RuntimeError, err:
for s in err:
print s
raise RuntimeError(err)
finally:
pygame.quit()
| [
"geoffrey.matthews@wwu.edu"
] | geoffrey.matthews@wwu.edu |
c647eb211f1f09affb1fb04662ac52f8ad38bc12 | a518141ca3ba2b6fa63a7961b51936d9438ff022 | /11172 - Relational Operator.py | d328188ace2103f64e0214f15f2353ea201ea847 | [] | no_license | jlhung/UVA-Python | ec93b2c98e04c753e8356f3e4825584fae4a8663 | 7a0db4fecffd7ac4f377f93da41291a8e998ee9b | refs/heads/master | 2022-11-28T04:47:49.270187 | 2020-08-10T13:19:58 | 2020-08-10T13:19:58 | 116,969,745 | 19 | 9 | null | null | null | null | UTF-8 | Python | false | false | 171 | py | '''
20180114 jlhung v1.0
'''
n = int(input())
for i in range(n):
x, y = map(int, input().split())
if x > y:
print(">")
elif x < y:
print("<")
else:
print("=") | [
"35291112+jlhung@users.noreply.github.com"
] | 35291112+jlhung@users.noreply.github.com |
300ac82a1c4baf849884d7d2fe7cd07efe1e0f2d | bbf744bfbfd9a935bd98c7cf54152a5d41194161 | /chapter_05/e5-10_ordinal_numbers.py | cf9d01ad4c3aee9140eec1916f92707ff314803c | [] | no_license | terranigmark/python-crash-course-projects | 65a7863be2d26fe8b91ac452b12203386eb0259a | 79ed9ed8e6a1bf015990a9556689379274231d13 | refs/heads/master | 2022-12-05T21:59:00.352140 | 2020-08-21T04:59:50 | 2020-08-21T04:59:50 | 266,263,493 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 370 | py |
def main():
numbers = [number for number in range(1, 10)]
print(numbers)
for number in numbers:
if number == 1:
print(f"{number}st")
elif number == 2:
print(f"{number}nd")
elif number == 3:
print(f"{number}rd")
else:
print(f"{number}th")
if __name__ == "__main__":
main() | [
"linnk99@gmail.com"
] | linnk99@gmail.com |
70de302fb8ee0861e18fba202c456c1afe87f9f9 | e90a772733e73e45b4cdbb5f240ef3b4a9e71de1 | /346. Moving Average from Data Stream.py | 7d66cf03d18e6f3b8d76865f2b9725ca038acae7 | [] | no_license | jiewu-stanford/leetcode | 102829fcbcace17909e4de49c01c3d705b6e6e3a | cbd47f713d3307f900daf55c8f27301c70542fc4 | refs/heads/master | 2022-05-28T18:25:00.885047 | 2022-05-18T05:16:22 | 2022-05-18T05:16:22 | 214,486,622 | 2 | 0 | null | null | null | null | UTF-8 | Python | false | false | 688 | py | '''
Title : 346. Moving Average from Data Stream ($$$)
Problem : https://leetcode.com/problems/moving-average-from-data-stream/
: https://www.lintcode.com/problem/moving-average-from-data-stream/description
'''
class MovingAverage:
def __init__(self, size):
self._size = size
self._array = []
self._sum = 0
def next(self, val):
self._sum += val
self._array.append(val)
if len(self._array) > self._size:
self._sum -= self._array.pop(0)
return self._sum/len(self._array)
# Your MovingAverage object will be instantiated and called as such:
# obj = MovingAverage(size)
# param = obj.next(val) | [
"bayernscience@hotmail.com"
] | bayernscience@hotmail.com |
3b2c4f1223e39221895f4054e2206db3288db630 | 741c5c70bf4a0adb05db6b0777c8d07e28eb9cf6 | /lib/python3.4/site-packages/IPython/nbconvert/preprocessors/tests/test_extractoutput.py | 4b2c515324994f3df53c0b8285135c1fe45333fe | [] | no_license | andybp85/hyLittleSchemer | e686d2dc0f9067562367ea1173f275e8e2d2cb85 | af5cb6adf6a196cc346aa7d14d7f9509e084c414 | refs/heads/master | 2021-01-19T07:48:31.309949 | 2015-01-04T00:57:30 | 2015-01-04T00:57:30 | 28,496,304 | 6 | 0 | null | null | null | null | UTF-8 | Python | false | false | 2,601 | py | """
Module with tests for the extractoutput preprocessor
"""
#-----------------------------------------------------------------------------
# Copyright (c) 2013, the IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
from .base import PreprocessorTestsBase
from ..extractoutput import ExtractOutputPreprocessor
#-----------------------------------------------------------------------------
# Class
#-----------------------------------------------------------------------------
class TestExtractOutput(PreprocessorTestsBase):
"""Contains test functions for extractoutput.py"""
def build_preprocessor(self):
"""Make an instance of a preprocessor"""
preprocessor = ExtractOutputPreprocessor()
preprocessor.extract_output_types = {'text', 'png', 'application/pdf'}
preprocessor.enabled = True
return preprocessor
def test_constructor(self):
"""Can a ExtractOutputPreprocessor be constructed?"""
self.build_preprocessor()
def test_output(self):
"""Test the output of the ExtractOutputPreprocessor"""
nb = self.build_notebook()
res = self.build_resources()
preprocessor = self.build_preprocessor()
nb, res = preprocessor(nb, res)
# Check if text was extracted.
output = nb.worksheets[0].cells[0].outputs[1]
assert 'text_filename' in output
text_filename = output['text_filename']
# Check if png was extracted.
output = nb.worksheets[0].cells[0].outputs[6]
assert 'png_filename' in output
png_filename = output['png_filename']
# Check that pdf was extracted
output = nb.worksheets[0].cells[0].outputs[7]
assert 'application/pdf_filename' in output
pdf_filename = output['application/pdf_filename']
# Verify text output
assert text_filename in res['outputs']
self.assertEqual(res['outputs'][text_filename], b'b')
# Verify png output
assert png_filename in res['outputs']
self.assertEqual(res['outputs'][png_filename], b'g')
# Verify pdf output
assert pdf_filename in res['outputs']
self.assertEqual(res['outputs'][pdf_filename], b'h')
| [
"andy@youshallthrive.com"
] | andy@youshallthrive.com |
f099090fe0b4ffbb9c84bebdf4e60b95afc751e5 | 86b6385bc0a0cc471e4a7e288bcdbe1f287adf52 | /utils/response_object.py | 62ac58196901874f16e12c99d13a39d96e34c88d | [] | no_license | AidarTaziev/EXAMPLE_PERSONAL_SERVICES | b688340c502380971798921caa6adc432eefb807 | 509ca43f254eb1f2626374fb5e429e32a0372015 | refs/heads/main | 2023-01-13T16:50:37.286108 | 2020-11-16T08:22:48 | 2020-11-16T08:22:48 | 313,234,087 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 141 | py | from django.http import JsonResponse
def create_response_object(error, message):
return JsonResponse({'error': error, 'data': message}) | [
"you@example.com"
] | you@example.com |
e1bacd8d697526fcd796c413b95da822d193d3a9 | 11ef4bbb8086ba3b9678a2037d0c28baaf8c010e | /Source Code/server/binaries/chromium/pyproto/components/gcm_driver/crypto/proto/gcm_encryption_data_pb2.py | 320d5e4043ed8b7fe0408cfcfca9734732f3f583 | [] | no_license | lineCode/wasmview.github.io | 8f845ec6ba8a1ec85272d734efc80d2416a6e15b | eac4c69ea1cf0e9af9da5a500219236470541f9b | refs/heads/master | 2020-09-22T21:05:53.766548 | 2019-08-24T05:34:04 | 2019-08-24T05:34:04 | null | 0 | 0 | null | null | null | null | UTF-8 | Python | false | true | 6,313 | py | # Generated by the protocol buffer compiler. DO NOT EDIT!
# source: gcm_encryption_data.proto
import sys
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from google.protobuf import reflection as _reflection
from google.protobuf import symbol_database as _symbol_database
# @@protoc_insertion_point(imports)
_sym_db = _symbol_database.Default()
DESCRIPTOR = _descriptor.FileDescriptor(
name='gcm_encryption_data.proto',
package='gcm',
syntax='proto2',
serialized_options=_b('H\003'),
serialized_pb=_b('\n\x19gcm_encryption_data.proto\x12\x03gcm\"v\n\x07KeyPair\x12\"\n\x04type\x18\x01 \x02(\x0e\x32\x14.gcm.KeyPair.KeyType\x12\x13\n\x0bprivate_key\x18\x02 \x01(\x0c\x12\x12\n\npublic_key\x18\x04 \x01(\x0c\"\x18\n\x07KeyType\x12\r\n\tECDH_P256\x10\x00J\x04\x08\x03\x10\x04\"\x81\x01\n\x0e\x45ncryptionData\x12\x0e\n\x06\x61pp_id\x18\x01 \x02(\t\x12\x19\n\x11\x61uthorized_entity\x18\x04 \x01(\t\x12\x1a\n\x04keys\x18\x02 \x03(\x0b\x32\x0c.gcm.KeyPair\x12\x13\n\x0bprivate_key\x18\x05 \x01(\t\x12\x13\n\x0b\x61uth_secret\x18\x03 \x01(\x0c\x42\x02H\x03')
)
_KEYPAIR_KEYTYPE = _descriptor.EnumDescriptor(
name='KeyType',
full_name='gcm.KeyPair.KeyType',
filename=None,
file=DESCRIPTOR,
values=[
_descriptor.EnumValueDescriptor(
name='ECDH_P256', index=0, number=0,
serialized_options=None,
type=None),
],
containing_type=None,
serialized_options=None,
serialized_start=122,
serialized_end=146,
)
_sym_db.RegisterEnumDescriptor(_KEYPAIR_KEYTYPE)
_KEYPAIR = _descriptor.Descriptor(
name='KeyPair',
full_name='gcm.KeyPair',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='type', full_name='gcm.KeyPair.type', index=0,
number=1, type=14, cpp_type=8, label=2,
has_default_value=False, default_value=0,
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='private_key', full_name='gcm.KeyPair.private_key', index=1,
number=2, type=12, cpp_type=9, label=1,
has_default_value=False, default_value=_b(""),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='public_key', full_name='gcm.KeyPair.public_key', index=2,
number=4, type=12, cpp_type=9, label=1,
has_default_value=False, default_value=_b(""),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
_KEYPAIR_KEYTYPE,
],
serialized_options=None,
is_extendable=False,
syntax='proto2',
extension_ranges=[],
oneofs=[
],
serialized_start=34,
serialized_end=152,
)
_ENCRYPTIONDATA = _descriptor.Descriptor(
name='EncryptionData',
full_name='gcm.EncryptionData',
filename=None,
file=DESCRIPTOR,
containing_type=None,
fields=[
_descriptor.FieldDescriptor(
name='app_id', full_name='gcm.EncryptionData.app_id', index=0,
number=1, type=9, cpp_type=9, label=2,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='authorized_entity', full_name='gcm.EncryptionData.authorized_entity', index=1,
number=4, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='keys', full_name='gcm.EncryptionData.keys', index=2,
number=2, type=11, cpp_type=10, label=3,
has_default_value=False, default_value=[],
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='private_key', full_name='gcm.EncryptionData.private_key', index=3,
number=5, type=9, cpp_type=9, label=1,
has_default_value=False, default_value=_b("").decode('utf-8'),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
_descriptor.FieldDescriptor(
name='auth_secret', full_name='gcm.EncryptionData.auth_secret', index=4,
number=3, type=12, cpp_type=9, label=1,
has_default_value=False, default_value=_b(""),
message_type=None, enum_type=None, containing_type=None,
is_extension=False, extension_scope=None,
serialized_options=None, file=DESCRIPTOR),
],
extensions=[
],
nested_types=[],
enum_types=[
],
serialized_options=None,
is_extendable=False,
syntax='proto2',
extension_ranges=[],
oneofs=[
],
serialized_start=155,
serialized_end=284,
)
_KEYPAIR.fields_by_name['type'].enum_type = _KEYPAIR_KEYTYPE
_KEYPAIR_KEYTYPE.containing_type = _KEYPAIR
_ENCRYPTIONDATA.fields_by_name['keys'].message_type = _KEYPAIR
DESCRIPTOR.message_types_by_name['KeyPair'] = _KEYPAIR
DESCRIPTOR.message_types_by_name['EncryptionData'] = _ENCRYPTIONDATA
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
KeyPair = _reflection.GeneratedProtocolMessageType('KeyPair', (_message.Message,), dict(
DESCRIPTOR = _KEYPAIR,
__module__ = 'gcm_encryption_data_pb2'
# @@protoc_insertion_point(class_scope:gcm.KeyPair)
))
_sym_db.RegisterMessage(KeyPair)
EncryptionData = _reflection.GeneratedProtocolMessageType('EncryptionData', (_message.Message,), dict(
DESCRIPTOR = _ENCRYPTIONDATA,
__module__ = 'gcm_encryption_data_pb2'
# @@protoc_insertion_point(class_scope:gcm.EncryptionData)
))
_sym_db.RegisterMessage(EncryptionData)
DESCRIPTOR._options = None
# @@protoc_insertion_point(module_scope)
| [
"wasmview@gmail.com"
] | wasmview@gmail.com |
721879e136706a48003650b8fbd0d1770c84fa4a | b5c17b494204ed215ecfdc65932b2c960fa9e121 | /test/functional/create_cache.py | 8cac7417df6be7b4791ae67c8af9e25fabf8b543 | [
"MIT"
] | permissive | syglee7/zenacoin-ver2 | 9c8943c84b8eefad4ce3fee6ac15a9878b87f1df | 90079b95bdf0ea2b7fce644c56d2a9626526e5e4 | refs/heads/master | 2023-03-10T07:29:47.772820 | 2021-02-21T13:57:41 | 2021-02-21T13:57:41 | 340,617,557 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 796 | py | #!/usr/bin/env python3
# Copyright (c) 2016-2019 The Zenacoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Create a blockchain cache.
Creating a cache of the blockchain speeds up test execution when running
multiple functional tests. This helper script is executed by test_runner when multiple
tests are being run in parallel.
"""
from test_framework.test_framework import ZenacoinTestFramework
class CreateCache(ZenacoinTestFramework):
# Test network and test nodes are not required:
def set_test_params(self):
self.num_nodes = 0
def setup_network(self):
pass
def run_test(self):
pass
if __name__ == '__main__':
CreateCache().main()
| [
"syglee7@gmail.com"
] | syglee7@gmail.com |
6db0e717a75b8c2e97b0faa41d5ff9342ac4dd59 | f84a247c47fbc44d2327c5fba9b66af9cbb6904d | /Code/DeNovoCompeting/applyExtreme.py | 46e1be8a3a335fec2220c7b694c54218169e4ed4 | [] | no_license | eggduzao/Costa_TfbsPrediction | e530b2e090d0a1382693a340d581c6f4aa5e441c | c47b9f8e38e3d414f06905f12aeb2c77a75ae55f | refs/heads/master | 2020-12-02T08:08:59.185158 | 2019-08-13T23:56:57 | 2019-08-13T23:56:57 | 96,719,524 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 7,410 | py | #################################################################################################
# Runs the pipeline for the EXTREME algorithm.
#
# The following are arguments for GappedKmerSearch.py, the word searching algorithm for the seeding:
# -l HALFLENGTH. The number of exact letters on each side of the word (default 4).
# -ming MINGAP. The minimum number of universal wildcard letters in the middle (default 0).
# -maxg MAXGAP. The maximum number of universal wildcard letters in the middle (default 10).
# -minsites MINSITES. Minimum number of sites a word should have to be included (default 10).
# -zthresh ZTHRESHOLD. Minimum normalized z-score for a word to be saved. A lower threshold increases
# the number of words saved (default 5).
#
# The following are arguments for run_consensus_clusering_using_wm.pl, the hierarchical clustering algorithm for the seeding:
# THRESHOLD. The threshold for the clustering. Has values between 0 and 1. A value closer to 1
# decreases the number of clusters, while a value closer to 0 increases the number
# of clusters. Recommended value is 0.3.
#
# The following are arguments for EXTREME.py, the EXTREME algorithm:
# -t TRIES. The number of different bias factors to try before giving up on the current seed.
# -s SEED. Random seed for shuffling sequences and dataset positions.
# -p PSEUDOCOUNTS. Uniform pseudo counts to add to initial PFM guess (default 0.0).
# -q INITALSTEP. The initial step size for the online EM algorithm. A VERY sensitive parameter.
# I get best success for ChIP size data (about 100,000 to 1,000,000 bps) with a step
# size of 0.05. For DNase footprinting, which usually has >5,000,000 bps, I find 0.02
# works best (default 0.05).
# -minsites MINSITES. Minimum number of sites the motif should have (default 10).
# -maxsites MAXSITES. Minimum number of sites the motif should have. If not specified, it is set to
# five times the number of predicted motif sites based on the initial PFM guess
# -saveseqs SAVESEQS. A switch. If used, the positive and negative sequence set will be saved to
# Positive_seq.fa and Negative_seq.fa, respectively, with instances of the
# discovered motif replaced with capital Ns.
#################################################################################################
params = []
params.append("###")
params.append("Input: ")
params.append(" 1. bedFileName = Name of the input bed file.")
params.append(" 2. genomeFileName = Genome to extract the sequences.")
params.append(" 3. outputLocation = Location of the output and temporary files.")
params.append("###")
params.append("Output: ")
params.append(" 1. EXTREME output.")
params.append("###")
#################################################################################################
# Import
import os
import sys
import glob
import re
lib_path = os.path.abspath("/".join(os.path.realpath(__file__).split("/")[:-2]))
sys.path.append(lib_path)
from util import *
if(len(sys.argv) <= 1):
for e in params: print e
sys.exit(0)
def natural_sort(l):
convert = lambda text: int(text) if text.isdigit() else text.lower()
alphanum_key = lambda key: [ convert(c) for c in re.split('([0-9]+)', key) ]
return sorted(l, key = alphanum_key)
###################################################################################################
# INPUT
###################################################################################################
# Reading input
bedFileName = sys.argv[1]
genomeFileName = sys.argv[2]
outputLocation = sys.argv[3]
if(outputLocation[-1] != "/"): outputLocation+="/"
# Parameters for GappedKmerSearch
halfSiteLength = "8"
ming = "0"
maxg = "10"
minsites = "5"
# Parameters for run_consensus_clusering_using_wm
clusterThresh = "0.3"
# Creating fasta file
inName = ".".join(bedFileName.split("/")[-1].split(".")[:-1])
fastaFileName = outputLocation+inName+".fasta"
toRemove = [fastaFileName]
os.system("fastaFromBed -fi "+genomeFileName+" -bed "+bedFileName+" -fo "+fastaFileName)
###################################################################################################
# EXTREME
###################################################################################################
loc = "/home/egg/Desktop/footprint_motifmatch/Extreme/EXTREME-2.0.0/src/"
# 1. Generates a dinucleotide shuffled version of the positive sequence set to serve as a negative sequence set
shuffledFileName = outputLocation+inName+"_shuffled.fasta"
toRemove.append(shuffledFileName)
os.system("python "+loc+"fasta-dinucleotide-shuffle.py -f "+fastaFileName+" > "+shuffledFileName)
# 2. Finds gapped words with two half-sites of length "-l", between "-ming" and "-maxg" universal wildcard gap letters, and at least "-minsites" occurrences in the positive sequence set
wordsFileName = outputLocation+inName+".words"
toRemove.append(wordsFileName)
os.system("python "+loc+"GappedKmerSearch.py -l "+halfSiteLength+" -ming "+ming+" -maxg "+maxg+" -minsites "+minsites+" "+fastaFileName+" "+shuffledFileName+" "+wordsFileName)
# 3. Clusters the words and outputs the results
clusterFileName = wordsFileName+".cluster.aln"
toRemove.append(clusterFileName)
os.system("perl "+loc+"run_consensus_clusering_using_wm.pl "+wordsFileName+" "+clusterThresh)
# 4. Converts the clusters into PFMs which can be used as seeds for the online EM algorithm
wmFileName = outputLocation+inName+".wm"
toRemove.append(wmFileName)
os.system("python "+loc+"Consensus2PWM.py "+clusterFileName+" "+wmFileName)
nbClusters = 0
wmFile = open(wmFileName,"r")
for line in wmFile:
if(line[0] == ">"): nbClusters += 1
wmFile.close()
# 5. EM algorithm
memePfmFileName = outputLocation+"all_pwms.meme"
memePfmFile = open(memePfmFileName,"w")
memePfmFile.write("MEME version 4.9.0\n\nALPHABET= ACGT\n\nstrands: + -\n\nBackground letter frequencies (from uniform background):\nA 0.25000 C 0.25000 G 0.25000 T 0.25000\n\n")
htmlFileName = outputLocation+"all_motifs.html"
htmlFile = open(htmlFileName,"w")
htmlFile.write("<html>\n<head></head>\n<body>\n")
for i in range(1,nbClusters+1):
os.system("python "+loc+"EXTREME.py "+fastaFileName+" "+shuffledFileName+" "+wmFileName+" "+str(i))
memeFile = open("./cluster"+str(i)+"/MEMEoutput.meme","r")
flagStart = False
for line in memeFile:
if(len(line) > 5 and line[:5] == "MOTIF"): flagStart = True
if(flagStart): memePfmFile.write(line)
htmlFile.write("<h1>cluster"+str(i)+"</h1>\n")
htmlFile.write("<table cellpadding=\"4\" style=\"border: 1px solid #000000; border-collapse: collapse;\" border=\"1\">\n")
pngList = natural_sort(glob.glob(outputLocation+"cluster"+str(i)+"/Motif*.png"))
for pngFileName in pngList:
mname = ".".join(pngFileName.split("/")[-1].split(".")[:-1])
htmlFile.write("<tr><td>"+mname+"</td><td><img src=\""+pngFileName+"\"></td></tr>\n")
htmlFile.write("</table>\n")
memeFile.close()
memePfmFile.close()
htmlFile.close()
###################################################################################################
# OUTPUT
###################################################################################################
# Remove temporary files
for e in toRemove: os.system("rm "+e)
| [
"eggduzao@gmail.com"
] | eggduzao@gmail.com |
2877643adfbcb52d6cc723fbb5d42cda73d5fde7 | 910eb6e2905fd10337b67f6265d80fa975c63768 | /freenasUI/plugins/migrations/0012_auto__del_field_configuration_collectionurl__add_field_configuration_r.py | abf536b3fea706cef2d8c8abc0f79516e739887a | [] | no_license | truenas/freenas-migrate93 | b6e7a32615137677dbb20f002f0455f5ca3cf5a2 | 9cd6170fc7bf636d55b0513af794f955fb7bfbce | refs/heads/master | 2023-08-18T20:24:45.513212 | 2023-02-07T12:58:01 | 2023-02-07T12:58:01 | 77,483,696 | 1 | 0 | null | 2023-04-27T10:41:55 | 2016-12-27T21:28:51 | Python | UTF-8 | Python | false | false | 2,999 | py | # -*- coding: utf-8 -*-
from south.db import db
from south.v2 import SchemaMigration
from freenasUI.plugins.plugin import PLUGINS_REPO
class Migration(SchemaMigration):
def forwards(self, orm):
# Deleting field 'Configuration.collectionurl'
db.delete_column(u'plugins_configuration', 'collectionurl')
# Adding field 'Configuration.repourl'
db.add_column(u'plugins_configuration', 'repourl',
self.gf('django.db.models.fields.CharField')(default=PLUGINS_REPO, max_length=255, blank=True),
keep_default=False)
def backwards(self, orm):
# Adding field 'Configuration.collectionurl'
db.add_column(u'plugins_configuration', 'collectionurl',
self.gf('django.db.models.fields.CharField')(default='', max_length=255, blank=True),
keep_default=False)
# Deleting field 'Configuration.repourl'
db.delete_column(u'plugins_configuration', 'repourl')
models = {
u'plugins.configuration': {
'Meta': {'object_name': 'Configuration'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'repourl': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'})
},
u'plugins.plugins': {
'Meta': {'object_name': 'Plugins'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'plugin_api_version': ('django.db.models.fields.CharField', [], {'default': "'1'", 'max_length': '20'}),
'plugin_arch': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
'plugin_enabled': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'plugin_ip': ('django.db.models.fields.IPAddressField', [], {'max_length': '15'}),
'plugin_jail': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
'plugin_name': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
'plugin_path': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
'plugin_pbiname': ('django.db.models.fields.CharField', [], {'max_length': '120'}),
'plugin_port': ('django.db.models.fields.IntegerField', [], {'max_length': '120'}),
'plugin_secret': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['services.RPCToken']", 'on_delete': 'models.PROTECT'}),
'plugin_version': ('django.db.models.fields.CharField', [], {'max_length': '120'})
},
u'services.rpctoken': {
'Meta': {'object_name': 'RPCToken'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'key': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
'secret': ('django.db.models.fields.CharField', [], {'max_length': '1024'})
}
}
complete_apps = ['plugins']
| [
"suraj@ixsystems.com"
] | suraj@ixsystems.com |
c85075fd007feb5b4fdc25b58ff728536d490e0f | 4074db4436d5fc5fa5395de072557def620f993e | /0x05-python-exceptions/2-safe_print_list_integers.py~ | 45b48e50405d79479ecfaf25f5542b82b3a9cb0b | [] | no_license | Hunt66/holbertonschool-higher_level_programming | 49b4a93a8b565cdd588e26e6348bed5d3e9d6953 | b26f42c1d41bb24842d77bf5cf86c441bd8fcf51 | refs/heads/master | 2020-03-28T11:11:52.204554 | 2019-03-25T19:45:28 | 2019-03-25T19:45:28 | 148,187,536 | 0 | 1 | null | null | null | null | UTF-8 | Python | false | false | 390 | #!/usr/bin/python3
def safe_print_list_integers(my_list=[], x=0):
try:
for i in range(0, x):
print("{:d}".format(my_list[i]), end='')
print('')
return i
except ValueError:
return 0
except IndexError:
for i in my_list:
print("{:d}".format(i), end='')
print('')
return i
except:
return 0
| [
"489@holbertonschool.com"
] | 489@holbertonschool.com | |
33d87a72c879d79bfd1ceb6f6d0e13ea24c6d194 | 44dea7bd1f7fc93ce5fa3ca14c949120024ef554 | /exercise/bubble.py | 50d760b4c94e3ff3e62b4a1102edb1ad23a72292 | [] | no_license | WillGhost/op | 09b5f94401453d7abdcdf1319d7a753288b4f083 | 1685f18ba3949a23295d408bc781f07f87a1009d | refs/heads/master | 2023-08-28T05:38:59.105302 | 2023-08-24T08:56:36 | 2023-08-24T08:56:36 | 14,950,011 | 6 | 2 | null | null | null | null | UTF-8 | Python | false | false | 299 | py | #!/usr/bin/env python3
import sys
inp = sys.argv[1:]
for i in range(len(inp)):
inp[i] = int(inp[i])
def bubble(xx):
length = len(xx)
for i in range(length-1):
for j in range(length-1-i):
if xx[j] > xx[j+1]:
xx[j],xx[j+1] = xx[j+1],xx[j]
return xx
print(inp)
print(bubble(inp))
| [
"you@example.com"
] | you@example.com |
c104b0cb17230d79f8f8a4956851bd07e3ee11e2 | 9d81fb4bfac02630c0ecf36c35cc63515470961e | /demo/calculated_flow.py | f2f685fa5c857feaf9ee78b842e750e61cefb0fd | [] | no_license | lechat/jenkinsflow | d36cc20af9f03dbbc1a82af5ce1c83f6bc365f2d | 87396069dda4f0681829e5d4e264e4f09ae34131 | refs/heads/master | 2020-04-05T04:35:39.314623 | 2016-08-26T22:18:59 | 2016-08-26T22:18:59 | 10,026,420 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 2,959 | py | #!/usr/bin/env python
# Copyright (c) 2012 - 2015 Lars Hupfeldt Nielsen, Hupfeldt IT
# All rights reserved. This work is under a BSD license, see LICENSE.TXT.
# Demonstrate that the flow can be dynamically calculated by the script
from __future__ import print_function
import sys, os, tempfile
import logging
from collections import OrderedDict
import demo_setup
demo_setup.sys_path()
from jenkinsflow.flow import serial
from jenkinsflow.unbuffered import UnBuffered
# Unbuffered output does not work well in Jenkins/Hudson, so in case
# this is run from a jenkins/hudson job, we want unbuffered output
sys.stdout = UnBuffered(sys.stdout)
import demo_security as security
def main(api):
logging.basicConfig()
logging.getLogger("").setLevel(logging.WARNING)
print("Doing stuff before flow ...")
demo_name = 'jenkinsflow_demo__calculated_flow'
hudson = os.environ.get('HUDSON_URL')
graph_output_dir = os.path.join(tempfile.gettempdir(), demo_name + ('_hudson' if hudson else '_jenkins'))
if not os.path.exists(graph_output_dir):
os.makedirs(graph_output_dir)
g1_components = range(1)
g2_components = range(2)
g3_components = range(2)
component_groups = OrderedDict((('g1', g1_components), ('g2', g2_components), ('g3', g3_components)))
# Flow
with serial(api, timeout=70, securitytoken=security.securitytoken, job_name_prefix=demo_name + '__', report_interval=3,
# Write json flow graph to display in browser, see INSTALL.md
json_dir=graph_output_dir, json_indent=4) as ctrl1:
ctrl1.invoke('prepare')
with ctrl1.parallel(timeout=0, report_interval=3) as ctrl2:
for gname, group in component_groups.items():
with ctrl2.serial(timeout=0, report_interval=3) as ctrl3:
for component in group:
ctrl3.invoke('deploy_component_' + gname + '_' + str(component))
with ctrl1.parallel(timeout=0, report_interval=3) as ctrl2:
ctrl2.invoke('report_deploy')
ctrl2.invoke('prepare_tests')
with ctrl1.parallel(timeout=40, report_interval=3) as ctrl2:
with ctrl2.serial(timeout=40, report_interval=3) as ctrl3:
ctrl3.invoke('test_ui')
with ctrl3.parallel(timeout=0, report_interval=3) as ctrl4:
for gname, group in component_groups.items():
for component in group:
ctrl4.invoke('test_component_' + gname + '_' + str(component))
ctrl2.invoke('test_x')
ctrl1.invoke('report', password='Y', s1='tst_regression', c1='complete')
ctrl1.invoke('promote')
print("Doing stuff after flow ...")
if __name__ == '__main__':
from jenkinsflow.jenkins_api import Jenkins
jenkins = Jenkins(os.environ.get('JENKINS_URL') or os.environ.get('HUDSON_URL') or "http://localhost:8080")
main(jenkins)
| [
"lhn@hupfeldtit.dk"
] | lhn@hupfeldtit.dk |
2d407ed2a59369382421c860ca69164825530a1b | ccddff63d10b9bf857ff5907ed14b1be85975a47 | /test/luna/run_api_tests.py | 608e3b5b61bfe8a2b08c3aacf560e0526a124536 | [
"LicenseRef-scancode-warranty-disclaimer",
"Apache-2.0"
] | permissive | webosose/avoutputd | 4d9aff450acce8c62faad22c1fe10d5984993ca1 | 32fa2fc02e76be75b0943a13e8c97d43fb71abdb | refs/heads/master | 2021-03-31T01:04:56.961145 | 2018-07-09T04:49:30 | 2018-08-01T05:29:15 | 125,002,453 | 3 | 3 | null | null | null | null | UTF-8 | Python | false | false | 244 | py | #!/usr/bin/python2
import unittest
import os
if __name__ == '__main__':
testdir = os.path.dirname(os.path.realpath(__file__))
testsuite = unittest.TestLoader().discover(testdir)
unittest.TextTestRunner(verbosity=1).run(testsuite)
| [
"changhyeok.bae@lge.com"
] | changhyeok.bae@lge.com |
5aa885bbab92bb6d71a9a139107820fa31c1f3b6 | 5bfca95abf14f7bb0ff29b58b018fc9062d3f837 | /apps/first_draft/migrations/0041_auto_20171120_2256.py | 34592e123aa65322113d68d5e838de3b53506734 | [] | no_license | wdudek82/django-ogame-clone | 621afb20ea2dd3c0f2e4b93dfdd604e0628bd7b8 | 472971da826d078176a5d619b3b5cad89e3d1c5c | refs/heads/master | 2021-09-08T15:19:49.407650 | 2017-11-26T19:14:48 | 2017-11-26T19:14:48 | 124,670,158 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 619 | py | # -*- coding: utf-8 -*-
# Generated by Django 1.11.7 on 2017-11-20 21:56
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('first_draft', '0040_auto_20171120_2250'),
]
operations = [
migrations.RenameField(
model_name='resource',
old_name='new_amount',
new_name='additional_amount',
),
migrations.AlterField(
model_name='resource',
name='amount',
field=models.PositiveIntegerField(default=0),
),
]
| [
"wdudek82@gmail.com"
] | wdudek82@gmail.com |
68fc75e9c08edbc00449bd58859742b88ae934ec | 5dfbfa153f22b3f58f8138f62edaeef30bad46d3 | /old_ws/build/baxter_simulator/baxter_gazebo/catkin_generated/pkg.develspace.context.pc.py | 0164fbae495acd3846f2e807fea2c9e97795f147 | [] | no_license | adubredu/rascapp_robot | f09e67626bd5a617a569c9a049504285cecdee98 | 29ace46657dd3a0a6736e086ff09daa29e9cf10f | refs/heads/master | 2022-01-19T07:52:58.511741 | 2019-04-01T19:22:48 | 2019-04-01T19:22:48 | null | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 437 | py | # generated from catkin/cmake/template/pkg.context.pc.in
CATKIN_PACKAGE_PREFIX = ""
PROJECT_PKG_CONFIG_INCLUDE_DIRS = "".split(';') if "" != "" else []
PROJECT_CATKIN_DEPENDS = "baxter_core_msgs;gazebo_ros_control;roscpp;controller_manager_msgs".replace(';', ' ')
PKG_CONFIG_LIBRARIES_WITH_PREFIX = "".split(';') if "" != "" else []
PROJECT_NAME = "baxter_gazebo"
PROJECT_SPACE_DIR = "/home/bill/ros_ws/devel"
PROJECT_VERSION = "1.2.12"
| [
"alphonsusbq436@gmail.com"
] | alphonsusbq436@gmail.com |
ae114df5ae9c386214f76e7cd76204f262611484 | ee3e1092daa3b8140ceea4bfef623b54302dfb6c | /core/views.py | 35017542527561aebd701de68bb91d62a9ae7655 | [] | no_license | safwanvk/craigslist | fa68a13b179f9b65ec76119448c03f93bfc845bb | 2ad79c2e6d418b5d7809871a928a24ae10e705ab | refs/heads/master | 2022-11-30T06:10:05.310661 | 2020-08-21T04:23:23 | 2020-08-21T04:23:23 | 289,067,703 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 1,602 | py | from urllib.parse import quote_plus
import requests
from django.shortcuts import render
from bs4 import BeautifulSoup
# Create your views here.
from . models import Search
BASE_CRAIGSLIST_URL = 'https://losangeles.craigslist.org/search/?query={}'
BASE_IMAGE_URL = 'https://images.craigslist.org/{}_300x300.jpg'
def home(request):
return render(request, 'core/base.html')
def new_search(request):
search = request.POST.get('search')
Search.objects.create(search=search)
final_url = BASE_CRAIGSLIST_URL.format(quote_plus(search))
response = requests.get(final_url)
data = response.text
soup = BeautifulSoup(data, features='html.parser')
post_listings = soup.find_all('li', {'class': 'result-row'})
final_postings = []
for post in post_listings:
post_title = post.find(class_='result-title').text
post_url = post.find('a').get('href')
if post.find(class_='result-price'):
post_price = post.find(class_='result-price').text
else:
post_price = 'N/A'
if post.find(class_='result-image').get('data-ids'):
post_image_id = post.find(class_='result-image').get('data-ids').split(',')[0].split(':')[1]
post_image_url = BASE_IMAGE_URL.format(post_image_id)
else:
post_image_url = 'https://craigslist.org/images/peace.jpg'
final_postings.append((post_title, post_url, post_price, post_image_url))
context = {
'search': search,
'final_postings': final_postings
}
return render(request, 'core/new_search.html', context)
| [
"safwanvalakundil@gmail.com"
] | safwanvalakundil@gmail.com |
293e1a3742444a723d6ba6b124a56450cbe4848f | 377fc6e13101a2a45826cd118110c790f396a805 | /abc098-b.py | 18748153555b09fd04b0e3e02a01bd011f6989da | [] | no_license | number09/atcoder | 4076e7223f424b9923754e73992d6442e0bb0de7 | f521ca1205b254d99744abaf6a7a5bfe69845fe0 | refs/heads/master | 2021-06-04T23:16:39.021645 | 2021-01-19T08:30:39 | 2021-01-19T08:30:39 | 132,128,927 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 197 | py | int_n = int(input())
str_s = input()
result_ar = []
for i in range(len(str_s)):
# print(str_s[:i], str_s[i:])
result_ar.append(len(set(str_s[:i]) & set(str_s[i:])))
print(max(result_ar))
| [
"cielo.abierto09@gmail.com"
] | cielo.abierto09@gmail.com |
a869f7fe8be2069a8b166e8e4e6df23fef8201c7 | de24f83a5e3768a2638ebcf13cbe717e75740168 | /moodledata/vpl_data/84/usersdata/162/53871/submittedfiles/lista1.py | 1b054bc98171dfca2ac844d491d8d9aa57da965c | [] | no_license | rafaelperazzo/programacao-web | 95643423a35c44613b0f64bed05bd34780fe2436 | 170dd5440afb9ee68a973f3de13a99aa4c735d79 | refs/heads/master | 2021-01-12T14:06:25.773146 | 2017-12-22T16:05:45 | 2017-12-22T16:05:45 | 69,566,344 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 402 | py | n=int(input('Digite o tamanho da lista:'))
lista=[]
for i in range(1,n+1,1):
numero=int(input('Digite o número:'))
lista.append(numero)
soma=0
soma2=0
cont=0
cont2=0
for i in range(0,len(lista),1):
if lista[i]%2!=0:
cont=cont+1
soma=soma+lista[i]
else:
soma2=soma2+lista[i]
cont2=cont2+1
print(soma)
print(soma2)
print(cont)
print(cont2)
print(lista)
| [
"rafael.mota@ufca.edu.br"
] | rafael.mota@ufca.edu.br |
158882e1a339bf6f2984af63cfcedd9e9c4c750e | 482b28d5680768c2e95d214a9c8b97e5c6e93191 | /project1/core python startingclasses/21.07.2018.2.py | 668431893f450270a62ad22fe48366da27a046f3 | [] | no_license | prasadnaidu1/projects | 2bf3cd0fa3b93e549775e928077e1848ac05955b | e41182a9f3c9ea46a2ac0352eac1c81fab79c08a | refs/heads/master | 2020-04-12T19:33:04.834208 | 2018-12-21T12:32:37 | 2018-12-21T12:32:37 | 155,504,638 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 315 | py | def calculate_find(enternumberofadults ,enternumberofchilds):
aduldsprice = 37555.0
childsprice = 12518.3
cost = aduldsprice + childsprice
tax = (cost * 7) / 100
discount = (cost+tax)*10 / 100
d=(aduldsprice+childsprice+tax)-discount
return d
x=input('enteradults,enter chids:')
print(x) | [
"you@example.com"
] | you@example.com |
6822c50c813c29ba240b591f977d8bd81ba30f4c | ca7aa979e7059467e158830b76673f5b77a0f5a3 | /Python_codes/p02411/s645571797.py | e8d470430047756d2fbf592005537cd9683254d5 | [] | no_license | Aasthaengg/IBMdataset | 7abb6cbcc4fb03ef5ca68ac64ba460c4a64f8901 | f33f1c5c3b16d0ea8d1f5a7d479ad288bb3f48d8 | refs/heads/main | 2023-04-22T10:22:44.763102 | 2021-05-13T17:27:22 | 2021-05-13T17:27:22 | 367,112,348 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 311 | py | while 1:
a, b, c = map(int, input().split())
if a == b == c == -1:
break
if a == -1 or b == -1 or a + b < 30:print('F')
elif a + b >= 80:print('A')
elif a + b >= 65: print('B')
elif a + b >= 50:print('C')
elif a + b >= 30 and c >= 50:print('C')
else:print('D')
| [
"66529651+Aastha2104@users.noreply.github.com"
] | 66529651+Aastha2104@users.noreply.github.com |
f6363026bf6685e36bc6dcd9bde036110c010a38 | cdb7bb6215cc2f362f2e93a040c7d8c5efe97fde | /C/CountPairsWithXORinaRange.py | bf199e04ea01b2a524ac620f74ff4ac3d4592251 | [] | no_license | bssrdf/pyleet | 8861bbac06dfe0f0f06f6ad1010d99f8def19b27 | 810575368ecffa97677bdb51744d1f716140bbb1 | refs/heads/master | 2023-08-20T05:44:30.130517 | 2023-08-19T21:54:34 | 2023-08-19T21:54:34 | 91,913,009 | 2 | 0 | null | null | null | null | UTF-8 | Python | false | false | 3,091 | py | '''
-Hard-
*Trie*
Given a (0-indexed) integer array nums and two integers low and high, return the number of nice pairs.
A nice pair is a pair (i, j) where 0 <= i < j < nums.length and low <= (nums[i] XOR nums[j]) <= high.
Example 1:
Input: nums = [1,4,2,7], low = 2, high = 6
Output: 6
Explanation: All nice pairs (i, j) are as follows:
- (0, 1): nums[0] XOR nums[1] = 5
- (0, 2): nums[0] XOR nums[2] = 3
- (0, 3): nums[0] XOR nums[3] = 6
- (1, 2): nums[1] XOR nums[2] = 6
- (1, 3): nums[1] XOR nums[3] = 3
- (2, 3): nums[2] XOR nums[3] = 5
Example 2:
Input: nums = [9,8,4,2,1], low = 5, high = 14
Output: 8
Explanation: All nice pairs (i, j) are as follows:
- (0, 2): nums[0] XOR nums[2] = 13
- (0, 3): nums[0] XOR nums[3] = 11
- (0, 4): nums[0] XOR nums[4] = 8
- (1, 2): nums[1] XOR nums[2] = 12
- (1, 3): nums[1] XOR nums[3] = 10
- (1, 4): nums[1] XOR nums[4] = 9
- (2, 3): nums[2] XOR nums[3] = 6
- (2, 4): nums[2] XOR nums[4] = 5
Constraints:
1 <= nums.length <= 2 * 104
1 <= nums[i] <= 2 * 104
1 <= low <= high <= 2 * 104
'''
from typing import List
class TrieNode:
def __init__(self):
self.child = {}
self.go = 0 # Number of elements goes through this node
def increase(self, number, d):
cur = self
for i in range(15, -1, -1):
bit = (number >> i) & 1
if bit not in cur.child: cur.child[bit] = TrieNode()
cur = cur.child[bit]
cur.go += d
def find(self, number, k):
cur, ans = self, 0
for i in range(15, -1, -1):
if not cur: break
bitx = (number >> i) & 1
bitk = (k >> i) & 1
# if bitk == 0, we know all nodes that have different bit value as
# "number" will result something larger so we can ignore all those and
# only traverse the sub-trie that has the same value as "bitx" (which,
# after xor, will result this digit to be zero)
if bitk == 0:
cur = cur.child.get(bitx, None)
continue
# if bitk == 1, then we know that all nodes having the same bit value as "number"
# will result this digit to be 0 after xor, which are guaranteed to
# be smaller than "k", so we can add all of those nodes and move
# onto the sub-trie that have different value than "bitx" (1^bit is
# just a fancier way to say "change 0 to 1 and change 1 to 0")
if bitx in cur.child:
ans += cur.child[bitx].go
cur = cur.child.get(1-bitx, None)
return ans
class Solution:
def countPairs(self, nums: List[int], low: int, high: int) -> int:
trieNode = TrieNode()
ans = 0
for x in nums:
print('x',x)
ans += trieNode.find(x, high+1) - trieNode.find(x, low)
trieNode.increase(x, 1)
return ans
if __name__ == "__main__":
print(Solution().countPairs(nums = [1,4,2,7], low = 2, high = 6)) | [
"merlintiger@hotmail.com"
] | merlintiger@hotmail.com |
1c6d5333b3330a919f394f03370a64f6476f1f2a | 8a2657f276e3b9c63c8bd0ce612237d9d66d80ae | /updater/update/ratelimit.py | f724af0aaa79792c4cd22f016025f032f8255a1c | [
"BSD-3-Clause"
] | permissive | codl/status.chitter.xyz | 25d46d5f3eb1904c25492f5374d6d0aa9ad2f3d6 | 034d04df05e2741507c329f36d427b0e4e4c7585 | refs/heads/master | 2023-05-14T21:17:49.797516 | 2022-02-03T14:38:17 | 2022-02-03T14:41:38 | 131,777,102 | 1 | 0 | BSD-3-Clause | 2023-05-01T20:20:43 | 2018-05-02T00:23:44 | JavaScript | UTF-8 | Python | false | false | 1,504 | py | from redis import StrictRedis as Redis
from pathlib import Path
import hashlib
import time
lua_script_path = Path(__file__).parent / 'ratelimit.lua'
with open(lua_script_path) as f:
LUA_SCRIPT = f.read()
del lua_script_path # don't want it polluting the module
class RateLimit(object):
def __init__(self,
redis_url='redis://',
redis_key_prefix='ratelimit',
bucket_size=50,
bucket_period=30):
self.redis = Redis.from_url(redis_url)
self.script = self.redis.register_script(LUA_SCRIPT)
self.redis_key_prefix = redis_key_prefix
self.bucket_size = bucket_size
self.bucket_period = bucket_period
def _exec(self, identifier, clear=False):
identifier_h = hashlib.blake2s(
identifier.encode('utf-8'), digest_size=6).hexdigest()
token_count_key = "{}:{}:count".format(self.redis_key_prefix,
identifier_h)
token_last_add_key = "{}:{}:last-add".format(self.redis_key_prefix,
identifier_h)
keys = [token_count_key, token_last_add_key]
argv = [self.bucket_size, self.bucket_period, int(time.time())]
if clear:
argv += [True]
return self.script(keys, argv)
def hit(self, identifier):
return int(self._exec(identifier))
def clear(self, identifier):
self._exec(identifier, clear=True)
| [
"codl@codl.fr"
] | codl@codl.fr |
d909f630eb3400d202f3924c5cbbe3919adb6f2c | ae65873c3584cef7139066b224daad04410af6d2 | /CodeTest.py | 2237c834df11974a47ef8e96969b150e0100c6cb | [] | no_license | rajatkashyap/Python | 2240c7472d07803c460c7a55d570e20694b694f9 | f74c85c65b0e209a5f7ab25b653d42835222faaf | refs/heads/master | 2022-06-25T19:20:52.847498 | 2022-06-08T14:40:45 | 2022-06-08T14:40:45 | 145,714,257 | 0 | 0 | null | 2022-04-25T00:18:37 | 2018-08-22T13:39:14 | Python | UTF-8 | Python | false | false | 620 | py | ## input no of elements
# input elements
# input threshold
#3 4 5 6 t -10
n=raw_input("Enter no of elements:")
a=raw_input("Enter elements:")
t=int(raw_input("Enter threshold:"))
elements=a.split()
print elements
sum=0
maxlist=[]
for x in range(0,len(elements)):
sum=0
for y in range(x, len(elements)):
if (sum + int(elements[y]) < t):
sum+=int(elements[y])
if (y==len(elements)-1):
maxlist.append(sum)
else:
maxlist.append(sum)
break
if(len(maxlist)==0): print 0
else: print "Max is:",max(maxlist)
| [
"rajatkashyap@Rajats-MBP.T-mobile.com"
] | rajatkashyap@Rajats-MBP.T-mobile.com |
667813317af2bd29df762c292eef9962fdee11a2 | d7d4df5f6db160cb7d090dd761aa43363eeb3351 | /Example/main_ev_nissan_leaf.py | 362df677c199363423a467061810958bc216b547 | [] | no_license | ximitiejiang/EVCable | 4fd9bb0a45e02f22faea80a54e09e2c21656f8c4 | 19959ea0eb2293107edc1953797bebe5c91bea1c | refs/heads/master | 2020-04-14T19:15:45.621049 | 2019-01-06T05:39:48 | 2019-01-06T05:39:48 | 164,051,675 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 1,763 | py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 4 22:58:22 2019
@author: suliang
"""
import os,sys
from EVCable import models
from importlib import import_module
from addict import Dict
class ConfigDict(Dict): # 可用于字典的便捷获取,并且适用于嵌套字典
def __init__(self, cfg_dict):
super().__init__()
self.cfg_dict = cfg_dict
# def __getattr__(self, name):
# value = super().__getattr__(name)
# return value
class Config():
pass
def main():
obj_type = 'Motor'
obj_type = getattr(models, obj_type)
motor = obj_type()
# 尝试实现Config功能
path = '../EVCable/configs/cfg_ev_nissan_leaf.py'
path = os.path.abspath(path)
# 加载dir
sys.path.insert(0, os.path.dirname(path)) # 不能带地址?不能带.py?
# 导入module
cfg = import_module(os.path.basename(path)[:-3])
# 去除dir
sys.path.pop(0)
print(cfg.run_config)
print(cfg.vehicle)
# print(cfg.battery) # battery是嵌套在内层的dict,不能识别
# cfg已经可以按属性访问了,但还是不够方便:不能识别嵌套的dict,也不能iter,也不能切片
# 解决办法是放到addict库的Dict类中
_cfg_dict = {
name: value
for name, value in cfg.__dict__.items() #__dict__存储对象的属性
if not name.startswith('__') #获得属性要么切片要么从__dict__去找
}
cfg_dict = Dict(_cfg_dict) # 字典数据转换为字典对象
print(cfg_dict.vehicle.type) # 调用字典对象的__getattr__()方法
print(cfg_dict.vehicle.battery)
if __name__=='__main__':
main() | [
"ximitiejiang@163.com"
] | ximitiejiang@163.com |
1ac29adf7a5a87fb932f4279d3b9685c0d7af77a | e70374ec1a1cb7a3a117780fabfbb6c16a111f33 | /setup.py | c2ed70ad479a1c296224ae1072382aedfaa89bad | [
"MIT"
] | permissive | smaggs/silica | 89bddd6b56a10fe6d6ea01bdf70d0faf29208e5f | f7f0a4cdcea1cd4c3c6b58e85aa26bc8152c5960 | refs/heads/master | 2021-01-17T21:46:38.955961 | 2016-06-10T01:26:07 | 2016-06-10T01:26:07 | 61,233,431 | 0 | 0 | null | 2016-06-15T19:02:41 | 2016-06-15T19:02:40 | null | UTF-8 | Python | false | false | 2,157 | py | """
The MIT License (MIT)
Copyright (c) 2016 Zagaran, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@author: Zags (Benjamin Zagorsky)
"""
import sys
from setuptools import setup, find_packages
if sys.version < '2.5':
print "ERROR: python version 2.5 or higher is required"
sys.exit(1)
setup(
name = "silica",
version = "0.0.1",
packages = find_packages(),
zip_safe = False,
include_package_data = True,
author = "Zagaran, Inc.",
author_email = "zags at zagaran.com",
description = "An automation layer between frontend and backend code. Currently supports Django and Angular.",
license = "MIT",
keywords = "django angular interface",
url = "https://zagaran.com",
install_requires = ["django >= 1.9"],
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: MIT License",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Operating System :: POSIX",
"Programming Language :: Python",
"Topic :: Database",
],
)
| [
"iamzags@gmail.com"
] | iamzags@gmail.com |
bba29333945223175b7565aeacc4cf5303e67b15 | ff81a9d7880f1b85a1dc19d5eba5ac72d7179c86 | /pychron/core/helpers/formatting.py | c75df90da927cdb7c8941b04ce060cc06cb1483d | [
"Apache-2.0"
] | permissive | UManPychron/pychron | 2fb7e479a9f492423c0f458c70102c499e1062c4 | b84c9fd70072f9cbda30abe2c471e64fe3dd75d8 | refs/heads/develop | 2022-12-03T23:32:45.579326 | 2020-01-29T19:02:20 | 2020-01-29T19:02:20 | 36,100,637 | 0 | 0 | null | 2015-05-23T00:10:06 | 2015-05-23T00:10:05 | null | UTF-8 | Python | false | false | 3,047 | py | # ===============================================================================
# Copyright 2012 Jake Ross
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================
# ============= enthought library imports =======================
# ============= standard library imports ========================
import math
from functools import partial
# ============= local library imports ==========================
def uformat_percent_error(u, *args, **kw):
from uncertainties import std_dev, nominal_value
return format_percent_error(nominal_value(u), std_dev(u), *args, **kw)
def format_percent_error(v, e, n=2, include_percent_sign=False):
p = calc_percent_error(v, e)
if not p == 'NaN':
sigpee = '{{:0.{}f}}'.format(n).format(p)
if include_percent_sign:
sigpee = '{}%'.format(sigpee)
else:
sigpee = 'NaN'
return sigpee
def calc_percent_error(v, e, scale=100):
try:
return abs(e / v * scale)
except (ZeroDivisionError, TypeError):
return 'NaN'
def errorfmt(v, e):
pe = format_percent_error(v, e)
return '{} ({}%)'.format(floatfmt(e), pe)
def standard_sigfigsfmt(v, e):
sf = 0
if abs(e) < 1:
sf = math.ceil((abs(math.log10(e))))
fmt = '{{:0.{}f}}'.format(sf)
return fmt.format(v), fmt.format(e)
def floatfmt(f, n=4, s=4, max_width=None, default='NaN', use_scientific=False):
"""
f: value to format
n: number of sig figs
use scientific notation
if f<10^-n (e.g n=#.## f=0.00001)
or
f>10^(s+1) (e.g s=### f=3001)
"""
if isinstance(f, str):
return f
if f is None:
return default
absf = abs(f)
if absf < 1e-20:
v = '0.0'
else:
if absf < math.pow(10, -n) or absf > math.pow(10, s + 1):
if use_scientific:
fmt = '{{:0.{}E}}'.format(s)
else:
if absf < math.pow(10, s + 1):
# f = Decimal(f)
# n = int(math.ceil(abs(math.log10(absf))))
n = int(round(abs(math.log10(absf))))
fmt = '{{:0.{}f}}'.format(n)
else:
fmt = '{{:0.{}f}}'.format(n)
v = fmt.format(f)
if max_width:
if len(v) > max_width:
v = v[:max_width]
return v
def pfloatfmt(**kw):
return partial(floatfmt, **kw)
# ============= EOF =============================================
| [
"jirhiker@gmail.com"
] | jirhiker@gmail.com |
68e01c21b8b43dc3c2a111b20661ff326b70db45 | d16fd8e182fb2e0997166c47432ff6dbefde3079 | /ibm_mq/tests/test_ibm_mq.py | 393f6354a99ec5de42a809556a9778a62c2afae4 | [] | permissive | CIBailey/integrations-core | 501345e4c9c164413929f61eeb27aaf948c9e43a | 2fe90fb044ff3b5db149407b5682cf2b5e0774bf | refs/heads/master | 2020-04-30T19:20:04.294666 | 2019-03-21T18:31:34 | 2019-03-21T18:31:34 | 177,035,275 | 1 | 0 | BSD-3-Clause | 2019-03-21T22:50:12 | 2019-03-21T22:50:12 | null | UTF-8 | Python | false | false | 2,774 | py | # (C) Datadog, Inc. 2018
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import logging
import pytest
from datadog_checks.ibm_mq import IbmMqCheck
log = logging.getLogger(__file__)
METRICS = [
'ibm_mq.queue.service_interval',
'ibm_mq.queue.inhibit_put',
'ibm_mq.queue.depth_low_limit',
'ibm_mq.queue.inhibit_get',
'ibm_mq.queue.harden_get_backout',
'ibm_mq.queue.service_interval_event',
'ibm_mq.queue.trigger_control',
'ibm_mq.queue.usage',
'ibm_mq.queue.scope',
'ibm_mq.queue.type',
'ibm_mq.queue.depth_max',
'ibm_mq.queue.backout_threshold',
'ibm_mq.queue.depth_high_event',
'ibm_mq.queue.depth_low_event',
'ibm_mq.queue.trigger_message_priority',
'ibm_mq.queue.depth_current',
'ibm_mq.queue.depth_max_event',
'ibm_mq.queue.open_input_count',
'ibm_mq.queue.persistence',
'ibm_mq.queue.trigger_depth',
'ibm_mq.queue.max_message_length',
'ibm_mq.queue.depth_high_limit',
'ibm_mq.queue.priority',
'ibm_mq.queue.input_open_option',
'ibm_mq.queue.message_delivery_sequence',
'ibm_mq.queue.retention_interval',
'ibm_mq.queue.open_output_count',
'ibm_mq.queue.trigger_type',
'ibm_mq.queue.depth_percent',
'ibm_mq.queue_manager.dist_lists',
'ibm_mq.queue_manager.max_msg_list',
]
OPTIONAL_METRICS = [
'ibm_mq.queue.max_channels',
'ibm_mq.channel.batch_size',
'ibm_mq.channel.batch_interval',
'ibm_mq.channel.long_retry_count',
'ibm_mq.channel.long_retry_interval',
'ibm_mq.channel.max_message_length',
'ibm_mq.channel.short_retry_count',
]
@pytest.mark.usefixtures("dd_environment")
def test_check(aggregator, instance, seed_data):
check = IbmMqCheck('ibm_mq', {}, {})
check.check(instance)
for metric in METRICS:
aggregator.assert_metric(metric)
for metric in OPTIONAL_METRICS:
aggregator.assert_metric(metric, at_least=0)
aggregator.assert_all_metrics_covered()
@pytest.mark.usefixtures("dd_environment")
def test_check_pattern(aggregator, instance_pattern, seed_data):
check = IbmMqCheck('ibm_mq', {}, {})
check.check(instance_pattern)
for metric in METRICS:
aggregator.assert_metric(metric)
for metric in OPTIONAL_METRICS:
aggregator.assert_metric(metric, at_least=0)
aggregator.assert_all_metrics_covered()
@pytest.mark.usefixtures("dd_environment")
def test_check_all(aggregator, instance_collect_all, seed_data):
check = IbmMqCheck('ibm_mq', {}, {})
check.check(instance_collect_all)
for metric in METRICS:
aggregator.assert_metric(metric)
for metric in OPTIONAL_METRICS:
aggregator.assert_metric(metric, at_least=0)
aggregator.assert_all_metrics_covered()
| [
"noreply@github.com"
] | CIBailey.noreply@github.com |
14805452716dfbf1e0d78d9c5e03cc883ea00a45 | e4610216140a5646e5ac6bb0b4931c198e6bbdd1 | /Day1/ex03.py | 9e64a62158eac2300b715961b2d054af5ce4e4ae | [] | no_license | kayartaya-vinod/2020_SEP_ABB_ADV_PYTHON | ce40e9e6d8664369e4e0540a4809c9579286ca09 | 79a1108ca5b1432df45f7193ea5bc878d93d1d46 | refs/heads/master | 2022-12-27T10:05:53.904914 | 2020-09-30T11:54:17 | 2020-09-30T11:54:17 | 299,226,493 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 1,035 | py | from ex00 import Person
class Employee(Person):
# the inherited __init__ is hidden or overridden by the newly defined __init__
def __init__(self, **kwargs):
# in other OO languages, like c++/Java/C# automatic execution of the
# super/base class constructor takes place.
# in Python, this constructor must make an explicit call to base/super constructor
super().__init__(**kwargs)
# Person.__init__(self, **kwargs)
self.salary = kwargs.get('salary', 35000) # executing the salary.setter function
def __str__(self):
return f'Employee ({super().__str__()}, Salary={self.salary})'
@property
def salary(self): return self.__salary
@salary.setter
def salary(self, value): self.__salary = value # TBD: validation of value
def main():
e1 = Employee(name='John', age=22)
print(f'attributes in e1 are {dir(e1)}')
print(e1) # e1.__str__()
e1.__init__(name='scott', salary=22200)
print(e1)
if __name__ == '__main__':
main()
| [
"kayartaya.vinod@gmail.com"
] | kayartaya.vinod@gmail.com |
54f211040364e5c9d83d6df4722c2fd8d7fc5ab8 | 2e7aaf5367b9555554ae22338b9184c616e3f69e | /fair_coin_toss_experiment.py | c4c8e300762b05824f528c63fb1d4f43293c856d | [
"MIT"
] | permissive | noelevans/sandpit | 413ec8586811dfdb8f31f5a50ba1f72fe4a79307 | e97bd599249be3ed7c9958328e3ded0d51fa1859 | refs/heads/master | 2023-03-10T08:59:27.178057 | 2023-03-06T21:12:54 | 2023-03-06T21:12:54 | 34,741,371 | 1 | 0 | MIT | 2021-03-20T01:25:00 | 2015-04-28T16:12:01 | HTML | UTF-8 | Python | false | false | 859 | py | from __future__ import division
import numpy as np
""" Implementing a slide from a PyCon talk, Statistics for Hackers.
https://speakerdeck.com/pycon2016/jake-vanderplas-statistics-for-hackers
The question posed:
"You toss a coin 30 times and see 22 heads. Is it a fair coin"
The key line of interest is the the if statement. Notice that we count the
test as an example of the criteria if 22 heads *or more* are rolled. Not
just 22 exactly.
"""
def main():
twenty_twos = 0
tests = 100000
for _ in range(tests):
run = np.random.randint(1+1, size=30)
if run.sum() >= 22: # 22
twenty_twos += 1
print(twenty_twos / tests)
print('Reject the null hypothesis; is the coin biased?')
print('Yes!' if twenty_twos / tests < 0.05 else 'No!')
if __name__ == '__main__':
main()
| [
"noelevans@gmail.com"
] | noelevans@gmail.com |
7dd335f4f20890e829af77798c5e171300f810bd | 3c3d9cbad17627316c18b28d894f4225b17e7cf4 | /tools/builtins_templates/render.tmpl.pyi | cfa8c7e31b467ca94df42fb4c5742c30a515d587 | [
"MIT",
"CC-BY-3.0"
] | permissive | WilliamTambellini/godot-python | 77ce74c0366b7ceaa8fd0aa4e0716238cf1ae59b | 74ba482c6f06e6b8eae15386e6e21c703acdf102 | refs/heads/master | 2022-11-23T15:02:05.310388 | 2020-07-25T18:47:18 | 2020-07-25T18:47:18 | 282,775,578 | 0 | 0 | NOASSERTION | 2020-07-27T02:31:24 | 2020-07-27T02:31:23 | null | UTF-8 | Python | false | false | 1,429 | pyi | {#- `render_target` must be defined by calling context -#}
{% set py_type = render_target_to_py_type(render_target) %}
{% set gd_type = py_to_gd_type(py_type) %}
{#- Define rendering macros -#}
{% macro render_method(pyname, return_type=None, args=(), gdname=None, gdapi="10") %}
{% set gdname = gdname or pyname %}
{% set return_type = cook_return_type(return_type) %}
{% set args = cook_args(args) %}
def {{ pyname }}(self{%- if args -%},{%- endif -%}
{%- for arg in args %}
{{ arg["name"] }}: {{ arg["py_type"] }}
{%- if not arg["is_base_type"] and arg["gd_type"] != "godot_variant" %}
not None
{%- endif -%}
,
{%- endfor -%}
) -> {{ return_type["signature_type"] }}: ...
{% endmacro %}
{% macro render_operator_eq() %}
def __eq__(self, other) -> bool: ...
{% endmacro %}
{% macro render_operator_ne() %}
def __ne__(self, other) -> bool: ...
{% endmacro %}
{% macro render_operator_lt() %}
def __lt__(self, other) -> bool: ...
{% endmacro %}
{% macro render_property(pyname, type, gdname_getter, gdname_setter=None) %}
{{ pyname }}: {{ type }}
{% endmacro %}
{#- Overwrite blocks to be ignored -#}
{% block python_defs %}
pass
{% endblock %}
{% block pxd_header %}{% endblock %}
{% block pyx_header %}{% endblock %}
{% block python_consts %}{% endblock %}
{% block cdef_attributes %}{% endblock %}
{#- Now the template will be generated with the context -#}
{% extends render_target_to_template(render_target) %}
| [
"emmanuel.leblond@gmail.com"
] | emmanuel.leblond@gmail.com |
365807961d027fee5bce6f43d0db5c9f20b67479 | 4ccff4c78aac4ad934fce42637f24829bdf26be7 | /icml/master_tree.py | 83207f7cb09efe97bf1acaa9c2c4dd49d94f5703 | [
"MIT"
] | permissive | islamazhar/trees | 185ddc67f1935149414d6ae12b82205213659ad6 | 502565c5bf02503c7bece09cddd93f9368da02c3 | refs/heads/master | 2022-11-16T12:03:55.299111 | 2020-07-19T13:45:10 | 2020-07-19T13:45:10 | 268,391,749 | 0 | 0 | MIT | 2020-06-01T00:51:28 | 2020-06-01T00:51:27 | null | UTF-8 | Python | false | false | 977 | py | import numpy as np
from trees import Tree, TreeNode, TreeLeaf
import cPickle as pickle
def make_master(X, y, name):
if name == 'mnist' or name == 'iris' or name == '20news':
return make_class_tree(X, y)
if name == 'zoo':
with open('data/zoo/zoo2.tree', 'rb') as fp:
tree = pickle.load(fp)
return tree
def make_class_tree(X, y):
tree = Tree()
tree.root = TreeNode()
C = np.unique(y)
nodes = {c: TreeNode() for c in C}
for i, c in enumerate(y):
node = nodes[c]
leaf = TreeLeaf(i)
node.add_child(leaf)
for node in nodes.values():
tree.root.add_child(node)
return tree
if __name__ == "__main__":
from trees.data import load
from util import plot_tree
mnist = load('mnist')
X, y = mnist.X, mnist.y.astype(np.int)
idx = np.random.permutation(xrange(X.shape[0]))[:100]
X = X[idx]
y = y[idx]
tree = make_master(X, y, 'mnist')
plot_tree(tree)
| [
"sharad.vikram@gmail.com"
] | sharad.vikram@gmail.com |
75dce560bda8c932b19b6dee9dc2bb62e480d742 | ca42e62ce157095ace5fbaec0bf261a4fb13aa6a | /edivorce/apps/core/views/pdf.py | e5942b9fac102fc6004dcfef11301e48b7edcd0b | [
"Apache-2.0"
] | permissive | ronald-rgr/ai-chatbot-smartguide | 58f1e7c76b00248923f5fe85f87c318b45e38836 | c9c830feb6b66c2e362f8fb5d147ef0c4f4a08cf | refs/heads/master | 2021-04-18T03:15:23.720397 | 2020-03-23T17:55:47 | 2020-03-23T17:55:47 | 249,500,344 | 0 | 0 | Apache-2.0 | 2021-04-16T20:45:28 | 2020-03-23T17:35:37 | Python | UTF-8 | Python | false | false | 3,392 | py | """ Views for generated forms """
import json
from django.conf import settings
from django.http import HttpResponse
from django.template.loader import render_to_string
import requests
from ..decorators import bceid_required
from ..utils.derived import get_derived_data
from ..utils.user_response import get_responses_from_db
EXHIBITS = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ'[::-1])
@bceid_required
def form(request, form_number):
""" View for rendering PDF's and previews """
responses = get_responses_from_db(request.user)
if (form_number == '1' or form_number.startswith('37') or
form_number.startswith('38')):
# Add an array of children that includes blanks for possible children
under = int(responses.get('number_children_under_19') or 0)
over = int(responses.get('number_children_under_19') or 0)
actual = json.loads(responses.get('claimant_children', '[]'))
total = len(actual)
responses['children'] = [actual[i] if i < total else {}
for i in range(0, max(under + over, total))]
if form_number == "37":
responses["which_claimant"] = 'both'
elif form_number == "37_claimant1":
form_number = "37"
responses = __add_claimant_info(responses, '_you')
responses['which_claimant'] = 'Claimant 1'
elif form_number == '37_claimant2':
form_number = '37'
responses = __add_claimant_info(responses, '_spouse')
responses['which_claimant'] = 'Claimant 2'
if form_number == "38":
responses["which_claimant"] = 'both'
elif form_number == '38_claimant1':
form_number = '38'
responses = __add_claimant_info(responses, '_you')
responses['which_claimant'] = 'Claimant 1'
elif form_number == '38_claimant2':
form_number = '38'
responses = __add_claimant_info(responses, '_spouse')
responses['which_claimant'] = 'Claimant 2'
return __render_form(request, 'form%s' % form_number, {
'css_root': settings.WEASYPRINT_CSS_LOOPBACK,
'responses': responses,
'derived': get_derived_data(responses),
'exhibits': EXHIBITS[:],
})
def __render_form(request, form_name, context):
output_as_html = request.GET.get('html', None) is not None
if output_as_html:
context['css_root'] = settings.FORCE_SCRIPT_NAME[:-1]
# render to form as HTML
rendered_html = render_to_string('pdf/' + form_name + '.html',
context=context, request=request)
# if '?html' is in the querystring, then return the plain html
if output_as_html:
return HttpResponse(rendered_html)
# post the html to the weasyprint microservice
url = settings.WEASYPRINT_URL + '/pdf?filename=' + form_name + '.pdf'
pdf = requests.post(url, data=rendered_html.encode('utf-8'))
# return the response as a pdf
response = HttpResponse(pdf, content_type='application/pdf')
response['Content-Disposition'] = 'inline;filename=' + form_name + '.pdf'
return response
def __add_claimant_info(responses, claimant):
claimant_info = {}
for key in responses:
if key.endswith(claimant):
claimant_key = key.replace(claimant, '_claimant')
claimant_info[claimant_key] = responses[key]
responses.update(claimant_info)
return responses
| [
"ronald.garcia@gmail.com"
] | ronald.garcia@gmail.com |
131d6d0f90195feb8309fe3d5371985ceac32b40 | 31e141e8929a52ae248eb020f5a769b73d6f36d8 | /lino/modlib/checkdata/fixtures/checkdata.py | 825dc20c61e076973facbd427bdb8038062b21d8 | [
"BSD-2-Clause"
] | permissive | NewRGB/lino | e07e1bb9a6c25103ac9eda9b09de36afd4e6ecbc | 43799e42107169ff173d3b8bc0324d5773471499 | refs/heads/master | 2020-09-09T18:59:15.996197 | 2019-11-12T04:50:52 | 2019-11-12T04:50:52 | 221,534,233 | 1 | 0 | BSD-2-Clause | 2019-11-13T19:20:02 | 2019-11-13T19:20:01 | null | UTF-8 | Python | false | false | 299 | py | # -*- coding: UTF-8 -*-
# Copyright 2015 Rumma & Ko Ltd
# License: BSD (see file COPYING for details)
"""Runs the :manage:`checkdata` management command with `--fix`
option.
"""
from django.core.management import call_command
def objects():
call_command('checkdata', fix=True)
return []
| [
"luc.saffre@gmail.com"
] | luc.saffre@gmail.com |
3283d2ba7e9fbf4a897ed18e7e8bc8ec4d73b48f | 2dde58651cf409ad28d1b9b9218a53a17fcacb26 | /convokit/model/utterance.py | 0180e3aca18bab705234622b958c0ba68692ee2a | [
"MIT"
] | permissive | KatyBlumer/Cornell-Conversational-Analysis-Toolkit | 34bae043c4a5680d508af69ce16801a2143a81f1 | 086a6ea25ada45ad70c43e01ec9f82e8dbfa16e7 | refs/heads/master | 2020-07-22T11:05:29.358854 | 2020-02-14T03:41:18 | 2020-02-14T03:41:18 | 207,177,918 | 0 | 0 | MIT | 2019-09-08T21:49:09 | 2019-09-08T21:49:09 | null | UTF-8 | Python | false | false | 2,653 | py | from typing import Dict, List, Collection, Hashable, Callable, Set, Generator, Tuple, Optional, ValuesView
from .user import User
class Utterance:
"""Represents a single utterance in the dataset.
:param id: the unique id of the utterance. Can be any hashable type.
:param user: the user giving the utterance.
:param root: the id of the root utterance of the conversation.
:param reply_to: id of the utterance this was a reply to.
:param timestamp: timestamp of the utterance. Can be any
comparable type.
:param text: text of the utterance.
:type text: str
:ivar id: the unique id of the utterance.
:ivar user: the user giving the utterance.
:ivar root: the id of the root utterance of the conversation.
:ivar reply_to: id of the utterance this was a reply to.
:ivar timestamp: timestamp of the utterance.
:ivar text: text of the utterance.
"""
def __init__(self, id: Optional[Hashable]=None, user: Optional[User]=None,
root: Optional[Hashable]=None, reply_to: Optional[Hashable]=None,
timestamp: Optional[int]=None, text: Optional[str]=None,
meta: Optional[Dict]=None):
self.id = id
self.user = user
self.root = root
self.reply_to = reply_to
self.timestamp = timestamp
self.text = text
self.meta = meta if meta is not None else {}
def get(self, key: str):
if key == "id":
return self.id
elif key == "user":
return self.user
elif key == "root":
return self.root
elif key == "reply_to":
return self.reply_to
elif key == "timestamp":
return self.timestamp
elif key == "text":
return self.text
elif key == "meta":
return self.meta
# def copy(self):
# """
# :return: A duplicate of this Utterance with the same data and metadata
# """
# return Utterance(id=self.id,
# user=self.user,
# root=self.root,
# reply_to=self.reply_to,
# timestamp=self.timestamp,
# text=self.text,
# meta=self.meta.copy())
def add_meta(self, key: Hashable, value) -> None:
"""
Add a key-value pair to the Utterance metadata
:return: None
"""
self.meta[key] = value
def __eq__(self, other):
return self.__dict__ == other.__dict__
def __repr__(self):
return "Utterance(" + str(self.__dict__) + ")"
| [
"calebchiam@gmail.com"
] | calebchiam@gmail.com |
99dfcd1c549667547af246b081b2db3b89f1c7d7 | b120f8ec437709571dd363b5750835db6e6d4e32 | /twitter/__init__.py | 4f098cc9981f61bdabf54b21e136a9698206e5f7 | [] | no_license | pipoteam/pipobot-modules | 2b3e61542e95c0144118e56a4a6817e48d0c1822 | dcc6ec037723633f8fc314c6b7e314185e29860a | refs/heads/master | 2022-04-27T00:50:56.805541 | 2022-03-13T19:34:53 | 2022-03-13T19:34:53 | 4,283,568 | 3 | 6 | null | 2017-05-15T09:47:49 | 2012-05-10T11:22:35 | Python | UTF-8 | Python | false | false | 3,988 | py | # -*- coding: utf-8 -*-
from pipobot.lib.modules import AsyncModule, Pasteque
from pipobot.lib.utils import unescape
from twython import Twython, TwythonError
from .model import LastTweets, Tweets
URL = 'https://twitter.com'
RT = 'retweeted_status'
REPLY_NAME = 'in_reply_to_screen_name'
REPLY_TWEET = 'in_reply_to_status_id_str'
def user_url(user):
return '<a href="%s/%s">%s</a>' % (URL, user, user)
class Twitter(AsyncModule):
"""A module to follow tweets form some users"""
_config = (("users", list, []), ("app_key", str, ""), ("app_secret", str, ""),
("avoid_rt", bool, True), ("shy_start", bool, True), ("max_errors", int, 3))
def __init__(self, bot):
AsyncModule.__init__(self,
bot,
name="twitter",
desc="Displays tweets",
delay=60)
for user in self.users:
last = self.bot.session.query(LastTweets).order_by(LastTweets.last.desc()).first()
last_id = last.last if last is not None else 0
if not self.bot.session.query(LastTweets).filter(LastTweets.user == user).first():
self.bot.session.add(LastTweets(user=user, last=last_id))
self.bot.session.commit()
token = Twython(self.app_key, self.app_secret, oauth_version=2).obtain_access_token()
self.twitter = Twython(self.app_key, access_token=token)
self.err = 0
if self.shy_start:
self.action(say=False)
def action(self, say=True):
tweets = set()
def already_said(id):
if id in tweets:
return True
tweets.add(id)
q = self.bot.session.query(Tweets).filter(Tweets.id == id)
return self.bot.session.query(q.exists()).scalar()
for user in self.users:
last_tweet = self.bot.session.query(LastTweets).filter(LastTweets.user == user).first()
try:
timeline = self.twitter.get_user_timeline(screen_name=user)
except TwythonError as err:
if self.err >= self.max_errors:
raise Pasteque("TWITTER IS DOWN OMG OMG OMG\n%s" % err)
self.err += 1
return
self.err = 0
for tweet in timeline:
if tweet['id'] <= last_tweet.last:
break
if say and not (self.avoid_rt and RT in tweet and already_said(tweet[RT]['id'])):
text = tweet['text']
if RT in tweet:
fmt = u'Tweet de %s retweeté par %s : '
initial = tweet[RT][u'user'][u'screen_name']
fmt_text = fmt % (initial, user)
fmt_html = fmt % (user_url(initial), user_url(user))
text = tweet[RT]['text']
elif REPLY_NAME in tweet and tweet[REPLY_NAME] is not None and tweet[REPLY_TWEET] is not None:
fmt = u'Tweet de %s en réponse à %s : '
url_text = '%s/%s/status/%s' % (URL, tweet[REPLY_NAME], tweet[REPLY_TWEET])
url_html = '<a href="%s">%s</a>' % (url_text, tweet[REPLY_NAME])
fmt_text = fmt % (user, url_text)
fmt_html = fmt % (user_url(user), url_html)
else:
fmt = u'Tweet de %s : '
fmt_text = fmt % user
fmt_html = fmt % user_url(user)
self.bot.say({'text': fmt_text + unescape(text),
'xhtml': fmt_html + Twython.html_for_tweet(tweet)})
tweets.add(tweet['id'])
if timeline:
last_tweet.last = timeline[0]['id']
for tweet in tweets:
self.bot.session.merge(Tweets(id=tweet))
self.bot.session.commit()
| [
"guilhem.saurel@gmail.com"
] | guilhem.saurel@gmail.com |
57f671e63cea9812f85acdc16e062023c06efa55 | 10ca532599d96032aba24cfb2cf542407b0d2389 | /pylearn2/scripts/icml_2013_wrepl/black_box/learn_zca.py | 8f5aceaee06bd48f2ff2c7aba91f2c0ee7cfd1e1 | [
"BSD-3-Clause"
] | permissive | Coderx7/pylearn2 | a748a522e115c86611ab8a476075f4a9c47c5fac | 96edb376ced1b828962c749240059903686da549 | refs/heads/master | 2020-05-29T11:37:45.469205 | 2017-02-14T19:22:22 | 2017-02-14T19:22:22 | 66,489,783 | 1 | 0 | BSD-3-Clause | 2020-02-03T05:18:32 | 2016-08-24T18:34:44 | Python | UTF-8 | Python | false | false | 237 | py | from pylearn2.datasets.preprocessing import ZCA
from pylearn2.utils import serial
from black_box_dataset import BlackBoxDataset
extra = BlackBoxDataset('extra')
zca = ZCA(filter_bias=.1)
zca.fit(extra.X)
serial.save('zca.pkl', zca)
| [
"goodfellow.ian@gmail.com"
] | goodfellow.ian@gmail.com |
856a9964bbccb127acdd0865de509dd26a2b556a | 4a76ac7ad1aaeec44729ab6d5b121b1cae0d910c | /Week 1/SalesByMatch.py | 4b2ca73d4288dcf2642a84b22826b3fbd29d0e14 | [] | no_license | kalmad99/CompetitiveProgramming | 2d825e839faa9e13ef43dbb45498bd3eef6723ab | 6cbb1f12f7670d0016fa2af8f2dd597d9123070d | refs/heads/main | 2023-03-25T20:18:23.389396 | 2021-03-24T21:36:52 | 2021-03-24T21:36:52 | 325,816,614 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 670 | py | # Complete the sockMerchant function below.
# 9
# 10 20 20 10 10 30 50 10 20
import os
def sockMerchant(n, ar):
emptyl = []
result = 0
count = 0
for i in ar:
if i in emptyl:
continue
else:
emptyl.append(i)
for j in emptyl:
count = ar.count(j)
if count%2==0:
result += count/2
else:
result += count//2
return int(result)
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
n = int(input())
ar = list(map(int, input().rstrip().split()))
result = sockMerchant(n, ar)
fptr.write(str(result) + '\n')
fptr.close()
| [
"kalemesfin12@gmail.com"
] | kalemesfin12@gmail.com |
166c74052f4fdefdbd33eb3e69f815e776e5218b | 83de24182a7af33c43ee340b57755e73275149ae | /aliyun-python-sdk-cdn/aliyunsdkcdn/request/v20180510/CreateCdnDeliverTaskRequest.py | c1172c6f8e8f3ba180a7ac69b9972bc493a9d39a | [
"Apache-2.0"
] | permissive | aliyun/aliyun-openapi-python-sdk | 4436ca6c57190ceadbc80f0b1c35b1ab13c00c7f | 83fd547946fd6772cf26f338d9653f4316c81d3c | refs/heads/master | 2023-08-04T12:32:57.028821 | 2023-08-04T06:00:29 | 2023-08-04T06:00:29 | 39,558,861 | 1,080 | 721 | NOASSERTION | 2023-09-14T08:51:06 | 2015-07-23T09:39:45 | Python | UTF-8 | Python | false | false | 2,142 | py | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
from aliyunsdkcore.request import RpcRequest
from aliyunsdkcdn.endpoint import endpoint_data
class CreateCdnDeliverTaskRequest(RpcRequest):
def __init__(self):
RpcRequest.__init__(self, 'Cdn', '2018-05-10', 'CreateCdnDeliverTask')
self.set_method('POST')
if hasattr(self, "endpoint_map"):
setattr(self, "endpoint_map", endpoint_data.getEndpointMap())
if hasattr(self, "endpoint_regional"):
setattr(self, "endpoint_regional", endpoint_data.getEndpointRegional())
def get_Reports(self): # String
return self.get_body_params().get('Reports')
def set_Reports(self, Reports): # String
self.add_body_params('Reports', Reports)
def get_Schedule(self): # String
return self.get_body_params().get('Schedule')
def set_Schedule(self, Schedule): # String
self.add_body_params('Schedule', Schedule)
def get_Name(self): # String
return self.get_body_params().get('Name')
def set_Name(self, Name): # String
self.add_body_params('Name', Name)
def get_DomainName(self): # String
return self.get_body_params().get('DomainName')
def set_DomainName(self, DomainName): # String
self.add_body_params('DomainName', DomainName)
def get_Deliver(self): # String
return self.get_body_params().get('Deliver')
def set_Deliver(self, Deliver): # String
self.add_body_params('Deliver', Deliver)
| [
"sdk-team@alibabacloud.com"
] | sdk-team@alibabacloud.com |
84b81d5d7f7cb356e4f0b46b571e0a5e4fe4eea9 | 163bbb4e0920dedd5941e3edfb2d8706ba75627d | /Code/CodeRecords/2114/61053/281233.py | 919219fd9ce722f2f5cba1d774979a7bc09062df | [] | no_license | AdamZhouSE/pythonHomework | a25c120b03a158d60aaa9fdc5fb203b1bb377a19 | ffc5606817a666aa6241cfab27364326f5c066ff | refs/heads/master | 2022-11-24T08:05:22.122011 | 2020-07-28T16:21:24 | 2020-07-28T16:21:24 | 259,576,640 | 2 | 1 | null | null | null | null | UTF-8 | Python | false | false | 368 | py | def minSum(n):
lst = []
lst.append(0)
for i in range(1,n+1):
for j in range(1,i+1):
if i - j**2 >= 0:
if j == 1:
lst.append(lst[i-1]+1)
else:
lst[i] = min(lst[i],lst[i-j**2]+1)
return lst[n]
if __name__ == "__main__":
n = int(input())
print(minSum(n)) | [
"1069583789@qq.com"
] | 1069583789@qq.com |
fb566f65414eca423c9aa729951f0a5a47e2a081 | 72167bc16ffc678e5270dc83000013158d69aaf1 | /Chapter05/5.4.3.py | b2c941ecbc32e30f8281eeceff08a270f27d430f | [] | no_license | OSYouth/PythonCrashCourse | 6e37b53b5a83705db3366543b9ab80ef5dd4e3b7 | bbb88a087f489baa535d2b1477c08d023ae5b913 | refs/heads/master | 2021-08-22T17:35:27.702205 | 2021-04-16T13:01:16 | 2021-04-16T13:01:16 | 249,334,439 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 428 | py | available_toppings = ['mushrooms', 'olives', 'green peppers', 'pepperoni', 'pineapple', 'extra cheese']
requested_toppings = ['mushrooms', 'french fries', 'extra cheese']
for requested_topping in requested_toppings:
if requested_topping in available_toppings:
print("Adding " + requested_topping + ".")
else:
print("Sorry, we don't have " + requested_topping + ".")
print("\nFinished making your pizza!") | [
"benleolee@163.com"
] | benleolee@163.com |
07eae20cb6635e30f8d0e94a525a5b351d928f79 | ee8c4c954b7c1711899b6d2527bdb12b5c79c9be | /assessment2/amazon/run/core/controllers/call.py | e0f9b7714730874a42c41006d2e199a47dc7723c | [] | no_license | sqlconsult/byte | 02ac9899aebea4475614969b594bfe2992ffe29a | 548f6cb5038e927b54adca29caf02c981fdcecfc | refs/heads/master | 2021-01-25T14:45:42.120220 | 2018-08-11T23:45:31 | 2018-08-11T23:45:31 | 117,135,069 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 362 | py | #!/usr/bin/env python3
from flask import Blueprint, Flask, render_template, request, url_for
controller = Blueprint('call', __name__, url_prefix='/call')
# @controller.route('/<string:title>', methods=['GET'])
# def lookup(title):
# if title == 'Republic': # TODO 2
# return render_template('republic.html') # TODO 2
# else:
# pass
| [
"sqlconsult@hotmail.com"
] | sqlconsult@hotmail.com |
542bf395f97e2cd0e31c965ff605355d11844823 | 5a9d8c64c6478f3816b63f59f1cdaca73c0848eb | /Base/ex10/zy2_myfac.py | 657a9b0e2b55ce1ba2bb48adc87931f48d69de85 | [] | no_license | wangredfei/nt_py | f68134977e6d1e05cf17cec727644509f084c462 | fedf03c0d52565f588e9b342d1c51df0b6dc2681 | refs/heads/master | 2020-04-08T07:55:08.302589 | 2018-11-23T09:53:48 | 2018-11-23T09:53:48 | null | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 219 | py |
# 2. 给出一个数n,写一个函数myfac来计算n!(n的阶乘)
# n! = 1 * 2 * 3 * ... * n
# print(myfac(5)) # 120
def myfac(n):
N = 1
for i in range(1,n+1):
N *= i
return N
print(myfac(5)) | [
"289498360@qq.com"
] | 289498360@qq.com |
3fdf966b91d3d8fcc8fcb14fcfcbf40710556b46 | 1958631675a1eda1c2c5a018b636cb1117d90d9e | /0x0A-python-inheritance/10-square.py | 8788e4d9e7980b491126277e76078d9cf55b34e0 | [] | no_license | Valinor13/holbertonschool-higher_level_programming | f32d6507546584c3af59e3e8ece345af70a698d6 | 5fad6ea9f28f845820b5a893feb20e83ed3fe7b4 | refs/heads/main | 2023-06-05T21:15:29.774676 | 2021-06-27T23:08:54 | 2021-06-27T23:08:54 | 361,808,582 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 438 | py | #!/usr/bin/python3
"""A module containing the square class inherited from Rectangle"""
Rectangle = __import__('9-rectangle').Rectangle
class Square(Rectangle):
"""A class inherited from rectangle that deals with squares"""
def __init__(self, size):
super().integer_validator("size", size)
self.__size = size
super().__init__(size, size)
def area(self):
return self.__size * self.__size
| [
"jwcalhoun2@gmail.com"
] | jwcalhoun2@gmail.com |
785bc2ace46161ddefd564e79c2b6b21fc34a99e | c6ad3f65da16e714619bb62b27565efc00364c1c | /work-packages/f5500/python/f5500/CiscoIOSXRCryptoMibsIpsecflowmonCfg_ns.py | 881f7c8bb924a008aa386b5a48312eecf1fe3276 | [] | no_license | janlindblad/eantc20 | c0c74a1e6476ca5e5a2906f18472259d8a515b21 | e9051c77de16578c97dcf1f7ecb0a5ef30ad2e68 | refs/heads/master | 2020-12-21T19:09:36.076797 | 2020-03-17T18:17:04 | 2020-03-17T18:17:04 | 236,523,910 | 0 | 3 | null | null | null | null | UTF-8 | Python | false | false | 1,228 | py | #
# BEWARE BEWARE BEWARE BEWARE BEWARE BEWARE BEWARE BEWARE BEWARE
# This file has been auto-generated by the confdc compiler.
# Source: ../load-dir/Cisco-IOS-XR-crypto-mibs-ipsecflowmon-cfg.fxs
# BEWARE BEWARE BEWARE BEWARE BEWARE BEWARE BEWARE BEWARE BEWARE
#
# Autogenerated namespace class for YANG module Cisco-IOS-XR-crypto-mibs-ipsecflowmon-cfg.yang
class ns(object):
hash = 1114965550
id = "_f5500-nc-1.0:f5500-nc-1.0#http://cisco.com/ns/yang/Cisco-IOS-XR-crypto-mibs-ipsecflowmon-cfg"
uri = "_f5500-nc-1.0:f5500-nc-1.0#http://cisco.com/ns/yang/Cisco-IOS-XR-crypto-mibs-ipsecflowmon-cfg"
prefix = "Cisco-IOS-XR-crypto-mibs-ipsecflowmon-cfg"
Cisco_IOS_XR_crypto_mibs_ipsecflowmon_cfg_ip_sec = 1865369357
Cisco_IOS_XR_crypto_mibs_ipsecflowmon_cfg_ip_sec_ = "ip-sec"
Cisco_IOS_XR_crypto_mibs_ipsecflowmon_cfg_tunnel_stop = 516899736
Cisco_IOS_XR_crypto_mibs_ipsecflowmon_cfg_tunnel_stop_ = "tunnel-stop"
Cisco_IOS_XR_crypto_mibs_ipsecflowmon_cfg_tunnel_start = 1619857664
Cisco_IOS_XR_crypto_mibs_ipsecflowmon_cfg_tunnel_start_ = "tunnel-start"
Cisco_IOS_XR_crypto_mibs_ipsecflowmon_cfg_isakmp = 1297549514
Cisco_IOS_XR_crypto_mibs_ipsecflowmon_cfg_isakmp_ = "isakmp"
| [
"jlindbla@cisco.com"
] | jlindbla@cisco.com |
d10e8caa2292cc529759d48213936b44634fb90e | abcf63644ff1f4767f81261f8bc32efb91767771 | /zuoye3/ZUOYE.PY | 8c88abc6faf459d15562fa92e6d67032322f9774 | [] | no_license | Ran-oops/python | cf296711a01c1a01e2794e2310447a5684181f53 | 5ba09234120084f4ea7b13a4945935d38f356dea | refs/heads/master | 2020-11-29T21:18:58.391800 | 2019-12-27T10:52:17 | 2019-12-27T10:52:17 | 230,217,192 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 1,114 | py | import os
os.chdir(r'C:\Users\Acer\Desktop\zuoye3')
print(os.getcwd())
list1=os.listdir(os.getcwd())
print(list1)
while True:
handle_file=input('请输入接下来的操作:m:创建文件;rm:删除文件;n:修改文件名;e:退出\n')
if handle_file=='m':
mk_file=input('请输入需要创建的文件夹名称\n')
os.mkdir(mk_file)
if mk_file in os.listdir(os.getcwd()):
print('创建成功')
elif handle_file=='rm':
rm_file=input('请输入您要删除的文件夹名称:\n')
if rm_file in os.listdir(os.getcwd()):
os.rmdir(rm_file)
if rm_file not in os.listdir(getcwd()):
print('恭喜您,删除成功!')
else:
print('您输入的文件夹不存在!')
elif handle_file=='n':
res=input('请输入需要修改的文件:\n')
if res in os.listdir(getcwd()):
re=input('请输入需要改成的名字!\n')
os.rename(res,re)
if re in os.listdir(os.getcwd()):
print('修改成功!')
else:
print('您输入的文件不存在!')
elif handle_file=='e':
exit()
else:
print('输入有误,请按提示输入内容,谢谢!')
| [
"18291893776@139.com"
] | 18291893776@139.com |
c689ff58ee57c2c81dfde575173f89051306f798 | 3ae62276c9aad8b9612d3073679b5cf3cb695e38 | /easyleetcode/leetcodes/Leetcode_005_Longest_Palindromic_Substring.py | dd29056683ec824c6e618d3d9a6846c6283a2d06 | [
"Apache-2.0"
] | permissive | gongtian1234/easy_leetcode | bc0b33c3c4f61d58a6111d76707903efe0510cb4 | d2b8eb5d2cafc71ee1ca633ce489c1a52bcc39ce | refs/heads/master | 2022-11-16T17:48:33.596752 | 2020-07-13T02:55:03 | 2020-07-13T02:55:03 | null | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 1,499 | py | # 1穷举
class Solution:
def str(self, s):
if not s:
return ''
n = len(s)
logest, left, right = 0, 0, 0
for i in range(0, n):
for j in range(i + 1, n + 1):
substr = s[i:j]
if self.isPalindrome(substr) and len(substr) > logest:
logest = len(substr)
left, right = i, j
return s[left:right]
def isPalindrome(self, s):
if not s:
return False
return s == s[::-1]
class Solution2:
def str(self, s):
if s == None or len(s) == 0:
return s
res = ''
for i in range(len(s)):
# 奇数情况
t = self.pali(s, i, i)
if len(t) > len(res):
res = t
# 偶数情况
t = self.pali(s, i, i + 1)
if len(t) > len(res):
res = t
return res
def pali(self, s, l, r):
# 只要是回文串,就一直扩充
while l >= 0 and r < len(s) and s[l] == s[r]:
l -= 1
r += 1
# l+1 !!
return s[l + 1:r]
print('<iframe src="//player.bilibili.com/player.html?aid=968696647&bvid=BV1Rp4y1U7ag&cid=208409065&page=1" scrolling="no" border="0" frameborder="no" framespacing="0" allowfullscreen="true"> </iframe>')
if __name__ == '__main__':
s = Solution()
# s2 = Solution2()
print(s.str('abcdzdcab'))
# print(s2.str('abcdzdcab111'))
| [
"425776024@qq.com"
] | 425776024@qq.com |
f123fb96b9fc9be0b130cb0616266daca2a4b1f0 | 4791bde7bb7275fc25480fdf0cd81d1a9450a50c | /articles/migrations/0002_article_thumb.py | f990e16292870d560147e2f25f5793b8e00c4c80 | [] | no_license | VinneyJ/RU-I-tech-app | 9692f0681dd704ce52c621b3d080d1a90fbe501b | dd15335f26a35d8e32477e7dd384f3a80351d25d | refs/heads/master | 2020-05-02T21:04:17.773867 | 2019-03-28T13:25:18 | 2019-03-28T13:25:18 | 178,209,692 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 409 | py | # Generated by Django 2.1.7 on 2019-03-07 18:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('articles', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='article',
name='thumb',
field=models.ImageField(blank=True, default='default.png', upload_to=''),
),
]
| [
"vincentjayden49@gmail.com"
] | vincentjayden49@gmail.com |
aea9b526917cfd144e682e610acce9676629ad37 | 3f09e77f169780968eb4bd5dc24b6927ed87dfa2 | /src/Problems/Linked_List_Cycle.py | d954942bb12a57f59ca94bcca0dceb6070ef809a | [] | no_license | zouyuanrenren/Leetcode | ad921836256c31e31cf079cf8e671a8f865c0660 | 188b104b81e6c73792f7c803c0fa025f9413a484 | refs/heads/master | 2020-12-24T16:59:12.464615 | 2015-01-19T21:59:15 | 2015-01-19T21:59:15 | 26,719,111 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 824 | py | '''
Created on 17 Nov 2014
@author: zouyuanrenren
'''
'''
Given a linked list, determine if it has a cycle in it.
Follow up:
Can you solve it without using extra space?
'''
'''
Can be done with two pointers:
1. one fast pointer;
2. one slow pointer;
3. the list has a cycle iff fast == slow at some point
'''
# Definition for singly-linked list.
class ListNode:
def __init__(self, x):
self.val = x
self.next = None
class Solution:
# @param head, a ListNode
# @return a boolean
def hasCycle(self, head):
fast = head
slow = head
if head == None:
return False
while fast != None and fast.next != None:
fast = fast.next.next
slow = slow.next
if fast == slow:
return True
return False | [
"y.ren@abdn.ac.uk"
] | y.ren@abdn.ac.uk |
4ffcca5c272df580b13e18d5d6c875ec77f8e30b | c8f5d69d21ac4df40d79a811dea2e3ad82fb5e04 | /src/stock_list_upd.py | 8985c45bee57d8f3d21e912834f494b47f4fdfdf | [] | no_license | webclinic017/usstock | e71ab18534fd3afc05ab2452578821584750e2b9 | c724f00bc1c5d2a41ee58e037ba0b1b3f0904f70 | refs/heads/master | 2023-08-15T05:22:14.275202 | 2021-10-14T21:19:53 | 2021-10-14T21:19:53 | null | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 1,972 | py | #!/usr/bin/env python
'''
TBD, Wed Jan 30 21:47:38 EST 2019
to automate 1). sp500 ticker selection, 2.) additional ticker price hist update 3. split adj (TBD), 4. dividends adj (TBD), 5. earnings update 6. financials update
Procedure:
1. pull sp500 stock list to [sp500_component]
2. pull available stock list to [iex_company_temp]
3. add additional new sp500 list to [mapping_ticker_cik] via "mapping_ticker_cik.add.upd.sql"
4. check stock status in [mapping_ticker_cik]
update [mapping_ticker_cik] set act_code=0
if act_code=1 is no longer available in [iex_company_temp]
5. pull iex stock "quotes" in daily basis based on [iex_company_temp]
6. pull iex stock "chart" in weekly basis based on [iex_company_temp]
7. check splits, M&A activies daily basis
'''
import sys
import pandas as pd
from pprint import pprint
from _alan_calc import sqlQuery,conn2pgdb,upd_temp2hist
def printerr(s,file=sys.stderr,end='\n'):
file.write(s+end)
dbname='ara';hostname='localhost'
pgDB=conn2pgdb(dbname=dbname,hostname=hostname)
xqr = """select * from (select a.pbdate,a.name,a.close,b.close,(a.close/b.close-1)*100. as pchg from prc_hist_iex a,prc_temp_iex b, (select name,min(pbdate) mndate from prc_temp_iex group by name) as c where a.pbdate=c.mndate and b.pbdate=c.mndate and a.pbdate=b.pbdate and a.name=b.name and a.name=c.name ) as x where abs(pchg)>0.5 ORDER BY abs(pchg)
"""
scLst = sqlQuery(xqr,engine=pgDB)
if len(scLst)>0:
tb_temp='temp_list'
scLst.to_sql(tb_temp,pgDB,index=False,schema='public',if_exists='replace')
xlst = "('{}')".format("','".join(scLst['name']))
#fp=open('stock_list_upd.tmp','w')
#fp.write(scLst.to_csv(index=False,sep='|'))
#fp.close()
printerr(xlst)
# delete entire hist if temp in the earliest is not consistent
xqr = """delete from prc_hist_iex where name in {}""".format(xlst)
printerr(xqr)
pgDB.execute(xqr,pgDB)
# update temp to hist
upd_temp2hist(pgDB,temp='prc_temp_iex',hist='prc_hist_iex',pcol=['name','pbdate'])
| [
"facebook@beyondbond.com"
] | facebook@beyondbond.com |
31ee31ef742d9ac8ad49c4ca2f2a2c422d62dfd0 | e489b2f77b52d33bbf952066b0975485a30ec8f9 | /BootCRUDICApp/urls.py | 26f1cd46f50089a767ac6d5c45fa439ca1cbcf0c | [
"Apache-2.0"
] | permissive | cs-fullstack-2019-spring/django-bootstrapcrud-ic-Kenn-CodeCrew | 9e837b6a4d8f6b637273bcb5478c2ee844b1301e | dd65eda49daf8527d01f96c7b39f3c874f371138 | refs/heads/master | 2020-04-27T18:34:02.209542 | 2019-03-08T20:45:31 | 2019-03-08T20:45:31 | 174,576,966 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 168 | py | from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index'),
path('addMember/', views.addMember, name='addMember'),
] | [
"kenn+git@code-crew.org"
] | kenn+git@code-crew.org |
5a8fa6e8941d07f985b6f4dddff4736e33c5f14c | d2327e4277629ff5c04cfdfb71cdae7209d56fa7 | /sample codes/topic6/py_test6.py | 43b88b93dc59ce1a63f4197fb2a40aeda7050b52 | [] | no_license | tertiarycourses/Full-ROS-Training | 77caeedda216e6e065fec0664a93d66df38ba571 | b9bdb7daf2a08421d163001cb2b22cbfb1221f23 | refs/heads/main | 2023-03-04T09:04:02.432243 | 2021-02-16T15:57:51 | 2021-02-16T15:57:51 | 314,543,129 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 362 | py | #!/usr/bin/env python
import rospy
from std_msgs.msg import Float32
def callback(msg_data):
rospy.loginfo(msg_data)
def listener():
rospy.init_node('iot_sensor')
rospy.Subscriber('temperature',Float32,callback)
rospy.spin()
if __name__ == '__main__':
try:
listener()
except rospy.ROSInterruptException:
rospy.shutdown() | [
"angch@tertiaryinfotech.com"
] | angch@tertiaryinfotech.com |
3ad485aaa42a75f2c082663ae1879b0af554ddba | fbbe424559f64e9a94116a07eaaa555a01b0a7bb | /Keras_tensorflow_nightly/source2.7/markdown/extensions/sane_lists.py | 651b12b257b63a3aa6f281602a59f9a40c8a6c26 | [
"MIT"
] | permissive | ryfeus/lambda-packs | 6544adb4dec19b8e71d75c24d8ed789b785b0369 | cabf6e4f1970dc14302f87414f170de19944bac2 | refs/heads/master | 2022-12-07T16:18:52.475504 | 2022-11-29T13:35:35 | 2022-11-29T13:35:35 | 71,386,735 | 1,283 | 263 | MIT | 2022-11-26T05:02:14 | 2016-10-19T18:22:39 | Python | UTF-8 | Python | false | false | 1,597 | py | """
Sane List Extension for Python-Markdown
=======================================
Modify the behavior of Lists in Python-Markdown to act in a sane manor.
See <https://Python-Markdown.github.io/extensions/sane_lists>
for documentation.
Original code Copyright 2011 [Waylan Limberg](http://achinghead.com)
All changes Copyright 2011-2014 The Python Markdown Project
License: [BSD](http://www.opensource.org/licenses/bsd-license.php)
"""
from __future__ import absolute_import
from __future__ import unicode_literals
from . import Extension
from ..blockprocessors import OListProcessor, UListProcessor
import re
class SaneOListProcessor(OListProcessor):
SIBLING_TAGS = ['ol']
def __init__(self, parser):
super(SaneOListProcessor, self).__init__(parser)
self.CHILD_RE = re.compile(r'^[ ]{0,%d}((\d+\.))[ ]+(.*)' %
(self.tab_length - 1))
class SaneUListProcessor(UListProcessor):
SIBLING_TAGS = ['ul']
def __init__(self, parser):
super(SaneUListProcessor, self).__init__(parser)
self.CHILD_RE = re.compile(r'^[ ]{0,%d}(([*+-]))[ ]+(.*)' %
(self.tab_length - 1))
class SaneListExtension(Extension):
""" Add sane lists to Markdown. """
def extendMarkdown(self, md, md_globals):
""" Override existing Processors. """
md.parser.blockprocessors['olist'] = SaneOListProcessor(md.parser)
md.parser.blockprocessors['ulist'] = SaneUListProcessor(md.parser)
def makeExtension(*args, **kwargs):
return SaneListExtension(*args, **kwargs)
| [
"ryfeus@gmail.com"
] | ryfeus@gmail.com |
9dada075fc6880ae3051f749c69383a9d71ad79e | f4dedea53630c9cbdc6297ae4a7e2a8195fd7691 | /10 Advanced Techniques/21 Dynamic Connectivity.py | 7cca06fb0f10671253d333d96b04477b6777f2fa | [] | no_license | nikkisora/cses_problemset | d089db048444e07e002f131b4323adc9df95b05b | 03160f33e36cdc6d538403357b36bcb015b4dba7 | refs/heads/master | 2023-07-03T10:34:23.487709 | 2021-08-05T21:13:49 | 2021-08-05T21:13:49 | 379,251,540 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 1,243 | py | '''
CSES - Dynamic Connectivity
Time limit: 1.00 s
Memory limit: 512 MB
Consider an undirected graph that consists of n nodes and m edges. There are two types of events that can happen:
A new edge is created between nodes a and b.
An existing edge between nodes a and b is removed.
Your task is to report the number of components after every event.
Input
The first input line has three integers n, m and k: the number of nodes, edges and events.
After this there are m lines describing the edges. Each line has two integers a and b: there is an edge between nodes a and b. There is at most one edge between any pair of nodes.
Then there are k lines describing the events. Each line has the form "t a b" where t is 1 (create a new edge) or 2 (remove an edge). A new edge is always created between two nodes that do not already have an edge between them, and only existing edges can get removed.
Output
Print k+1 integers: first the number of components before the first event, and after this the new number of components after each event.
Constraints
2 <= n <= 10^5
1 <= m,k <= 10^5
1 <= a,b <= n
Example
Input:
5 3 3
1 4
2 3
3 5
1 2 5
2 3 5
1 1 2
Output:
2 2 2 1
''' | [
"32413317+nikkisora@users.noreply.github.com"
] | 32413317+nikkisora@users.noreply.github.com |
4f770d7903cc4c618074e9115637038e89b1a77c | 6a819308924a005aa66475515bd14586b97296ae | /venv/lib/python3.6/site-packages/setuptools/py31compat.py | e80573126c1c9604f492fb04516ad2e619c23349 | [] | no_license | AlexandrTyurikov/my_first_Django_project | a2c655dc295d3904c7688b8f36439ae8229d23d1 | 1a8e4d033c0ff6b1339d78c329f8beca058b019a | refs/heads/master | 2020-05-04T13:20:20.100479 | 2019-05-04T23:41:39 | 2019-05-04T23:41:39 | 179,156,468 | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 1,187 | py | __all__ = ['get_config_vars', 'get_path']
try:
# Python 2.7 or >=3.2
from sysconfig import get_config_vars, get_path
except ImportError:
from distutils.sysconfig import get_config_vars, get_python_lib
def get_path(name):
if name not in ('platlib', 'purelib'):
raise ValueError("Name must be purelib or platlib")
return get_python_lib(name == 'platlib')
try:
# Python >=3.2
from tempfile import TemporaryDirectory
except ImportError:
import shutil
import tempfile
class TemporaryDirectory(object):
"""
Very simple temporary book context manager.
Will try to delete afterward, but will also ignore OS and similar
errors on deletion.
"""
def __init__(self):
self.name = None # Handle mkdtemp raising an exception
self.name = tempfile.mkdtemp()
def __enter__(self):
return self.name
def __exit__(self, exctype, excvalue, exctrace):
try:
shutil.rmtree(self.name, True)
except OSError: # removal errors are not the only possible
pass
self.name = None
| [
"tyur.sh@gmail.com"
] | tyur.sh@gmail.com |
3692dfd4e01349c9d821ab23d96b5c0ced307d96 | f07a42f652f46106dee4749277d41c302e2b7406 | /Data Set/bug-fixing-4/1c6aa5e912cb777ad2a6a9b42097c64e3f0d2f71-<send_message>-bug.py | e08ebe23393d18dd9b4df26cfe0c4d549738a144 | [] | no_license | wsgan001/PyFPattern | e0fe06341cc5d51b3ad0fe29b84098d140ed54d1 | cc347e32745f99c0cd95e79a18ddacc4574d7faa | refs/heads/main | 2023-08-25T23:48:26.112133 | 2021-10-23T14:11:22 | 2021-10-23T14:11:22 | null | 0 | 0 | null | null | null | null | UTF-8 | Python | false | false | 264 | py | def send_message(self, queue_url, message_body, delay_seconds=0, message_attributes=None):
return self.get_conn().send_message(QueueUrl=queue_url, MessageBody=message_body, DelaySeconds=delay_seconds, MessageAttributes=(message_attributes or {
})) | [
"dg1732004@smail.nju.edu.cn"
] | dg1732004@smail.nju.edu.cn |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.