This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
define('TEMPLATE_DIR', 'path/to/my/templates'); | |
/** | |
* Processes a PHP template. | |
* | |
* Looks in OCRA_TEMPLATE_DIR for {$template}.tpl, and includes it, | |
* probably generating an HTML page. | |
* | |
* @author Adam Bradley <[email protected]> | |
* |
This file contains hidden or 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
#States is a data.frame with at least the following columns: | |
# $color: Any string identifiable as a color by CSS (It's included in a `style` attribute. | |
# $letter: The letter corresponding to this state in the Stately font. | |
# | |
# states$id and states$class will be used as the `id` and `class` | |
# attributes of the list elements for the states. All other columns | |
# will be inserted as data-<column-name> attributes (in case you want | |
# to use them with JavaScript). | |
statelify <- function(states) { |
This file contains hidden or 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
<?php | |
$defaults=array('a'=>1, 'b'=>2, 'c'=>3); | |
$input=array('a'=> 'boo', 'c'=>4, 'd'=>5, 'e'=>6); | |
$output = array_intersect_key($input+$defaults, $defaults); | |
//Might want to provide a warning if $unused isn't empty. | |
$unused = array_diff_key($input, $defaults); |
This file contains hidden or 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: Messy code. | |
#(It's been repurposed a few times.) | |
library(plyr) | |
library(ggplot2) | |
plotData <- function(date) { | |
und <- c(unemp[unemp$Date==date, -1]) | |
und <- und[order(names(und))] | |
und <- t(as.data.frame(und)) | |