Skip to content

Instantly share code, notes, and snippets.

View drjwbaker's full-sized avatar

James Baker drjwbaker

View GitHub Profile
# Takes an ordered vector of numeric values and returns a small bar chart made
# out of Unicode block elements. Works well inside dplyr mutate() or summarise()
# calls on grouped data frames.
sparkbar <- function(values) {
span <- max(values) - min(values)
if(span > 0 & !is.na(span)) {
steps <- round(values / (span / 7))
blocks <- c('', '', '', '', '', '', '', '')
paste(sapply(steps - (min(steps) - 1), function(i) blocks[i]), collapse = '')
@mhawksey
mhawksey / gist:7770536
Last active May 3, 2016 06:28
Google Apps Script code used in 'Keep your Twitter Archive fresh on Google Drive' http://mashe.hawksey.info/2013/01/sync-twitter-archive-with-google-drive/. To fix getContentAsString error open Tools > Script editor in your copy and replace the code with version below and test run the function updateArchive()
/*
Copyright 2013 Martin Hawksey
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
import csv
import json
INPUTFILE = "History_Journal_Articles_KW.csv"
OUTPUTFILE = INPUTFILE[:-4] + "_numbered.csv"
in_file = open(INPUTFILE, "r") # "r" == Open file for reading
out_file = open(OUTPUTFILE, "w") # "w" for writing