This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wordcount <- function(str) { | |
sapply(gregexpr("\\b\\W+\\b", str, perl=TRUE), function(x) sum(x>0) ) + 1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$outp = array_map('serialize', $outp); | |
$outp = array_unique($outp); | |
$outp = array_map('unserialize', $outp); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Warning: Ugly code; first project with paper.js. | |
var lblHeight = 0; | |
var marX = 30; | |
var marY = 10; | |
var marDesc = 3; | |
var labels = []; | |
var dataurl = '/data/states.json'; | |
//var dataurl = 'data/mtcars.json'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from lxml import etree | |
import requests | |
from datetime import date | |
def findId(xml): | |
for cat in xml.findall('category'): | |
if cat.text.startswith('HH_'): | |
return cat.text | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="windows-1252"?> | |
<xsl:stylesheet xmlns="http://www.w3.org/2000/svg" | |
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:exsl="http://exslt.org/common" | |
extension-element-prefixes="exsl" | |
version="1.0"> | |
<xsl:output method="xml" indent="yes" encoding="UTF-8" omit-xml-declaration="yes" /> | |
<xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyzàèìòùáéíóúýâêîôûãñõäëïöüÿåæœçðø'" /> | |
<xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÈÌÒÙÁÉÍÓÚÝÂÊÎÔÛÃÑÕÄËÏÖÜŸÅÆŒÇÐØ'" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Via http://stackoverflow.com/a/29579591/76367 | |
function svg_link(svgid) { | |
svg = document.getElementById(svgid); | |
return $('<a/>').attr('href', 'data:image/svg+xml;utf8,' + svg.outerHTML); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
import feedparser | |
import yaml | |
import pinboard | |
from time import mktime | |
import os | |
class RssToPinboard(object): | |
def __init__(self, settings): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//NOTE: Depends on paper.js. | |
if ('undefined' == typeof unset) function isset(x) { return !('undefined' == typeof x) } | |
if ( !isset(ifunset) ) function ifunset(x, def) { return ('undefined' == typeof x) ? def : x; } | |
//These are defaults; config variables can be set before loading this script. | |
var LOGGING = ifunset(LOGGING, false); | |
var CANVAS_SELECTOR = ifunset(CANVAS_SELECTOR, 'canvas.sparkler'); | |
var XMARGIN = ifunset(XMARGIN, 2); | |
var YMARGIN = ifunset(YMARGIN, 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lp <- function(givenName, givenQuantity, resources, needsChart) { | |
if ( !all.equal(names(resources), colnames(needsChart)[2:length(colnames(needsChart))]) ) { | |
warning("constraints and needsChart don't match.") | |
return(NA) | |
} else if ( dim(needsChart)[1] != 2 ) { | |
warning("Can only handle two products.") | |
return(NA) | |
} | |
sapply(givenQuantity, function(x) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"), ] |