Skip to content

Instantly share code, notes, and snippets.

@docsteveharris
docsteveharris / Solarized (Dark).tmTheme
Created August 16, 2012 21:55 — forked from eleclerc/Solarized (Dark).tmTheme
Solarized theme (dark & light) with markdown support for Sublime Text 2 editor
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Solarized (dark)</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
@docsteveharris
docsteveharris / fix_slope_graph_labels.do
Created April 2, 2013 15:42
overlapping labels in slope graphs in stata
// try and handle labels over-writing by altering the label position
// pos_gap is a variable that controls how close two labels must be before the position is changed
// it can only handle a series of 3 overlapping labels
// the first is assigned up a clock position
// the second is assigned down a clock positon
local pos_gap 0.1
bys this_icode (percent): replace pos = pos + 1 ///
if abs(percent[_n] - percent[_n+1]) < `pos_gap' ///
& pos[_n] == pos[_n+1]
bys this_icode (percent): replace pos = pos - 1 ///
@docsteveharris
docsteveharris / main.js
Created June 7, 2014 21:16
FoldingText keybindings to focus in or out by a level
// Log
// ===
// 140607 - cloned from demo keybindings.ftplugin
define(function(require, exports, module) {
'use strict';
var Extensions = require('ft/core/extensions').Extensions;
Extensions.addInit(function (editor) {
#! /usr/bin/python
# author: Steve Harris
# Convert short nvAlt image links to full path for previewing in Marked
# Todo
# ====
# - move the pathto line to a variable
# - post this script as a gist
@docsteveharris
docsteveharris / Asset.js
Created July 14, 2014 16:09
Load data in d3
var dataset; // declare a global var to hold data
d3.csv("data/univar.csv", function(error, data) {
if(error) {
console.log(error);
}
else {
console.log(data);
}
@docsteveharris
docsteveharris / Asset.py
Created July 14, 2014 16:11
24 hour clock time regex with option separator
time24_regex = re.compile( r"""\b ([01]?\d|2(?=[0-3])\d) [:|.]? ([0-5]?\d) \b""", re.VERBOSE)
@docsteveharris
docsteveharris / qqplot.R
Last active August 29, 2015 14:10
qqplot in R
# Test data: 1000 patients with two different age distributions
tdt <- data.table(age.old=rnorm(1000, mean=65, sd=15), age.young=rnorm(1000,mean=55,sd=10))
# Function to compare two distributions using qplot
qqplot <- function(x,y, data=wdt, n=100) {
lab.x = x
lab.y = y
x <- with(data, get(x))
x <- sapply(seq(0,1,1/n), function(q) quantile(x, q, na.rm=TRUE))
y <- with(data, get(y))
@docsteveharris
docsteveharris / charlson.score.R
Created November 27, 2014 12:13
Create Charlson Score
score.charlson <- function(data) {
# data is a datatable containing the columns you need
# identify the columns with pmh in the name
require(data.table)
charlson.values <- data[,.(pmhmi, pmhhf, pmhpvd, pmhcvd, pmhdem, pmhcopd, pmhcopd, pmhctd, pmhud, pmhmld, pmhdm, pmhhemi, pmhckd, pmhdmend, pmhtumour, pmhleuk, pmhlymph, pmhsld, pmhmets, pmhaids)]
charlson.matrix <- as.matrix(charlson.values)
# Now I need to convert the NA's to 0 and >0 to 1 in matrix
charlson.matrix <- apply(charlson.matrix, 2, function(x) ifelse(is.na(x), 0, ifelse(x>=1,1, 0)))
# Now create a vector of scores
# Note that the order of the columns selected above *must* match the order of the scores here
@docsteveharris
docsteveharris / derive_sofa.R
Created February 11, 2015 12:54
Derive SOFA score
gen.sofa.c <- function(bpsys, bpdia, rxcvs_drug=NULL, rxcvs_dose=NULL) {
rx1 <- c("Adrenaline", "Noradrenaline")
rx2 <- c("Dopamine")
rx3 <- c("Vasopressin")
rx <- c(rx1, rx2, rx3, "Other")
# Print these descriptions so you know what you have passed to the function
bpmap <- round(bpdia + (bpsys - bpdia) / 3)
/*
## Create a rug plot
_____________________
CreatedBy: Steve Harris
CreatedAt: 111291
ModifiedAt: 120701
Log