Skip to content

Instantly share code, notes, and snippets.

@khalido
khalido / .bash_profile
Last active September 14, 2017 04:13
.bash_profile for mac #config
test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"
# Tell ls to be colourful
export CLICOLOR=1
export LSCOLORS=Exfxcxdxbxegedabagacad
# Tell grep to highlight matches
export GREP_OPTIONS='--color=auto'
@khalido
khalido / ipython_config.py
Last active September 14, 2017 04:13
ipython config file #config
# Configuration file for ipython.
# saved in ~/ipython/profile_default
# enable powerline in ipython
from powerline.bindings.ipython.since_5 import PowerlinePrompts
c = get_config()
c.TerminalInteractiveShell.simple_prompt = False
c.TerminalInteractiveShell.prompts_class = PowerlinePrompts
@khalido
khalido / download.py
Last active March 13, 2023 05:20
[download multiple files using python] and save to data dir #file
exprs__url = "https://github.com/cs109/2014_data/raw/master/exprs_GSE5859.csv"
sampleinfo_url = "https://github.com/cs109/2014_data/raw/master/sampleinfo_GSE5859.csv"
urls = [exprs__url, sampleinfo_url]
filenames = ["exprs_GSE5859.csv", "sampleinfo_GSE5859.csv"]
for url, filename in zip(urls, filenames):
r = requests.get(url, stream=True)
with open("data/"+filename, 'wb') as fd:
for chunk in r.iter_content(chunk_size=256):
@khalido
khalido / config.ini
Last active March 5, 2018 00:00
[configparser] saving passwords etc in a ini file and pulling it into a script later. python code and sample config.ini file. See https://docs.python.org/3/library/configparser.html
# see https://docs.python.org/3/library/configparser.html for deets
[twitter]
c_key = secret_secret_something
c_secret = secret_secret_something
a_token = secret_secret_something
a_secret = secret_secret_something
  • introductory book designed from a computation first, math second point of view.
  • the book uses PyMC3, a python package for all things Bayesian
  • work through the book by cloning its repo and working through the juypyter notebooks.
  • ask questions on stack exchanges stat site Cross Validated.
  • we all update our beliefs as more data rolls in - this is the gist of bayesian inference
# autoreload linked files
%load_ext autoreload
%autoreload 2
# the viz stuff
%matplotlib inline
import matplotlib.pyplot as plt # mpl is the base of all python plotting angst
import seaborn as sns # put some trainer wheels & lipstick on mpl
from IPython import display # to display pics and other stuff which markdown doesn't
@khalido
khalido / upload_s3.py
Created October 15, 2017 22:26
[upload image to a s3 bucket]
import boto3 # Amazon's aws library for python 3
import numpy as np
import matplotlib.pyplot as plt
# create a connection to s3
s3 = boto3.resource('s3',
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key)
# you need a bucket, make one and put its name here
@khalido
khalido / mac setup.md
Last active October 17, 2017 12:44
[setup mac for dev] #mac

the basics

Open a terminal

Install Command Line Tools for Xcode - needed for homebrew to run

xcode-select --install

Install Homebrew

@khalido
khalido / expand dictionaries.py
Last active December 6, 2019 05:07
[pandas tips] common things to do in pandas which i always have to look up
# take a single col from your df and drop the nulls
s = df['some_col'].dropna()
# this should return an expanded df from the col of dicts:
expanded_df = s.apply(lambda row: pandas.Series(row))
# then merge the two dataframes - pandas will put NaNs for the missing values in the expanded df
pd.concat([data1, expanded_df], axis=1)
@khalido
khalido / keybase.md
Created February 22, 2018 01:00
establishing keybase link

Keybase proof

I hereby claim:

  • I am khalido on github.
  • I am khalido (https://keybase.io/khalido) on keybase.
  • I have a public key whose fingerprint is AFB8 329B D65D AD66 8BD7 AD76 D822 F0BE B9BF 0ED2

To claim this, I am signing this object: