Skip to content

Instantly share code, notes, and snippets.

@jbmartin
jbmartin / SortByLetterColumn.R
Last active August 29, 2015 14:02
Sort data frame by letter column. Handles multiple letter cases A, B, ..., AA, ..., AAA,.... as commonly found in Excel spreadsheets.
SortByLetterColumn <- function(df, column_to_sort_by) {
# Sorts a data frame by a column containing letters. E.g., A, B, C, ..., AA, BB,...
#
# Args:
# df: data frame to be sorted
# column_to_sort_by: (str) column to sort df by
#
# Returns:
# Data frame sorted by specified column.
sorted <- df[order(nchar(df[,column_to_sort_by]), df[,column_to_sort_by]), ]
@jbmartin
jbmartin / import_svg.js
Last active December 21, 2015 07:48
This gist provides an API that wraps and extends d3's svg/xml import methods. This API aims to avoid callback nesting by wrapping D3's async xml calls in promises (see jQuery 1.8+ docs). This approach allows users to ignore common async issues because promises are resolved internally. In sum, this is really just syntactic sugar for d3's [xhr obj…
// Requires d3 3.2+ and jQuery 1.8+
// CONTRACT
// void -> SVG
//
// PURPOSE
// This API both abstracts and extends d3's svg/xml import methods. The goal is to avoid
// callback nesting by wrapping d3's async xml calls in a promise, and
// then resolving them internally (see jQuery 1.8+ AJAX specs). All
// methods return `this` to allow for method cascading.