Skip to content

Instantly share code, notes, and snippets.

View ksindi's full-sized avatar
🚀
Shipping

Kamil Sindi ksindi

🚀
Shipping
View GitHub Profile
@ksindi
ksindi / iquery.py
Created February 21, 2016 19:20
Yields rows in chunks.
def chunk_query(sql, cursor, chunksize=10):
"""Yields rows in chunks."""
cursor.execute(sql)
while True:
nextrows = cursor.fetchmany(chunksize)
if not nextrows:
break
yield nextrows
def iquery(sql, cursor, chunksize=10):
@ksindi
ksindi / s3.py
Created March 30, 2016 12:19
Get data from boto3
import json
import boto3
s3 = boto3.resource('s3')
obj = s3.Object(bucket, key)
data = obj.get()['Body'].read()
d = json.loads(data)
@ksindi
ksindi / graceful_int_handler.py
Created March 30, 2016 18:11 — forked from nonZero/graceful_int_handler.py
GracefulInterruptHandler
import signal
class GracefulInterruptHandler(object):
def __init__(self, sig=signal.SIGINT):
self.sig = sig
def __enter__(self):
self.interrupted = False
@ksindi
ksindi / spark_notes.md
Created April 25, 2016 21:46 — forked from robcowie/spark_notes.md
Apache Spark Notes

Install Apache Spark (OSX)

$ brew install apache-spark

Run the Spark python shell

A python shell with a preconfigured SparkContext (available as sc). It is

@ksindi
ksindi / spark-csv.ipynb
Created April 26, 2016 02:49 — forked from parente/spark-csv.ipynb
Use spark-csv from Jupyter Notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ksindi
ksindi / bokeh_utils.py
Created May 28, 2016 17:56 — forked from robintw/bokeh_utils.py
Bokeh Utils
from bokeh.plotting import figure, ColumnDataSource
from bokeh.models import HoverTool
def scatter_with_hover(df, x, y,
fig=None, cols=None, name=None, marker='x',
fig_width=500, fig_height=500, **kwargs):
"""
Plots an interactive scatter plot of `x` vs `y` using bokeh, with automatic
tooltips showing columns from `df`.
@ksindi
ksindi / update.py
Created June 12, 2016 17:33
Recursively merge or update dict-like objects
import collections
def update(d, other):
"""Recursively merge or update dict-like objects.
>>> from pprint import pprint
>>> pprint(update({'k1': {'k2': 2}}, {'k1': {'k2': {'k3': 3}}, 'k4': 4}))
{'k1': {'k2': {'k3': 3}}, 'k4': 4}
>>> pprint(update({'k1': {'k2': 2}}, {'k1': {'k3': 3}}))
{'k1': {'k2': 2, 'k3': 3}}
>>> pprint(update({'k1': {'k2': 2}}, dict()))
import pandas as pd
from io import StringIO
datastring = StringIO("""\
ticker avg_spread max_spread timestamp
a 0.22 1.84 2016-06-03 03:00:00
aa 0.01 0.10 2016-06-03 02:00:00
aaap 2.07 2.17 2016-06-03 01:00:00
aal 0.15 0.5 2016-06-03 04:00:00
""")
# Working example for my blog post at:
# https://danijar.github.io/structuring-your-tensorflow-models
import functools
import tensorflow as tf
import sets
def lazy_property(function):
attribute = '_' + function.__name__
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os.path
import re
import sys
import tarfile
import numpy as np