Instantly share code, notes, and snippets.

View unnest.py
# https://benjcunningham.org/blog/unnest-list-columns-in-pandas.html
import pandas as pd
def unnest(df, col):
unnested = (df.apply(lambda x: pd.Series(x[col]), axis=1)
.stack()
.reset_index(level=1, drop=True))
unnested.name = col
return df.drop(col, axis=1).join(unnested)
View strava_bitbar.go
package main
/*
# <bitbar.title>Strava</bitbar.title>
# <bitbar.version>v0.0.1</bitbar.version>
# <bitbar.author>Daniel Cook</bitbar.author>
# <bitbar.author.github>danielecook</bitbar.author.github>
# <bitbar.desc>Bitbar Strava tracker</bitbar.desc>
*/
View log.sql
SET GLOBAL general_log = 'ON';
SET GLOBAL general_log_file = "/Users/dancook/Documents/snippet-q/snippet-q/mysql.log";
SET GLOBAL log_output = 'FILE';
View stocks.py
import html
import requests
from bs4 import BeautifulSoup
def boolify(s):
if s == 'True':
return True
if s == 'False':
return False
raise ValueError("huh?")
View packages
✔ Alignment | ✔ Anaconda
✔ ayu | ✔ Color Highlighter
✔ Gist | ✔ Git
✔ GitGutter | ✔ Jinja2
✔ LESS | ✔ MarkdownEditing
✔ Package Control | ✔ PackagesUI
✔ Pretty JSON | ✔ Python 3
✔ Python Improved | ✔ rainbow_csv
✔ Se
View gist:5add33abe559a89c4a53b6b19013a1de
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
sudo /usr/libexec/locate.updatedb
View pyenv.sublime-build
{
"cmd": ["/usr/local/var/pyenv/shims/python", "-u", "$file"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
View summarize_vcf.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Author: Daniel E. Cook
This script summarizes variation for samples.
"""
import sys
View rarefaction.R
library(tidyverse)
# bcftools query -f "[%GT\t]\n" WI.20170531.impute.vcf.gz | awk '{ gsub(":GT", "", $0); gsub("(# )?\[[0-9]+\]","",$0); print $0 }' | sed 's/0|0/0/g' | sed 's/1|1/1/g' | sed 's/0|1/NA/g' | sed 's/1|0/NA/g' | head -n 1000000 | gzip > ~/Desktop/impute_gts.test.tsv.gz
df_use <- tseries::read.matrix(gzfile("~/Desktop/impute_gts.tsv.gz"))
storage.mode(df_use) <- "logical"
# cols