Skip to content

Instantly share code, notes, and snippets.

View atbradley's full-sized avatar

Adam Bradley atbradley

View GitHub Profile
@atbradley
atbradley / import_links_from_delicious.php
Created June 17, 2011 21:07
Sample event to demonstrate importing outside data (Delicious links from RSS) into the Symphony CMS
@atbradley
atbradley / gist:2014184
Created March 11, 2012 00:15
Return a String representation of an XmlParser Node.
/*
Similar to XSLT's copy-of element. Useful if e.g. you have node containing XHTML
that you want to return as-is.
*/
Node.metaClass.asString = {
def text = []
delegate.children().each { child ->
@atbradley
atbradley / gist:2710414
Created May 16, 2012 13:41
EAP creation example using XmlSlurper
import groovy.xml.MarkupBuilder
//Read a tab-delimited file.
def tdl = new TLD('comiclist.txt', false, 'Box No.')
/*
//Turn it into a simple xml format, one 'comic' per spreadsheet row.
def wrt = new StringWriter()
def xml = new MarkupBuilder(wrt)
xml.comics {
@atbradley
atbradley / profile.R
Created July 18, 2012 19:30
Configure RStudio to generate fragments, not full webpages, from R Markdown
library(markdown)
options(rstudio.markdownToHTML =
function(i,o) {
markdownToHTML(i,o,fragment.only=TRUE)
}
)
@atbradley
atbradley / gist:3184120
Last active October 7, 2015 15:08
Post to Tumblr (as draft) when generating HTML from R Markdown (R Studio) No longer works--Tumblr's eliminated v1 of their API for everything but retrieving posts.
#in .Rprofile:
tumblr.user <- "myemail@example.com"
tumblr.pass <- "tumblrPassword"
library(markdown)
library(httr)
options(rstudio.markdownToHTML =
function(i,o) {
markdownToHTML(i,o,fragment.only=TRUE)
@atbradley
atbradley / gist:3370335
Created August 16, 2012 14:04
Grape-decorated import statements needed to enable Ant scp and sshexec tasks.
@GrabConfig(systemClassLoader=true)
@Grab(group='com.jcraft', module='jsch', version='0.1.48')
import com.jcraft.jsch.*;
@Grab(group='org.apache.ant', module='ant-jsch', version='1.8.4')
import org.apache.tools.ant.taskdefs.optional.ssh.Scp
@atbradley
atbradley / gistify.R
Last active October 8, 2015 18:28
Upload a file as a GitHub gist from R
#options('gh_token') should be a GitHub API token with the 'gist' scope.
#(See http://developer.github.com/v3/gists/)
library(httr)
library(rjson)
gistify <- function(filename, desc=F, public=F) {
data <- list(public = public)
if ( desc != F ) data$description = desc
@atbradley
atbradley / choroplethr_format_labels.R
Last active November 5, 2015 12:19
Generate a state map using choroplethr and add custom-formatted labels.
c = StateChoropleth$new(df_state_demographics)
c$title = "Population by State, Percent Black"
c$set_num_colors(7)
c$show_labels = F
df_state_labels = data.frame(long = state.center$x, lat =
state.center$y, name=tolower(state.name), label = state.abb)
df_state_labels = df_state_labels[!df_state_labels$name %in% c("alaska",
"hawaii"), ]
@atbradley
atbradley / 015-imageColor.R
Last active December 11, 2015 23:28
R functions for reading images and analyzing colors in images. Demo at http://www.nottamuntown.com/2013/02/reading-images-in-r.html .
library(reshape)
library(ggplot2)
library(ReadImages)
ccodes <- read.csv('http://sandbox.adamtbradley.com/colors/')
#From http://is-r.tumblr.com/post/36586614678
#Read an image from the web and shape it into a data.frame.
#codeColors() uses this--I don't call it directly.
@atbradley
atbradley / server.R
Created February 8, 2013 03:01
A shiny app using Social Security baby names data aggregated by Hadley Wickham (https://github.com/hadley/data-baby-names).
library(shiny)
library(ggplot2)
#This is at http://raw.github.com/hadley/data-baby-names/master/baby-names.csv
names <- read.csv('~/R/baby-names.csv')
# Define server logic required to plot various variables against mpg
shinyServer(function(input, output) {
# Return the formula text for printing as a caption
output$caption <- reactiveText(function() {