Skip to content

Instantly share code, notes, and snippets.

View jasonrhaas's full-sized avatar
🎯
Consulting @ Data North

Jason Haas jasonrhaas

🎯
Consulting @ Data North
View GitHub Profile
@jasonrhaas
jasonrhaas / gist:e0669fedccdc562a905f
Last active August 29, 2015 14:01
helpful bash commands

##general bash commands

history prints out a numbers list of historical commands
!654 executes the command number 654 from history
vim file powerful text editor, but takes some learning
cat file read out the contents of the file to the terminal
less file more powerfull than cat. it gives you the abililty to search and scroll, among many other things
newcommand !! execute your new command followed by the previous command (!!)
newcommand !$ execute your new command followed by the last word of your previous command.
@jasonrhaas
jasonrhaas / config.json
Last active August 29, 2015 14:14
Streamparse deploy errors
{
"library": "",
"topology_specs": "topologies/",
"virtualenv_specs": "virtualenvs/",
"envs": {
"prod": {
"user": "",
"nimbus": "",
"workers": [],
"log": {
@jasonrhaas
jasonrhaas / gnip_snippet.py
Last active August 29, 2015 14:16
Make GNIP data serialized (\n) JSON
#!/usr/bin/env python
import json
import fileinput
def process_file(files):
record_count = 0
errors = 0
objs = []
for chunk in files:
@jasonrhaas
jasonrhaas / gnip_rules_api.py
Last active August 29, 2015 14:17
GNIP for allowing outside parties to manage the GNIP ruleset
GET (pull ruleset)
{
"stream": "prod-darpa", # GNIP stream to pull rules from. Choices are `prod-darpa` or `dev-darpa`
"rules": [
{"tag": "House", "value": "Highgarden"},
{"tag": "Tyrell", "value": "Mace"},
{"tag": "Tyrell", "value": "Margery"},
]
}
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',
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
@jasonrhaas
jasonrhaas / match_pattern.py
Created November 21, 2017 17:25
datadog interview question
# Python 3.6
import re
import logging
import unittest
from itertools import zip_longest
logging.basicConfig(level=logging.DEBUG)
@jasonrhaas
jasonrhaas / blueprints.py
Created January 30, 2019 19:27
Swagger blueprint
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)
@jasonrhaas
jasonrhaas / factory.py
Created January 30, 2019 19:31
Register Swagger Blueprint
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)
@jasonrhaas
jasonrhaas / app.py
Created January 30, 2019 22:23
Url model
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