Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Parmer chriddyp

View GitHub Profile
View QA Offline Mode.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View plotly.js inside ipython notebook.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@chriddyp
chriddyp / my sublime text keyboard mapping
Last active Mar 13, 2017
map the arrow keys to JKLI with `cntrl` and jump code blocks with `cntrl`-`option`-K, `cntrl`-`option`-I
View my sublime text keyboard mapping
[
{ "keys": ["ctrl+j"], "command": "move", "args": {"by": "words", "forward": false} },
{ "keys": ["ctrl+l"], "command": "move", "args": {"by": "words", "forward": true} },
{ "keys": ["ctrl+k"], "command": "move", "args": {"by": "lines", "forward": true} },
{ "keys": ["ctrl+i"], "command": "move", "args": {"by": "lines", "forward": false} },
{ "keys": ["ctrl+alt+j"], "command": "move", "args": {"by": "words", "forward": false} },
{ "keys": ["ctrl+alt+l"], "command": "move", "args": {"by": "words", "forward": true} },
{ "keys": ["ctrl+alt+k"], "command": "move", "args": {"by": "stops", "empty_line": true, "forward": true} },
@chriddyp
chriddyp / DictFactory.py
Created Sep 1, 2015
Subclass dictionaries with validation. A fun pattern for wrapping JSON APIs!
View DictFactory.py
def DictFactory(name, argnames, default_keys={}):
def __init__(self, **kwargs):
for key, value in kwargs.items():
if key not in argnames:
raise TypeError("Argument %s not valid for %s"
% (key, self.__class__.__name__))
kwargs.update(default_keys)
dict.__init__(self, **kwargs)
newclass = type(name, (dict,),{"__init__": __init__})
View Python Themes.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View example-data.csv
X Data 1 Y Data 1 X Data 2 Y Data 2
-2.06E-02 -1.53E-02 -2.35E-02 -1.73E-02
-1.40E-02 -1.01E-02 -1.65E-02 -1.18E-02
-1.09E-02 -7.71E-03 -1.31E-02 -9.26E-03
-1.42E-02 -1.05E-02 -1.65E-02 -1.20E-02
-1.62E-02 -1.23E-02 -1.89E-02 -1.42E-02
-1.31E-02 -1.01E-02 -1.56E-02 -1.18E-02
-1.29E-02 -8.75E-03 -1.51E-02 -1.03E-02
-1.64E-02 -1.19E-02 -1.92E-02 -1.39E-02
-3.54E-03 -5.62E-03 -9.08E-03 -9.35E-03
View hansrosling_2007.csv
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Country Year Population Continent Life Exp GDP per Cap
Afghanistan 2007 31889923 Asia 43.828 974.5803384
Albania 2007 3600523 Europe 76.423 5937.029526
Algeria 2007 33333216 Africa 72.301 6223.367465
Angola 2007 12420476 Africa 42.731 4797.231267
Argentina 2007 40301927 Americas 75.32 12779.37964
Australia 2007 20434176 Oceania 81.235 34435.36744
Austria 2007 8199783 Europe 79.829 36126.4927
Bahrain 2007 708573 Asia 75.635 29796.04834
Bangladesh 2007 150448339 Asia 64.062 1391.253792
View gist:1a34b39e85afec58ab54
{"nbformat_minor": 0, "cells": [{"execution_count": 8, "cell_type": "code", "source": "import plotly.plotly as py\nfrom plotly.graph_objs import *\n\nimport datetime\n\ndef to_unix_time(dt):\n epoch = datetime.datetime.utcfromtimestamp(0)\n return (dt - epoch).total_seconds() * 1000\n\nx = [\n datetime.datetime(year=2013, month=10, day=04),\n datetime.datetime(year=2013, month=11, day=05),\n datetime.datetime(year=2013, month=12, day=06)\n]\n\ndata = Data([\n Scatter(\n x=x,\n y=[1, 3, 6]\n )\n])\n\nlayout = Layout(\n xaxis = XAxis(\n range = [\n to_unix_time(datetime.datetime(2013, 10, 17)),\n to_unix_time(datetime.datetime(2013, 11, 20))\n ]\n )\n)\n\n\nfig = Figure(data = data, layout = layout)\n\nplot_url = py.plot(fig, filename='python-datetime-custom-ranges')", "outputs": [], "metadata": {"collapsed": false, "trusted": true}}, {"execution_count": 9, "cell_type": "code", "source": "fig", "outputs": [{"execution_count": 9, "outp
View NYC_311_100_Complaints.csv
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 52 columns, instead of 19. in line 1.
Unique Key,Created Date,Closed Date,Agency,Agency Name,Complaint Type,Descriptor,Location Type,Incident Zip,Incident Address,Street Name,Cross Street 1,Cross Street 2,Intersection Street 1,Intersection Street 2,Address Type,City,Landmark,Facility Type,Status,Due Date,Resolution Action Updated Date,Community Board,Borough,X Coordinate (State Plane),Y Coordinate (State Plane),Park Facility Name,Park Borough,School Name,School Number,School Region,School Code,School Phone Number,School Address,School City,School State,School Zip,School Not Found,School or Citywide Complaint,Vehicle Type,Taxi Company Borough,Taxi Pick Up Location,Bridge Highway Name,Bridge Highway Direction,Road Ramp,Bridge Highway Segment,Garage Lot Name,Ferry Direction,Ferry Terminal Name,Latitude,Longitude,Location
29300358,11/16/2014 11:46:00 PM,11/16/2014 11:46:00 PM,DSNY,BCC - Queens East,Derelict Vehicles,14 Derelict Vehicles,Street,11432,80-25 PARSONS BOULEVARD,PARSONS BOULEVARD,UNION TURNPIKE,GOETHALS AVENUE,,,ADDRESS,Jamaica,,DSNY Garag
View gist:54d8a69ff6f01e60381a
{"nbformat_minor": 0, "cells": [{"execution_count": 1, "cell_type": "code", "source": "import copy\nimport plotly.plotly as py\nimport Quandl\nimport datetime\nimport numpy as np\nfrom plotly.graph_objs import *\npy.sign_in('chriddyp', 'o1do5o15p8')", "outputs": [], "metadata": {"collapsed": true, "trusted": true}}, {"execution_count": 31, "cell_type": "code", "source": "basefig = py.get_figure('jackp', 4771)\nbasefig['data'].remove(basefig['data'][-1])\nbasefig['data'].remove(basefig['data'][5])\nbasefig['data'].remove(basefig['data'][5])\nbasefig['data'][1]['x'][0] = 0\n\nadjusted = basefig['data'].pop(5) # move adjusted_close to the end, to be drawn on top\nbasefig['data'].append(adjusted)\n\nbasefig['layout']['margin']['l'] = 2\n\nbasefig['layout']['annotations'] = Annotations([\n # 0\n Annotation(\n x=1,\n y=1.4071023494463948,\n xref=u'x',\n yref=u'y',\n text=u'VIX Index',\n showarrow=False\n ),\n # 1\n Annotation(\n x=1.5066964285714284,\n