This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from github import Github | |
| import os | |
| import sys | |
| # First create a Github instance: using an access token | |
| access_token = os.getenv('GITHUB_ACCESS_TOKEN') | |
| g = Github(access_token) | |
| # Select your repo |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE OR REPLACE FUNCTION pseudo_encrypt(VALUE bigint) returns bigint AS $$ | |
| DECLARE | |
| l1 bigint; | |
| l2 bigint; | |
| r1 bigint; | |
| r2 bigint; | |
| i int:=0; | |
| BEGIN | |
| l1:= (VALUE >> 32) & 4294967295::bigint; | |
| r1:= VALUE & 4294967295; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @app.route('/<tiny_url>', methods=['GET']) | |
| def get_long_url(tiny_url): | |
| if request.method == 'GET': | |
| try: | |
| url_id = short_url.decode_url(tiny_url) | |
| except Exception: | |
| abort(500) | |
| app.logger.debug(url_id) | |
| url = Url.query.filter_by(id=url_id).first() | |
| app.logger.debug(url) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @app.route('/', methods=['GET', 'POST']) | |
| def get_tiny_url(): | |
| if request.method == 'POST' and request.is_json: | |
| long_url = request.get_json().get('url') | |
| if not long_url: | |
| abort(400) | |
| if not long_url.startswith('http'): | |
| long_url = f'http://{long_url}' | |
| h = blake2b(long_url.encode(), digest_size=20).hexdigest() | |
| app.logger.debug(h) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Url(db.Model): | |
| id = db.Column(db.Integer, primary_key=True) | |
| hash = db.Column(db.String(80), unique=True, nullable=False) | |
| long = db.Column(db.Text(), nullable=False) | |
| hits = db.Column(db.Numeric(), nullable=False, default=0) | |
| def __repr__(self): | |
| return '<Url %r>' % self.id |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| swagger_bps = Swagger.blueprint(spec=self.spec, api_name=self.name) | |
| restless_bps = Restless.blueprints( | |
| # url_prefix='/{}'.format(self.name), | |
| exclusions=self.exclusions, | |
| app=self.app, | |
| db=self.db, | |
| models=self.models, | |
| ) | |
| self.register_blueprints(welcome, restless_bps, swagger_bps, self.other_bps) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from flask import Blueprint, jsonify | |
| from connexion import Api | |
| class Swagger: | |
| def blueprint(spec, **yaml_kwargs): | |
| api = Api(spec, swagger_ui=True, strict_validation=True, validate_responses=False, arguments=yaml_kwargs) | |
| bp = api.blueprint | |
| @bp.errorhandler(404) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Python 3.6 | |
| import re | |
| import logging | |
| import unittest | |
| from itertools import zip_longest | |
| logging.basicConfig(level=logging.DEBUG) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| in-slave03.nj.istresearch.com] out: 2015-11-06 11:25:23,434 - pykafka.simpleconsumer - INFO - Autocommitting consumer offset for consumer group scrapy-janitor and topic memex.crawled_firehose | |
| [in-slave02.nj.istresearch.com] out: 2015-11-06 11:25:28,692 - kazoo.recipe.watchers - ERROR - timed out | |
| [in-slave02.nj.istresearch.com] out: Traceback (most recent call last): | |
| [in-slave02.nj.istresearch.com] out: File "/tmp/virtualenv/virtualenv_root/scrapy-janitor/lib/python2.7/site-packages/kazoo/recipe/watchers.py", line 333, in _get_children | |
| [in-slave02.nj.istresearch.com] out: result = self._func(children) | |
| [in-slave02.nj.istresearch.com] out: File "/tmp/virtualenv/virtualenv_root/scrapy-janitor/lib/python2.7/site-packages/pykafka/balancedconsumer.py", line 599, in _brokers_changed | |
| [in-slave02.nj.istresearch.com] out: self._rebalance() | |
| [in-slave02.nj.istresearch.com] out: File "/tmp/virtualenv/virtualenv_root/scrapy-janitor/lib/python2.7/site-packages/pykafka/balancedconsumer.py", line 454, in _rebalan |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pykafka import KafkaClient | |
| import logging | |
| logging.basicConfig(level=logging.INFO) | |
| class KafkaConnect(object): | |
| def __init__(self, | |
| kafka_hosts='localhost:9092', | |
| zk_hosts='localhost:2181', |
NewerOlder