commit
stringlengths
40
40
subject
stringlengths
4
1.73k
repos
stringlengths
5
127k
old_file
stringlengths
2
751
new_file
stringlengths
2
751
new_contents
stringlengths
1
8.98k
old_contents
stringlengths
0
6.59k
license
stringclasses
13 values
lang
stringclasses
23 values
255a7e7e15eec5b20dda416bc269a468fcd9c7c5
test of new getStudyIngestMessagesForNexSON treemachine service... the rest of the commit.
OpenTreeOfLife/opentree-testrunner,OpenTreeOfLife/opentree-testrunner
test_gols_get_study_ingest_messages.py
test_gols_get_study_ingest_messages.py
#!/usr/bin/env python import sys import requests import json from opentreetesting import config, summarize_json_response DOMAIN = config('host', 'golshost') p = '/ext/GoLS/graphdb/getStudyIngestMessagesForNexSON' if DOMAIN.startswith('http://127.0.0.1'): p = '/db/data' + p SUBMIT_URI = DOMAIN + p payload = { 'nexsonBlob': open('data/359', 'rU').read() } headers = { 'content-type' : 'application/json', 'accept' : 'application/json', } d = json.dumps(payload) resp = requests.post(SUBMIT_URI, headers=headers, data=d, allow_redirects=True) summarize_json_response(resp) or sys.exit(1)
bsd-2-clause
Python
796dd87582c5327865602fdeeac74f8e35407ccf
Add compiler file
Diego999/compiler
compiler.py
compiler.py
from lex_1 import generate_lex from parser_2 import generate_parser from semantic_3 import generate_semantic from generator_4 import generate_output if __name__ == "__main__": import os test_dir = "./tests/compiling/" for file in os.listdir(test_dir): prog = open(test_dir+file).read() generate_lex(prog) result = generate_parser(prog) generate_semantic(prog) generate_output(result, file.split('.')[0])
mit
Python
b75de39ae75b3780988673ffbab869dec20c1521
Add uwsgi conf file for star and shadow
BenMotz/cubetoolkit,BenMotz/cubetoolkit,BenMotz/cubetoolkit,BenMotz/cubetoolkit
serverconfig/toolkit_uwsgi_star_shadow.py
serverconfig/toolkit_uwsgi_star_shadow.py
# mysite_uwsgi.ini file # http://uwsgi-docs.readthedocs.io/en/latest/tutorials/Django_and_nginx.html [uwsgi] # Django-related settings # the base directory (full path) chdir = /home/users/starandshadow/star_site # Django's wsgi file module = wsgi # the virtualenv (full path) home = /home/users/starandshadow/star_site/venv env = DJANGO_SETTINGS_MODULE=toolkit.settings # process-related settings # master master = true # maximum number of worker processes processes = 2 # the socket (use the full path to be saf)e socket = /tmp/starandshadow_django.sock # TODO work out permission to run in /var/run #socket = /var/run/ed_django.sock # Socket permissions. Was 664, then 666. 660 works now chmod-socket = 660 # clear environment on exit vacuum = true uid = www-data gid = www-data enable-threads = true # http://uwsgi-docs.readthedocs.io/en/latest/articles/SerializingAccept.html thunder-lock = true #harakiri = 20 # respawn processes taking more than 20 seconds # limit the project to 128 MB limit-as = 512 # Enable stats stats = 127.0.0.1:9194 safe-pidfile = /tmp/star_shadow_django.pid daemonize = /var/log/starandshadow/star_django.log
agpl-3.0
Python
4bfc3f650bd5560f2e2e469252ea1166496a4b6b
Add dodgy NetCDF creation example
omad/datacube-experiments
example1.py
example1.py
from __future__ import print_function from datacube.api.model import DatasetType, Satellite, Ls57Arg25Bands, Fc25Bands, Pq25Bands from datacube.api.query import list_tiles_as_list from datacube.api.utils import get_dataset_metadata from datacube.api.utils import get_dataset_data from geotiff_to_netcdf import BandAsDimensionNetCDF, SeparateBandsTimeSlicedNetCDF from datetime import date import sys # Define a DatasetType mapping DS_TYPES_MAP = {'arg25': DatasetType.ARG25, 'fc25': DatasetType.FC25, 'pq25': DatasetType.PQ25} cell_x = 146 cell_y = -34 min_date = date(2014, 1, 1) max_date = date(2014, 12, 31) satellites = 'LS5,LS7' satellites = [Satellite(i) for i in satellites.split(',')] dataset_types = 'ARG25,FC25,PQ25' dataset_types = [i.lower() for i in dataset_types.split(',')] dataset_types = [DS_TYPES_MAP[i] for i in dataset_types] tiles = list_tiles_as_list(x=[cell_x], y=[cell_y], acq_min=min_date, acq_max=max_date, dataset_types=dataset_types, satellites=satellites) netcdf_filename = 'multi_band.nc' arg25paths = [dstile.path for tile in tiles for dstile in tile.datasets.itervalues() if dstile.bands == Ls57Arg25Bands] initial_file = [path for path in arg25paths if path.endswith("tif")][0] arg25paths.remove(initial_file) print("Creating {}".format(netcdf_filename)) multi_band_file = SeparateBandsTimeSlicedNetCDF(netcdf_filename, mode='w') print("Creating netcdf structure from {}".format(initial_file)) multi_band_file.create_from_geotiff(initial_file) print("Appending from {}".format(arg25paths[1])) multi_band_file.append_geotiff(arg25paths[1]) multi_band_file.close() # for path in arg25paths: # multi_band_file
bsd-3-clause
Python
f12500c836d2d5f04d3ad68b2b227f11b68af136
Add python script to send example task to the queue to test it
leibowitz/perfmonitor,leibowitz/perfmonitor,leibowitz/perfmonitor
bin/send.py
bin/send.py
#!/usr/bin/env python import pika import json msg = { 'url':'http://www.google.co.uk', 'site': 'gtk', 'account': 'me', 'type': 'har' } connection = pika.BlockingConnection(pika.ConnectionParameters( 'localhost')) channel = connection.channel() channel.exchange_declare(exchange='perfmonitor', type='direct') channel.queue_declare(queue='perf') channel.basic_publish(exchange='perfmonitor', routing_key='perftest', body=json.dumps(msg)) print " [x] Sent 'Hello World!'" connection.close()
mit
Python
bbf28b1c7fa3fb9f9074b9d4879c30e810ab3f31
Add premise of Bench Manager
ktbs/ktbs-bench,ktbs/ktbs-bench
ktbs_bench/utils/bench_manager.py
ktbs_bench/utils/bench_manager.py
from contextlib import contextmanager from ktbs_bench.utils.decorators import bench as util_bench class BenchManager: def __init__(self): self._contexts = [] self._bench_funcs = [] def bench(self, func): """Prepare a function to be benched and add it to the list to be run later.""" func = util_bench(func) self._bench_funcs.append(func) def context(self, func): """Decorate a function to act as a context.""" func = contextmanager(func) self._contexts.append(func) def run(self, output_file): """Execute each collected function against each context.""" pass
mit
Python
cbb182ff0e999954c7a5c8fd19097a441762666b
Add sdb driver for etcd
saltstack/salt,saltstack/salt,saltstack/salt,saltstack/salt,saltstack/salt
salt/sdb/etcd_db.py
salt/sdb/etcd_db.py
# -*- coding: utf-8 -*- ''' etcd Database Module :maintainer: SaltStack :maturity: New :depends: python-etcd :platform: all This module allows access to the etcd database using an ``sdb://`` URI. This package is located at ``https://pypi.python.org/pypi/python-etcd``. Like all sdb modules, the etcd module requires a configuration profile to be configured in either the minion or master configuration file. This profile requires very little. In the example: .. code-block:: yaml myetcd: driver: etcd etcd.host: 127.0.0.1 etcd.port: 4001 The ``driver`` refers to the etcd module, ``etcd.host`` refers to the host that is hosting the etcd database and ``etcd.port`` refers to the port on that host. .. code-block:: yaml password: sdb://etcd/mypassword .. versionadded:: 2014.1.4 (Hydrogen) ''' # import python libs import logging try: import salt.utils.etcd_util HAS_LIBS = True except ImportError: HAS_LIBS = False log = logging.getLogger(__name__) __func_alias__ = { 'set_': 'set' } __virtualname__ = 'etcd' def __virtual__(): ''' Only load the module if keyring is installed ''' if HAS_LIBS: return __virtualname__ return False def set_(key, value, service=None, profile=None): # pylint: disable=W0613 ''' Set a key/value pair in the etcd service ''' client = _get_conn(profile) client.set(key, value) return get(key, service, profile) def get(key, service=None, profile=None): # pylint: disable=W0613 ''' Get a value from the etcd service ''' client = _get_conn(profile) result = client.get(key) return result.value def _get_conn(profile): ''' Get a connection ''' return salt.utils.etcd_util.get_conn(profile)
apache-2.0
Python
23bb5deda2f6217ceab6a6e60e26234919a1f24e
Add buildbot.py
steinwurf/kw,steinwurf/kw
buildbot.py
buildbot.py
#!/usr/bin/env python # encoding: utf-8 import os import sys import json import subprocess project_name = 'kw' def run_command(args): print("Running: {}".format(args)) sys.stdout.flush() subprocess.check_call(args) def get_tool_options(properties): options = "" if 'tool_options' in properties: # Make sure that the values are correctly comma separated for key, value in properties['tool_options'].items(): if value is None: options += ',{0}'.format(key) else: options += ',{0}={1}'.format(key, value) return options def configure(properties): command = [sys.executable, 'waf'] if properties.get('build_distclean'): command += ['distclean'] command += ['configure', '--git-protocol=git@'] if 'waf_bundle_path' in properties: command += ['--bundle-path=' + properties['waf_bundle_path']] if 'dependency_project' in properties: command += ['--{0}-use-checkout={1}'.format( properties['dependency_project'], properties['dependency_checkout'])] options = "--options=cxx_mkspec={}".format(properties['cxx_mkspec']) options += get_tool_options(properties) command += [options] run_command(command) def build(properties): command = [sys.executable, 'waf', 'build', '-v'] run_command(command) def run_tests(properties): command = [sys.executable, 'waf', '-v'] options = '--options=run_tests,run_always' run_cmd = None if properties.get('valgrind_run'): run_cmd = 'valgrind --error-exitcode=1 %s' if run_cmd: options += ",run_cmd={}".format(run_cmd) options += get_tool_options(properties) command += [options] run_command(command) def install(properties): command = [sys.executable, 'waf', '-v', 'install'] options = [] if 'install_path' in properties: options += ['install_path={0}'.format(properties['install_path'])] if properties.get('install_relative'): options += ['install_relative'] if len(options) > 0: command += ['--options={}'.format(",".join(options))] run_command(command) def main(): argv = sys.argv if len(argv) != 3: print("Usage: {} <command> <properties>".format(argv[0])) sys.exit(0) cmd = argv[1] properties = json.loads(argv[2]) if cmd == 'configure': configure(properties) elif cmd == 'build': build(properties) elif cmd == 'run_tests': run_tests(properties) elif cmd == 'install': install(properties) else: print("Unknown command: {}".format(cmd)) if __name__ == '__main__': main()
bsd-3-clause
Python
916c453d2ba939fb7eb15f4d87557c37bfc57a21
Add test for shell command
Julian/home-assistant,ct-23/home-assistant,mezz64/home-assistant,pottzer/home-assistant,joopert/home-assistant,FreekingDean/home-assistant,eagleamon/home-assistant,betrisey/home-assistant,eagleamon/home-assistant,open-homeautomation/home-assistant,aequitas/home-assistant,open-homeautomation/home-assistant,bdfoster/blumate,nkgilley/home-assistant,leppa/home-assistant,tinloaf/home-assistant,nugget/home-assistant,robjohnson189/home-assistant,devdelay/home-assistant,srcLurker/home-assistant,instantchow/home-assistant,pottzer/home-assistant,robjohnson189/home-assistant,shaftoe/home-assistant,ma314smith/home-assistant,srcLurker/home-assistant,caiuspb/home-assistant,MartinHjelmare/home-assistant,ct-23/home-assistant,Julian/home-assistant,hmronline/home-assistant,balloob/home-assistant,toddeye/home-assistant,mikaelboman/home-assistant,morphis/home-assistant,philipbl/home-assistant,jnewland/home-assistant,adrienbrault/home-assistant,jamespcole/home-assistant,luxus/home-assistant,leoc/home-assistant,tboyce1/home-assistant,florianholzapfel/home-assistant,mezz64/home-assistant,LinuxChristian/home-assistant,Julian/home-assistant,jabesq/home-assistant,robjohnson189/home-assistant,happyleavesaoc/home-assistant,auduny/home-assistant,miniconfig/home-assistant,eagleamon/home-assistant,shaftoe/home-assistant,LinuxChristian/home-assistant,kyvinh/home-assistant,partofthething/home-assistant,oandrew/home-assistant,molobrakos/home-assistant,alexmogavero/home-assistant,devdelay/home-assistant,fbradyirl/home-assistant,Duoxilian/home-assistant,oandrew/home-assistant,tinloaf/home-assistant,jnewland/home-assistant,Danielhiversen/home-assistant,tboyce021/home-assistant,justyns/home-assistant,HydrelioxGitHub/home-assistant,philipbl/home-assistant,stefan-jonasson/home-assistant,soldag/home-assistant,sander76/home-assistant,hmronline/home-assistant,GenericStudent/home-assistant,mikaelboman/home-assistant,DavidLP/home-assistant,JshWright/home-assistant,eagleamon/home-assistant,keerts/home-assistant,Duoxilian/home-assistant,sfam/home-assistant,tboyce021/home-assistant,PetePriority/home-assistant,ewandor/home-assistant,leoc/home-assistant,persandstrom/home-assistant,dmeulen/home-assistant,jaharkes/home-assistant,PetePriority/home-assistant,ma314smith/home-assistant,emilhetty/home-assistant,hexxter/home-assistant,deisi/home-assistant,tboyce1/home-assistant,mKeRix/home-assistant,sffjunkie/home-assistant,ct-23/home-assistant,kennedyshead/home-assistant,pschmitt/home-assistant,keerts/home-assistant,nnic/home-assistant,sdague/home-assistant,dmeulen/home-assistant,MartinHjelmare/home-assistant,emilhetty/home-assistant,miniconfig/home-assistant,emilhetty/home-assistant,Theb-1/home-assistant,jaharkes/home-assistant,aronsky/home-assistant,molobrakos/home-assistant,joopert/home-assistant,hexxter/home-assistant,alexmogavero/home-assistant,MungoRae/home-assistant,Theb-1/home-assistant,rohitranjan1991/home-assistant,balloob/home-assistant,jnewland/home-assistant,badele/home-assistant,Julian/home-assistant,varunr047/homefile,varunr047/homefile,jamespcole/home-assistant,JshWright/home-assistant,MungoRae/home-assistant,philipbl/home-assistant,turbokongen/home-assistant,lukas-hetzenecker/home-assistant,Smart-Torvy/torvy-home-assistant,shaftoe/home-assistant,nnic/home-assistant,LinuxChristian/home-assistant,robjohnson189/home-assistant,MungoRae/home-assistant,xifle/home-assistant,PetePriority/home-assistant,nevercast/home-assistant,toddeye/home-assistant,nugget/home-assistant,badele/home-assistant,leoc/home-assistant,hexxter/home-assistant,varunr047/homefile,happyleavesaoc/home-assistant,keerts/home-assistant,shaftoe/home-assistant,betrisey/home-assistant,turbokongen/home-assistant,ct-23/home-assistant,coteyr/home-assistant,sander76/home-assistant,sfam/home-assistant,Teagan42/home-assistant,leoc/home-assistant,DavidLP/home-assistant,kennedyshead/home-assistant,miniconfig/home-assistant,happyleavesaoc/home-assistant,titilambert/home-assistant,srcLurker/home-assistant,auduny/home-assistant,emilhetty/home-assistant,kyvinh/home-assistant,florianholzapfel/home-assistant,w1ll1am23/home-assistant,MungoRae/home-assistant,coteyr/home-assistant,nevercast/home-assistant,hmronline/home-assistant,miniconfig/home-assistant,fbradyirl/home-assistant,luxus/home-assistant,ewandor/home-assistant,HydrelioxGitHub/home-assistant,deisi/home-assistant,deisi/home-assistant,jaharkes/home-assistant,coteyr/home-assistant,xifle/home-assistant,alexmogavero/home-assistant,mKeRix/home-assistant,justyns/home-assistant,Zyell/home-assistant,Cinntax/home-assistant,nkgilley/home-assistant,Cinntax/home-assistant,aequitas/home-assistant,ma314smith/home-assistant,rohitranjan1991/home-assistant,mikaelboman/home-assistant,titilambert/home-assistant,sffjunkie/home-assistant,devdelay/home-assistant,aoakeson/home-assistant,mKeRix/home-assistant,pottzer/home-assistant,w1ll1am23/home-assistant,sdague/home-assistant,tboyce1/home-assistant,Duoxilian/home-assistant,jaharkes/home-assistant,robbiet480/home-assistant,dmeulen/home-assistant,happyleavesaoc/home-assistant,betrisey/home-assistant,sffjunkie/home-assistant,caiuspb/home-assistant,nnic/home-assistant,sffjunkie/home-assistant,Teagan42/home-assistant,Zac-HD/home-assistant,tchellomello/home-assistant,bdfoster/blumate,bdfoster/blumate,instantchow/home-assistant,Smart-Torvy/torvy-home-assistant,jawilson/home-assistant,qedi-r/home-assistant,varunr047/homefile,varunr047/homefile,postlund/home-assistant,mikaelboman/home-assistant,dmeulen/home-assistant,tchellomello/home-assistant,soldag/home-assistant,hexxter/home-assistant,LinuxChristian/home-assistant,auduny/home-assistant,Zyell/home-assistant,tinloaf/home-assistant,oandrew/home-assistant,nugget/home-assistant,adrienbrault/home-assistant,HydrelioxGitHub/home-assistant,morphis/home-assistant,tboyce1/home-assistant,instantchow/home-assistant,jawilson/home-assistant,Zac-HD/home-assistant,sfam/home-assistant,caiuspb/home-assistant,home-assistant/home-assistant,srcLurker/home-assistant,stefan-jonasson/home-assistant,Danielhiversen/home-assistant,aoakeson/home-assistant,Smart-Torvy/torvy-home-assistant,xifle/home-assistant,betrisey/home-assistant,balloob/home-assistant,hmronline/home-assistant,hmronline/home-assistant,aequitas/home-assistant,GenericStudent/home-assistant,FreekingDean/home-assistant,nevercast/home-assistant,Theb-1/home-assistant,fbradyirl/home-assistant,luxus/home-assistant,kyvinh/home-assistant,lukas-hetzenecker/home-assistant,persandstrom/home-assistant,ct-23/home-assistant,open-homeautomation/home-assistant,Duoxilian/home-assistant,stefan-jonasson/home-assistant,JshWright/home-assistant,partofthething/home-assistant,morphis/home-assistant,alexmogavero/home-assistant,bdfoster/blumate,xifle/home-assistant,molobrakos/home-assistant,mKeRix/home-assistant,JshWright/home-assistant,florianholzapfel/home-assistant,Zyell/home-assistant,DavidLP/home-assistant,oandrew/home-assistant,Smart-Torvy/torvy-home-assistant,Zac-HD/home-assistant,sffjunkie/home-assistant,aoakeson/home-assistant,justyns/home-assistant,LinuxChristian/home-assistant,emilhetty/home-assistant,keerts/home-assistant,Zac-HD/home-assistant,MungoRae/home-assistant,florianholzapfel/home-assistant,ma314smith/home-assistant,MartinHjelmare/home-assistant,deisi/home-assistant,kyvinh/home-assistant,persandstrom/home-assistant,rohitranjan1991/home-assistant,badele/home-assistant,devdelay/home-assistant,robbiet480/home-assistant,philipbl/home-assistant,aronsky/home-assistant,pschmitt/home-assistant,home-assistant/home-assistant,jabesq/home-assistant,ewandor/home-assistant,bdfoster/blumate,stefan-jonasson/home-assistant,jamespcole/home-assistant,open-homeautomation/home-assistant,leppa/home-assistant,deisi/home-assistant,jabesq/home-assistant,postlund/home-assistant,morphis/home-assistant,qedi-r/home-assistant,mikaelboman/home-assistant
tests/components/test_shell_command.py
tests/components/test_shell_command.py
""" tests.test_shell_command ~~~~~~~~~~~~~~~~~~~~~~~~ Tests demo component. """ import os import tempfile import unittest from homeassistant import core from homeassistant.components import shell_command class TestShellCommand(unittest.TestCase): """ Test the demo module. """ def setUp(self): # pylint: disable=invalid-name self.hass = core.HomeAssistant() def tearDown(self): # pylint: disable=invalid-name """ Stop down stuff we started. """ self.hass.stop() def test_executing_service(self): """ Test if able to call a configured service. """ with tempfile.TemporaryDirectory() as tempdirname: path = os.path.join(tempdirname, 'called.txt') shell_command.setup(self.hass, { 'shell_command': { 'test_service': "touch {}".format(path) } }) self.hass.services.call('shell_command', 'test_service', blocking=True) self.assertTrue(os.path.isfile(path))
mit
Python
029de4a3a10f31b2d300e100db7767722698f00a
Test for newly refactored literal rule
cmancone/mygrations,cmancone/mygrations
tests/core/parse/test_parse_literal.py
tests/core/parse/test_parse_literal.py
import unittest from mygrations.core.parse.rule_literal import rule_literal class test_parse_regexp( unittest.TestCase ): def get_rule( self, name, literal ): return rule_literal( False, { 'name': name, 'value': literal }, {} ) def test_name_not_required( self ): rule = self.get_rule( '', 'ASDF' ) self.assertEquals( rule.name, 'ASDF' ) def test_value_required( self ): with self.assertRaises( ValueError ): self.get_rule( 'bob', '' ) def test_can_init_with_name_and_value( self ): rule = self.get_rule( 'bob', ',' ) self.assertEquals( rule.name, 'bob' ) self.assertEquals( rule.literal, ',' ) def test_match_beginning_only( self ): rule = self.get_rule( 'bob', ',' ) self.assertFalse( rule.parse( 'hey,' ) ) self.assertEquals( '', rule.result ) def test_leftovers_is_input_for_no_match( self ): rule = self.get_rule( 'bob', ',' ) string = 'hey,' rule.parse( string ) self.assertEquals( string, rule.leftovers ) def test_no_leftovers_for_full_match( self ): string = '23483438' rule = self.get_rule( 'bob', string ) self.assertTrue( rule.parse( string ) ) self.assertEquals( string, rule.result ) self.assertEquals( '', rule.leftovers ) def test_calc_leftovers_trim( self ): rule = self.get_rule( 'bob', ',' ) string = ', bob' self.assertTrue( rule.parse( string ) ) self.assertEquals( ',', rule.result ) self.assertEquals( 'bob', rule.leftovers )
mit
Python
9bcd540b4ba9e9e38f674b02b47e42eb29a1cf2f
add gender choices data migration
masschallenge/django-accelerator,masschallenge/django-accelerator
accelerator/migrations/0029_add_gender_choices_data.py
accelerator/migrations/0029_add_gender_choices_data.py
# Generated by Django 2.2.10 on 2020-12-01 19:01 from django.db import migrations from accelerator_abstract.models.base_gender_choices import GENDER_CHOICES def add_gender_choices(apps, schema_editor): GenderChoices = apps.get_model('accelerator', 'GenderChoices') db_gender_choices = GenderChoices.objects.all().values_list('name', flat=True) missing_gender_choices = set(GENDER_CHOICES).difference(db_gender_choices) if missing_gender_choices: GenderChoices.objects.bulk_create( [GenderChoices(name=choice) for choice in missing_gender_choices]) class Migration(migrations.Migration): dependencies = [ ('accelerator', '0028_add_gender_fields'), ] operations = [ migrations.RunPython(add_gender_choices, migrations.RunPython.noop) ]
mit
Python
795bd9bca8779b32b1e48e420ab42fefbb73fdfc
add Driver migration
SRJ9/django-driver27,SRJ9/django-driver27,SRJ9/django-driver27
migrations/0001_initial.py
migrations/0001_initial.py
# -*- coding: utf-8 -*- # Generated by Django 1.10.1 on 2016-09-23 15:48 from __future__ import unicode_literals from django.db import migrations, models import django_countries.fields class Migration(migrations.Migration): initial = True dependencies = [ ] operations = [ migrations.CreateModel( name='Driver', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('last_name', models.CharField(max_length=50)), ('first_name', models.CharField(max_length=25)), ('year_of_birth', models.IntegerField()), ('country', django_countries.fields.CountryField(max_length=2)), ], ), migrations.AlterUniqueTogether( name='driver', unique_together=set([('last_name', 'first_name')]), ), ]
mit
Python
82301349226ec43dcec53d5ceceaa952d8d4b9b5
Test the use_plus_uconst optimizer
gbenson/i8c
i8c/tests/test_opt_use_plus_uconst.py
i8c/tests/test_opt_use_plus_uconst.py
from i8c.tests import TestCase SOURCE = """\ define test::optimize_use_plus_uconst returns int argument int x load %s add """ class TestOptimizeUsePlusUconst(TestCase): def test_optimize_use_plus_uconst(self): """Check that DW_OP_plus_uconst is used where possible.""" for value in ("TRUE", 5, 255, 16384, 327889, 123456789): tree, output = self.compile(SOURCE % value) ops = output.ops self.assertEqual(len(ops), 1) self.assertEqual(ops[0].name, "plus_uconst") self.assertEqual(ops[0].operand, value == "TRUE" and 1 or value) def test_optimize_dont_use_plus_uconst_neg(self): """Check that DW_OP_plus_uconst is not used for negative numbers.""" for value in (-1, -5, -255, -16384, -327889, -123456789): tree, output = self.compile(SOURCE % value) ops = output.ops self.assertEqual(len(ops), 2) self.assertEqual(ops[0].operand, value) self.assertEqual(ops[1].name, "plus") def test_optimize_dont_use_plus_uconst_zero(self): """Check that DW_OP_plus_uconst is not used for zero.""" for value in (0, "FALSE"): tree, output = self.compile(SOURCE % value) self.assertEqual(len(output.ops), 0) tree, output = self.compile(SOURCE.replace("int", "ptr") % value) self.assertEqual(len(output.ops), 0)
lgpl-2.1
Python
b583bf5dbd4a375df7824463dda0789ddc980f2e
Create lasagne-script.py
KhaledSharif/numerai-scripts
lasagne-script.py
lasagne-script.py
import numpy as np import pandas as pd from lasagne.init import Orthogonal, Constant from lasagne.layers import DenseLayer, MergeLayer from lasagne.layers import DropoutLayer from lasagne.layers import InputLayer from lasagne.nonlinearities import softmax, rectify, sigmoid from lasagne.objectives import categorical_crossentropy, binary_crossentropy from lasagne.updates import nesterov_momentum, adadelta from matplotlib import pyplot from nolearn.lasagne import NeuralNet, TrainSplit from sklearn.metrics import roc_auc_score from sklearn.preprocessing import StandardScaler import warnings warnings.filterwarnings("ignore") class MultiplicativeGatingLayer(MergeLayer): def __init__(self, gate, input1, input2, **kwargs): incomings = [gate, input1, input2] super(MultiplicativeGatingLayer, self).__init__(incomings, **kwargs) assert gate.output_shape == input1.output_shape == input2.output_shape def get_output_shape_for(self, input_shapes): return input_shapes[0] def get_output_for(self, inputs, **kwargs): return inputs[0] * inputs[1] + (1 - inputs[0]) * inputs[2] def highway_dense(incoming, Wh=Orthogonal(), bh=Constant(0.0), Wt=Orthogonal(), bt=Constant(-4.0), nonlinearity=rectify, **kwargs): num_inputs = int(np.prod(incoming.output_shape[1:])) l_h = DenseLayer(incoming, num_units=num_inputs, W=Wh, b=bh, nonlinearity=nonlinearity) l_t = DenseLayer(incoming, num_units=num_inputs, W=Wt, b=bt, nonlinearity=sigmoid) return MultiplicativeGatingLayer(gate=l_t, input1=l_h, input2=incoming) def remove_addition(X): return int(str(X[14]).split("_")[1]) # ==== Read in the csv and correct the c1 column ==== train = pd.read_csv('./Numerai/numerai_training_data.csv') train["cat"] = train.apply(remove_addition, axis=1) train = train.drop("c1", axis=1) # ==== Create more features from the current features we have ==== features = list(train.columns) features.remove("validation") features.remove("target") for f in features: for g in features: if f != g: if not (str(g) + "_" + str(f)) in train.columns: train[str(f) + "_" + str(g)] = train[f] * train[g] # ==== Splitting dataset into training and validation ==== training = train[train["validation"] == 0] validation = train[train["validation"] == 1] training = training.drop("validation", axis=1) validation = validation.drop("validation", axis=1) # ==== Standard scaling of the inputs ==== train = train.drop(["validation", "target"], axis=1) train = np.array(train).astype(np.float32) scaler = StandardScaler() scaler.fit(train) training_target = training["target"].values.T.astype(np.int32) training = training.drop("target", axis=1) validation_target = validation["target"].values.T.astype(np.int32) validation = validation.drop("target", axis=1) X = np.array(training).astype(np.float32) X = scaler.transform(X).astype(np.float32) Y = np.array(validation).astype(np.float32) Y = scaler.transform(Y).astype(np.float32) # ==== Parameters ==== num_features = X.shape[1] epochs = 20 hidden_layers = 4 hidden_units = 1024 dropout_p = 0.75 val_auc = np.zeros(epochs) # ==== Defining the neural network shape ==== l_in = InputLayer(shape=(None, num_features)) l_hidden1 = DenseLayer(l_in, num_units=hidden_units) l_hidden2 = DropoutLayer(l_hidden1, p=dropout_p) l_current = l_hidden2 for k in range(hidden_layers - 1): l_current = highway_dense(l_current) l_current = DropoutLayer(l_current, p=dropout_p) l_dropout = DropoutLayer(l_current, p=dropout_p) l_out = DenseLayer(l_dropout, num_units=2, nonlinearity=softmax) # ==== Neural network definition ==== net1 = NeuralNet(layers=l_out, update=adadelta, update_rho=0.95, update_learning_rate=1.0, objective_loss_function=categorical_crossentropy, train_split=TrainSplit(eval_size=0), verbose=0, max_epochs=1) # ==== Print out input shape for diagnosis ==== print(X.shape) print(training_target.shape) # ==== Train it for n iterations and validate on each iteration ==== for i in range(epochs): net1.fit(X, training_target) pred = net1.predict_proba(Y)[:, 1] val_auc[i] = roc_auc_score(validation_target, pred) print(i + 1, "\t", round(val_auc[i] * 100, 3), "\t", round(max(val_auc) * 100, 3), "\t") # ==== Make of the plot of the validation accuracy per iteration ==== pyplot.plot(val_auc, linewidth=2) pyplot.axhline(y=max(val_auc), xmin=0, xmax=epochs, c="blue", linewidth=3, zorder=0) pyplot.grid() pyplot.title("Maximum AUC is " + str(round(max(val_auc) * 100, 3)) + '%') pyplot.xlabel("Epoch") pyplot.ylabel("Validation AUC") pyplot.show()
mit
Python
a72516f4faae6993d55b7a542ef9b686c6e659fb
Add NoCommandAction to only continue execution when a non-command text event is received
alvarogzp/telegram-bot,alvarogzp/telegram-bot
bot/action/core/command/no_command.py
bot/action/core/command/no_command.py
from bot.action.core.action import IntermediateAction from bot.action.core.command import CommandAction class NoCommandAction(IntermediateAction): def process(self, event): for entity in self.get_entities(event): if self.is_valid_command(entity): break else: self._continue(event) @staticmethod def get_entities(event): return CommandAction.get_entities(event) @staticmethod def is_valid_command(entity): return CommandAction.is_valid_command(entity)
agpl-3.0
Python
31717dc26912aedd42ca475b4e3d1a406523e44a
add to connect mysql with pymysql
cwenao/python_web_learn
base100/crawler/data_store.py
base100/crawler/data_store.py
#!/usr/bin/python # --*-- UTF8 --*-- import pymysql def db_connect(): ''' 数据库配置 :return: con ''' con = pymysql.connect( host='172.16.223.10', user='root', passwd='123456', db='crawler', charset='utf8' ) return con def execute_query_sql(sql): print('execute sql: %s' % sql) con = db_connect() try: cursor = con.cursor() cursor.execute(sql) con.close() return cursor.fetchall() except: print('error to execute the sql') con.close() data = execute_query_sql("select version()") print('Database version %s ' % data)
apache-2.0
Python
b5b329af74f66443d33062f8a17a99b98833e7bb
add UiBench workload
ARM-software/lisa,ARM-software/lisa,bjackman/lisa,ARM-software/lisa,credp/lisa,mdigiorgio/lisa,mdigiorgio/lisa,ARM-software/lisa,arnoldlu/lisa,joelagnel/lisa,arnoldlu/lisa,bjackman/lisa,credp/lisa,joelagnel/lisa,credp/lisa,credp/lisa
libs/utils/android/workloads/uibench.py
libs/utils/android/workloads/uibench.py
# SPDX-License-Identifier: Apache-2.0 # # Copyright (C) 2015, ARM Limited and contributors. # # 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. # import re import os import logging from subprocess import Popen, PIPE from android import Screen, System, Workload from time import sleep class UiBench(Workload): """ Android UiBench workload """ # Package required by this workload package = 'com.android.test.uibench' # Supported activities list, obtained via: # adb shell dumpsys package | grep -i uibench | grep Activity test_BitmapUpload = 'BitmapUpload' test_DialogList = 'DialogList' test_EditTextType = 'EditTextType' test_FullscreenOverdraw = 'FullscreenOverdraw' test_GlTextureView = 'GlTextureView' test_InflatingList = 'InflatingList' test_Invalidate = 'Invalidate' test_ShadowGrid = 'ShadowGrid' test_TextCacheHighHitrate = 'TextCacheHighHitrate' test_TextCacheLowHitrate = 'TextCacheLowHitrate' test_Transition = 'Transition' test_TransitionDetails = 'TransitionDetails' test_TrivialAnimation = 'TrivialAnimation' test_TrivialList = 'TrivialList' test_TrivialRecyclerView = 'TrivialRecyclerView' def __init__(self, test_env): super(UiBench, self).__init__(test_env) self._log = logging.getLogger('UiBench') self._log.debug('Workload created') def run(self, exp_dir, test_name, duration_s, collect=''): activity = '.' + test_name + 'Activity' # Initialize energy meter results nrg_report = None # Press Back button to be sure we run the video from the start System.menu(self.target) System.back(self.target) # Close and clear application System.force_stop(self.target, self.package, clear=True) # Set airplane mode System.set_airplane_mode(self.target, on=True) # Start the main view of the app which must be running # to reset the frame statistics. System.monkey(self.target, self.package) # Force screen in PORTRAIT mode Screen.set_orientation(self.target, portrait=True) # Reset frame statistics System.gfxinfo_reset(self.target, self.package) sleep(1) # Clear logcat os.system(self._adb('logcat -c')); # Regexps for benchmark synchronization start_logline = r'ActivityManager: START.*'\ 'cmp=com.android.test.uibench/{}'.format(activity) UIBENCH_BENCHMARK_START_RE = re.compile(start_logline) self._log.debug("START string [%s]", start_logline) # Parse logcat output lines logcat_cmd = self._adb( 'logcat ActivityManager:* System.out:I *:S BENCH:*'\ .format(self.target.adb_name)) self._log.info("%s", logcat_cmd) # Start the activity System.start_activity(self.target, self.package, activity) logcat = Popen(logcat_cmd, shell=True, stdout=PIPE) while True: # read next logcat line (up to max 1024 chars) message = logcat.stdout.readline(1024) # Benchmark start trigger match = UIBENCH_BENCHMARK_START_RE.search(message) if match: if 'energy' in collect and self.te.emeter: self.te.emeter.reset() self._log.debug("Benchmark started!") break # Run the workload for the required time self._log.info('Benchmark [%s] started, waiting %d [s]', activity, duration_s) sleep(duration_s) self._log.debug("Benchmark done!") if 'energy' in collect and self.te.emeter: nrg_report = self.te.emeter.report(exp_dir) # Get frame stats db_file = os.path.join(exp_dir, "framestats.txt") System.gfxinfo_get(self.target, self.package, db_file) # Close and clear application System.force_stop(self.target, self.package, clear=True) # Go back to home screen System.home(self.target) # Switch back to original settings Screen.set_orientation(self.target, auto=True) System.set_airplane_mode(self.target, on=False) return db_file, nrg_report # vim :set tabstop=4 shiftwidth=4 expandtab
apache-2.0
Python
bc3ded5eda2cb31523dfaf9bf7eec4fbe1030a0b
add find_pcs.py, but only with some prep code and eline masking
zpace/stellarmass_pca
find_pcs.py
find_pcs.py
import numpy as np from astropy import constants as c, units as u class StellarPop_PCA(object): ''' class for determining PCs of a library of synthetic spectra ''' def __init__(self, l, spectra, dlogl=None): ''' params: - l: length-n array-like defining the wavelength bin centers (should be log-spaced) - spectra: m-by-n array of spectra (individual spectrum contained along one index in dimension 0) ''' self.l = l if dlogl is None: dlogl = np.mean(l[1:]/l[:-1]) - 1. self.dlogl = dlogl self.spectra = spectra self.mean_spectrum = np.mean(self.spectra, axis=0) @property def eline_masks(self, half_dv=500.*u.Unit('km/s')): from itertools import izip line_ctrs = u.AA * \ np.array([3727.09, 3729.88, 3889.05, 3969.81, 3968.53, # [OII] [OII] H8 [NeIII] [NeIII] 4341.69, 4102.92, 4862.69, 5008.24, 4960.30]) # Hg Hd Hb [OIII] [OIII] # compute mask edges mask_ledges = line_ctrs * (1 - (half_dv / c.c).to('')) mask_uedges = line_ctrs * (1 + (half_dv / c.c).to('')) # find whether each wavelength bin is used in for each eline's mask full_antimask = np.row_stack( [~((mask_ledges < self.l) * (self.l < mask_uedges)) for l, u in izip(mask_ledges, mask_uedges)]) antimask = np.prod(full_antimask, axis=0) return antimask.astype(bool)
mit
Python
2e20d0bb09234f36b5d43fc1f4b99cdb1da0e7f8
Add unsigned-workup utility script.
SaturdayNeighborhoodHealthClinic/clintools,SaturdayNeighborhoodHealthClinic/clintools,SaturdayNeighborhoodHealthClinic/clintools
scripts/check_unsigned.py
scripts/check_unsigned.py
from datetime import date from pttrack.models import Provider, Workup unsigned_workups = Workup.objects.filter(signer=None) print unsigned_workups for wu in unsigned_workups: d = wu.clinic_day.clinic_date providers = Provider.objects.filter( signed_workups__in=Workup.objects.filter( clinic_day__clinic_date=d)).distinct() print wu.patient, providers, d
mit
Python
ffefdb6e9ac678d0b7e1f65a7712e01a874507fb
ADD script to collect nemo results
mlindauer/EPM_DNN
scripts/collect_result.py
scripts/collect_result.py
import numpy as np import pandas as pd from _collections import OrderedDict data = {} flat_data = OrderedDict() scens = ["SPEAR-SWV","SPEAR-IBM","CPLEX-RCW","CPLEX-REG","CPLEX-CORLAT"] models = ["DNN", "RF"] EVA_BUDGETs = [1]#,3600] WC_BUDGET = 86400 # sec RUNS = 3 for scen in scens: for model in models: for EVA_BUDGET in EVA_BUDGETs: data[scen] = data.get(scen,{}) data[scen][model] = data[scen].get(model,{}) data[scen][model][EVA_BUDGET] = data[scen][model].get(EVA_BUDGET,{}) t = [] rmse_train = [] rmsle_train = [] rmse_valid = [] rmsle_valid = [] rmse_test = [] rmsle_test = [] for seed in range(1,RUNS+1): with open("{0}_{1}_{2}_{3}_{4}.log".format(scen, model, EVA_BUDGET,WC_BUDGET, seed)) as fp: for line in fp: if line.startswith("Training Time: "): t.append(int(line.split(":")[1])) elif line.startswith("RMSE (train)"): rmse_train.append(float(line.split(":")[1])) elif line.startswith("RMSLE (train)"): rmsle_train.append(float(line.split(":")[1])) elif line.startswith("RMSE (valid)"): rmse_valid.append(float(line.split(":")[1])) elif line.startswith("RMSLE (valid)"): rmsle_valid.append(float(line.split(":")[1])) elif line.startswith("RMSE (test)"): rmse_test.append(float(line.split(":")[1])) elif line.startswith("RMSLE (test)"): rmsle_test.append(float(line.split(":")[1])) data[scen][model][EVA_BUDGET]["time"] = np.median(t) data[scen][model][EVA_BUDGET]["RMSE (train)"] = np.median(rmse_train) data[scen][model][EVA_BUDGET]["RMSEL (train)"] = np.median(rmsle_train) data[scen][model][EVA_BUDGET]["RMSE (valid)"] = np.median(rmse_valid) data[scen][model][EVA_BUDGET]["RMSEL (valid)"] = np.median(rmsle_valid) data[scen][model][EVA_BUDGET]["RMSE (test)"] = np.median(rmse_test) data[scen][model][EVA_BUDGET]["RMSEL (test)"] = np.median(rmsle_test) key = "{0}_{1}_{2}".format(scen, model, EVA_BUDGET) flat_data[key] = flat_data.get(key,OrderedDict()) flat_data[key]["time [sec]"] = np.median(t) flat_data[key]["RMSE (train)"] = np.median(rmse_train) flat_data[key]["RMSEL (train)"] = np.median(rmsle_train) flat_data[key]["RMSE (valid)"] = np.median(rmse_valid) flat_data[key]["RMSEL (valid)"] = np.median(rmsle_valid) flat_data[key]["RMSE (test)"] = np.median(rmse_test) flat_data[key]["RMSEL (test)"] = np.median(rmsle_test) df = pd.DataFrame.from_dict(data=flat_data) with pd.option_context('display.max_rows', None, 'display.max_columns', None): print(df)
bsd-2-clause
Python
e41ce4338334794466ba6918fc3b8a1f118d6b41
Add first example test of using h2o python API to gradle build regression suite.
mrgloom/h2o-3,brightchen/h2o-3,kyoren/https-github.com-h2oai-h2o-3,nilbody/h2o-3,madmax983/h2o-3,jangorecki/h2o-3,pchmieli/h2o-3,kyoren/https-github.com-h2oai-h2o-3,madmax983/h2o-3,YzPaul3/h2o-3,ChristosChristofidis/h2o-3,brightchen/h2o-3,jangorecki/h2o-3,michalkurka/h2o-3,printedheart/h2o-3,h2oai/h2o-3,PawarPawan/h2o-v3,ChristosChristofidis/h2o-3,kyoren/https-github.com-h2oai-h2o-3,brightchen/h2o-3,datachand/h2o-3,spennihana/h2o-3,bikash/h2o-dev,tarasane/h2o-3,h2oai/h2o-3,pchmieli/h2o-3,weaver-viii/h2o-3,h2oai/h2o-3,bospetersen/h2o-3,madmax983/h2o-3,bospetersen/h2o-3,pchmieli/h2o-3,mathemage/h2o-3,nilbody/h2o-3,jangorecki/h2o-3,bikash/h2o-dev,nilbody/h2o-3,datachand/h2o-3,spennihana/h2o-3,madmax983/h2o-3,nilbody/h2o-3,madmax983/h2o-3,junwucs/h2o-3,mathemage/h2o-3,PawarPawan/h2o-v3,tarasane/h2o-3,YzPaul3/h2o-3,ChristosChristofidis/h2o-3,bikash/h2o-dev,ChristosChristofidis/h2o-3,YzPaul3/h2o-3,h2oai/h2o-dev,PawarPawan/h2o-v3,junwucs/h2o-3,datachand/h2o-3,bospetersen/h2o-3,jangorecki/h2o-3,YzPaul3/h2o-3,weaver-viii/h2o-3,kyoren/https-github.com-h2oai-h2o-3,printedheart/h2o-3,h2oai/h2o-3,madmax983/h2o-3,datachand/h2o-3,printedheart/h2o-3,junwucs/h2o-3,YzPaul3/h2o-3,bospetersen/h2o-3,jangorecki/h2o-3,bikash/h2o-dev,junwucs/h2o-3,h2oai/h2o-dev,michalkurka/h2o-3,ChristosChristofidis/h2o-3,michalkurka/h2o-3,tarasane/h2o-3,PawarPawan/h2o-v3,mathemage/h2o-3,jangorecki/h2o-3,michalkurka/h2o-3,brightchen/h2o-3,tarasane/h2o-3,bikash/h2o-dev,kyoren/https-github.com-h2oai-h2o-3,weaver-viii/h2o-3,michalkurka/h2o-3,mathemage/h2o-3,mrgloom/h2o-3,jangorecki/h2o-3,datachand/h2o-3,michalkurka/h2o-3,printedheart/h2o-3,mrgloom/h2o-3,bospetersen/h2o-3,nilbody/h2o-3,bikash/h2o-dev,weaver-viii/h2o-3,pchmieli/h2o-3,h2oai/h2o-3,tarasane/h2o-3,h2oai/h2o-dev,h2oai/h2o-dev,pchmieli/h2o-3,junwucs/h2o-3,printedheart/h2o-3,weaver-viii/h2o-3,spennihana/h2o-3,spennihana/h2o-3,datachand/h2o-3,brightchen/h2o-3,nilbody/h2o-3,junwucs/h2o-3,mathemage/h2o-3,printedheart/h2o-3,mathemage/h2o-3,bospetersen/h2o-3,spennihana/h2o-3,tarasane/h2o-3,pchmieli/h2o-3,junwucs/h2o-3,madmax983/h2o-3,mrgloom/h2o-3,printedheart/h2o-3,PawarPawan/h2o-v3,h2oai/h2o-3,PawarPawan/h2o-v3,YzPaul3/h2o-3,spennihana/h2o-3,kyoren/https-github.com-h2oai-h2o-3,michalkurka/h2o-3,mathemage/h2o-3,bospetersen/h2o-3,ChristosChristofidis/h2o-3,mrgloom/h2o-3,h2oai/h2o-3,brightchen/h2o-3,h2oai/h2o-dev,kyoren/https-github.com-h2oai-h2o-3,datachand/h2o-3,mrgloom/h2o-3,h2oai/h2o-3,PawarPawan/h2o-v3,weaver-viii/h2o-3,h2oai/h2o-dev,nilbody/h2o-3,spennihana/h2o-3,tarasane/h2o-3,brightchen/h2o-3,YzPaul3/h2o-3,weaver-viii/h2o-3,h2oai/h2o-dev,ChristosChristofidis/h2o-3,mrgloom/h2o-3,pchmieli/h2o-3
py/testdir_multi_jvm/test_gbm_prostate.py
py/testdir_multi_jvm/test_gbm_prostate.py
import sys sys.path.insert(1, '../../h2o-py/src/main/py') from h2o import H2OConnection from h2o import H2OFrame from h2o import H2OGBM from tabulate import tabulate ###################################################### # Parse command-line args. # # usage: python test_name.py --usecloud ipaddr:port # ip_port = sys.argv[2].split(":") print ip_port ip = ip_port[0] port = int(ip_port[1]) ###################################################### # # Sample Running GBM on prostate.csv # Connect to a pre-existing cluster cluster = H2OConnection(ip = ip, port = port) df = H2OFrame(remote_fname="../../../smalldata/logreg/prostate.csv") print df.describe() # Remove ID from training frame del df['ID'] # For VOL & GLEASON, a zero really means "missing" vol = df['VOL'] vol[vol==0] = None gle = df['GLEASON'] gle[gle==0] = None # Convert CAPSULE to a logical factor df['CAPSULE'] = df['CAPSULE'].asfactor() # Test/train split r = vol.runif() train = df[r< 0.8] test = df[r>=0.8] # See that the data is ready print train.describe() print test .describe() # Run GBM gbm = H2OGBM(dataset=train,x="CAPSULE",validation_dataset=test,ntrees=50,max_depth=5,learn_rate=0.1) #print gbm._model mm = gbm.metrics() mm0 = mm[0] cm = mm0['cm'] conf = cm['confusion_matrix'] print tabulate(conf)
apache-2.0
Python
c27685da10c85cb9876b4c73012da3ebff1915dc
Add exercise horse racing duals
AntoineAugusti/katas,AntoineAugusti/katas,AntoineAugusti/katas
codingame/easy/horse-racing_duals.py
codingame/easy/horse-racing_duals.py
N = int(raw_input()) lst = [] # Read the list for i in xrange(N): lst.append(int(raw_input())) # Sort the list, ascending order a = sorted(lst) # Find the min difference print min(y-x for x,y in zip(a, a[1:]))
mit
Python
cf592b24b0cc8e8944f32e1389379d57c8b9d96a
add list of universities
Impactstory/total-impact-webapp,total-impact/total-impact-webapp,Impactstory/total-impact-webapp,total-impact/total-impact-webapp,Impactstory/total-impact-webapp,total-impact/total-impact-webapp,total-impact/total-impact-webapp,Impactstory/total-impact-webapp
scripts/make_unis_list.py
scripts/make_unis_list.py
import re import json def make_country_key_to_iso_code_dict(country_lines): country_key_to_iso_code = {} for line in country_lines: m = re.match("\((\d+),", line) if m is not None: country_key = int(m.group(1)) iso_code = line.split(",")[1].replace("'", "").strip() country_key_to_iso_code[country_key] = iso_code return country_key_to_iso_code def make_uni_list(uni_lines, iso_code_dict): ret = [] for line in uni_lines: uni_obj = uni_obj_from_line(line) ret.append(uni_obj) return [uni for uni in ret if uni is not None] def uni_obj_from_line(line): print line if not line.startswith("("): return None uni_country_key = int(line.split(",")[1]) uni_name = line.split(",")[2].replace("'", "").strip() uni_url = line.split(",")[3].replace("'", "").strip() uni_iso_code = iso_code_dict[uni_country_key] return { "name": uni_name, "country": uni_iso_code, "url": uni_url } lines = open("world_university_names.sql", "r").read() country_lines = lines.split("[split here]")[0].split("\n") uni_lines = lines.split("[split here]")[1].split("\n") iso_code_dict = make_country_key_to_iso_code_dict(country_lines) uni_list = make_uni_list(uni_lines, iso_code_dict) with open("unis.json", "w") as outfile: json.dump(uni_list, outfile, sort_keys=True, indent=4) print "success!"
mit
Python
c1894e280f7d4b8d2afac6b4febaae451894306c
Add command to view exons in the database
Clinical-Genomics/scout,Clinical-Genomics/scout,Clinical-Genomics/scout
scout/commands/view/exons.py
scout/commands/view/exons.py
import logging import click from pprint import pprint as pp from flask.cli import with_appcontext from scout.server.extensions import store LOG = logging.getLogger(__name__) @click.command('exons', short_help='Display exons') @click.option('-b', '--build', default='37', type=click.Choice(['37', '38'])) @click.option('-i', '--hgnc-id', type=int) @click.option('--json', is_flag=True) @with_appcontext def exons(build, hgnc_id, json): """Show exons in the database""" LOG.info("Running scout view exons") adapter = store exon = adapter.exon(build=build) pp(exon) # if not json: # click.echo("Chromosome\tstart\tend\ttranscript_id\thgnc_id\trefseq\tis_primary") # i = 0 # for i,tx_obj in enumerate(adapter.transcripts(build=build, hgnc_id=hgnc_id),1): # if json: # pp(tx_obj) # continue # click.echo("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}".format( # tx_obj['chrom'], # tx_obj['start'], # tx_obj['end'], # tx_obj['ensembl_transcript_id'], # tx_obj['hgnc_id'], # tx_obj.get('refseq_id', ''), # tx_obj.get('is_primary') or '', # )) # if i == 0: # LOG.info("Could not find gene %s", hgnc_id)
bsd-3-clause
Python
685e9cc5f285bb6fadddea8d94d5a9820ace39e6
Initialize manager module for server
TheUnderscores/midi-beeper-orchestra
src/server/manager.py
src/server/manager.py
class Event: def __init__(self, t, hz): self.t = t self.hz = hz class Layer: def __init__(self): self.events = [] def addEvent(self, e): self.events.append(e) class Client: def __init__(self, connection): self.connection = connection class Manager: def __init__(self, clients): self.layers = [] # Connected clients self.clients = clients def updLyrDist(self): """ Updates layer distribution. In other words, which client is playing which channel. """ if len(self.clients) <= len(self.layers): for c_i, c in enumerate(self.clients): c.layer = c_i else: perLayer = int(len(self.clients) / len(self.layers)) pos = 0 for l_i in range(len(self.layers)): for c_i in range(pos, pos + perLayer): self.clients[c_i].layer = l_i pos += perLayer if pos < len(self.clients): # Assign leftover clients to different layers, starting # with layer 0 leftOver = len(self.clients) - pos for l_i in range(0, leftOver): self.clients[pos+l_i].layer = l_i def addLayer(self): self.layers.append(Layer()) self.updLyrDist() def rmvLayer(self, c_i): self.layers.pop(c_i) self.updLyrDist() def update(dt): """ Updates the manage dt is delta-time in milliseconds """ pass # TODO # TEST clients = [] for c_i in range(10): clients.append(Client('foo')) man = Manager(clients) for l_i in range(6): man.addLayer() for c_i, c in enumerate(man.clients): print(c.layer) # EOF TEST
agpl-3.0
Python
6be3900d26a25495101de2a14a9f62b59d9b776a
use posixpath to generate thumbnail-src
Chilledheart/seahub,miurahr/seahub,miurahr/seahub,cloudcopy/seahub,madflow/seahub,Chilledheart/seahub,Chilledheart/seahub,miurahr/seahub,madflow/seahub,cloudcopy/seahub,Chilledheart/seahub,madflow/seahub,madflow/seahub,cloudcopy/seahub,cloudcopy/seahub,madflow/seahub,Chilledheart/seahub,miurahr/seahub
seahub/thumbnail/utils.py
seahub/thumbnail/utils.py
import posixpath from seahub.utils import get_service_url def get_thumbnail_src(repo_id, obj_id, size): return posixpath.join(get_service_url(), "thumbnail", repo_id, obj_id, size)
import os from seahub.utils import get_service_url def get_thumbnail_src(repo_id, obj_id, size): return os.path.join(get_service_url(), "thumbnail", repo_id, obj_id, size, '')
apache-2.0
Python
ccadcfe891871032ea5e4c1974db67ed1b69a0e8
add undocumented function to display new messages.
michael-lazar/rtv,5225225/rtv,TheoPib/rtv,TheoPib/rtv,shaggytwodope/rtv,5225225/rtv,michael-lazar/rtv,bigplus/rtv,shaggytwodope/rtv,yskmt/rtv,michael-lazar/rtv,yskmt/rtv
rtv/docs.py
rtv/docs.py
from .__version__ import __version__ __all__ = ['AGENT', 'SUMMARY', 'AUTH', 'CONTROLS', 'HELP', 'COMMENT_FILE', 'SUBMISSION_FILE', 'COMMENT_EDIT_FILE'] AGENT = """\ desktop:https://github.com/michael-lazar/rtv:{} (by /u/civilization_phaze_3)\ """.format(__version__) SUMMARY = """ Reddit Terminal Viewer is a lightweight browser for www.reddit.com built into a terminal window. """ AUTH = """\ Authenticating is required to vote and leave comments. If only a username is given, the program will display a secure prompt to enter a password. """ CONTROLS = """ Controls -------- RTV currently supports browsing both subreddits and individual submissions. In each mode the controls are slightly different. In subreddit mode you can browse through the top submissions on either the front page or a specific subreddit. In submission mode you can view the self text for a submission and browse comments. """ HELP = """ Basic Commands `j/k` or `UP/DOWN` : Move the cursor up/down `m/n` or `PgUp/PgDn`: Jump to the previous/next page `o` or `ENTER` : Open the selected item as a webpage `r` or `F5` : Refresh page content `u` : Log in or switch accounts `?` : Show the help screen `q` : Quit Authenticated Commands `a/z` : Upvote/downvote `c` : Compose a new post or comment `e` : Edit an existing post or comment `d` : Delete an existing post or comment `i` : Display new messages prompt `s` : Open/close subscribed subreddits list Subreddit Mode `l` or `RIGHT` : Enter the selected submission `/` : Open a prompt to switch subreddits `f` : Open a prompt to search the current subreddit Submission Mode `h` or `LEFT` : Return to subreddit mode `SPACE` : Fold the selected comment, or load additional comments """ COMMENT_FILE = u""" # Please enter a comment. Lines starting with '#' will be ignored, # and an empty message aborts the comment. # # Replying to {author}'s {type} {content} """ COMMENT_EDIT_FILE = u"""{content} # Please enter a comment. Lines starting with '#' will be ignored, # and an empty message aborts the comment. # # Editing your comment """ SUBMISSION_FILE = u"""{content} # Please enter your submission. Lines starting with '#' will be ignored, # and an empty field aborts the submission. # # The first line will be interpreted as the title # The following lines will be interpreted as the content # # Posting to {name} """
from .__version__ import __version__ __all__ = ['AGENT', 'SUMMARY', 'AUTH', 'CONTROLS', 'HELP', 'COMMENT_FILE', 'SUBMISSION_FILE', 'COMMENT_EDIT_FILE'] AGENT = """\ desktop:https://github.com/michael-lazar/rtv:{} (by /u/civilization_phaze_3)\ """.format(__version__) SUMMARY = """ Reddit Terminal Viewer is a lightweight browser for www.reddit.com built into a terminal window. """ AUTH = """\ Authenticating is required to vote and leave comments. If only a username is given, the program will display a secure prompt to enter a password. """ CONTROLS = """ Controls -------- RTV currently supports browsing both subreddits and individual submissions. In each mode the controls are slightly different. In subreddit mode you can browse through the top submissions on either the front page or a specific subreddit. In submission mode you can view the self text for a submission and browse comments. """ HELP = """ Basic Commands `j/k` or `UP/DOWN` : Move the cursor up/down `m/n` or `PgUp/PgDn`: Jump to the previous/next page `o` or `ENTER` : Open the selected item as a webpage `r` or `F5` : Refresh page content `u` : Log in or switch accounts `i` : Display new messages prompt `?` : Show the help screen `q` : Quit Authenticated Commands `a/z` : Upvote/downvote `c` : Compose a new post or comment `e` : Edit an existing post or comment `d` : Delete an existing post or comment `s` : Open/close subscribed subreddits list Subreddit Mode `l` or `RIGHT` : Enter the selected submission `/` : Open a prompt to switch subreddits `f` : Open a prompt to search the current subreddit Submission Mode `h` or `LEFT` : Return to subreddit mode `SPACE` : Fold the selected comment, or load additional comments """ COMMENT_FILE = u""" # Please enter a comment. Lines starting with '#' will be ignored, # and an empty message aborts the comment. # # Replying to {author}'s {type} {content} """ COMMENT_EDIT_FILE = u"""{content} # Please enter a comment. Lines starting with '#' will be ignored, # and an empty message aborts the comment. # # Editing your comment """ SUBMISSION_FILE = u"""{content} # Please enter your submission. Lines starting with '#' will be ignored, # and an empty field aborts the submission. # # The first line will be interpreted as the title # The following lines will be interpreted as the content # # Posting to {name} """
mit
Python
9ffcadf3a79459b6685cf64a6a77d5186f8fc691
add main file, data base connection and one simple insertion test
sebasvega95/dist-systems-chat,sebasvega95/dist-systems-chat,sebasvega95/dist-systems-chat
main.py
main.py
from users_handler import UsersHandler import pymongo import logging import sys logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG) try: client = pymongo.MongoClient("mongodb://root:chat1234@ds135797.mlab.com:35797/chat") logging.info("Connected to the data base: {}".format(client.address)) except pymongo.errors.ConnectionFailure, e: logging.error("Could not connect to DB server: {}".format(e)) user_data = { 'first_name': 'Leiver', 'last_name': 'Campeon', 'username' : 'leiverandres', 'password' : '1234', 'age' : '21', 'gender': 'male' } db = client.chat handler = UsersHandler(db) handler.create_user(user_data)
mit
Python
7ca529e9afe68033c5f6f552aae6f5316a406555
check for peru file before running
olson-sean-k/peru,buildinspace/peru,oconnor663/peru,buildinspace/peru,scalp42/peru,olson-sean-k/peru,scalp42/peru,oconnor663/peru,enzochiau/peru,enzochiau/peru,ierceg/peru,ierceg/peru,nivertech/peru,nivertech/peru
main.py
main.py
#! /usr/bin/env python3 import os import sys import runtime import module def main(): peru_file_name = os.getenv("PERU_FILE_NAME") or "peru" if not os.path.isfile(peru_file_name): print("no peru file found") sys.exit(1) r = runtime.Runtime() m = module.parse(r, peru_file_name) if len(sys.argv) > 1: target = sys.argv[1].split('.') else: target = [] m.build(r, target) if __name__ == '__main__': main()
#! /usr/bin/env python3 import os import sys import runtime import module def main(): r = runtime.Runtime() peru_file_name = os.getenv("PERU_FILE_NAME") or "peru" m = module.parse(r, peru_file_name) if len(sys.argv) > 1: target = sys.argv[1].split('.') else: target = [] m.build(r, target) if __name__ == '__main__': main()
mit
Python
a7ba6c3872103bf46d838202da37e1426e285525
Add example skeleton
alepulver/my-thesis,alepulver/my-thesis,alepulver/my-thesis,alepulver/my-thesis
main.py
main.py
from random import random from kivy.app import App from kivy.uix.widget import Widget from kivy.uix.button import Button from kivy.graphics import Color, Ellipse, Line class MyPaintWidget(Widget): def on_touch_down(self, touch): color = (random(), 1, 1) with self.canvas: Color(*color, mode='hsv') d = 30. Ellipse(pos=(touch.x - d / 2, touch.y - d / 2), size=(d, d)) touch.ud['line'] = Line(points=(touch.x, touch.y)) def on_touch_move(self, touch): touch.ud['line'].points += [touch.x, touch.y] class MyPaintApp(App): def build(self): parent = Widget() painter = MyPaintWidget() clearbtn = Button(text='Clear') parent.add_widget(painter) parent.add_widget(clearbtn) def clear_canvas(obj): painter.canvas.clear() clearbtn.bind(on_release=clear_canvas) return parent if __name__ == '__main__': MyPaintApp().run()
mit
Python
b627cccbd77dbb4f8d87189d7d85cb66d2324b2e
add helpers.py file to notebooks folder for common helper functions for notebooks to use
joeymeyer/raspberryturk
notebooks/helpers.py
notebooks/helpers.py
import itertools import numpy as np import matplotlib.pyplot as plt def plot_confusion_matrix(cm, classes, normalize=False, title='Confusion matrix', cmap=plt.cm.Blues): """ This function prints and plots the confusion matrix. Normalization can be applied by setting `normalize=True`. """ plt.imshow(cm, interpolation='nearest', cmap=cmap) plt.title(title) plt.colorbar() tick_marks = np.arange(len(classes)) plt.xticks(tick_marks, classes, rotation=45) plt.yticks(tick_marks, classes) if normalize: cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis] thresh = cm.max() / 2. for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])): plt.text(j, i, cm[i, j], horizontalalignment="center", color="white" if cm[i, j] > thresh else "black") plt.tight_layout() plt.ylabel('True label') plt.xlabel('Predicted label') plt.show()
mit
Python
59ba6d2db5fa27878653f000cb1e6f8cfd6ccc89
Check ptavi.p3
arealg/ptavi-p3
check-p3.py
check-p3.py
#!/usr/bin/python3 # -*- coding: utf-8 -*- """ Script de comprobación de entrega de práctica Para ejecutarlo, desde la shell: $ python check-p3.py login_github """ import os import random import sys if len(sys.argv) != 2: print() sys.exit("Usage : $ python3 check-p3.py login_github") repo_git = "http://github.com/" + sys.argv[1] + "/ptavi-p3" python_files = [ 'smallsmilhandler.py', 'karaoke.py', ] files = ['README.md', 'LICENSE', '.gitignore', 'check-p3.py', '.git' ] aleatorio = str(int(random.random() * 1000000)) error = 0 print() print("Clonando el repositorio " + repo_git + "\n") os.system('git clone ' + repo_git + ' /tmp/' + aleatorio + ' > /dev/null 2>&1') try: student_file_list = os.listdir('/tmp/' + aleatorio) except OSError: error = 1 print("Error: No se ha podido acceder al repositorio " + repo_git + ".") print() sys.exit() if len(student_file_list) != len(files) + len(python_files): error = 1 print("Error: solamente hay que subir al repositorio los ficheros") print("indicados en las guion de practicas, que son en total") print(str(len(python_files) + len(files)) + " (incluyendo .git):") for filename in files + python_files: if filename not in student_file_list: error = 1 print(" Error: " + filename + " no encontrado.", "Tienes que subirlo al repositorio.") if not error: print("Parece que la entrega se ha realizado bien.") print() print("La salida de pep8 es: (si todo va bien, no ha de mostrar nada)") print() files = '' for python_file in python_files: files += ' /tmp/' + aleatorio + '/' + python_file os.system('pep8 --repeat --show-source --statistics ' + files) print()
apache-2.0
Python
db689744216f19ed425e3155dd8d57d792497f4a
create VersionList module and class to manage the list of blender version installed on user system
CaptainDesAstres/Simple-Blender-Render-Manager,CaptainDesAstres/Blender-Render-Manager
settingMod/VersionList.py
settingMod/VersionList.py
#!/usr/bin/python3.4 # -*-coding:Utf-8 -* '''module to manage list of all know version of Blender in the system''' import xml.etree.ElementTree as xmlMod class VersionList: '''class dedicated to Blender version managing''' def __init__(self, xml= None): '''initialize Blender version list with default value or values extracted from an xml object''' if xml is None: self.defaultInit() else: self.fromXml(xml) def defaultInit(self): '''initialize Blender version list with default value''' def fromXml(self, xml): '''initialize Blender version list with values extracted from an xml object''' def toXml(self): '''export Blender version list into xml syntaxed string''' return '' def see(self, log): '''method to see Blender version list and access edition menu'''
mit
Python
56e48a414b1145e4955aeea58e409cebd0b4d9d0
Add serialize tests
absent1706/sqlalchemy-mixins
sqlalchemy_mixins/tests/test_serialize.py
sqlalchemy_mixins/tests/test_serialize.py
import unittest import sqlalchemy as sa from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import Session from sqlalchemy_mixins import SerializeMixin Base = declarative_base() class BaseModel(Base, SerializeMixin): __abstract__ = True pass class User(BaseModel): __tablename__ = 'user' id = sa.Column(sa.Integer, primary_key=True) name = sa.Column(sa.String) posts = sa.orm.relationship('Post') class Post(BaseModel): __tablename__ = 'post' id = sa.Column(sa.Integer, primary_key=True) body = sa.Column(sa.String) user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id')) archived = sa.Column(sa.Boolean, default=False) user = sa.orm.relationship('User') comments = sa.orm.relationship('Comment') class Comment(BaseModel): __tablename__ = 'comment' id = sa.Column(sa.Integer, primary_key=True) body = sa.Column(sa.String) user_id = sa.Column(sa.Integer, sa.ForeignKey('user.id')) post_id = sa.Column(sa.Integer, sa.ForeignKey('post.id')) rating = sa.Column(sa.Integer) user = sa.orm.relationship('User') post = sa.orm.relationship('Post') class TestSerialize(unittest.TestCase): @classmethod def setUpClass(cls): cls.engine = create_engine('sqlite:///:memory:', echo=False) def setUp(self): self.session = Session(self.engine) Base.metadata.create_all(self.engine) user_1 = User(name='Bill u1', id=1) self.session.add(user_1) self.session.commit() user_2 = User(name='Alex u2', id=2) self.session.add(user_2) self.session.commit() self.session.commit() post_11 = Post( id=11, body='Post 11 body.', archived=True ) post_11.user = user_1 self.session.add(post_11) self.session.commit() comment_11 = Comment( id=11, body='Comment 11 body', user=user_1, post=post_11, rating=1 ) self.session.add(comment_11) self.session.commit() def tearDown(self): Base.metadata.drop_all(self.engine) def test_serialize_single(self): result = self.session.query(User).first().to_dict() expected = { 'id': 1, 'name': 'Bill u1' } self.assertDictEqual(result, expected) def test_serialize_list(self): result = [user.to_dict() for user in self.session.query(User).all()] expected = [ { 'id': 1, 'name': 'Bill u1' }, { 'id': 2, 'name': 'Alex u2' }, ] self.assertListEqual(expected, result) def test_serialize_nested(self): result = self.session.query(Post).first().to_dict(nested=True) expected = { 'id': 11, 'body': 'Post 11 body.', 'archived': True, 'user_id': 1, 'user': { 'id': 1, 'name': 'Bill u1' }, 'comments': [ { 'id': 11, 'body': 'Comment 11 body', 'user_id': 1, 'post_id': 11, 'rating': 1, } ] } self.assertDictEqual(result, expected) if __name__ == '__main__': unittest.main()
mit
Python
d84b0a0c882737971787b6a4da20733301de56b6
add weixin backend
duoduo369/python-social-auth,duoduo369/python-social-auth
social/backends/weixin.py
social/backends/weixin.py
#coding:utf8 # author:duoduo3369@gmail.com https://github.com/duoduo369 """ Weixin OAuth2 backend, docs at: """ from requests import HTTPError from social.backends.oauth import BaseOAuth2 from social.exceptions import AuthCanceled, AuthUnknownError class WeixinOAuth2(BaseOAuth2): """Weixin OAuth authentication backend""" name = 'weixin' ID_KEY = 'openid' AUTHORIZATION_URL = 'https://open.weixin.qq.com/connect/qrconnect' ACCESS_TOKEN_URL = 'https://api.weixin.qq.com/sns/oauth2/access_token' ACCESS_TOKEN_METHOD = 'POST' REDIRECT_STATE = False EXTRA_DATA = [ ('nickname', 'username'), ('headimgurl', 'profile_image_url'), ] def get_user_details(self, response): """Return user details from Weixin. API URL is: https://api.weixin.qq.com/sns/userinfo """ if self.setting('DOMAIN_AS_USERNAME'): username = response.get('domain', '') else: username = response.get('nickname', '') profile_image_url = response.get('headimgurl', '') return {'username': username, 'profile_image_url': profile_image_url} def user_data(self, access_token, *args, **kwargs): data = self.get_json('https://api.weixin.qq.com/sns/userinfo', params={'access_token': access_token, 'openid': kwargs['response']['openid']}) nickname = data.get('nickname') if nickname: # 微信蛇精病的接口,返回的是一个奇怪的东西 data['nickname'] = nickname.encode('raw_unicode_escape').decode('utf-8') return data def auth_params(self, state=None): appid, secret = self.get_key_and_secret() params = { 'appid': appid, 'redirect_uri': self.get_redirect_uri(state) } if self.STATE_PARAMETER and state: params['state'] = state if self.RESPONSE_TYPE: params['response_type'] = self.RESPONSE_TYPE return params def auth_complete_params(self, state=None): appid, secret = self.get_key_and_secret() return { 'grant_type': 'authorization_code', # request auth code 'code': self.data.get('code', ''), # server response code 'appid': appid, 'secret': secret, 'redirect_uri': self.get_redirect_uri(state) } def refresh_token_params(self, token, *args, **kwargs): appid, secret = self.get_key_and_secret() return { 'refresh_token': token, 'grant_type': 'refresh_token', 'appid': appid, 'secret': secret } def auth_complete(self, *args, **kwargs): """Completes loging process, must return user instance""" self.process_error(self.data) try: response = self.request_access_token( self.ACCESS_TOKEN_URL, data=self.auth_complete_params(self.validate_state()), headers=self.auth_headers(), method=self.ACCESS_TOKEN_METHOD ) except HTTPError as err: if err.response.status_code == 400: raise AuthCanceled(self) else: raise except KeyError: raise AuthUnknownError(self) if 'errcode' in response: raise AuthCanceled(self) self.process_error(response) return self.do_auth(response['access_token'], response=response, *args, **kwargs)
bsd-3-clause
Python
238f62cadfe4514b116ffaa0b0c2206e31132d8e
Add poll.py, which polls an F5 load balancer for virtual service stats and sends them to Graphite
mjulian/pysnmp-examples
poll.py
poll.py
#!/usr/bin/env python from pysnmp.entity.rfc3413.oneliner import cmdgen from pysnmp.smi import builder import time import socket import struct import pickle hostname = socket.gethostname().split('.') colo = hostname[1] CARBON_SERVER = "" CARBON_PORT = 2004 COMMUNITY_STRING = "" cmdGen = cmdgen.CommandGenerator() mibBuilder = cmdGen.snmpEngine.msgAndPduDsp.mibInstrumController.mibBuilder mibSources = mibBuilder.getMibSources() + ( builder.DirMibSource('/opt/pymibs'), ) mibBuilder.setMibSources(*mibSources) def get_slb_list(): # This function commented out for proprietary reasons # You can build this list statically or using some external # data source (I prefer to query SQL or an API) return def send_metrics(metric_data): package = pickle.dumps(metric_data, 1) size = struct.pack('!L', len(package)) sock = socket.socket() sock.connect((CARBON_SERVER, CARBON_PORT)) sock.sendall(size) sock.sendall(package) def poll_f5_virtual_service(slb): """ This function takes the FQDN of an SLB and polls via SNMP for the current connections on a VIP. The results are formatted into a Graphite metric, pickled, and sent to Graphite. SLB name, as sent to Graphite, is only the short name (the name before the first domain suffix, eg, slb1a). """ slb_name, colo, domain = slb.split('.', 2) metric_data = ([]) errorIndication, errorStatus, errorIndex, varBindTable = cmdGen.nextCmd( cmdgen.CommunityData(COMMUNITY_STRING), cmdgen.UdpTransportTarget((slb, 161)), cmdgen.MibVariable('F5-BIGIP-LOCAL-MIB', 'ltmVirtualServStatClientCurConns'), lookupValues=True, lookupNames=True, ) for varBindTableRow in varBindTable: for name, val in varBindTableRow: customer, service = name.prettyPrint().lstrip("F5-BIGIP-LOCAL-MIB::ltmVirtualServStatClientCurConns.").strip('\"').lstrip('/').split('/') val = int(val.prettyPrint()) metric_data.append(('slb.%s.%s.%s.%s' % (colo, slb_name, customer, service), (int(time.time()), val))) send_metrics(metric_data) if __name__ == "__main__": for device_name, device_colo, device_model in get_slb_list(): if device_colo == colo: poll_f5_virtual_service(device_name)
mit
Python
013016bf533a91e7dceffd806a8a1db0e8b6a74c
add admin.py to device logs for text-based searching
SEL-Columbia/commcare-hq,puttarajubr/commcare-hq,dimagi/commcare-hq,dimagi/commcare-hq,qedsoftware/commcare-hq,qedsoftware/commcare-hq,puttarajubr/commcare-hq,SEL-Columbia/commcare-hq,qedsoftware/commcare-hq,qedsoftware/commcare-hq,dimagi/commcare-hq,SEL-Columbia/commcare-hq,puttarajubr/commcare-hq,dimagi/commcare-hq,qedsoftware/commcare-hq,dimagi/commcare-hq,puttarajubr/commcare-hq
corehq/ex-submodules/phonelog/admin.py
corehq/ex-submodules/phonelog/admin.py
from django.contrib import admin from .models import * class DeviceReportEntryAdmin(admin.ModelAdmin): model = DeviceReportEntry list_display = [ 'xform_id', 'msg', 'type', 'domain', 'date', 'username', ] search_fields = [ 'xform_id', 'msg', 'type', 'domain', 'date', 'username', ] admin.site.register(DeviceReportEntry, DeviceReportEntryAdmin)
bsd-3-clause
Python
717f3c5d4babe9feeb4e0d82fb2ea839d735c4b4
Test database.common for full coverage of database
LINKIWI/linkr,LINKIWI/linkr,LINKIWI/linkr
test/backend/test_database/test_common.py
test/backend/test_database/test_common.py
import mock from linkr import db import database.common from test.backend.test_case import LinkrTestCase class TestCommon(LinkrTestCase): def test_create_tables(self): with mock.patch.object(db, 'create_all') as mock_create: database.common.create_tables() self.assertTrue(mock_create.called)
mit
Python
62962e852b24e9659b82615190cf184896fe08d7
Add account tasks
fin/froide,stefanw/froide,fin/froide,fin/froide,stefanw/froide,stefanw/froide,fin/froide,stefanw/froide,stefanw/froide
froide/account/tasks.py
froide/account/tasks.py
from django.conf import settings from django.utils import translation from froide.celery import app as celery_app from .models import User @celery_app.task def cancel_account_task(user_pk): from .utils import cancel_user translation.activate(settings.LANGUAGE_CODE) try: user = User.objects.get(pk=user_pk) except User.DoesNotExist: return cancel_user(user) @celery_app.task def delete_unconfirmed_users_task(): from .utils import delete_unconfirmed_users translation.activate(settings.LANGUAGE_CODE) delete_unconfirmed_users() @celery_app.task def delete_deactivated_users_task(): from .utils import delete_deactivated_users translation.activate(settings.LANGUAGE_CODE) delete_deactivated_users()
mit
Python
97c93e1c678c93dccb9a361bdffe5b1edd51f144
make ansi
scopatz/xolors
make_ansi.py
make_ansi.py
#!/usr/bin/env python import re import math from pprint import pprint, pformat from colortrans import rgb2short from from pygments.styles import get_style_by_name, get_all_styles BASE_COLORS = { 'BLACK': (0, 0, 0), 'RED': (170, 0, 0), 'GREEN': (0, 170, 0), 'YELLOW': (170, 85, 0), 'BLUE': (0, 0, 170), 'PURPLE': (170, 0, 170), 'CYAN': (0, 170, 170), 'WHITE' (170, 170, 170), 'INTENSE_BLACK': (85, 85, 85), 'INTENSE_RED': (255, 85, 85), 'INTENSE_GREEN': (85, 255, 85), 'INTENSE_YELLOW': (255, 255, 85), 'INTENSE_BLUE': (85, 85, 255), 'INTENSE_PURPLE': (255, 85, 255), 'INTENSE_CYAN': (85, 255, 255), 'INTENSE_WHITE': (255, 255, 255), } RE_RGB = re.compile(r'(..)(..)(..)') def rgb2ints(rgb): return tuple([int(h, 16) for h in RE_RGB.split(rgb)[1:4]]) def dist(x, y): return math.sqrt((x[0]-y[0])**2 + (x[1]-y[1])**2 + (x[2]-y[2])**2) def find_closest(x, pallette): key = lambda k: dist(x, pallette[k]) return min(pallette.keys(), key=key) def make_ansi_style(pallette): style = {} for name, t in BASE_COLORS.items(): closest = find_closest(t, pallette) short = rgb2short(closest) style[name] = '38;5;' + short style['BOLD_'+name] = '1;38;5;' + short style['UNDERLINE_'+name] = '4;38;5;' + short style['BOLD_UNDERLINE_'+name] = '1;4;38;5;' + short style['BACKGROUND_'+name] = '48;5;' + short return style def make_pallete(strings): pallette = {} for s in strings: while '#' in s: _, t = s.split('#', 1) pallette[t[:6]] = rgb2ints(t[:6]) s = t[6:] return pallette for name in get_all_styles(): if name == 'default': continue pstyle = get_style_by_name() pallette = make_pallete(pstyle.styles.values()) astyle = make_ansi_style(pallette) out = name.upper() + '_STYLE = ' + pformat(astyle, indent=4) + '\n' print(out) print('styles = {') for name in get_all_styles(): print(" '"+name+"': " +name.upper() + '_STYLE,') print('}')
bsd-2-clause
Python
4316122225d2e523ff310f65479ea676e0aa02e3
Add methods for loading data sets
brilee/MuGo
load_data_sets.py
load_data_sets.py
import os import numpy as np import sgf_wrapper def load_sgf_positions(*dataset_names): for dataset in dataset_names: dataset_dir = os.path.join(os.getcwd(), 'data', dataset) dataset_files = [os.path.join(dataset_dir, name) for name in os.listdir(dataset_dir)] all_datafiles = filter(os.path.isfile, dataset_files) for file in all_datafiles: with open(file) as f: sgf = sgf_wrapper.SgfWrapper(f.read()) for position_w_context in sgf.get_main_branch(): if position_w_context.is_usable(): yield position_w_context def extract_features(features, positions): num_feature_planes = sum(f.planes for f in features) num_positions = len(positions) output = np.zeros([num_positions, 19, 19, num_feature_planes]) for i, pos in enumerate(positions): output[i] = np.concatenate([feature.extract(pos) for feature in features], axis=2) return output
apache-2.0
Python
263fb51df80a9da6efc567f7e6e3b26012e12a4c
Fix bug for url_to_s3
dkuner/example-modules,dkuner/example-modules,DataCanvasIO/example-modules,dkuner/example-modules,DataCanvasIO/example-modules,DataCanvasIO/example-modules,DataCanvasIO/example-modules,dkuner/example-modules
modules/data_source/url_to_s3/main.py
modules/data_source/url_to_s3/main.py
#!/usr/bin/env python # -*- coding: utf-8 -*- from specparser import get_settings_from_file import os import sys import boto import requests from StringIO import StringIO def percent_cb(complete, total): sys.stdout.write('.') sys.stdout.flush() def s3_multipart_upload(bucket, url, remote_filename): from urlparse import urlparse r = requests.get(url, stream=True) fn_remote = urlparse(remote_filename).path fn_remote_full = remote_filename print("Multi-Part upload...") print("From : %s" % url) print("To : %s" % fn_remote_full) buffer_size = 10 * 1024 * 1024 mp = bucket.initiate_multipart_upload(fn_remote) num_part = 1 try: for buf in r.iter_content(buffer_size): if not buf: break io = StringIO(buf) mp.upload_part_from_file(io, num_part, cb=percent_cb, num_cb=1, size=len(buf)) num_part += 1 io.close() except IOError as e: mp.cancel_upload() raise e mp.complete_upload() print("") return fn_remote_full def get_s3_working_dir(settings, s3_bucket, path=""): ps = settings glb_vars = ps.GlobalParam remote_path = os.path.normpath(os.path.join(s3_bucket.name, 'zetjob', glb_vars['userName'], "job%s" % glb_vars['jobId'], "blk%s" % glb_vars['blockId'], path)) return os.path.join("s3://", remote_path) def main(): settings = get_settings_from_file("spec.json") print(settings) p = settings.Param s3_conn = boto.connect_s3(p.AWS_ACCESS_KEY_ID, p.AWS_ACCESS_KEY_SECRET) s3_bucket = s3_conn.get_bucket(p.S3_BUCKET) remote_filename = get_s3_working_dir(settings, s3_bucket, "OUTPUT_dest_s3/dest_s3") remote_filename_full = s3_multipart_upload(s3_bucket, p.SOURCE_URL, remote_filename) remote_dir = os.path.dirname(remote_filename_full) with open(settings.Output.dest_s3, "w") as f: f.write(remote_dir) print("Done") if __name__ == "__main__": main()
#!/usr/bin/env python # -*- coding: utf-8 -*- from specparser import get_settings_from_file import os import sys import boto import requests from StringIO import StringIO def percent_cb(complete, total): sys.stdout.write('.') sys.stdout.flush() def s3_multipart_upload(bucket, url, remote_filename): from urlparse import urlparse r = requests.get(url, stream=True) fn_remote = urlparse(remote_filename).path fn_remote_full = remote_filename print("Multi-Part upload...") print("From : %s" % url) print("To : %s" % fn_remote_full) buffer_size = 10 * 1024 * 1024 mp = bucket.initiate_multipart_upload(fn_remote) num_part = 1 try: for buf in r.iter_content(buffer_size): if not buf: break io = StringIO(buf) mp.upload_part_from_file(io, num_part, cb=percent_cb, num_cb=1, size=len(buf)) num_part += 1 io.close() except IOError as e: raise e mp.complete_upload() print("") return fn_remote_full def get_s3_working_dir(settings, s3_bucket, path=""): ps = settings glb_vars = ps.GlobalParam remote_path = os.path.normpath(os.path.join(s3_bucket.name, 'zetjob', glb_vars['userName'], "job%s" % glb_vars['jobId'], "blk%s" % glb_vars['blockId'], path)) return os.path.join("s3://", remote_path) def main(): settings = get_settings_from_file("spec.json") print(settings) p = settings.Param s3_conn = boto.connect_s3(p.AWS_ACCESS_KEY_ID, p.AWS_ACCESS_KEY_SECRET) s3_bucket = s3_conn.get_bucket(p.S3_BUCKET) remote_filename = get_s3_working_dir(settings, s3_bucket, "OUTPUT_dest_s3/dest_s3") remote_filename_full = s3_multipart_upload(s3_bucket, p.SOURCE_URL, remote_filename) remote_dir = os.path.dirname(remote_filename_full) with open(settings.Output.dest_s3, "w") as f: f.write(remote_dir) print("Done") if __name__ == "__main__": main()
bsd-3-clause
Python
02401c9cdccaa52cf933ffc16225dc6bcbc2a1c3
Create matrix.py
fnielsen/dasem,fnielsen/dasem
dasem/matrix.py
dasem/matrix.py
"""Matrix. Usage: dasem.docterm save-wikipedia-doc-term-matrix [options] <filename> Options: --output-filename Filename to write to -h --help Help message --max-n-pages=<int> Maximum number of pages -v --verbose Verbose debug messaging """ import json from scipy import io from .wikipedia import XmlDumpFile class DocTermMatrix(object): def __init__(self, matrix, rows, columns): """Setup matrix values and row and column annotation. Parameters ---------- matrix : matrix from scipy or numpy Values rows : list of str Row annotation. columns : list of str Column annotation. """ self.matrix = matrix self.rows = rows self.columns = columns def __str__(self): """Return string representation.""" return "<DocTermMatrix({}x{})>".format(*self.matrix.shape) __repr__ = __str__ def save(self, filename): """Save matrix to a Matrix Market file. Parameters ---------- filename : str Output filename. """ comment = json.dumps({'rows': self.rows, 'columns': self.columns}) io.mmwrite(filename, self.matrix, comment=comment) def load_doc_term_matrix(filename): """Load matrix from Matrix market file. Parameters ---------- filename : str Input filename. """ matrix = io.mmread(filename) with open(filename) as f: line = f.readline() # Ignore first line line = f.readline() data = json.loads(line[1:]) rows = data['rows'] columns = data['columns'] doc_term_matrix = DocTermMatrix(matrix, rows, columns) return doc_term_matrix def main(): """Handle command-line interface.""" from docopt import docopt arguments = docopt(__doc__) if arguments['save-wikipedia-doc-term-matrix']: dump_file = XmlDumpFile() matrix, rows, columns = dump_file.doc_term_matrix( max_n_pages=int(arguments['--max-n-pages']), verbose=arguments['--verbose']) doc_term_matrix = DocTermMatrix(matrix, rows, columns) doc_term_matrix.save( filename=arguments['<filename>']) if __name__ == '__main__': main()
apache-2.0
Python
715e02da3f2bdf8bff6d18258295e0152c27acef
Add the procedure generator
SanaMobile/sana.protocol_builder,SanaMobile/sana.protocol_builder,SanaMobile/sana.protocol_builder,SanaMobile/sana.protocol_builder,SanaMobile/sana.protocol_builder
src-backend/api/generator.py
src-backend/api/generator.py
from xml.etree import ElementTree from xml.dom import minidom from models import * class ProcedureGenerator: def __init__(self, procedure): self.name = 'Procedure' self.procedure = procedure def _get_properties(self): props = { 'title': self.procedure.title, 'author': self.procedure.author } if not procedure.version: props['version'] = self.procedure.version if not procedure.uuid: props['uuid'] = self.procedure.uuid return props def generate(self): element = ElementTree.Element(self.name) element.attrib = self._get_properties() return element.attrib class PageGenerator: def __init__(self, page): self.name = 'Page' self.page = page def generate(self, parent): return ElementTree.SubElement(parent, self.name) class ElementGenerator: def __init__(self, element): self.name = 'Name' self.element = element def _get_properties(self): props = { 'type': element.element_type, 'id': element.eid, 'concept': element.concept, 'question': element.question, 'answer': element.answer } if not element.numeric: props['numeric'] = self.element.numeric if not element.choices: props['choices'] = self.element.choices return props def generate(self, parent): props = self._get_properties() ElementTree.SubElement(parent, self.name, props) class ProtocolBuilder: @classmethod def _prettify(cls, elem): rough_string = ElementTree.tostring(elem, 'utf-8') reparsed = minidom.parseString(rough_string) return reparsed.toprettyxml(indent=" ") @classmethod def generate(cls, owner, pk): try: procedure = Procedure.objects.get(pk=pk) except Procedure.DoesNotExist: raise ValueError('Invalid procedure id') if procedure.owner != owner: raise ValueError('Invalid owner') procedureElement = ProcedureGenerator(procedure).generate() for page in procedure.pages: pageElement = PageGenerator(page).generate(procedureElement) for element in page.elements: ElementGenerator(element).generate(pageElement) return cls._prettify(procedureElement)
bsd-3-clause
Python
b97c67277c049602b6a41d7222539ba459155cdb
Create imagebot.py
CallmeTorre/TelegramBot
imagebot.py
imagebot.py
import urllib import time import json import requests import os TOKEN = "<your-bot-token>" URL = "https://api.telegram.org/bot{}/".format(TOKEN) IMAGE_URL = "https://api.telegram.org/file/bot{}/".format(TOKEN) DOWNLOADED_IMAGE_PATH = "/Telegram/" def get_url(url): """Downloads the content from a URL and gives us a string""" response = requests.get(url) content = response.content.decode("utf8") return content def get_json_from_url(url): """Gets the string response as above and parses this into a Python dictionary using json.loads()""" content = get_url(url) js = json.loads(content) return js def get_updates(offset=None): """Call this command https://api.telegram.org/bot<your-bot-token>/getUpdates and retrieves a list of updates""" url = URL + "getUpdates?timeout=100" if offset: #If this is specified, we'll pass it along to the Telegram API to indicate that we don't want to receive any messages with smaller IDs this. url += "&offset={}".format(offset) js = get_json_from_url(url) return js def get_last_update_id(updates): """Calculates the highest ID of all the updates we receive from getUpdates""" update_ids = [] for update in updates["result"]: update_ids.append(int(update["update_id"])) return max(update_ids) def send_message(text,chat_id,reply_markup=None): """Takes the text of the message we want to send (text) and the chat ID of the chat where we want to send the message (chat_id)""" text = urllib.quote_plus(text) url = URL + "sendMessage?text={}&chat_id={}&parse_mode=Markdown".format(text, chat_id) if reply_markup: url += "&reply_markup={}".format(reply_markup) get_url(url) def request_image_path(photo_id): """Call this command https://api.telegram.org/bot<your-bot-token>/getFile?file_id=<id>, retrieves the information of the image selected and return the file path""" url = URL + "getFile?file_id={}".format(photo_id) js = get_json_from_url(url) file_path = js["result"]["file_path"] return file_path def get_image(image_path): """Receive a path and download the image in a folder named Telegram""" filename = image_path[image_path.find("/")+1:] url = IMAGE_URL + image_path try: image_on_web = urllib.urlopen(url) buf = image_on_web.read() path = os.getcwd() + DOWNLOADED_IMAGE_PATH file_path = "%s%s" % (path, filename) downloaded_image = file(file_path, "wb") downloaded_image.write(buf) downloaded_image.close() image_on_web.close() except: return False return True def handle_updates(updates): """Manage the incomming updates and check if the user send an image and call get_image method""" for update in updates["result"]: try: text = update["message"]["text"] except: text = None chat = update["message"]["chat"]["id"] if text == "/start": send_message("Welcome to Image Bot. Send any image and I'll store it forever >:D", chat) elif text: send_message("That is not an image", chat) else: photo_list = update["message"]["photo"] biggest_index = len(photo_list)-1 photo_id = photo_list[biggest_index]["file_id"] photo_path = request_image_path(photo_id) if get_image(photo_path): send_message("Image Saved", chat) else: send_message("Oops :C", chat) def main(): last_update_id = None while True: print("getting updates") updates = get_updates(last_update_id) if len(updates["result"])> 0: last_update_id = get_last_update_id(updates) + 1 handle_updates(updates) if __name__ == '__main__': main()
mit
Python
9707ccdab7f51e61dda2ac290ffda882d3610ee8
Create retrieve_newest_file_from_nas.py
jebstone/datascience
retrieve_newest_file_from_nas.py
retrieve_newest_file_from_nas.py
#!/bin/env python3 """ Copies the most recent datafile from a secure NAS to a local file. """ key_file = 'key_rsa' # NOT .pub import paramiko import sqlite3 from datetime import datetime host = 'hostname' port = 22 username = '' filecount = 15 localdir = r"C:/" remotedir = r"/nas/data/" # SSH Key my_key = paramiko.RSAKey.from_private_key_file(key_file) def copy_file(filename): localpath = localdir + filename remotepath = remotedir + filename sftp.get(remotepath, localpath) print("Done") # SFTP Connection transport = paramiko.Transport((host, port)) transport.connect(username=username, pkey=my_key) sftp = paramiko.SFTPClient.from_transport(transport) # Get Top N records file_list = sftp.listdir(remotedir) file_list.sort(reverse=True) file_list = file_list[:filecount] # get the first record myfile=file_list.pop() # Copy the most recent file down to localpath copy_file(myfile) # Close connections sftp.close() transport.close()
unlicense
Python
d88c53ba3dac62c361f60523196d3dc7b9bd90b1
Add spider for Einstein Bros. Closes #784
iandees/all-the-places,iandees/all-the-places,iandees/all-the-places
locations/spiders/einsteinbros.py
locations/spiders/einsteinbros.py
# -*- coding: utf-8 -*- import datetime import re import scrapy from locations.items import GeojsonPointItem from locations.hours import OpeningHours DAY_MAPPING = { 'Monday': 'Mo', 'Tuesday': 'Tu', 'Wednesday': 'We', 'Thursday': 'Th', 'Friday': 'Fr', 'Saturday': 'Sa', 'Sunday': 'Su' } class EinsteinBrosSpider(scrapy.Spider): download_delay = 0.5 name = "einsteinbros" allowed_domains = ["einsteinbros.com"] start_urls = ( 'https://locations.einsteinbros.com/us', ) def parse_hours(self, elements): opening_hours = OpeningHours() for elem in elements: day = elem.xpath('.//td[@class="c-location-hours-details-row-day"]/text()').extract_first() intervals = elem.xpath('.//td[@class="c-location-hours-details-row-intervals"]') if intervals.xpath('./text()').extract_first() == "Closed": continue if intervals.xpath('./span/text()').extract_first() == "Open 24 hours": opening_hours.add_range(day=DAY_MAPPING[day], open_time='0:00', close_time='23:59') else: start_time = elem.xpath( './/span[@class="c-location-hours-details-row-intervals-instance-open"]/text()').extract_first() end_time = elem.xpath( './/span[@class="c-location-hours-details-row-intervals-instance-close"]/text()').extract_first() opening_hours.add_range(day=DAY_MAPPING[day], open_time=datetime.datetime.strptime(start_time, '%H:%M %p').strftime('%H:%M'), close_time=datetime.datetime.strptime(end_time, '%H:%M %p').strftime('%H:%M')) return opening_hours.as_opening_hours() def parse_store(self, response): ref = re.search(r'.+/(.+)$', response.url).group(1) address1 = response.xpath('//span[@class="c-address-street-1"]/text()').extract_first() address2 = response.xpath('//span[@class="c-address-street-2"]/text()').extract_first() or '' properties = { 'addr_full': " ".join([address1, address2]).strip(), 'phone': response.xpath('//span[@itemprop="telephone"]/text()').extract_first(), 'city': response.xpath('//span[@class="c-address-city"]/text()').extract_first(), 'state': response.xpath('//span[@itemprop="addressRegion"]/text()').extract_first(), 'postcode': response.xpath('//span[@itemprop="postalCode"]/text()').extract_first(), 'country': response.xpath('//abbr[@itemprop="addressCountry"]/text()').extract_first(), 'ref': ref, 'website': response.url, 'lat': float(response.xpath('//meta[@itemprop="latitude"]/@content').extract_first()), 'lon': float(response.xpath('//meta[@itemprop="longitude"]/@content').extract_first()), 'name': response.xpath('//h1[@id="location-name"]/text()').extract_first() } hours = self.parse_hours(response.xpath('//table[@class="c-location-hours-details"]//tbody/tr')) if hours: properties['opening_hours'] = hours yield GeojsonPointItem(**properties) def parse(self, response): urls = response.xpath('//a[@class="Directory-listLink"]/@href').extract() is_store_list = response.xpath('//section[contains(@class,"LocationList")]').extract() if not urls and is_store_list: urls = response.xpath('//a[contains(@class,"Teaser-titleLink")]/@href').extract() for url in urls: if re.search(r'us/.{2}/.+/.+',url): yield scrapy.Request(response.urljoin(url), callback=self.parse_store) else: yield scrapy.Request(response.urljoin(url))
mit
Python
38587aa6c906b87e5a908a6b963d89cbc2fc5505
move manage.py into src folder
telefonicaid/orchestrator,telefonicaid/orchestrator
src/manage.py
src/manage.py
#!/usr/bin/env python import os import sys if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") from django.core.management import execute_from_command_line execute_from_command_line(sys.argv)
agpl-3.0
Python
e8880307030922f1ab7b2445ee67179fe276f1b1
add trayicon test
cr33dog/pyxfce,cr33dog/pyxfce,cr33dog/pyxfce
netk/tests/testtrayicon.py
netk/tests/testtrayicon.py
#!/usr/bin/env python import pygtk pygtk.require("2.0") import xfce4 label = gtk.Label("Boo!") label.show() ti = xfce4.netk.TrayIcon(gtk.gdk.screen_get_default()) ti.add(label) ti.show() gtk.main()
bsd-3-clause
Python
ca000b194397d314473040cd634d203b8aa0828a
add task generator for subtask 2
google/BIG-bench,google/BIG-bench
bigbench/benchmark_tasks/unit_conversion/2_novel_systems/task_generator.py
bigbench/benchmark_tasks/unit_conversion/2_novel_systems/task_generator.py
#!/usr/bin/env python # coding: utf-8 import json from math import floor, log10, sqrt import numpy as np import random def generate_question(q_type, amount1, amount2, q_ind1, q_ind2, conv_rate): # Generate question to ask model to convert $amount of unit1 into unit2. unit1 = base_quantity[q_ind1] unit2 = base_quantity[q_ind2] question = "" # if q_type == 0: question = f'Q: {amount1} {plural(unit1, amount1)} is {amount1*conv_rate} {plural(unit2, amount1*conv_rate)}. Convert {amount2} {plural(unit1, amount2)} to {plural(unit2, 1.0)}.' # elif q_type == 1: # question = f'Q: How many {plural(unit2, 1.0)} are in {amount} {plural(unit2, amount)}?' return question def correct_answer(amount, conv_rate): answer = amount * conv_rate # answer = int(answer) if type(amount) == int and answer > 1 else answer return answer def plural(quantity, amount): if amount != 1 or type(amount) is not int: return quantity + 's' return quantity def round_to_n(x, n): return round(x, -int(floor(log10(x))) + (n - 1)) def prime_factors(n): factors = [] while n % 2 == 0: factors.append(2) n = n / 2 for i in range(3, int(sqrt(n)) + 1, 2): while n % i == 0: factors.append(i) n = n / i if n > 2: factors.append(n) return list(set(factors)) def generate_answers(amount2, q_ind2, conv_rate): answers = [] unit2 = base_quantity[q_ind2] correct = correct_answer(amount2, conv_rate) answers.append((f'{correct} {plural(unit2, correct)}', 1)) wrong_conv_range = np.arange(-10, 11) wrong_conv_range = np.delete(wrong_conv_range, np.where(wrong_conv_range == 1)) wrong_convs = random.sample(list(wrong_conv_range), 3) for w in wrong_convs: answers.append((f'{correct*w} {plural(unit2, correct*w)}', 0)) random.shuffle(answers) answers = dict(answers) return answers def generate_examples(num_examples): examples = [] for i in range(num_examples): amount1 = np.random.randint(0, 101) # Generate random number between 0 and 50 amount2 = np.random.randint(0, 101) q_ind1 = np.random.randint(0, NUM_QUANTITIES) q_ind2 = np.random.randint(0, NUM_QUANTITIES) # Ensure we aren't converting unit to itself while q_ind2 == q_ind1: q_ind2 = np.random.randint(0, NUM_QUANTITIES) # p_factors = prime_factors(amount) # conv_type = (np.random.randint(0,2) == 1) # if conv_type: conv_rate = np.random.randint(0, 51) #q_type = np.random.randint(0, 2) q_type = 0 question = generate_question(q_type, amount1, amount2, q_ind1, q_ind2, conv_rate) answers = generate_answers(amount2, q_ind2, conv_rate) example = dict() example["input"] = question example["target_scores"] = answers examples.append(example) return examples if __name__ == "__main__": base_quantity = ('blerb', 'blarb', 'rega', 'riga', 'swert', 'swort', 'yut', 'yot') NUM_QUANTITIES = len(base_quantity) examples_json = json.dumps(generate_examples(3), indent=4) print(examples_json)
apache-2.0
Python
b3265f241ad4c405bc56cc1b4a5154dc3a4098bd
Create settings.py
marmikcfc/tweet-search
settings.py
settings.py
API_KEY = "API_KEY" API_SECRET = "API_SECRET" ACCESS_TOKEN="ACCESS_TOKEN" ACCESS_TOKEN_SECRET="ACCESS_TOKEN_SECRET"
mit
Python
97c149057bf68ef8063316acad2b4c86f6579452
Create maximum-vacation-days.py
kamyu104/LeetCode,kamyu104/LeetCode,tudennis/LeetCode---kamyu104-11-24-2015,tudennis/LeetCode---kamyu104-11-24-2015,kamyu104/LeetCode,jaredkoontz/leetcode,yiwen-luo/LeetCode,kamyu104/LeetCode,jaredkoontz/leetcode,kamyu104/LeetCode,jaredkoontz/leetcode,yiwen-luo/LeetCode,tudennis/LeetCode---kamyu104-11-24-2015,jaredkoontz/leetcode,jaredkoontz/leetcode,tudennis/LeetCode---kamyu104-11-24-2015,tudennis/LeetCode---kamyu104-11-24-2015,yiwen-luo/LeetCode,yiwen-luo/LeetCode,yiwen-luo/LeetCode
Python/maximum-vacation-days.py
Python/maximum-vacation-days.py
# Time: O(n^2 * k) # Space: O(k) class Solution(object): def maxVacationDays(self, flights, days): """ :type flights: List[List[int]] :type days: List[List[int]] :rtype: int """ if not days or not flights: return 0 dp = [[0] * len(days) for _ in xrange(2)] for week in reversed(xrange(len(days[0]))): for cur_city in xrange(len(days)): dp[week % 2][cur_city] = days[cur_city][week] + dp[(week+1) % 2][cur_city] for dest_city in xrange(len(days)): if flights[cur_city][dest_city] == 1: dp[week % 2][cur_city] = max(dp[week % 2][cur_city], \ days[dest_city][week] + dp[(week+1) % 2][dest_city]) return dp[0][0]
mit
Python
612fb44b33c4f52488f3565c009188d61a8343c2
Add an auto join script
arai-wa/hexchat-addons
python/autojoin_on_invite.py
python/autojoin_on_invite.py
__module_name__ = "autojoin on invite" __module_version__ = "1.0" import hexchat def join(word, word_eol, userdata): hexchat.command('join ' + word[0]) hexchat.hook_print('Invited', join)
apache-2.0
Python
3fd3b376b1334dba0ffea3641dcbb32d788f4083
Add migration script to fix templated orphans.
amyshi188/osf.io,fabianvf/osf.io,mluke93/osf.io,GaryKriebel/osf.io,KAsante95/osf.io,ckc6cz/osf.io,revanthkolli/osf.io,cslzchen/osf.io,Nesiehr/osf.io,zkraime/osf.io,reinaH/osf.io,mluke93/osf.io,haoyuchen1992/osf.io,ckc6cz/osf.io,asanfilippo7/osf.io,laurenrevere/osf.io,zkraime/osf.io,aaxelb/osf.io,emetsger/osf.io,Ghalko/osf.io,HarryRybacki/osf.io,billyhunt/osf.io,monikagrabowska/osf.io,fabianvf/osf.io,rdhyee/osf.io,zachjanicki/osf.io,laurenrevere/osf.io,Johnetordoff/osf.io,ticklemepierce/osf.io,samchrisinger/osf.io,jinluyuan/osf.io,adlius/osf.io,samchrisinger/osf.io,arpitar/osf.io,doublebits/osf.io,GageGaskins/osf.io,KAsante95/osf.io,Nesiehr/osf.io,jmcarp/osf.io,dplorimer/osf,felliott/osf.io,bdyetton/prettychart,cwisecarver/osf.io,billyhunt/osf.io,pattisdr/osf.io,billyhunt/osf.io,sbt9uc/osf.io,caseyrygt/osf.io,mfraezz/osf.io,zachjanicki/osf.io,GaryKriebel/osf.io,Ghalko/osf.io,felliott/osf.io,brandonPurvis/osf.io,asanfilippo7/osf.io,baylee-d/osf.io,HalcyonChimera/osf.io,brandonPurvis/osf.io,lyndsysimon/osf.io,doublebits/osf.io,petermalcolm/osf.io,jmcarp/osf.io,rdhyee/osf.io,zachjanicki/osf.io,wearpants/osf.io,mattclark/osf.io,wearpants/osf.io,kushG/osf.io,emetsger/osf.io,jmcarp/osf.io,mluo613/osf.io,alexschiller/osf.io,binoculars/osf.io,sloria/osf.io,chrisseto/osf.io,lamdnhan/osf.io,danielneis/osf.io,samchrisinger/osf.io,kch8qx/osf.io,njantrania/osf.io,Johnetordoff/osf.io,zamattiac/osf.io,chrisseto/osf.io,doublebits/osf.io,danielneis/osf.io,TomHeatwole/osf.io,mattclark/osf.io,ckc6cz/osf.io,chrisseto/osf.io,icereval/osf.io,mluo613/osf.io,mluke93/osf.io,kch8qx/osf.io,samanehsan/osf.io,revanthkolli/osf.io,cwisecarver/osf.io,mluo613/osf.io,lyndsysimon/osf.io,GageGaskins/osf.io,erinspace/osf.io,himanshuo/osf.io,kch8qx/osf.io,MerlinZhang/osf.io,KAsante95/osf.io,CenterForOpenScience/osf.io,acshi/osf.io,brandonPurvis/osf.io,lamdnhan/osf.io,kwierman/osf.io,hmoco/osf.io,njantrania/osf.io,aaxelb/osf.io,acshi/osf.io,kushG/osf.io,brianjgeiger/osf.io,hmoco/osf.io,himanshuo/osf.io,ticklemepierce/osf.io,chrisseto/osf.io,alexschiller/osf.io,sloria/osf.io,caneruguz/osf.io,haoyuchen1992/osf.io,MerlinZhang/osf.io,acshi/osf.io,monikagrabowska/osf.io,TomHeatwole/osf.io,adlius/osf.io,erinspace/osf.io,adlius/osf.io,arpitar/osf.io,caneruguz/osf.io,jeffreyliu3230/osf.io,CenterForOpenScience/osf.io,asanfilippo7/osf.io,kwierman/osf.io,jolene-esposito/osf.io,jeffreyliu3230/osf.io,jnayak1/osf.io,monikagrabowska/osf.io,SSJohns/osf.io,Nesiehr/osf.io,amyshi188/osf.io,RomanZWang/osf.io,ZobairAlijan/osf.io,felliott/osf.io,RomanZWang/osf.io,wearpants/osf.io,lyndsysimon/osf.io,brandonPurvis/osf.io,laurenrevere/osf.io,crcresearch/osf.io,MerlinZhang/osf.io,jnayak1/osf.io,jmcarp/osf.io,KAsante95/osf.io,SSJohns/osf.io,billyhunt/osf.io,DanielSBrown/osf.io,haoyuchen1992/osf.io,kwierman/osf.io,HarryRybacki/osf.io,kch8qx/osf.io,Ghalko/osf.io,baylee-d/osf.io,caneruguz/osf.io,jeffreyliu3230/osf.io,haoyuchen1992/osf.io,alexschiller/osf.io,barbour-em/osf.io,wearpants/osf.io,DanielSBrown/osf.io,cslzchen/osf.io,binoculars/osf.io,sbt9uc/osf.io,caseyrollins/osf.io,zamattiac/osf.io,barbour-em/osf.io,icereval/osf.io,abought/osf.io,mluke93/osf.io,brianjgeiger/osf.io,cldershem/osf.io,caseyrollins/osf.io,himanshuo/osf.io,ckc6cz/osf.io,DanielSBrown/osf.io,lyndsysimon/osf.io,samanehsan/osf.io,reinaH/osf.io,jeffreyliu3230/osf.io,TomHeatwole/osf.io,jinluyuan/osf.io,jolene-esposito/osf.io,GaryKriebel/osf.io,dplorimer/osf,fabianvf/osf.io,mfraezz/osf.io,cldershem/osf.io,aaxelb/osf.io,njantrania/osf.io,rdhyee/osf.io,danielneis/osf.io,acshi/osf.io,Ghalko/osf.io,kch8qx/osf.io,icereval/osf.io,cosenal/osf.io,hmoco/osf.io,ticklemepierce/osf.io,TomBaxter/osf.io,pattisdr/osf.io,caneruguz/osf.io,bdyetton/prettychart,cldershem/osf.io,chennan47/osf.io,cosenal/osf.io,erinspace/osf.io,ticklemepierce/osf.io,HalcyonChimera/osf.io,zachjanicki/osf.io,revanthkolli/osf.io,GageGaskins/osf.io,fabianvf/osf.io,abought/osf.io,amyshi188/osf.io,aaxelb/osf.io,RomanZWang/osf.io,CenterForOpenScience/osf.io,brandonPurvis/osf.io,ZobairAlijan/osf.io,brianjgeiger/osf.io,Johnetordoff/osf.io,brianjgeiger/osf.io,GageGaskins/osf.io,HarryRybacki/osf.io,lamdnhan/osf.io,bdyetton/prettychart,DanielSBrown/osf.io,leb2dg/osf.io,jinluyuan/osf.io,crcresearch/osf.io,himanshuo/osf.io,asanfilippo7/osf.io,SSJohns/osf.io,pattisdr/osf.io,monikagrabowska/osf.io,abought/osf.io,amyshi188/osf.io,TomHeatwole/osf.io,SSJohns/osf.io,HalcyonChimera/osf.io,saradbowman/osf.io,petermalcolm/osf.io,emetsger/osf.io,njantrania/osf.io,zkraime/osf.io,mluo613/osf.io,crcresearch/osf.io,cldershem/osf.io,felliott/osf.io,kwierman/osf.io,zamattiac/osf.io,KAsante95/osf.io,jolene-esposito/osf.io,saradbowman/osf.io,jinluyuan/osf.io,caseyrygt/osf.io,rdhyee/osf.io,cslzchen/osf.io,AndrewSallans/osf.io,TomBaxter/osf.io,cwisecarver/osf.io,samchrisinger/osf.io,sloria/osf.io,cosenal/osf.io,alexschiller/osf.io,cslzchen/osf.io,mfraezz/osf.io,mattclark/osf.io,zkraime/osf.io,RomanZWang/osf.io,leb2dg/osf.io,acshi/osf.io,HalcyonChimera/osf.io,Johnetordoff/osf.io,caseyrygt/osf.io,emetsger/osf.io,TomBaxter/osf.io,lamdnhan/osf.io,arpitar/osf.io,cwisecarver/osf.io,doublebits/osf.io,jolene-esposito/osf.io,GageGaskins/osf.io,dplorimer/osf,ZobairAlijan/osf.io,sbt9uc/osf.io,doublebits/osf.io,MerlinZhang/osf.io,leb2dg/osf.io,samanehsan/osf.io,kushG/osf.io,zamattiac/osf.io,kushG/osf.io,caseyrygt/osf.io,samanehsan/osf.io,sbt9uc/osf.io,jnayak1/osf.io,baylee-d/osf.io,monikagrabowska/osf.io,RomanZWang/osf.io,revanthkolli/osf.io,dplorimer/osf,reinaH/osf.io,GaryKriebel/osf.io,leb2dg/osf.io,AndrewSallans/osf.io,chennan47/osf.io,billyhunt/osf.io,petermalcolm/osf.io,jnayak1/osf.io,mfraezz/osf.io,bdyetton/prettychart,danielneis/osf.io,CenterForOpenScience/osf.io,cosenal/osf.io,mluo613/osf.io,chennan47/osf.io,ZobairAlijan/osf.io,binoculars/osf.io,barbour-em/osf.io,reinaH/osf.io,abought/osf.io,adlius/osf.io,arpitar/osf.io,petermalcolm/osf.io,hmoco/osf.io,alexschiller/osf.io,Nesiehr/osf.io,caseyrollins/osf.io,HarryRybacki/osf.io,barbour-em/osf.io
scripts/fix_templated_orphans.py
scripts/fix_templated_orphans.py
# -*- coding: utf-8 -*- """Find orphaned templated nodes without parents, then attempt to identify and restore their parent nodes. Due to a bug in templating that has since been fixed, several templated nodes were not attached to the `nodes` lists of their parents. """ import logging from modularodm import Q from framework.auth import Auth from website.models import Node from website.app import init_app from nose.tools import * from tests.base import OsfTestCase from tests.factories import ProjectFactory, NodeFactory logger = logging.getLogger(__name__) logger.setLevel(logging.INFO) def find_candidate_parents(node): return Node.find( Q('logs', 'eq', node.logs[0]._id) & Q('is_fork', 'eq', node.is_fork) & Q('is_registration', 'eq', node.is_registration) ) def resolve_templated_orphan(orphan): candidate_parents = find_candidate_parents(orphan) if candidate_parents.count() != 1: logger.warn('Could not identify unique candidate parent for node {}'.format(orphan._id)) return if candidate_parents[0].date_created != orphan.date_created: logger.warn('Creation dates of candidate parent and orphan {} did not match'.format(orphan._id)) logger.info('Adding orphan to `nodes` list of candidate parent') candidate_parents[0].nodes.append(orphan) candidate_parents[0].save() def find_templated_orphans(): return Node.find( Q('template_node', 'ne', None) & Q('category', 'ne', 'project') & Q('__backrefs.parent.node.nodes.0', 'exists', False) ) if __name__ == '__main__': init_app() orphans = find_templated_orphans() for orphan in orphans: resolve_templated_orphan(orphan) class TestResolveTemplatedOrphans(OsfTestCase): def setUp(self): super(TestResolveTemplatedOrphans, self).setUp() self.node = NodeFactory() self.project = ProjectFactory(creator=self.node.creator) self.project.nodes.append(self.node) self.project.save() self.templated_project = self.project.use_as_template( Auth(self.node.creator) ) self.templated_node = self.templated_project.nodes[0] self.templated_project.nodes = [] self.templated_project.save() def test_find(self): orphans = find_templated_orphans() assert_equal(orphans.count(), 1) assert_equal(orphans[0], self.templated_node) def test_resolve(self): assert_not_in(self.templated_node, self.templated_project.nodes) resolve_templated_orphan(self.node) assert_in(self.node, self.project.nodes)
apache-2.0
Python
8f6bbbe30b77c2722c5ea0f03432e2c77b2eb4c6
add CLI stub for calendar service
quantrocket-llc/quantrocket-client,quantrocket-llc/quantrocket-client
quantrocket/cli/subcommands/calendar.py
quantrocket/cli/subcommands/calendar.py
# Copyright 2017 QuantRocket - All Rights Reserved # # 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. def add_subparser(subparsers): _parser = subparsers.add_parser("calendar", description="QuantRocket calendar CLI", help="quantrocket calendar -h") _subparsers = _parser.add_subparsers(title="subcommands", dest="subcommand") _subparsers.required = True parser = _subparsers.add_parser("isopen", help="assert that one or more exchanges is open and return a non-zero exit code if closed") parser.add_argument("exchanges", metavar="EXCHANGE", nargs="+", help="the exchange(s) to check") parser.add_argument("-i", "--in", metavar="TIMEDELTA", help="assert that the exchange(s) will be open in the future (use Pandas timedelta string, e.g. 2h)") parser.add_argument("-a", "--ago", metavar="TIMEDELTA", help="assert that the exchange(s) was open in the past (use Pandas timedelta string, e.g. 2h)") parser.set_defaults(func="quantrocket.calendar.is_open") parser = _subparsers.add_parser("isclosed", help="assert that one or more exchanges is closed and return a non-zero exit code if open") parser.add_argument("exchanges", metavar="EXCHANGE", nargs="+", help="the exchange(s) to check") parser.add_argument("-i", "--in", metavar="TIMEDELTA", help="assert that the exchange(s) will be closed in the future (use Pandas timedelta string)") parser.add_argument("-a", "--ago", metavar="TIMEDELTA", help="assert that the exchange(s) was closed in the past (use Pandas timedelta string)") parser.set_defaults(func="quantrocket.calendar.is_closed") parser = _subparsers.add_parser("closings", help="get exchange closings") parser.add_argument("-x", "--exchanges", metavar="EXCHANGE", help="limit to these exchanges") parser.add_argument("-s", "--start-date", metavar="YYYY-MM-DD", help="limit to closings on or after this date") parser.add_argument("-e", "--end-date", metavar="YYYY-MM-DD", help="limit to closings on or before this date") parser.add_argument("-a", "--after", metavar="TIMEDELTA", help="limit to closings on or after this many days/hours/etc in the past (use Pandas timedelta string, e.g. 7d)") parser.add_argument("-b", "--before", metavar="TIMEDELTA", help="limit to closings on or before this many days/hours/etc in the future (use Pandas timedelta string, e.g. 7d)") parser.add_argument("-t", "--types", choices=["full", "half"], help="limit to these closing types") parser.set_defaults(func="quantrocket.calendar.get_closings") parser = _subparsers.add_parser("load", help="load exchange closings from file") parser.add_argument("filename", type=str, help="CSV containing with columns 'date', 'exchange', and optionally 'type' ('full' or 'half') ") parser.set_defaults(func="quantrocket.calendar.load_closings")
apache-2.0
Python
f18e500ff7eb1b73097786892673934346c9a94f
Create sign_rpm.py
CyberAnalyticDevTeam/SimpleRock,CyberAnalyticDevTeam/SimpleRock,rocknsm/rock,CyberAnalyticDevTeam/SimpleRock,rocknsm/SimpleRock,spartan782/rock,spartan782/rock,rocknsm/SimpleRock,spartan782/rock,rocknsm/SimpleRock,rocknsm/rock,rocknsm/rock
sign_rpm.py
sign_rpm.py
+#!/bin/python + +import argparse, subprocess, shlex, os +defaults = {} +defaults['rpm_dir'] = '' + +def get_args(): + parser = argparse.ArgumentParser(description="Setup a GPG macro to be used in signing an rpm. Optionally you can provide the location of rpm's and sign them as well") + parser.add_argument('-r', '--rpm', type=str, help='Direct Path to rpm you want signed', required=False, default='') + parser.add_argument('-k', '--key', type=str, help='Direct Path to gpg-key you want to use for signing', required=True) + parser.add_argument('-n', '--name', type=str, help='Name used when the gpg key was generated example Johnathon Hall', required=True) + #this would be needed if the user wanted to provide multiple paths instead of a wildcard for multiple rpm's to be signed. + #parser.add_argument('-r', '--rpm', metavar='/Path/To/RPM', nargs='+', type=str, help='Space Sperated Path(s) to the rpm(s) you want signed', required=True) + args = parser.parse_args() + + return args.rpm, args.key, args.name + +def sign_rpm(rpm_path, key_path, key_name): + + #import key into rpm database + subprocess.call(shlex.split('sudo rpm --import '+key_path)) + gpg_location = subprocess.check_output(shlex.split('which gpg')) + + #get home directory + home = os.path.expanduser('~') + #setup rpm macro for signing + f = open(home+'/.rpmmacros', 'w') + f.write('%_signature gpg\n \ + %_gpg_path ~/.gnupg\n \ + %_gpg_name '+key_name+'\n\ + %_gpgbin '+gpg_location+'\n') + + print 'rpm macro for signing setup\n\nIf you want to sign an rpm during the build process from a spec file use \n\t"rpmbuild -OPTIONS --sign /path/to/spec/file"' + + if rpm_path != '': + #sign rpm + subprocess.call(shlex.split('rpm --addsign '+rpm_path)) + + #check if sign worked + ok = subprocess.check_output(shlex.split('rpm --checksig '+rpm_path)) + + if 'OK' in ok: + print 'rpm signed successfully' + else: + print 'something didn\'t work. Verify your gpgkey path and make sure that it is the public key' + + +rpm_path, key_path, key_name = get_args() +sign_rpm(rpm_path, key_path, key_name)
unknown
Python
8995e45946812f5cd982d52bd12a99915a8b03cc
Add script to migrate artifact references
apache/allura,leotrubach/sourceforge-allura,heiths/allura,leotrubach/sourceforge-allura,apache/incubator-allura,leotrubach/sourceforge-allura,Bitergia/allura,apache/incubator-allura,apache/allura,apache/allura,lym/allura-git,Bitergia/allura,Bitergia/allura,heiths/allura,lym/allura-git,apache/allura,lym/allura-git,heiths/allura,Bitergia/allura,lym/allura-git,apache/incubator-allura,Bitergia/allura,apache/allura,apache/incubator-allura,heiths/allura,lym/allura-git,leotrubach/sourceforge-allura,heiths/allura
scripts/migrate-artifact-refs.py
scripts/migrate-artifact-refs.py
import sys import logging from cPickle import loads from pylons import c from allura import model as M log = logging.getLogger('allura.migrate-artifact-refs') # Threads have artifact references that must be migrated to the new system def main(): test = sys.argv[-1] == 'test' all_projects = M.Project.query.find().all() log.info('Fixing artifact references in threads') seen_dbs = set() for project in all_projects: if project.database_uri in seen_dbs: continue seen_dbs.add(project.database_uri) c.project = project db = M.project_doc_session.db for thread in db.thread.find(): ref = thread.pop('artifact_reference', None) if ref is None: continue Artifact = loads(ref['artifact_type']) artifact = Artifact.query.get(_id=ref['artifact_id']) M.ArtifactReference.from_artifact(artifact) thread['ref_id'] = artifact.index_id() if not test: db.thread.save(thread) log.info('saving thread %s', thread['_id']) else: log.info('would save thread %s', thread['_id']) M.artifact_orm_session.clear() if __name__ == '__main__': main()
apache-2.0
Python
e7394973e5383fc72c4f8004390a05bc91b9053e
Add a skeleton Python file that can be reused.
aawc/cryptopals
skeleton.py
skeleton.py
# Copyright 2017 Varun Khaneja # 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. def main(): pass if __name__ == "__main__": main()
mit
Python
4b44eec7bde92c77f513aac664fe5b52736b874c
Add test code.
segfaulthunter/burrahobbit,segfaulthunter/burrahobbit
burrahobbit/test/test_dict.py
burrahobbit/test/test_dict.py
# Copyright (C) 2011 by Florian Mayer <flormayer@aim.com> # # 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. import pytest from burrahobbit.treedict import PersistentTreeMap, VolatileTreeMap def test_fromdict(): mp = PersistentTreeMap.from_dict( {'hello': 'world', 'spam': 'eggs'} ) assert mp['hello'] == 'world' assert mp['spam'] == 'eggs' def test_persistence(): mp = PersistentTreeMap() mp1 = mp.assoc('a', 'hello') assert mp1['a'] == 'hello' mp2 = mp1.assoc('b', 'world') assert mp2['a'] == 'hello' assert mp2['b'] == 'world' mp3 = mp2.without('a') assert mp3['b'] == 'world' with pytest.raises(KeyError) as excinfo: assert mp3['a'] == 'hello' assert excinfo.value.args[0] == 'a' def test_iteration(): mp = PersistentTreeMap.from_dict({'a': 'hello', 'b': 'world'}) assert set(mp.iterkeys()) == set(mp) == set(['a', 'b']) assert set(mp.itervalues()) == set(['hello', 'world']) assert set(mp.iteritems()) == set([('a', 'hello'), ('b', 'world')]) def test_novaluecopy(): mp = PersistentTreeMap() bar = [] mp = mp.assoc("foo", bar) mv = mp.volatile() bar.append("test") assert mp["foo"] == mv["foo"] == bar def test_volatile(): mp = PersistentTreeMap.from_dict({'foo': 'baz'}) mp2 = mp.volatile() mp3 = mp2.assoc('foo', 'bar') assert mp2['foo'] == 'bar' assert mp3['foo'] == 'bar' assert mp2 is mp3 assert mp['foo'] == 'baz' mp4 = mp3.persistent() mp5 = mp4.assoc('foo', 'spam') assert mp2['foo'] == 'bar' assert mp3['foo'] == 'bar' assert mp4['foo'] == 'bar' assert mp5['foo'] == 'spam' def main(): import os import time # Prevent expensive look-up in loop, hence the from-import. from copy import copy mp = PersistentTreeMap().volatile() for _ in xrange(22500): one, other = os.urandom(20), os.urandom(25) mp2 = mp.assoc(one, other) assert mp[one] == other assert mp2[one] == other mp = mp2 pmp = mp.persistent() s = time.time() mp = PersistentTreeMap() for _ in xrange(225000): one, other = os.urandom(20), os.urandom(25) mp2 = mp.assoc(one, other) try: mp[one] except KeyError: assert True else: assert False try: mp2.without(one)[one] except KeyError: assert True else: assert False mp = mp2 assert mp[one] == other print 'PersistentHashMap:', time.time() - s assert mp[one] == other # This /may/ actually fail if we are unlucky, but it's a good start. assert len(list(iter(mp))) == 225000 if __name__ == '__main__': main()
mit
Python
df17f792faab74955f5e9573bf7dd9812b489bd3
Add a hybridization example using Slate manually
thomasgibson/firedrake-hybridization
hybridization_solver.py
hybridization_solver.py
from __future__ import absolute_import, print_function, division from firedrake import * qflag = False degree = 1 mesh = UnitSquareMesh(8, 8, quadrilateral=qflag) n = FacetNormal(mesh) if qflag: RT = FiniteElement("RTCF", quadrilateral, degree) DG = FiniteElement("DQ", quadrilateral, degree - 1) Te = FiniteElement("HDiv Trace", quadrilateral, degree - 1) else: RT = FiniteElement("RT", triangle, degree) DG = FiniteElement("DG", triangle, degree - 1) Te = FiniteElement("HDiv Trace", triangle, degree - 1) Vd = FunctionSpace(mesh, BrokenElement(RT)) U = FunctionSpace(mesh, DG) T = FunctionSpace(mesh, Te) W = Vd * U sigma, u = TrialFunctions(W) tau, v = TestFunctions(W) f = Function(U) x, y = SpatialCoordinate(mesh) f.interpolate((1 + 8*pi*pi)*sin(2*pi*x)*sin(2*pi*y)) a = (dot(sigma, tau) - div(tau)*u + v*div(sigma) + u*v)*dx L = f*v*dx bcs = DirichletBC(T, Constant(0.0), (1, 2, 3, 4)) gammar = TestFunction(T) trace_form = dot(sigma, n)*gammar('+')*dS K = Tensor(trace_form) A = Tensor(a) F = Tensor(L) S = assemble(K * A.inv * K.T, bcs=bcs) E = assemble(K * A.inv * F) lambda_sol = Function(T) solve(S, lambda_sol, E, solver_parameters={'pc_type': 'lu', 'ksp_type': 'preonly'})
mit
Python
efa84ed71e6804d71dd639715299a6438824fd64
add unit tests for nacelle's session handling
nacelle/nacelle,nacelle/nacelle
nacelle/tests/tests_session_handling.py
nacelle/tests/tests_session_handling.py
""" Test nacelle's session handling """ # third-party imports import webapp2 # local imports from nacelle.conf import settings from nacelle.test.testcases import NacelleTestCase # test fixtures: we need to set up a local wsgi app so we can test the login # decorators against real handlers def set_session_var(request): session = request.session() session['test'] = 'just testing' return webapp2.Response('success') def get_session_var(request): session = request.session() return webapp2.Response(session.get('test', 'no sell :(')) # Define our WSGI app so GAE can run it routes = [('/get_session_var', get_session_var), ('/set_session_var', set_session_var)] wsgi = webapp2.WSGIApplication(routes, debug=True, config={ 'webapp2_extras.sessions': {'secret_key': 'xxxxxxxxxxxxxxxxxxxxxx'} }) # attach dispatcher and error_handler to the WSGI app dispatcher = webapp2.import_string(settings.DISPATCHER_MODULE) wsgi.router.set_dispatcher(dispatcher) class SessionHandlingTests(NacelleTestCase): def test_setting_session_var_and_retrieve_on_next_request(self): """Test persisting a session variable in a cookie """ response = wsgi.get_response('/set_session_var') self.assertEqual(200, response.status_int) self.assertEqual('success', response.body) # Can do the same for data, allowing you to store it as a map. headers = [('Cookie', response.headers['Set-Cookie'])] response = wsgi.get_response('/get_session_var', headers=headers) self.assertEqual(200, response.status_int) self.assertEqual('just testing', response.body)
mit
Python
3523879c9b67766a3d248c7c1260715534ee0671
add test_list
Akagi201/learning-python,Akagi201/learning-python,Akagi201/learning-python,Akagi201/learning-python,Akagi201/learning-python
misc/test_list.py
misc/test_list.py
# -*- coding: utf-8 -*- # 可以看出这四种方式都可以向列表中添加一个新元素,除了"+"之外,其他三种方式都是在原列表上添加数据, # "+"则会创建一个新的列表,并且"+"只能连接两个列表,如果连接一个元素跟一个列表会报错 # 添加一个元素到列表中 a = ["a", "b", "c"] print ("append|添加前id:%s" % id(a)), a.append("d") print ("添加后id:%s, %s" % (id(a), a)) print ("-"*62) a = ["a", "b", "c"] print ("extend|添加前id:%s" % id(a)), a.extend("d") print ("添加后id:%s, %s" % (id(a), a)) print ("-"*62) a = ["a", "b", "c"] print (" +|添加前id:%s" % id(a)), a = a + ["d"] print ("添加后id:%s, %s" % (id(a), a)) print ("-"*62) a = ["a", "b", "c"] print (" +=|添加前id:%s" % id(a)), a += "d" print ("添加后id:%s, %s" % (id(a), a)) print ("-"*62) # append方法当添加的元素是列表时会回将整个列表添加进原列表,extend与"+="的效果是一样的, # 会将列表中的元素添加到原列表,"+"也会将两个列表中的元素复制到一个新创建的列表中,所不同的会创建一个新的列表 # 添加一个列表到列表中 a = ["a", "b", "c"] print ("append|添加前id:%s" % id(a)), a.append(["d", "e", "f"]) print ("添加后id:%s, %s" % (id(a), a)) print ("-"*62) a = ["a", "b", "c"] print ("extend|添加前id:%s" % id(a)), a.extend(["d", "e", "f"]) print ("添加后id:%s, %s" % (id(a), a)) print ("-"*62) a = ["a", "b", "c"] print (" +|添加前id:%s" % id(a)), a = a + ["d", "e", "f"] print ("添加后id:%s, %s" % (id(a), a)) print ("-"*62) a = ["a", "b", "c"] print (" +=|添加前id:%s" % id(a)), a += ["d", "e", "f"] print ("添加后id:%s, %s" % (id(a), a)) print ("-"*62)
mit
Python
ba2d1a707a0869ad0266380b818f88fe626e0267
Add alphabet_lstm.py
aidiary/keras_examples,aidiary/keras_examples
alphabet_lstm.py
alphabet_lstm.py
import numpy as np from keras.models import Sequential from keras.layers import Dense from keras.layers import LSTM from keras.utils import np_utils # http://machinelearningmastery.com/understanding-stateful-lstm-recurrent-neural-networks-python-keras/ if __name__ == "__main__": # fix random seed for reproducibility np.random.seed(7) # define the raw dataset alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" # create mapping of characters to integers (0-25) and the reverse char_to_int = dict((c, i) for i, c in enumerate(alphabet)) int_to_char = dict((i, c) for i, c in enumerate(alphabet)) # prepare the dataset of input to output pairs encoded as integers seq_length = 1 dataX = [] dataY = [] for i in range(0, len(alphabet) - seq_length, 1): seq_in = alphabet[i:i + seq_length] seq_out = alphabet[i + seq_length] dataX.append([char_to_int[char] for char in seq_in]) dataY.append(char_to_int[seq_out]) # reshape X to be [samples, sequence length, features] X = np.reshape(dataX, (len(dataX), seq_length, 1)) # normalize X = X / float(len(alphabet)) # one hot encode the output variable y = np_utils.to_categorical(dataY) # create LSTM model batch_size = 1 model = Sequential() model.add(LSTM(32, batch_input_shape=(batch_size, X.shape[1], X.shape[2]), stateful=True)) model.add(Dense(y.shape[1], activation='softmax')) model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy']) # fit the model for i in range(300): model.fit(X, y, nb_epoch=1, batch_size=batch_size, verbose=2, shuffle=False) model.reset_states() # summarize performance of the model scores = model.evaluate(X, y, batch_size=batch_size, verbose=0) model.reset_states() print("Model accuracy (train data): %.2f%%" % (scores[1] * 100)) # demonstrate some model predictions seed = [char_to_int[alphabet[0]]] for i in range(0, len(alphabet) - 1): x = np.reshape(seed, (1, len(seed), 1)) x = x / float(len(alphabet)) prediction = model.predict(x, verbose=0) index = np.argmax(prediction) print(int_to_char[seed[0]], '->', int_to_char[index]) seed = [index] model.reset_states() # demonstrate a random starting point letter = 'K' seed = [char_to_int[letter]] print("New start:", letter) for i in range(0, 5): x = np.reshape(seed, (1, len(seed), 1)) x = x / float(len(alphabet)) prediction = model.predict(x, verbose=0) index = np.argmax(prediction) print(int_to_char[seed[0]], '->', int_to_char[index]) model.reset_states()
mit
Python
46e66f00ab8c340ca1f104c40c6b9a76762d7ec3
Add example script
modin-project/modin,modin-project/modin
examples/cluster/experimental_cloud.py
examples/cluster/experimental_cloud.py
# Licensed to Modin Development Team under one or more contributor license agreements. # See the NOTICE file distributed with this work for additional information regarding # copyright ownership. The Modin Development Team 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. """ This is a very basic sample script for running things remotely. It requires `aws_credentials` file to be present next to it. On credentials file format see https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-where """ import os import logging logging.basicConfig(format='%(asctime)s %(message)s') logger = logging.getLogger() logger.setLevel(logging.DEBUG) from modin.experimental.cloud import Provider, cluster, get_connection aws = Provider(Provider.AWS, os.path.join(os.path.abspath(os.path.dirname(__file__)), 'aws_credentials'), 'us-west-1') with cluster(aws, cluster_name='rayscale-test') as c: conn = get_connection() modin = conn.modules.modin print(modin)
apache-2.0
Python
3ddb3c93693822f0fdb3256a360754a4994a954e
add qutebrowser config
charlesdaniels/dotfiles,charlesdaniels/dotfiles,charlesdaniels/dotfiles
overlay/.config/qutebrowser/config.py
overlay/.config/qutebrowser/config.py
c.url.start_pages = ["https://start.duckduckgo.com"] c.content.javascript.enabled = False c.content.headers.accept_language = "en-US,en;q=0.5" c.content.headers.custom = {"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"} c.content.headers.user_agent = 'Mozilla/5.0 (Windows NT 6.1; rv:52.0) Gecko/20100101 Firefox/52.0' config.bind(',ff', 'spawn firefox {url}') config.bind(',m', 'spawn --userscript /usr/share/qutebrowser/userscripts/view_in_mpv') config.bind('<Ctrl-k>', 'spawn --userscript /usr/share/qutebrowser/userscripts/qute-keepass -p ~/Dropbox/Crypted/database.kdbx', mode="insert") config.bind('<Ctrl-p>', 'spawn --userscript /usr/share/qutebrowser/userscripts/qute-keepass -w -p ~/Dropbox/Crypted/database.kdbx', mode="insert") config.bind('<Ctrl-u>', 'spawn --userscript /usr/share/qutebrowser/userscripts/qute-keepass -e -p ~/Dropbox/Crypted/database.kdbx', mode="insert")
bsd-3-clause
Python
73a00c9ac8e237dbd317e3e81ab19521cd7942de
Add donorresponse types
pwyf/IATI-Data-Quality,pwyf/IATI-Data-Quality,pwyf/IATI-Data-Quality,pwyf/IATI-Data-Quality
iatidq/donorresponse.py
iatidq/donorresponse.py
# IATI Data Quality, tools for Data QA on IATI-formatted publications # by Mark Brough, Martin Keegan, Ben Webb and Jennifer Smith # # Copyright (C) 2013 Publish What You Fund # # This programme is free software; you may redistribute and/or modify # it under the terms of the GNU Affero General Public License v3.0 RESPONSE_TYPES = { '': { 'id': None, 'text': "", 'description': "" }, 'reviewed': { 'id': 0, 'text': 'reviewed', 'description': "reviewed this survey" }, 'emailresponse': { 'id': 3, 'text': 'replied by email', 'description': "responded by email, and provided general comments, but not specific comments" }, 'declined': { 'id': 5, 'text': 'declined to review', 'description': "responded by email, but declined to review the survey" }, 'noreply': { 'id': 6, 'text': 'did not respond', 'description': "did not respond to our attempts to contact them" } } RESPONSE_IDS = dict(map(lambda x: (x[1]["id"], { "id": x[0], "text": x[1]["text"], "description": x[1]["description"] }), RESPONSE_TYPES.items()))
agpl-3.0
Python
4107696d3605d600b09ebf1f0a5a2c97fbae0b10
Move wordcount with metrics to its own file.
lukecwik/incubator-beam,chamikaramj/beam,lukecwik/incubator-beam,chamikaramj/beam,robertwb/incubator-beam,apache/beam,lukecwik/incubator-beam,robertwb/incubator-beam,robertwb/incubator-beam,chamikaramj/beam,lukecwik/incubator-beam,chamikaramj/beam,robertwb/incubator-beam,lukecwik/incubator-beam,robertwb/incubator-beam,lukecwik/incubator-beam,robertwb/incubator-beam,chamikaramj/beam,apache/beam,robertwb/incubator-beam,apache/beam,chamikaramj/beam,apache/beam,lukecwik/incubator-beam,lukecwik/incubator-beam,apache/beam,apache/beam,chamikaramj/beam,robertwb/incubator-beam,chamikaramj/beam,chamikaramj/beam,robertwb/incubator-beam,lukecwik/incubator-beam,robertwb/incubator-beam,apache/beam,apache/beam,apache/beam,chamikaramj/beam,apache/beam,apache/beam,lukecwik/incubator-beam
sdks/python/apache_beam/examples/wordcount_with_metrics.py
sdks/python/apache_beam/examples/wordcount_with_metrics.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. # """A word-counting workflow.""" # pytype: skip-file from __future__ import absolute_import import argparse import logging import re from past.builtins import unicode import apache_beam as beam from apache_beam.io import ReadFromText from apache_beam.io import WriteToText from apache_beam.metrics import Metrics from apache_beam.metrics.metric import MetricsFilter from apache_beam.options.pipeline_options import PipelineOptions from apache_beam.options.pipeline_options import SetupOptions class WordExtractingDoFn(beam.DoFn): """Parse each line of input text into words.""" def __init__(self): # TODO(BEAM-6158): Revert the workaround once we can pickle super() on py3. # super(WordExtractingDoFn, self).__init__() beam.DoFn.__init__(self) self.words_counter = Metrics.counter(self.__class__, 'words') self.word_lengths_counter = Metrics.counter(self.__class__, 'word_lengths') self.word_lengths_dist = Metrics.distribution( self.__class__, 'word_len_dist') self.empty_line_counter = Metrics.counter(self.__class__, 'empty_lines') def process(self, element): """Returns an iterator over the words of this element. The element is a line of text. If the line is blank, note that, too. Args: element: the element being processed Returns: The processed element. """ text_line = element.strip() if not text_line: self.empty_line_counter.inc(1) words = re.findall(r'[\w\']+', text_line, re.UNICODE) for w in words: self.words_counter.inc() self.word_lengths_counter.inc(len(w)) self.word_lengths_dist.update(len(w)) return words def run(argv=None, save_main_session=True): """Main entry point; defines and runs the wordcount pipeline.""" parser = argparse.ArgumentParser() parser.add_argument( '--input', dest='input', default='gs://dataflow-samples/shakespeare/kinglear.txt', help='Input file to process.') parser.add_argument( '--output', dest='output', required=True, help='Output file to write results to.') known_args, pipeline_args = parser.parse_known_args(argv) # We use the save_main_session option because one or more DoFn's in this # workflow rely on global context (e.g., a module imported at module level). pipeline_options = PipelineOptions(pipeline_args) pipeline_options.view_as(SetupOptions).save_main_session = save_main_session p = beam.Pipeline(options=pipeline_options) # Read the text file[pattern] into a PCollection. lines = p | 'read' >> ReadFromText(known_args.input) # Count the occurrences of each word. def count_ones(word_ones): (word, ones) = word_ones return (word, sum(ones)) counts = ( lines | 'split' >> (beam.ParDo(WordExtractingDoFn()).with_output_types(unicode)) | 'pair_with_one' >> beam.Map(lambda x: (x, 1)) | 'group' >> beam.GroupByKey() | 'count' >> beam.Map(count_ones)) # Format the counts into a PCollection of strings. def format_result(word_count): (word, count) = word_count return '%s: %d' % (word, count) output = counts | 'format' >> beam.Map(format_result) # Write the output using a "Write" transform that has side effects. # pylint: disable=expression-not-assigned output | 'write' >> WriteToText(known_args.output) result = p.run() result.wait_until_finish() # Do not query metrics when creating a template which doesn't run if (not hasattr(result, 'has_job') # direct runner or result.has_job): # not just a template creation empty_lines_filter = MetricsFilter().with_name('empty_lines') query_result = result.metrics().query(empty_lines_filter) if query_result['counters']: empty_lines_counter = query_result['counters'][0] logging.info('number of empty lines: %d', empty_lines_counter.result) word_lengths_filter = MetricsFilter().with_name('word_len_dist') query_result = result.metrics().query(word_lengths_filter) if query_result['distributions']: word_lengths_dist = query_result['distributions'][0] logging.info('average word length: %d', word_lengths_dist.result.mean) if __name__ == '__main__': logging.getLogger().setLevel(logging.INFO) run()
apache-2.0
Python
4ca364980441dc3f41339db62f774f077588be40
Add first version of the manager
NeutronUfscarDatacom/DriverDatacom
dcclient/xml_manager/manager.py
dcclient/xml_manager/manager.py
""" Methos to create and manipulate the XML """ import data_structures class ManagedXml: def __init__(self): self.xml = data_structures.Cfg_data() def addVlan(self, vid, name='', ports=[]): """ This method adds a vlan to the XML an returns it's instance. """ vlan = data_structures.Vlan_global(vid) if name: vlan.name = name if ports: vlan.ports = data_structures.Pbits(ports) self.xml.vlans.append(vlan) return vlan if __name__ == '__main__': xml = ManagedXml() vlan = xml.addVlan(42, name='aaa', ports=[1, 3, 4])
apache-2.0
Python
8e982c72829574a00a97f389ac169e5760d53f3c
Create restartable_thread.py
ev0x/stuff,ev0x/stuff
restartable_thread.py
restartable_thread.py
import threading import time class ThreadRestartable(threading.Thread): def __init__(self, theName): threading.Thread.__init__(self, name=theName) def run(self): print "In ThreadRestartable\n" time.sleep(10) thd = ThreadRestartable("WORKER") thd.start() while(1): i = 0 for t in threading.enumerate(): if t.name is "WORKER": i = 1 print threading.enumerate() if i == 0: thd = ThreadRestartable("WORKER") thd.start() time.sleep(5)
mit
Python
8a844b78c5ded93ce7a75585a6ad2b86d8b4cb13
Add recognize decoding typedef or local type
goodwinxp/ATFGenerator,goodwinxp/ATFGenerator,goodwinxp/ATFGenerator
pida_type_decoder.py
pida_type_decoder.py
from pida_types import IDA_TYPES from pida_tlocal_type import IdaTLocalType def decode_step(ida_type): # TODO : pass def decode_hybrid_type(ida_type): value = {'idt': None, 'value': None} rbyte = ord(ida_type[0]) if not (ida_type[1] == '#' and rbyte in [4, 5]): value = {'idt': IDA_TYPES['str'], 'value': value[1:rbyte]} return rbyte, value offset = 2 ext = False if rbyte == 5: offset += 1 ext = True local_type = IdaTLocalType(ida_type=IDA_TYPES['local_type']) local_type.decode(ida_type[offset:], ext=ext) value = local_type.get_type() return rbyte, value
mit
Python
a8507ef2f4d3eaa4f3eeeebbb9dbeb5f008b2737
Add tmux-process-search.py
MikeDacre/mike_tools,MikeDacre/mike_tools,MikeDacre/mike_tools
bin/tmux-process-search.py
bin/tmux-process-search.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Search the tmux process tree. """ import sys as _sys import argparse as _argparse import subprocess as sub import shlex as sh import psutil TMUX_LIST_CMD = 'tmux list-panes -a -F "#{pane_pid} #{session_name}" | grep {0}' def find_session(pid): """Return the tmux session for a given pid.""" proc = psutil.Process(pid) procs = [] cur = proc while True: if cur.name() == 'tmux: server': if not procs: raise ValueError('You entered a tmux server PID') session_child = procs.pop() break procs.append(cur) cur = cur.parent() if cur is None: _sys.stderr.write( 'PID {0} does not appear to be in a tmux session' .format(pid) ) return None code, out, err = run( TMUX_LIST_CMD.format(session_child.pid), shell=True ) if code != 0: _sys.stderr.write( 'Failed to find tmux session of process\n' ) return None return out.split(' ')[-1] def run(cmd, shell=False, check=False, get='all'): """Replicate getstatusoutput from subprocess. Params ------ cmd : str or list shell : bool, optional Run as a shell, allows piping check : bool, optional Raise exception if command failed get : {'all', 'code', 'stdout', 'stderr'}, optional Control what is returned: - all: (code, stdout, stderr) - code/stdout/stderr: only that item - None: code only Returns ------- output : str or tuple See get above. Default return value: (code, stdout, stderr) """ get_options = ['all', 'stdout', 'stderr', 'code', None] if get not in get_options: raise ValueError( 'get must be one of {0} is {1}'.format(get_options, get) ) if not shell and isinstance(cmd, str): cmd = sh.split(cmd) if get != 'code' and get is not None: pp = sub.Popen(cmd, shell=shell, stdout=sub.PIPE, stderr=sub.PIPE) out, err = pp.communicate() else: pp = sub.Popen(cmd, shell=shell) pp.communicate() if not isinstance(out, str): out = out.decode() if not isinstance(err, str): err = err.decode() code = pp.returncode if check and code != 0: if get: _sys.stderr.write( 'Command failed\nSTDOUT:\n{0}\nSTDERR:\n{1}\n' .format(out, err) ) raise sub.CalledProcessError(code, cmd) if get == 'all': return code, out.rstrip(), err.rstrip() elif get == 'stdout': return out.rstrip() elif get == 'stderr': return err.rstrip() return code def main(argv=None): """Run as a script.""" if not argv: argv = _sys.argv[1:] parser = _argparse.ArgumentParser( description=__doc__, formatter_class=_argparse.RawDescriptionHelpFormatter ) parser.add_argument('pid', type=int, help='PID to search for') args = parser.parse_args(argv) session_name = find_session(pid) if __name__ == '__main__' and '__file__' in globals(): _sys.exit(main())
unlicense
Python
f0c1263f1ca6d9a4f45eea3b19b9f818ed303d26
Add examples/tic_ql_tab_simple_selfplay.py
davidrobles/mlnd-capstone-code
examples/tic_ql_tab_simple_selfplay.py
examples/tic_ql_tab_simple_selfplay.py
''' The Q-learning algorithm is used to estimate the state-action values for a simple Tic-Tac-Toe position by playing games against itself (self-play). ''' from capstone.game.games import TicTacToe from capstone.game.players import RandPlayer from capstone.game.utils import tic2pdf from capstone.rl import Environment, GameMDP from capstone.rl.learners import QLearningSelfPlay from capstone.rl.policies import RandomPolicy from capstone.rl.utils import EpisodicWLDPlotter, QValuesPlotter from capstone.rl.value_functions import TabularQ seed = 23 board = [[' ', ' ', 'X'], [' ', 'X', ' '], ['O', 'O', ' ']] game = TicTacToe(board) mdp = GameMDP(game) env = Environment(mdp) qlearning = QLearningSelfPlay( env=env, qfunction=TabularQ(random_state=seed), policy=RandomPolicy(env.actions, random_state=seed), learning_rate=0.1, discount_factor=1.0, n_episodes=4000, ) qlearning.train( callbacks=[ QValuesPlotter( state=game, actions=game.legal_moves(), filepath='figures/tic_ql_tab_simple_selfplay_progress.pdf' ) ] ) #################### # Generate figures # #################### tic2pdf('figures/tic_ql_tab_simple_selfplay_cur.pdf', game.board) for move in game.legal_moves(): print('*' * 80) value = qlearning.qfunction[(game, move)] print('Move: %d' % move) print('Value: %f' % value) new_game = game.copy().make_move(move) print(new_game) filename = 'figures/tic_ql_tab_simple_selfplay_move_{}.pdf'.format(move) tic2pdf(filename, new_game.board)
mit
Python
6b00d2a2ca774bff57b523339c10759be4619da6
add cluster name to detected cluster
Tendrl/node_agent,Tendrl/node_agent,Tendrl/node-agent,Tendrl/node-agent,r0h4n/node-agent,Tendrl/node-agent,r0h4n/node-agent,r0h4n/node-agent
tendrl/node_agent/node_sync/sds_detect.py
tendrl/node_agent/node_sync/sds_detect.py
import etcd from tendrl.commons.event import Event from tendrl.commons.message import Message, ExceptionMessage from tendrl.node_agent.discovery.sds import manager as sds_manager def load_and_execute_sds_discovery_plugins(): Event( Message( priority="info", publisher=NS.publisher_id, payload={"message": "load_and_execute_sds_discovery_plugins"} ) ) try: sds_discovery_manager = sds_manager.SDSDiscoveryManager() except ValueError as ex: Event( ExceptionMessage( priority="error", publisher=NS.publisher_id, payload={"message": "Failed to init SDSDiscoveryManager.", "exception": ex } ) ) return # Execute the SDS discovery plugins and tag the nodes with data for plugin in sds_discovery_manager.get_available_plugins(): sds_details = plugin.discover_storage_system() if sds_details: try: NS.tendrl.objects.DetectedCluster( detected_cluster_id=sds_details.get( 'detected_cluster_id'), detected_cluster_name=sds_details.get( 'detected_cluster_name'), sds_pkg_name=sds_details.get('pkg_name'), sds_pkg_version=sds_details.get('pkg_version'), ).save() except etcd.EtcdException as ex: Event( ExceptionMessage( priority="error", publisher=NS.publisher_id, payload={"message": "Failed to update etcd .", "exception": ex } ) ) break
import etcd from tendrl.commons.event import Event from tendrl.commons.message import Message, ExceptionMessage from tendrl.node_agent.discovery.sds import manager as sds_manager def load_and_execute_sds_discovery_plugins(): Event( Message( priority="info", publisher=NS.publisher_id, payload={"message": "load_and_execute_sds_discovery_plugins"} ) ) try: sds_discovery_manager = sds_manager.SDSDiscoveryManager() except ValueError as ex: Event( ExceptionMessage( priority="error", publisher=NS.publisher_id, payload={"message": "Failed to init SDSDiscoveryManager.", "exception": ex } ) ) return # Execute the SDS discovery plugins and tag the nodes with data for plugin in sds_discovery_manager.get_available_plugins(): sds_details = plugin.discover_storage_system() if sds_details: try: NS.tendrl.objects.DetectedCluster( detected_cluster_id=sds_details.get( 'detected_cluster_id'), sds_pkg_name=sds_details.get('pkg_name'), sds_pkg_version=sds_details.get('pkg_version'), ).save() except etcd.EtcdException as ex: Event( ExceptionMessage( priority="error", publisher=NS.publisher_id, payload={"message": "Failed to update etcd .", "exception": ex } ) ) break
lgpl-2.1
Python
0663a2f90870e0f8b902aa97a479ee9d8ab3b23c
Add usage example to tf.keras.utils.to_categorical
davidzchen/tensorflow,aldian/tensorflow,tensorflow/tensorflow-pywrap_saved_model,Intel-tensorflow/tensorflow,freedomtan/tensorflow,Intel-Corporation/tensorflow,sarvex/tensorflow,karllessard/tensorflow,gautam1858/tensorflow,paolodedios/tensorflow,renyi533/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,renyi533/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,gunan/tensorflow,tensorflow/tensorflow,yongtang/tensorflow,cxxgtxy/tensorflow,gunan/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,yongtang/tensorflow,frreiss/tensorflow-fred,petewarden/tensorflow,frreiss/tensorflow-fred,tensorflow/tensorflow-pywrap_tf_optimizer,freedomtan/tensorflow,aam-at/tensorflow,gunan/tensorflow,annarev/tensorflow,renyi533/tensorflow,Intel-tensorflow/tensorflow,gautam1858/tensorflow,aam-at/tensorflow,tensorflow/tensorflow,paolodedios/tensorflow,gunan/tensorflow,gunan/tensorflow,davidzchen/tensorflow,aam-at/tensorflow,petewarden/tensorflow,petewarden/tensorflow,petewarden/tensorflow,aam-at/tensorflow,paolodedios/tensorflow,xzturn/tensorflow,jhseu/tensorflow,jhseu/tensorflow,tensorflow/tensorflow-pywrap_saved_model,karllessard/tensorflow,tensorflow/tensorflow-pywrap_saved_model,xzturn/tensorflow,jhseu/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,gautam1858/tensorflow,petewarden/tensorflow,davidzchen/tensorflow,sarvex/tensorflow,Intel-tensorflow/tensorflow,Intel-Corporation/tensorflow,aam-at/tensorflow,davidzchen/tensorflow,aldian/tensorflow,davidzchen/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,tensorflow/tensorflow-experimental_link_static_libraries_once,renyi533/tensorflow,Intel-Corporation/tensorflow,gautam1858/tensorflow,tensorflow/tensorflow-pywrap_saved_model,tensorflow/tensorflow,gunan/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,annarev/tensorflow,annarev/tensorflow,yongtang/tensorflow,aam-at/tensorflow,xzturn/tensorflow,jhseu/tensorflow,annarev/tensorflow,cxxgtxy/tensorflow,yongtang/tensorflow,cxxgtxy/tensorflow,renyi533/tensorflow,yongtang/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,tensorflow/tensorflow-experimental_link_static_libraries_once,petewarden/tensorflow,Intel-tensorflow/tensorflow,freedomtan/tensorflow,frreiss/tensorflow-fred,davidzchen/tensorflow,renyi533/tensorflow,gunan/tensorflow,petewarden/tensorflow,aldian/tensorflow,renyi533/tensorflow,tensorflow/tensorflow-pywrap_saved_model,xzturn/tensorflow,jhseu/tensorflow,sarvex/tensorflow,gautam1858/tensorflow,tensorflow/tensorflow,freedomtan/tensorflow,karllessard/tensorflow,renyi533/tensorflow,sarvex/tensorflow,freedomtan/tensorflow,xzturn/tensorflow,gautam1858/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,Intel-Corporation/tensorflow,petewarden/tensorflow,frreiss/tensorflow-fred,Intel-tensorflow/tensorflow,tensorflow/tensorflow-pywrap_saved_model,cxxgtxy/tensorflow,gautam1858/tensorflow,aldian/tensorflow,frreiss/tensorflow-fred,tensorflow/tensorflow-pywrap_saved_model,jhseu/tensorflow,paolodedios/tensorflow,aldian/tensorflow,aam-at/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,gunan/tensorflow,tensorflow/tensorflow,jhseu/tensorflow,frreiss/tensorflow-fred,freedomtan/tensorflow,yongtang/tensorflow,annarev/tensorflow,gautam1858/tensorflow,frreiss/tensorflow-fred,aam-at/tensorflow,tensorflow/tensorflow-pywrap_saved_model,cxxgtxy/tensorflow,frreiss/tensorflow-fred,gautam1858/tensorflow,frreiss/tensorflow-fred,sarvex/tensorflow,tensorflow/tensorflow-pywrap_saved_model,xzturn/tensorflow,xzturn/tensorflow,davidzchen/tensorflow,annarev/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,aldian/tensorflow,tensorflow/tensorflow-pywrap_saved_model,freedomtan/tensorflow,gautam1858/tensorflow,davidzchen/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,renyi533/tensorflow,paolodedios/tensorflow,paolodedios/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,aldian/tensorflow,paolodedios/tensorflow,xzturn/tensorflow,tensorflow/tensorflow,tensorflow/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,petewarden/tensorflow,aam-at/tensorflow,annarev/tensorflow,Intel-tensorflow/tensorflow,jhseu/tensorflow,yongtang/tensorflow,karllessard/tensorflow,jhseu/tensorflow,xzturn/tensorflow,tensorflow/tensorflow,jhseu/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,annarev/tensorflow,Intel-Corporation/tensorflow,karllessard/tensorflow,sarvex/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,cxxgtxy/tensorflow,tensorflow/tensorflow,freedomtan/tensorflow,jhseu/tensorflow,karllessard/tensorflow,Intel-Corporation/tensorflow,xzturn/tensorflow,davidzchen/tensorflow,tensorflow/tensorflow-experimental_link_static_libraries_once,petewarden/tensorflow,gunan/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,xzturn/tensorflow,davidzchen/tensorflow,gunan/tensorflow,petewarden/tensorflow,Intel-tensorflow/tensorflow,sarvex/tensorflow,davidzchen/tensorflow,sarvex/tensorflow,aldian/tensorflow,annarev/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,yongtang/tensorflow,Intel-Corporation/tensorflow,tensorflow/tensorflow-pywrap_tf_optimizer,renyi533/tensorflow,freedomtan/tensorflow,gautam1858/tensorflow,freedomtan/tensorflow,cxxgtxy/tensorflow,karllessard/tensorflow,karllessard/tensorflow,tensorflow/tensorflow-pywrap_saved_model,karllessard/tensorflow,yongtang/tensorflow,freedomtan/tensorflow,davidzchen/tensorflow,paolodedios/tensorflow,annarev/tensorflow,Intel-tensorflow/tensorflow,Intel-tensorflow/tensorflow,frreiss/tensorflow-fred,yongtang/tensorflow,jhseu/tensorflow,karllessard/tensorflow,freedomtan/tensorflow,renyi533/tensorflow,gautam1858/tensorflow,karllessard/tensorflow,frreiss/tensorflow-fred,paolodedios/tensorflow,yongtang/tensorflow,paolodedios/tensorflow,Intel-tensorflow/tensorflow,xzturn/tensorflow,aam-at/tensorflow,frreiss/tensorflow-fred,tensorflow/tensorflow,gunan/tensorflow,tensorflow/tensorflow,annarev/tensorflow,cxxgtxy/tensorflow,aam-at/tensorflow,Intel-Corporation/tensorflow,Intel-tensorflow/tensorflow,gunan/tensorflow,petewarden/tensorflow,aam-at/tensorflow,renyi533/tensorflow,paolodedios/tensorflow
tensorflow/python/keras/utils/np_utils.py
tensorflow/python/keras/utils/np_utils.py
# Copyright 2018 The TensorFlow Authors. All Rights Reserved. # # 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. # ============================================================================== """Numpy-related utilities.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import numpy as np from tensorflow.python.util.tf_export import keras_export @keras_export('keras.utils.to_categorical') def to_categorical(y, num_classes=None, dtype='float32'): """Converts a class vector (integers) to binary class matrix. E.g. for use with categorical_crossentropy. Usage Example: >>> y = [0, 1, 2, 3] >>> tf.keras.utils.to_categorical(y, num_classes=4) array([...], dtype=float32) Arguments: y: class vector to be converted into a matrix (integers from 0 to num_classes). num_classes: total number of classes. dtype: The data type expected by the input. Default: `'float32'`. Returns: A binary matrix representation of the input. The classes axis is placed last. """ y = np.array(y, dtype='int') input_shape = y.shape if input_shape and input_shape[-1] == 1 and len(input_shape) > 1: input_shape = tuple(input_shape[:-1]) y = y.ravel() if not num_classes: num_classes = np.max(y) + 1 n = y.shape[0] categorical = np.zeros((n, num_classes), dtype=dtype) categorical[np.arange(n), y] = 1 output_shape = input_shape + (num_classes,) categorical = np.reshape(categorical, output_shape) return categorical @keras_export('keras.utils.normalize') def normalize(x, axis=-1, order=2): """Normalizes a Numpy array. Arguments: x: Numpy array to normalize. axis: axis along which to normalize. order: Normalization order (e.g. 2 for L2 norm). Returns: A normalized copy of the array. """ l2 = np.atleast_1d(np.linalg.norm(x, order, axis)) l2[l2 == 0] = 1 return x / np.expand_dims(l2, axis)
# Copyright 2018 The TensorFlow Authors. All Rights Reserved. # # 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. # ============================================================================== """Numpy-related utilities.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import numpy as np from tensorflow.python.util.tf_export import keras_export @keras_export('keras.utils.to_categorical') def to_categorical(y, num_classes=None, dtype='float32'): """Converts a class vector (integers) to binary class matrix. E.g. for use with categorical_crossentropy. Arguments: y: class vector to be converted into a matrix (integers from 0 to num_classes). num_classes: total number of classes. dtype: The data type expected by the input. Default: `'float32'`. Returns: A binary matrix representation of the input. The classes axis is placed last. """ y = np.array(y, dtype='int') input_shape = y.shape if input_shape and input_shape[-1] == 1 and len(input_shape) > 1: input_shape = tuple(input_shape[:-1]) y = y.ravel() if not num_classes: num_classes = np.max(y) + 1 n = y.shape[0] categorical = np.zeros((n, num_classes), dtype=dtype) categorical[np.arange(n), y] = 1 output_shape = input_shape + (num_classes,) categorical = np.reshape(categorical, output_shape) return categorical @keras_export('keras.utils.normalize') def normalize(x, axis=-1, order=2): """Normalizes a Numpy array. Arguments: x: Numpy array to normalize. axis: axis along which to normalize. order: Normalization order (e.g. 2 for L2 norm). Returns: A normalized copy of the array. """ l2 = np.atleast_1d(np.linalg.norm(x, order, axis)) l2[l2 == 0] = 1 return x / np.expand_dims(l2, axis)
apache-2.0
Python
8dc22c4c575b7c6931ab3ed14ef40b43dc03a685
TEST initiated
JohnGriffiths/dipy,demianw/dipy,beni55/dipy,StongeEtienne/dipy,samuelstjean/dipy,matthieudumont/dipy,mdesco/dipy,beni55/dipy,oesteban/dipy,Messaoud-Boudjada/dipy,demianw/dipy,villalonreina/dipy,StongeEtienne/dipy,samuelstjean/dipy,FrancoisRheaultUS/dipy,nilgoyyou/dipy,villalonreina/dipy,maurozucchelli/dipy,jyeatman/dipy,mdesco/dipy,sinkpoint/dipy,rfdougherty/dipy,sinkpoint/dipy,rfdougherty/dipy,matthieudumont/dipy,oesteban/dipy,Messaoud-Boudjada/dipy,maurozucchelli/dipy,nilgoyyou/dipy,JohnGriffiths/dipy,samuelstjean/dipy,jyeatman/dipy,maurozucchelli/dipy,FrancoisRheaultUS/dipy
dipy/core/tests/test_stensor.py
dipy/core/tests/test_stensor.py
""" Testing qball """ import os from os.path import join as pjoin import numpy as np import dipy.core.stensor as ten from nose.tools import assert_true, assert_false, \ assert_equal, assert_raises from numpy.testing import assert_array_equal, assert_array_almost_equal from dipy.testing import parametric from dipy.io import pickles as pkls #@parametric def test_slvector(): fname=pjoin(os.path.dirname(__file__),'data/eg_3voxels.pkl') print fname #dix=pkls.load_pickle(fname) #b=dix['bs'] #g=dix['gs'] #data=dix['data'] #yield assert_true, b[0],0. #real_sh = qball.real_sph_harm(0, 0, 0, 0) #yield assert_true(True) #yield assert_false(True)
bsd-3-clause
Python
45c836283232e48e13c139188dac0b11128cb0ac
Add drawcrowd support
kupiakos/LapisMirror,Shugabuga/LapisMirror
plugins/drawcrowd.py
plugins/drawcrowd.py
# The MIT License (MIT) # Copyright (c) 2015 kupiakos # 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. import logging import re import html from urllib.parse import urlsplit import traceback import requests import mimeparse import bs4 import praw class DrawcrowdPlugin: """A tiny import plugin for drawcrowd.com """ def __init__(self, useragent: str, **options): """Initialize the drawcrowd import API. :param useragent: The useragent to use for querying tinypic. :param options: Other options in the configuration. Ignored. """ self.log = logging.getLogger('lapis.drawcrowd') self.headers = {'User-Agent': useragent} self.regex = re.compile(r'^(.*?\.)?drawcrowd\.com$') def import_submission(self, submission: praw.objects.Submission) -> dict: """Import a submission from drawcrowd. Uses raw HTML scraping. As it turns out, drawcrowd likes to provide different data (all in <meta> tags) to non-web-browser requests. Since it provides enough information anyways, we don't bother getting around it and just parse that. This function will define the following values in its return data: - author: The author of the post - source: The url of the submission - importer_display/header - import_urls :param submission: A reddit submission to parse. """ try: url = html.unescape(submission.url) if not self.regex.match(urlsplit(url).netloc): return None data = {'source': url} r = requests.head(url, headers=self.headers) if r.status_code == 301: # Moved Permanently return None mime_text = r.headers.get('Content-Type') mime = mimeparse.parse_mime_type(mime_text) if mime[0] == 'image': data['author'] = 'An unknown drawcrowd user' image_url = url else: # Note: Drawcrowd provides different content to non-web-browsers. r = requests.get(url, headers=self.headers) bs = bs4.BeautifulSoup(r.content.decode('utf-8')) matched = bs.find(property='og:image') if not matched: self.log.warning('Could not find locate drawcrowd image to scrape.') return None image_url = matched['content'] matched = bs.find(property='og:title') if matched: data['author'] = matched['content'] else: data['author'] = 'an unknown drawcrowd author' data['importer_display'] = {'header': 'Mirrored image from {}:\n\n'.format(data['author'])} assert image_url data['import_urls'] = [image_url] return data except Exception: self.log.error('Could not import drawcrowd URL %s (%s)', submission.url, traceback.format_exc()) return None __plugin__ = DrawcrowdPlugin # END OF LINE.
mit
Python
775bca5465022e905a58859d72a970749973dba4
Create main.py
0x424D/crappy,0x424D/crappy
msort/src/main.py
msort/src/main.py
def split(L:list) -> list: ret = [] for i in L: ret.append([i]) while len(ret) > 1: ret[0] = merge(ret[0], ret[1]) del ret[1] return ret[0] def merge(L1:list, L2:list) -> list: for i in L2: for n, j in enumerate(L1): if i <= j: L1.insert(n, i) break else: L1.append(i) return L1 def main(): from random import randint L = [randint(0, 999) for i in range(20)] print(f"L (unsorted): {L}") print(f"L (sorted): {split(L)}") if __name__ == "__main__": main()
agpl-3.0
Python
ac8759778ba3bb9af64259685f4f9526b7a452e3
add shortcuts for number localization
eXcomm/gratipay.com,eXcomm/gratipay.com,studio666/gratipay.com,gratipay/gratipay.com,mccolgst/www.gittip.com,studio666/gratipay.com,mccolgst/www.gittip.com,gratipay/gratipay.com,eXcomm/gratipay.com,eXcomm/gratipay.com,studio666/gratipay.com,gratipay/gratipay.com,mccolgst/www.gittip.com,studio666/gratipay.com,mccolgst/www.gittip.com,gratipay/gratipay.com
gittip/utils/i18n.py
gittip/utils/i18n.py
from __future__ import print_function, unicode_literals import os from aspen.utils import utcnow from babel.dates import format_timedelta import babel.messages.pofile from babel.numbers import ( format_currency, format_decimal, format_number, format_percent ) def to_age(dt, loc): return format_timedelta(utcnow() - dt, add_direction=True, locale=loc) def load_langs(localeDir): langs = {} for file in os.listdir(localeDir): parts = file.split(".") if len(parts) == 2 and parts[1] == "po": lang = parts[0] with open(os.path.join(localeDir, file)) as f: catalog = babel.messages.pofile.read_po(f) catalog_dict = {} for message in catalog: if message.id: catalog_dict[message.id] = message.string langs[lang] = catalog_dict return langs LANGS = load_langs("i18n") def get_locale_for_request(request): accept_lang = request.headers.get("Accept-Language", "") languages = (lang.split(";", 1)[0] for lang in accept_lang.split(",")) for loc in languages: if loc.startswith("en") or LANGS.has_key(loc): return loc return "en" def inbound(request): loc = request.context.locale = get_locale_for_request(request) request.context._ = lambda s: LANGS[loc].get(s, s) if loc in LANGS else s request.context.format_number = lambda *a: format_number(*a, locale=loc) request.context.format_decimal = lambda *a: format_decimal(*a, locale=loc) request.context.format_currency = lambda *a: format_currency(*a, locale=loc) request.context.format_percent = lambda *a: format_percent(*a, locale=loc) request.context.to_age = lambda delta: to_age(delta, loc)
from __future__ import print_function, unicode_literals import os from aspen.utils import utcnow from babel.dates import format_timedelta import babel.messages.pofile def to_age(dt, loc): return format_timedelta(utcnow() - dt, add_direction=True, locale=loc) def load_langs(localeDir): langs = {} for file in os.listdir(localeDir): parts = file.split(".") if len(parts) == 2 and parts[1] == "po": lang = parts[0] with open(os.path.join(localeDir, file)) as f: catalog = babel.messages.pofile.read_po(f) catalog_dict = {} for message in catalog: if message.id: catalog_dict[message.id] = message.string langs[lang] = catalog_dict return langs LANGS = load_langs("i18n") def get_locale_for_request(request): accept_lang = request.headers.get("Accept-Language", "") languages = (lang.split(";", 1)[0] for lang in accept_lang.split(",")) for loc in languages: if loc.startswith("en") or LANGS.has_key(loc): return loc return "en" def inbound(request): loc = request.context.locale = get_locale_for_request(request) request.context._ = lambda s: LANGS[loc].get(s, s) if loc in LANGS else s request.context.to_age = lambda delta: to_age(delta, loc)
mit
Python
915dd2ca82bd42ed58768cb1139ceaceada42c84
add simple bmp station application
lagopus/ryu-lagopus-ext,TakeshiTseng/ryu,shinpeimuraoka/ryu,Tesi-Luca-Davide/ryu,habibiefaried/ryu,gopchandani/ryu,lsqtongxin/ryu,openvapour/ryu,alanquillin/ryu,zangree/ryu,zyq001/ryu,pichuang/ryu,ysywh/ryu,fkakuma/ryu,alanquillin/ryu,Tesi-Luca-Davide/ryu,lagopus/ryu-lagopus-ext,jazzmes/ryu,fkakuma/ryu,diogommartins/ryu,gareging/SDN_Framework,alyosha1879/ryu,evanscottgray/ryu,John-Lin/ryu,alyosha1879/ryu,fkakuma/ryu,castroflavio/ryu,iwaseyusuke/ryu,fujita/ryu,John-Lin/ryu,zyq001/ryu,OpenState-SDN/ryu,Tejas-Subramanya/RYU_MEC,Tesi-Luca-Davide/ryu,StephenKing/summerschool-2015-ryu,haniehrajabi/ryu,TakeshiTseng/ryu,sivaramakrishnansr/ryu,alyosha1879/ryu,habibiefaried/ryu,TakeshiTseng/ryu,pichuang/ryu,osrg/ryu,StephenKing/ryu,jalilm/ryu,lsqtongxin/ryu,lagopus/ryu-lagopus-ext,lsqtongxin/ryu,gareging/SDN_Framework,muzixing/ryu,haniehrajabi/ryu,alanquillin/ryu,Tejas-Subramanya/RYU_MEC,takahashiminoru/ryu,Tejas-Subramanya/RYU_MEC,OpenState-SDN/ryu,ttsubo/ryu,zyq001/ryu,elahejalalpour/ELRyu,openvapour/ryu,haniehrajabi/ryu,StephenKing/summerschool-2015-ryu,ynkjm/ryu,muzixing/ryu,gareging/SDN_Framework,StephenKing/ryu,hisaharu/ryu,castroflavio/ryu,Tejas-Subramanya/RYU_MEC,sivaramakrishnansr/ryu,darjus-amzn/ryu,muzixing/ryu,haniehrajabi/ryu,jkoelker/ryu,jkoelker/ryu,elahejalalpour/ELRyu,alanquillin/ryu,Zouyiran/ryu,jalilm/ryu,pichuang/ryu,gopchandani/ryu,lagopus/ryu-lagopus-ext,fujita/ryu,gopchandani/ryu,gopchandani/ryu,lzppp/mylearning,umkcdcrg01/ryu_openflow,StephenKing/ryu,lzppp/mylearning,yamt/ryu,elahejalalpour/ELRyu,alanquillin/ryu,darjus-amzn/ryu,takahashiminoru/ryu,StephenKing/summerschool-2015-ryu,OpenState-SDN/ryu,fujita/ryu,StephenKing/summerschool-2015-ryu,darjus-amzn/ryu,OpenState-SDN/ryu,iwaseyusuke/ryu,sivaramakrishnansr/ryu,takahashiminoru/ryu,haniehrajabi/ryu,sivaramakrishnansr/ryu,lzppp/mylearning,habibiefaried/ryu,TakeshiTseng/ryu,zangree/ryu,Tesi-Luca-Davide/ryu,fujita/ryu,alyosha1879/ryu,diogommartins/ryu,takahashiminoru/ryu,Zouyiran/ryu,fujita/ryu,ynkjm/ryu,gareging/SDN_Framework,zangree/ryu,zyq001/ryu,muzixing/ryu,diogommartins/ryu,shinpeimuraoka/ryu,hisaharu/ryu,hisaharu/ryu,jalilm/ryu,openvapour/ryu,yamt/ryu,diogommartins/ryu,ysywh/ryu,pichuang/ryu,habibiefaried/ryu,lagopus/ryu-lagopus-ext,ysywh/ryu,habibiefaried/ryu,jazzmes/ryu,zangree/ryu,ysywh/ryu,iwaseyusuke/ryu,yamt/ryu,umkcdcrg01/ryu_openflow,John-Lin/ryu,elahejalalpour/ELRyu,darjus-amzn/ryu,umkcdcrg01/ryu_openflow,zangree/ryu,pichuang/ryu,yamt/ryu,shinpeimuraoka/ryu,jkoelker/ryu,evanscottgray/ryu,osrg/ryu,Zouyiran/ryu,hisaharu/ryu,muzixing/ryu,osrg/ryu,jalilm/ryu,lzppp/mylearning,fkakuma/ryu,StephenKing/ryu,umkcdcrg01/ryu_openflow,TakeshiTseng/ryu,Zouyiran/ryu,ynkjm/ryu,osrg/ryu,zyq001/ryu,lsqtongxin/ryu,ttsubo/ryu,ysywh/ryu,gareging/SDN_Framework,darjus-amzn/ryu,iwaseyusuke/ryu,hisaharu/ryu,shinpeimuraoka/ryu,lsqtongxin/ryu,castroflavio/ryu,ynkjm/ryu,evanscottgray/ryu,OpenState-SDN/ryu,osrg/ryu,elahejalalpour/ELRyu,diogommartins/ryu,openvapour/ryu,StephenKing/ryu,iwaseyusuke/ryu,openvapour/ryu,jalilm/ryu,sivaramakrishnansr/ryu,shinpeimuraoka/ryu,StephenKing/summerschool-2015-ryu,Tejas-Subramanya/RYU_MEC,yamt/ryu,fkakuma/ryu,Tesi-Luca-Davide/ryu,umkcdcrg01/ryu_openflow,takahashiminoru/ryu,John-Lin/ryu,jazzmes/ryu,Zouyiran/ryu,ttsubo/ryu,ynkjm/ryu,John-Lin/ryu,ttsubo/ryu,lzppp/mylearning,gopchandani/ryu,ttsubo/ryu
ryu/app/bmpstation.py
ryu/app/bmpstation.py
import socket import logging logging.basicConfig(level=logging.DEBUG) from ryu.base import app_manager from ryu.lib import hub from ryu.lib.hub import StreamServer from ryu.lib.packet.bmp import * SERVER_HOST = '0.0.0.0' SERVER_PORT = 11019 class BMPStation(app_manager.RyuApp): def __init__(self): super(BMPStation, self).__init__() self.name = 'bmpstation' def start(self): super(BMPStation, self).start() return hub.spawn(StreamServer((SERVER_HOST, SERVER_PORT), self.loop).serve_forever) def loop(self, sock, addr): logging.debug("started bmp loop.") self.is_active = True buf = bytearray() required_len = BMPMessage._HDR_LEN while self.is_active: buf = sock.recv(BMPMessage._HDR_LEN) if len(buf) == 0: self.is_active = False break _, len_, _ = BMPMessage.parse_header(buf) body = sock.recv(len_ - BMPMessage._HDR_LEN) if len(body) == 0: self.is_active = False break msg, rest = BMPMessage.parser(buf + body) assert len(rest) == 0 print msg, '\n'
apache-2.0
Python
b077fb6e577e013cf95b57b1ea7d42febc3b03e7
Add encoding module.
dbarella/steganographic-image-processing
encoding.py
encoding.py
"""Script for encoding a payload into an image.""" from PIL import Image, ImageMath def encode(host, payload): # type: (PIL.Image, PIL.Image) -> PIL.Image """Encode a payload into an image.""" output_rgb_channels = [] for host_channel, payload_channel in zip(host.split(), payload.split()): # Mask out all but the least significant byte, encoding payload there expression = "convert((host & 0xfe) | (payload & 0x1), 'L')" output_rgb_channels.append( ImageMath.eval( expression, host=host_channel, payload=payload_channel)) return Image.merge('RGB', output_rgb_channels)
mit
Python
241a2820c90817be6dbabb6642b499cf1a224925
Add limb drawing example
dpshelio/sunpy,dpshelio/sunpy,dpshelio/sunpy
examples/gallery/plot_AIA_limb_STEREO.py
examples/gallery/plot_AIA_limb_STEREO.py
# -*- coding: utf-8 -*- """ ================================= Drawing AIA Limb on STEREO Images ================================= In this example we use a STEREO-B and an SDO image to demonstrate how to overplot the limb as seen by AIA on an EUVI-B image. This makes use of functionality added in Astropy 1.3. """ ############################################################################## # Start by importing the necessary modules. from __future__ import print_function, division import numpy as np import matplotlib.pyplot as plt import astropy.units as u from astropy.coordinates import SkyCoord import sunpy.map import sunpy.coordinates import sunpy.coordinates.wcs_utils from sunpy.net import vso ############################################################################## # The first step is to download some data, we are going to get an image from # early 2011 when the STEREO spacecraft were roughly 90 deg seperated from the # Earth. stereo = (vso.attrs.Source('STEREO_B') & vso.attrs.Instrument('EUVI') & vso.attrs.Time('2011-01-01', '2011-01-01T00:10:00')) aia = (vso.attrs.Instrument('AIA') & vso.attrs.Sample(24 * u.hour) & vso.attrs.Time('2011-01-01', '2011-01-02')) wave = vso.attrs.Wave(30 * u.nm, 31 * u.nm) vc = vso.VSOClient() res = vc.query(wave, aia | stereo) ############################################################################## # The results from VSO query: print(res) ############################################################################## # Download the files: files = vc.get(res).wait() ############################################################################## # Create a dictionary with the two maps, cropped down to full disk. maps = {m.detector: m.submap((-1100, 1100) * u.arcsec, (-1100, 1100) * u.arcsec) for m in sunpy.map.Map(files)} ############################################################################## # Calculate points on the limb in the AIA image for the half that can be seen # from STEREO. r = maps['AIA'].rsun_obs - 1 * u.arcsec # remove the one arcsec so it's on disk. # Adjust the following range if you only want to plot on STEREO_A th = np.linspace(-180*u.deg, 0*u.deg) x = r * np.sin(th) y = r * np.cos(th) coords = SkyCoord(x, y, frame=maps['AIA'].coordinate_frame) ############################################################################## # Plot both maps fig = plt.figure(figsize=(15, 5)) ax1 = fig.add_subplot(1, 2, 1, projection=maps['AIA']) maps['AIA'].plot(axes=ax1) maps['AIA'].draw_limb() ax2 = fig.add_subplot(1, 2, 2, projection=maps['EUVI']) maps['EUVI'].plot(axes=ax2) ax2.plot_coord(coords, color='w')
bsd-2-clause
Python
38b416453c0e0b64d86270232879fb73b2f67d36
Add async Api class
xeroc/python-graphenelib
grapheneasync/api.py
grapheneasync/api.py
# -*- coding: utf-8 -*- import asyncio import logging from grapheneapi.exceptions import NumRetriesReached from grapheneapi.api import Api as OriginalApi from .websocket import Websocket from .http import Http log = logging.getLogger(__name__) class Api(OriginalApi): def __init__(self, *args, **kwargs): # We cannot call connect() because our connect() is a coroutine, and we can't turn __init__ into coroutine super().__init__(connect=False, *args, **kwargs) def updated_connection(self): if self.url[:2] == "ws": return Websocket(self.url, **self._kwargs) elif self.url[:4] == "http": return Http(self.url, **self._kwargs) else: raise ValueError("Only support http(s) and ws(s) connections!") async def connect(self): try: await self.connection.connect() except Exception as e: log.warning(str(e)) self.error_url() await self.next() self.register_apis() async def disconnect(self): await self.connection.disconnect() async def next(self): await self.connection.disconnect() self.url = self.find_next() await self.connect() async def find_next(self): """ Find the next url in the list """ if int(self.num_retries) < 0: # pragma: no cover self._cnt_retries += 1 sleeptime = (self._cnt_retries - 1) * 2 if self._cnt_retries < 10 else 10 if sleeptime: log.warning( "Lost connection to node during rpcexec(): %s (%d/%d) " % (self.url, self._cnt_retries, self.num_retries) + "Retrying in %d seconds" % sleeptime ) await asyncio.sleep(sleeptime) return next(self.urls) urls = [ k for k, v in self._url_counter.items() if ( # Only provide URLS if num_retries is bigger equal 0, # i.e. we want to do reconnects at all int(self.num_retries) >= 0 # the counter for this host/endpoint should be smaller than # num_retries and v <= self.num_retries # let's not retry with the same URL *if* we have others # available and (k != self.url or len(self._url_counter) == 1) ) ] if not len(urls): raise NumRetriesReached url = urls[0] return url
mit
Python
0ad8d8665f064542346c3788cecaffdcb68f168a
Create tests for custom exceptions and warnings
StanczakDominik/PlasmaPy
plasmapy/utils/tests/test_exceptions.py
plasmapy/utils/tests/test_exceptions.py
import pytest import warnings from .. import (PlasmaPyError, PhysicsError, RelativityError, AtomicError) from .. import (PlasmaPyWarning, PhysicsWarning, RelativityWarning, AtomicWarning) plasmapy_exceptions = [ PlasmaPyError, PhysicsError, RelativityError, AtomicError, ] plasmapy_warnings = [ PlasmaPyWarning, PhysicsWarning, RelativityWarning, AtomicWarning, ] @pytest.mark.parametrize("exception", plasmapy_exceptions) def test_exceptions(exception): r"""Test that custom PlasmaPy exceptions can be raised with an error message.""" with pytest.raises(exception): raise exception("What an exceptionally exceptional exception!") @pytest.mark.parametrize("warning", plasmapy_warnings) def test_warnings(warning): r"""Test that custom PlasmaPy warnings can be issued with a warning message.""" with pytest.warns(warning): warnings.warn("Coverage decreased (-0.00002%)", warning) @pytest.mark.parametrize("exception", plasmapy_exceptions) def test_PlasmaPyError_subclassing(exception): r"""Test that each custom PlasmaPy exception can be caught as a PlasmaPyError.""" with pytest.raises(PlasmaPyError): raise exception("I'm sorry, Dave. I'm afraid I can't do that.") @pytest.mark.parametrize("warning", plasmapy_warnings) def test_PlasmaPyWarning_subclassing(warning): r"""Test that custom PlasmaPy warnings can all be caught as a PlasmaPyWarning.""" with pytest.warns(PlasmaPyWarning): warnings.warn("Electrons are WEIRD.", warning)
bsd-3-clause
Python
47bc22166213e50b4f5a2bc583752ff10babd188
add scripts/check_dict.py
fortranlee/cppjieba,fortranlee/cppjieba,songinfo/cppjieba,fortranlee/cppjieba,songinfo/cppjieba,songinfo/cppjieba
scripts/check_dict.py
scripts/check_dict.py
#!/usr/bin/python import sys if len(sys.argv) == 1: print "usage : %s dict_file1 dict_file2 ..." exit(1) d = {} for fname in sys.argv[1:]: with open(fname, "r") as fin: for i, line in enumerate(fin): try: word, cnt, tag = line.strip().split(" ") if word in d: print "error file[%s] line[%s] : %s" %(fname, i, line) exit(1) else: d[word] = True if 0 >= int(cnt) : print "error file[%s] line[%s] : %s" %(fname, i, line) exit(1) except Exception as err: print "error file[%s] line[%s] : %s" %(fname, i, line) exit(1) print "OK"
mit
Python
7a039a9c99e0a3fbd786de7794a798063b271b2f
Create parse_selected_language.py
mewturn/Python
parse_selected_language.py
parse_selected_language.py
# # Main idea: to extract only a particular "language" from text content containing words / characters from different language. # Using regex, we search for characters within particular unicode ranges and exclude the rest. # import re def parse_only_text(string, setting): ''' Available settings: * "alphabets": A-Z ASCII alphabets * "chinese" Chinese characters ''' regex_setting = { "alphabets": r"[A-Za-z '\"]+", "chinese": r"[\u4e00-\u9fff]+" } if setting in regex_setting: comp = regex_setting[setting] result = re.findall(comp, string) if setting == "alphabets": joiner = " " else: joiner = "" return (joiner.join(result)) if __name__ == "__main__": filepath = "C:\\Users\\user\\Desktop\\8501_\\" files = [ "AST_Ep4_SRT.srt", "AST_Ep1_.SRT", "AST_Ep2_.SRT", "AST_Ep3_SRT.srt" ] for file in files: path = f"{filepath}{file}" text_en = "" text_zh = "" with open(path, "r", encoding="utf-8") as f: for line in f: result_en = parse_only_text(line, "alphabets") result_zh = parse_only_text(line, "chinese") if result_en and not result_en.isspace(): text_en += f"{result_en}\n" if result_zh and not result_zh.isspace(): text_zh += f"{result_zh}\n" out_filename = file.replace(".srt", "") out_en = f"{filepath}{out_filename}_en.srt" out_zh = f"{filepath}{out_filename}_zh.srt" with open(out_en, "w", encoding="utf-8") as f_en: f_en.write(text_en) with open(out_zh, "w", encoding="utf-8") as f_zh: f_zh.write(text_zh)
mit
Python
ad934a9abd973141434a12eb346a339d876b5baf
Add regression test for #693
raphael0202/spaCy,raphael0202/spaCy,raphael0202/spaCy,Gregory-Howard/spaCy,explosion/spaCy,honnibal/spaCy,oroszgy/spaCy.hu,recognai/spaCy,recognai/spaCy,spacy-io/spaCy,raphael0202/spaCy,recognai/spaCy,explosion/spaCy,recognai/spaCy,oroszgy/spaCy.hu,oroszgy/spaCy.hu,Gregory-Howard/spaCy,aikramer2/spaCy,Gregory-Howard/spaCy,recognai/spaCy,oroszgy/spaCy.hu,spacy-io/spaCy,honnibal/spaCy,explosion/spaCy,raphael0202/spaCy,Gregory-Howard/spaCy,raphael0202/spaCy,explosion/spaCy,Gregory-Howard/spaCy,honnibal/spaCy,explosion/spaCy,Gregory-Howard/spaCy,honnibal/spaCy,spacy-io/spaCy,recognai/spaCy,aikramer2/spaCy,spacy-io/spaCy,spacy-io/spaCy,aikramer2/spaCy,spacy-io/spaCy,explosion/spaCy,aikramer2/spaCy,oroszgy/spaCy.hu,oroszgy/spaCy.hu,aikramer2/spaCy,aikramer2/spaCy
spacy/tests/regression/test_issue693.py
spacy/tests/regression/test_issue693.py
# coding: utf8 from __future__ import unicode_literals import pytest @pytest.mark.xfail @pytest.mark.models def test_issue693(EN): """Test that doc.noun_chunks parses the complete sentence.""" text1 = "the TopTown International Airport Board and the Goodwill Space Exploration Partnership." text2 = "the Goodwill Space Exploration Partnership and the TopTown International Airport Board." doc1 = EN(text1) doc2 = EN(text2) chunks1 = [chunk for chunk in doc1.noun_chunks] chunks2 = [chunk for chunk in doc2.noun_chunks] assert len(chunks1) == 2 assert len(chunks2) == 2
mit
Python
6cd12f2aaa6170daef88a913ee78b725b6450d61
Add check for 'not guilty beyond a reasonable doubt'
amperser/proselint,amperser/proselint,amperser/proselint,amperser/proselint,amperser/proselint
proselint/checks/garner/not_guilty.py
proselint/checks/garner/not_guilty.py
# -*- coding: utf-8 -*- """Not guilty beyond a reasonable doubt. --- layout: post source: Garner's Modern American Usage source_url: http://bit.ly/1T4alrY title: Not guilty beyond a reasonable doubt. date: 2016-03-09 15:50:31 categories: writing --- This phrasing is ambiguous. The standard by which a jury decides criminal charges is this: a defendant is guilty only if the evidence shows, beyond a reasonable doubt, that he or she committed the crime. Otherwise, the defendant is not guilty. Thus, we say that a defendant was not found "guilty beyond a reasonable doubt." If somebody is found not guilty, say "not guilty." Omit the standard ("beyond a reasonable doubt") to prevent a miscue. Not guilty beyond a reasonable doubt """ from proselint.tools import existence_check, memoize @memoize def check(text): """Check the text.""" err = "misc.not_guilty" msg = u"'not guilty beyond a reasonable doubt' is an ambiguous phrasing." regex = r"not guilty beyond (a |any )?reasonable doubt" return existence_check(text, [regex], err, msg)
bsd-3-clause
Python
5127914f6842e77e9a1613b58ff28fae420b0da8
Create chi_make_a_smoothie_bot.py
jbzdarkid/Random,jbzdarkid/Random,jbzdarkid/Random,jbzdarkid/Random,jbzdarkid/Random,jbzdarkid/Random,jbzdarkid/Random,jbzdarkid/Random,jbzdarkid/Random
chi_make_a_smoothie_bot.py
chi_make_a_smoothie_bot.py
from asyncio import sleep import discord import subprocess import time from datetime import datetime import sys from pathlib import Path client = discord.Client() client.started = False @client.event async def on_ready(): if client.started: # @Hack: Properly deal with disconnection / reconnection await client.close() return client.started = True print(f'Logged in as {client.user.name} (id: {client.user.id})') channel = client.get_channel(699493553444749367) sent_today = False while 1: now = datetime.now() tomorrow = datetime(now.year, now.month, now.day + 1) def is_a_workday(day): return day.weekday() >= 0 and day.weekday() <= 4 if is_a_workday(tomorrow) and not sent_today and now.hour == 18: # 6 PM sent_today = True message = await channel.send(content='Chi! Make a smoothie.') await sleep(60) await client.close() if __name__ == '__main__': if 'subtask' not in sys.argv: while 1: subprocess.run([sys.executable, __file__, 'subtask'] + sys.argv) # Speedrun.com throttling limit is 100 requests/minute time.sleep(60) else: with open(Path(__file__).parent / 'chi_make_a_smoothie_token.txt', 'r') as f: token = f.read().strip() client.run(token, reconnect=True)
apache-2.0
Python
024280702c11d896195706b299767fdbd73d59f6
add script
adamewing/tebreak,adamewing/tebreak
scripts/map_filter.py
scripts/map_filter.py
#!/usr/bin/env python import pysam import argparse def avgmap(maptabix, chrom, start, end): ''' return average mappability across chrom:start-end region; maptabix = pysam.Tabixfile''' scores = [] if None in (start, end): return None if chrom in maptabix.contigs: for rec in maptabix.fetch(chrom, int(start), int(end)): mchrom, mstart, mend, mscore = rec.strip().split() mstart, mend = int(mstart), int(mend) mscore = float(mscore) while mstart < mend and mstart: mstart += 1 if mstart >= int(start) and mstart <= int(end): scores.append(mscore) if len(scores) > 0: return sum(scores) / float(len(scores)) else: return 0.0 else: return 0.0 def main(args): maptabix = pysam.Tabixfile(args.maptabix) cutoff = float(args.cutoff) header = [] with open(args.table, 'r') as table: for i, line in enumerate(table): if i == 0: header = line.strip().split('\t') print line.strip() else: rec = {} for n, field in enumerate(line.strip().split('\t')): rec[header[n]] = field mapscore = avgmap(maptabix, rec['Chromosome'], int(rec['Left_Extreme']), int(rec['Right_Extreme'])) if mapscore > cutoff: print line.strip() if __name__ == '__main__': parser = argparse.ArgumentParser(description='foo') parser.add_argument('-t', '--table', required=True, help='TEBreak table') parser.add_argument('-m', '--maptabix', required=True, help='use mappability tabix') parser.add_argument('-c', '--cutoff', default=0.5, help='mappability cutoff (default = 0.5)') args = parser.parse_args() main(args)
mit
Python
62dc9c91c277bc4755f81597adca030a43d0ce5f
Add async_apple_scanner example (#719)
jstasiak/python-zeroconf
examples/async_apple_scanner.py
examples/async_apple_scanner.py
#!/usr/bin/env python3 """ Scan for apple devices. """ import argparse import asyncio import logging from typing import Any, Optional, cast from zeroconf import DNSQuestionType, IPVersion, ServiceStateChange, Zeroconf from zeroconf.aio import AsyncServiceBrowser, AsyncServiceInfo, AsyncZeroconf HOMESHARING_SERVICE: str = "_appletv-v2._tcp.local." DEVICE_SERVICE: str = "_touch-able._tcp.local." MEDIAREMOTE_SERVICE: str = "_mediaremotetv._tcp.local." AIRPLAY_SERVICE: str = "_airplay._tcp.local." COMPANION_SERVICE: str = "_companion-link._tcp.local." RAOP_SERVICE: str = "_raop._tcp.local." AIRPORT_ADMIN_SERVICE: str = "_airport._tcp.local." DEVICE_INFO_SERVICE: str = "_device-info._tcp.local." ALL_SERVICES = [ HOMESHARING_SERVICE, DEVICE_SERVICE, MEDIAREMOTE_SERVICE, AIRPLAY_SERVICE, COMPANION_SERVICE, RAOP_SERVICE, AIRPORT_ADMIN_SERVICE, DEVICE_INFO_SERVICE, ] log = logging.getLogger(__name__) def async_on_service_state_change( zeroconf: Zeroconf, service_type: str, name: str, state_change: ServiceStateChange ) -> None: print("Service %s of type %s state changed: %s" % (name, service_type, state_change)) if state_change is not ServiceStateChange.Added: return base_name = name[: -len(service_type) - 1] device_name = f"{base_name}.{DEVICE_INFO_SERVICE}" asyncio.ensure_future(_async_show_service_info(zeroconf, service_type, name)) # Also probe for device info asyncio.ensure_future(_async_show_service_info(zeroconf, DEVICE_INFO_SERVICE, device_name)) async def _async_show_service_info(zeroconf: Zeroconf, service_type: str, name: str) -> None: info = AsyncServiceInfo(service_type, name) await info.async_request(zeroconf, 3000, question_type=DNSQuestionType.QU) print("Info from zeroconf.get_service_info: %r" % (info)) if info: addresses = ["%s:%d" % (addr, cast(int, info.port)) for addr in info.parsed_addresses()] print(" Name: %s" % name) print(" Addresses: %s" % ", ".join(addresses)) print(" Weight: %d, priority: %d" % (info.weight, info.priority)) print(" Server: %s" % (info.server,)) if info.properties: print(" Properties are:") for key, value in info.properties.items(): print(" %s: %s" % (key, value)) else: print(" No properties") else: print(" No info") print('\n') class AsyncAppleScanner: def __init__(self, args: Any) -> None: self.args = args self.aiobrowser: Optional[AsyncServiceBrowser] = None self.aiozc: Optional[AsyncZeroconf] = None async def async_run(self) -> None: self.aiozc = AsyncZeroconf(ip_version=ip_version) await self.aiozc.zeroconf.async_wait_for_start() print("\nBrowsing %s service(s), press Ctrl-C to exit...\n" % ALL_SERVICES) kwargs = {'handlers': [async_on_service_state_change], 'question_type': DNSQuestionType.QU} if self.args.target: kwargs["addr"] = self.args.target self.aiobrowser = AsyncServiceBrowser(self.aiozc.zeroconf, ALL_SERVICES, **kwargs) # type: ignore while True: await asyncio.sleep(1) async def async_close(self) -> None: assert self.aiozc is not None assert self.aiobrowser is not None await self.aiobrowser.async_cancel() await self.aiozc.async_close() if __name__ == '__main__': logging.basicConfig(level=logging.DEBUG) parser = argparse.ArgumentParser() parser.add_argument('--debug', action='store_true') version_group = parser.add_mutually_exclusive_group() version_group.add_argument('--target', help='Unicast target') version_group.add_argument('--v6', action='store_true') version_group.add_argument('--v6-only', action='store_true') args = parser.parse_args() if args.debug: logging.getLogger('zeroconf').setLevel(logging.DEBUG) if args.v6: ip_version = IPVersion.All elif args.v6_only: ip_version = IPVersion.V6Only else: ip_version = IPVersion.V4Only loop = asyncio.get_event_loop() runner = AsyncAppleScanner(args) try: loop.run_until_complete(runner.async_run()) except KeyboardInterrupt: loop.run_until_complete(runner.async_close())
lgpl-2.1
Python
3740edf4488456e5b04d3943d47f9a2586f3b0e5
add a Riemann phase plot
JeffDestroyerOfWorlds/hydro_examples,zingale/hydro_examples
compressible/riemann-phase.py
compressible/riemann-phase.py
# plot the Hugoniot loci for a compressible Riemann problem import numpy as np import pylab gamma = 1.4 class State: """ a simple container """ def __init__(self, p=1.0, u=0.0, rho=1.0): self.p = p self.u = u self.rho = rho def u_hugoniot(p, state, dir): c = np.sqrt(gamma*state.p/state.rho) u = np.zeros_like(p) if dir == "left": s = 1.0 elif dir == "right": s = -1.0 # rarefaction index_rare = np.where(p < state.p) u[index_rare] = state.u + s*(2.0*c/(gamma-1.0))* \ (1.0 - (p[index_rare]/state.p)**((gamma-1.0)/(2.0*gamma))) # shock index_shock = np.where(p >= state.p) beta = (gamma+1.0)/(gamma-1.0) u[index_shock] = state.u + s*(2.0*c/np.sqrt(2.0*gamma*(gamma-1.0)))* \ (1.0 - p[index_shock]/state.p)/np.sqrt(1.0 + beta*p[index_shock]/state.p) return u, index_shock, index_rare # setup the problem -- Sod left = State(p = 1.0, u = 0.0, rho = 1.0) right = State(p = 0.1, u = 0.0, rho = 0.125) # make the plots N = 200 p_min = 0.0 p_max = 1.5 p = np.arange(N)*(p_max - p_min)/N + p_min # curves u_left, ish, ir = u_hugoniot(p, left, "left") pylab.plot(p[ish], u_left[ish], c="b", ls=":", lw=2) pylab.plot(p[ir], u_left[ir], c="b", ls="-", lw=2) pylab.scatter([left.p], [left.u], marker="x", c="b", s=40) u_right, ish, ir = u_hugoniot(p, right, "right") pylab.plot(p[ish], u_right[ish], c="r", ls=":", lw=2) pylab.plot(p[ir], u_right[ir], c="r", ls="-", lw=2) pylab.scatter([right.p], [right.u], marker="x", c="r", s=40) du = 0.025*(max(np.max(u_left), np.max(u_right)) - min(np.min(u_left), np.min(u_right))) pylab.text(left.p, left.u+du, "left", horizontalalignment="center", color="b") pylab.text(right.p, right.u+du, "right", horizontalalignment="center", color="r") pylab.xlim(p_min, p_max) pylab.xlabel(r"$p$", fontsize="large") pylab.ylabel(r"$u$", fontsize="large") legs = [] legnames = [] legs.append(pylab.Line2D((0,1),(0,0), color="k", ls=":", marker=None)) legnames.append("shock") legs.append(pylab.Line2D((0,1),(0,0), color="k", ls="-", marker=None)) legnames.append("rarefaction") pylab.legend(legs, legnames, frameon=False, loc="best") pylab.tight_layout() pylab.savefig("riemann-phase.png")
bsd-3-clause
Python
3eb70001e175077b9f8e6a696f009ca2a2b76002
Add python solution to 001
whoshuu/euler
001/001.py
001/001.py
print sum([a * b for a, b in zip(map(lambda n: sum(filter(lambda x: not x % n, range(1000))), (3, 5, 15)), (1, 1, -1))])
unlicense
Python
2c9760da48caaf9656c8b1e3f81e70671b7e7c5e
Add missing migration for audit app.
wlanslovenija/django-postgres
postgres/audit/migrations/0003_auditlog_app_session.py
postgres/audit/migrations/0003_auditlog_app_session.py
# -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations class Migration(migrations.Migration): dependencies = [ ('audit', '0002_auditlog'), ] operations = [ migrations.AddField( model_name='auditlog', name='app_session', field=models.TextField(null=True), preserve_default=True, ), ]
bsd-3-clause
Python
9198b5f153fa21a6a1134cbb3499b767f7780fb1
add the first version of enemy class
TsvetaKandilarova/Escape-The-Labyrinth
enemy.py
enemy.py
import entity class Enemy(entity.Entity): def __init__(self, health, damage): super().__init__(health, damage) def __str__(self): return "enemy:\n" + super().__str__()
mit
Python
d138b826d1c26853ad9ec2cb49c39c2a11617b84
Add __init__.py to appease older python versions
vikasgorur/wrangler
wrangler/__init__.py
wrangler/__init__.py
mit
Python
b261a85300dfd6413bb436114b549b087aab211b
allow module execution (#184)
coveralls-clients/coveralls-python,coagulant/coveralls-python
coveralls/__main__.py
coveralls/__main__.py
from .cli import main if __name__ == '__main__': main()
mit
Python
a4be10de8f6b7ef59e73f6e5c81bb73a3d769145
Create fetchseq.py
goyalsid/phageParser,goyalsid/phageParser,phageParser/phageParser,phageParser/phageParser,mbonsma/phageParser,mbonsma/phageParser,phageParser/phageParser,mbonsma/phageParser,mbonsma/phageParser,goyalsid/phageParser,phageParser/phageParser
fetchseq.py
fetchseq.py
# -*- coding: utf-8 -*- """ Created on Fri Jun 3 14:15:58 2016 @author: Ahmed """ """Fetch sequences in fasta format for given antiCRISPR protein accession numbers. Adapted from https://www.biostars.org/p/66921/ + acc2gb.py USAGE: cat <file> | python fetchseq.py <email> > <output> where: <file> is the name of a file containing accession numbers to download sequences for <email> is the email address associated with your NCBI account <output> is the name of the file you'd like to write the results to DEPENDENCIES: Biopython """ import sys from Bio import Entrez #define email for entrez login db = "protein" Entrez.email = sys.argv[-1] #get accession numbers out of stdin accs = [ l.strip() for l in sys.stdin if l.strip() ] #fetch sys.stderr.write( "Fetching %s entries from GenBank: %s\n" % (len(accs), ", ".join(accs[:10]))) for i,acc in enumerate(accs): try: sys.stderr.write( " %9i %s \r" % (i+1,acc)) handle = Entrez.efetch(db=db, rettype="fasta", retmode="text", id=acc) #print output to stdout sys.stdout.write(handle.read()) with open('sequences.txt','a') as ourFile: ourFile.write(handle.read()) except: sys.stderr.write( "Error! Cannot fetch: %s \n" % acc)
mit
Python
b90b57adae8a5a32c3c914c880d8900bd008e9f3
Add fedjax/experimental/__init__.py
google/fedjax,google/fedjax
fedjax/experimental/__init__.py
fedjax/experimental/__init__.py
# Copyright 2021 Google LLC # # 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. """Experimental modules for fedjax. APIs in the experimental package are subject to changes without guarantee of backward compatibility. Certain modules may not even work. """ from fedjax.experimental import client_datasets from fedjax.experimental import federated_algorithm from fedjax.experimental import federated_data from fedjax.experimental import for_each_client from fedjax.experimental import metrics from fedjax.experimental import model from fedjax.experimental import optimizers from fedjax.experimental import serialization from fedjax.experimental import sqlite_federated_data from fedjax.experimental import typing
apache-2.0
Python
7ada16150f5a77bf9578de40a2bd8390c0ddea7e
Add minimal Info cog
sliceofcode/dogbot,sliceofcode/dogbot,slice/dogbot,slice/dogbot,slice/dogbot
dog/ext/info.py
dog/ext/info.py
""" Information extension. """ import discord from discord.ext import commands from dog import Cog from dog.core import utils cm = lambda v: utils.commas(v) SERVER_INFO_MEMBERS = '''{} total member(s) {} online, {} offline {}% online''' SERVER_INFO_COUNT = '''{} role(s) {} text channel(s), {} voice channel(s) {} channel(s)''' class Info(Cog): @commands.command() @commands.guild_only() async def server(self, ctx): """ Shows information about the server. """ g = ctx.guild embed = discord.Embed(title=g.name) # server icon if g.icon_url: embed.set_thumbnail(url=g.icon_url) # members total_members = len(g.members) num_online = len(list(filter(lambda m: m.status is discord.Status.online, g.members))) num_offline = len(list(filter(lambda m: m.status is discord.Status.offline, g.members))) embed.add_field(name='Members', value=SERVER_INFO_MEMBERS.format( cm(total_members), cm(num_online), cm(num_offline), round((num_online / total_members) * 100, 2) )) embed.add_field(name='Count', value=SERVER_INFO_COUNT.format( cm(len(g.roles)), cm(len(g.text_channels)), cm(len(g.voice_channels)), cm(len(g.channels)) )) # guild owner embed.set_footer(text=f'Owned by {g.owner}', icon_url=g.owner.avatar_url) await ctx.send(embed=embed) def setup(bot): bot.add_cog(Info(bot))
mit
Python
9b0c3888912b6da4c4632da2623075c4eef9444d
Create fizzbuzz.py
bluewitch/Code-Blue-Python
fizzbuzz.py
fizzbuzz.py
# Python: fizzbuzz.py import sys for i in range(-50, 100): if i%3==0: sys.stdout.write('Fizz') if i%5==0: sys.stdout.write('Buzz') if (i%5<>0 and i%3<>0): print i, print
mit
Python